Hi all, I am toying around with sqldelight in a KM...
# squarelibraries
u
Hi all, I am toying around with sqldelight in a KMP project to evaluate for future use. I am currently trying to understand how database creation is meant to work and can not find a lot about it in the docs. For Jvm with the app.cash.sqldelight:sqlite-driver driver, I had SQLDelight complain, that the database file does not exist at first run. So I added code to check if the db file exists and call Schema.create(driver). On native, I realized, that I can not give a path to the driver, but just a name. Then I had to reverse engineer the full path to check if the DB already exists … This is not what I expect from a square library, so I must have missed something here?
h
u
cool. will take a look
hmm. so only the JvmDriver needs Schema.create() to be called? And for that driver it is ok to call Schema.create every time, even if the db already exists?
Copy code
return JdbcSqliteDriver(url = "jdbc:sqlite:${databasePath.absolutePath}").also { driver ->
            Database.Schema.create(driver = driver)
        }
this fails at second start
Copy code
[SQLITE_ERROR] SQL error or missing database (table Xxxxx already exists)
which makes total sense. Why would i call create on an already existing DB?
@Hristijan Thanks for your support and your blog post. I suggest to fix your post to show how to conditionally call Database.Schema.create(driver = driver) only if the db file does not yet exist. With so little information around, it is really a pity if the information that is available is misleading.
So research suggests, that all sqlite drivers, except the one for JVM (i.e. Android and native) automatically create the database for you if required. Shouldn’t that be unified to give a better multi platform experience? And why can’t i give a full path to the native driver? If there is no platform specific reason I would also consider that unlucky divergence of platforms in a multi platform framework.