New to backend dev, what's the TLDR for adding a database to my jvm backend hosted on railway?
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?
56 Replies
Project ID:
N/A
N/A
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.
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 databaseCool. 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?
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...
Getting Started - SQLDelight
SQLDelight - Generates typesafe Kotlin APIs from SQL
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.
1. create db/postgres on railway
2. then "connect" to it via private address railway gives me.
bingo
as for the how to connect, I wouldn't know, but spring's docs would! π
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
dashboard looks right?
![No description](https://cdn.answeroverflow.com/1219046712635818035/CleanShot_2024-03-17_at_18.15.462x.png)
yep!
would i be trying to connect to postgres.railway.internal or the postgresql://... ?
![No description](https://cdn.answeroverflow.com/1219098701881020436/CleanShot_2024-03-17_at_21.42.082x.png)
![No description](https://cdn.answeroverflow.com/1219098702149451846/CleanShot_2024-03-17_at_21.42.182x.png)
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