R
Railwayβ€’6mo ago
coltonidle

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
Percy
Percyβ€’6mo ago
Project ID: N/A
coltonidle
coltonidleβ€’6mo ago
N/A
Brody
Brodyβ€’6mo ago
are you good with using postgres?
coltonidle
coltonidleβ€’6mo ago
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.
Brody
Brodyβ€’6mo 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
coltonidle
coltonidleβ€’6mo ago
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?
Brody
Brodyβ€’6mo ago
you'd get all the connection details from the database's service variables, ideally you would use the private url you are given
coltonidle
coltonidleβ€’6mo ago
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
Brody
Brodyβ€’6mo ago
yeah postgres is what I'd recommend, all around great database and uses the lowest base amount of memory when compared to MySQL
coltonidle
coltonidleβ€’6mo ago
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.
Brody
Brodyβ€’6mo ago
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
coltonidle
coltonidleβ€’6mo ago
dashboard looks right?
No description
Brody
Brodyβ€’6mo ago
yep!
coltonidle
coltonidleβ€’6mo ago
would i be trying to connect to postgres.railway.internal or the postgresql://... ?
No description
No description
Brody
Brodyβ€’6mo 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
Want results from more Discord servers?
Add your server