2 years ago
New to backend dev (android/kotlin dev originally) and I'm using ktor to handle some basic incoming routes at the moment. Easy stuff. I want to now be able to take an incoming route POST request and insert it into a basic sql/sqlite database (not really married to what db. ive used sqlite on android because it comes out of the box). What's the tldr for doing that on railway?
83 Replies
2 years ago
are you good with using postgres?
never used postgres. but im open to using it. going to be reallllly basic stuff going in there for right now. 😊
my understanding of postgres is that its just another variant of sql. so anything in that realm of things should be fine.
2 years ago
click the + New button at the top right and deploy your postgres database, then reference spring's docs on how you would get spring to connect to such a database
Cool. So (sorry for the noob question). But essentially is connecting to a db from my server like, just giving it an ip of the db?
2 years ago
you'd get all the connection details from the database's service variables, ideally you would use the private url you are given
lemme check it out. a nice sql library in kotlin land is SQLDelight. type safe, generated kotlin from sql queries.
https://cashapp.github.io/sqldelight/2.0.0/jvm_postgresql/
and i see it supports postgres. so that'd be legit…
2 years ago
yeah postgres is what I'd recommend, all around great database and uses the lowest base amount of memory when compared to MySQL
cool. okay. so its basically as "complicated" as I thought it'd be.
create db/postgres on railway
then "connect" to it via private address railway gives me.
2 years ago
bingo
2 years ago
as for the how to connect, I wouldn't know, but spring's docs would! 🙂
2 years ago
maybe there's a template that comes with a postgres database and you could reference it's source code to see how they have setup the connection
2 years ago
yep!
would i be trying to connect to postgres.railway.internal or the postgresql://… ?


2 years ago
when your app runs on railway you'd want to use the private url, when it's not running on railway you want to use the public url
2 years ago
how so?
2 years ago
well one is just the hostname and one is a url
but just wanted to make sure postgres.railway.internal isn't some magic url
2 years ago
it is kinda magic
2 years ago
it can only be used by the service running on railway
2 years ago
try with the public url first
java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql://postgres:LONGCODE@viaduct.proxy.rlwy.net:52289/railway
2 years ago
is the the correct format for the URL?
2 years ago
time for a trip to the applicable docs
2 years ago
haha not railways docs this time
but still get
java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql://postgres:LONGCODE@viaduct.proxy.rlwy.net:52289/railway
2 years ago
do you have the necessary driver installed?
2 years ago
stop sending me trains lmao I don't even know java, but thank you
2 years ago
let me know if you make any progress
url looks right though: https://jdbc.postgresql.org/documentation/use/
2 years ago
there is a few spring templates for railway you could possibly check out? I wouldn't know what to look for in them though
idk wtf hikari is, but apparently its like the goto connection manager for dbs in java land?
2 years ago
I have no clue what that is either
Ktor: Hello, Java 17.0.9! and res HockeyPlayer(player_number=10, full_name=Corey Perry)2 years ago
awesome glad you could solve!
crashes on mobile. not that bad. user can reopen app. on server though. one wrong move. and the entire server is down waiting for me to restart it. lol
2 years ago
railway auto restarts when your service crashes 🙂
2 years ago
well up to 10 times
very cool that sqldelight just works though. i write sql code. and it generates type safe kotlin code for me. not bad 👌

no way. auto restarts? sick. i wonder if theres a way to get an alert when things go down, can't restart, etc. I assume that's going into the world of observability.
2 years ago
railway doesn't sent an alert for the auto restart, but they will send you an alert when you have exhausted the auto restarts and your container does the final crash
2 years ago
notifications for crashed deploys should be enabled by default, but check anyway
this is so cool though! I might not have to use firebase anymore as my first option for some of my little android/ios side projects.
2 years ago
hell yeah get firebase out of here, railway is for everything!
ill still give firebase the leg up when it comes to setting up auth though. super easy to get like 2-3 "login with XYZ" setup. really nice.
i know a lot of people have been going with supabase as well. might have to see what thats all about.
but in this case. i actually have an app im trying to ship thats just like dead simple, relaying api calls to a 3rd party. but i need to store those "requests" somewhere. so a db was needed.
2 years ago
theres other auth providers that only specialize in auth, i think there may even be some you can self host on railway?
ive worked with auth0 many many many years ago. such a poor experience. but yeah. might be time to learn something new 🙂
2 years ago
I've heard good things about clerk, don't know if they have a java sdk though


