Is trying to use `sqldelight` in ktor server a bad...
# squarelibraries
u
Is trying to use
sqldelight
in ktor server a bad idea? I'm already familiar with it but I'm unsure about the schema creation, ddl etc, since sqldelight seems to be driven by the DDL - which from what I gather is not used in backend apps? (I'm a android developer, backend noob)
j
It works fine. You just run the create/migrate APIs yourself
You can also use tools like flyway
There's a sql delight setting to derive the schema solely from the migration files for that case. Saves you from having to maintain it separately
u
yes I mean to use flyway - does that mean I should not call
Schema.create
and that's it?
j
If you use flyway then your code doesn't deal with the schema or migrations at all
u
so
CREATE TABLE bla bla
part in .sq files is optional? if I use the `*`deriveSchemaFromMigrations` ?`* https://sqldelight.github.io/sqldelight/2.1.0-SNAPSHOT/js_sqlite/migrations/
j
Yes. You'll write no create statements only queries
And migrations
u
And migrations
you mean in flyway, right?
neat; btw what about the blocking nonblocking drivers? is simply
withContext(IO)
wraping a blocking sqldelight call enough?
j
Unless you're using postgres with r2jdbc, all drivers are blocking and should be run from IO threads
u
yes and I'm now wondering what would wrapping in
withContext(IO)
mean, it would still tie up a thread that does the db work inside the lambda right? so not too too much of savings?
...I'm wondering, how can not having DDL available to sqldelight work? There's no source of truth for the queries to be type safe (how does it know what tables and columns there are?), am I missing something?
j
The schema is derived from the migrations
u
by migrations you mean sqldelight
.sqm
files? how does that play nice with flyway? doesn't flyway typically manage migrations? > `deriveSchemaFromMigrations` > Type:
Property<Boolean>
> If set to true, the schema for your database will be derived from your
.sqm
files as if each migration had been applied. If false, your schema is defined in
.sq
files. or do you mean this? and I can somehow let sqldelight take in flyway migration files?
j
Both tools will use the same files, yes
u
that would be neat - but doesnt flyway have it's own opionated way they need to be called & sqldelight does too?
V1__foo.sql
vs
1.sqm
j
Sql delight doesn't care that much
The former will work fine
u
how does it then infer order? I always thougt it was the filename being an integer
okay it does work as you said -- great! that should be documented somewhere though, I never thought it could be anything other than a single integer
oh no, sqldelight wont take in
.sql
for migrations -.-
Because we support custom types, the .sql files are generated