Hello! im an android dev that has only ever used s...
# squarelibraries
c
Hello! im an android dev that has only ever used sqldelight with sqlite. but im trying my hand at ktor to write an api for a side project app. So I want to use sqldelight but with postgres. I have it working (which is cool) but im not really sure of my impl. Can I get a sanity check on the db connection code? I'm mostly just confused on whether or not I should be using this Hikari thing (never heard of it before)
Copy code
val ds = HikariDataSource()
ds.driverClassName = "org.postgresql.Driver"
ds.jdbcUrl = "jdbc:<postgresql://blah:52289/railway>"
ds.username = "postgres"
ds.password = "password"

var driver: SqlDriver? = null

driver = ds.asJdbcDriver()

try {
    MyDb.Schema.create(driver)
} catch (e: Exception) {
    //Already created
}

 database = MyDb(driver)
j
The call to create is not right
You need to store the database version and conditionally create or migrate the schema
Or rely on an external schema management system
c
oh cool. I'll look that up then. but the hikari stuff seems good? thats what i was initially worried about, but good call on the create/migrate. I think Android typically handles that so I don't think ive really thought about that. wonder if theres a standard here to store the db version/migrate
l
@Colton Idle on the server I always recommend Flyway. We use Hikari for managing database connections but that isn't going to manage migrations. I don't know much about sqldelight in android but on the server for us it looks like: • Name all the sqm migration files according to the standard Flyway expected scheme
V1__create_some_table.sqm
(note the double underscore) • configure sqldelight to produce valid sql migrations • configure flyway to consume/run them we use the gradle plugin to run the migrations in local development, and containerize them to run as a job for running in deployed cloud environments.
I'm curious, did you find a solution along those lines or something else?
c
i haven't really looked into it too much after this post. its like #8 on my todo list. so hopefully ill get to it soon!
😂 1
🍻 1