cashapp / sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
https://cashapp.github.io/sqldelight/
Apache License 2.0
6.13k stars 513 forks source link

SQLiter driver's in memory mode not compatible with sqldelight #3241

Open kpgalligan opened 2 years ago

kpgalligan commented 2 years ago

SQLDelight Version

1.5.3+

Application Operating System

iOS, Native, etc

Describe the Bug

The in-memory mode of sqlite without a shared cache name allows only one connection. The sqldelight driver uses multiple connections. In earlier versions of sqliter, all in-memory connections were named, but that changed. You can skip the name on config, but that may cause issues with sqldelight.

Should investigate if that's actually an issue. If so, either modify the sqldelight driver to live with one connection, fail trying to use sqldelight in that mode with sqliter, or in some other way signal the issue. Mentioning it in docs is probably not enough.

For reference: https://github.com/touchlab/SQLiter/issues/7

Stacktrace

No response

05nelsonm commented 11 months ago

Would like to also note here, the use of temporary databases. If passing an empty string to SQLite for the file path, it will create a "temporary" database. SQLite will act as an in-memory db, but dumps to a temp file when needed (which gets deleted upon connection closure).

Using :memory: means no dumps, ever.

So, a single static connection would need to be maintained in that instance as well. You can achieve a "temporary" database configuration with SQLiter by passing empty strings for DatabaseConfiguration.name, and DatabaseConfiguration.Extended.basePath, and then passing false for DatabaseConfiguration.inMemory.

`

05nelsonm commented 11 months ago

Trying to resolve this, but running into issues regarding SQLite creating files for the named in-memory database (i.e. file:memdb1?mode=memory&cache=shared).

pic ![image](https://github.com/cashapp/sqldelight/assets/44778092/f1968891-d9d7-4256-a54c-6f6d9476546a)

I believe it is attributed to me being on Linux with an older version of sqlite3 which does not automatically clean up the files after all connections have been closed.

$ sqlite3 --version
3.37.2 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5dalt1

I do not have this issue in my own lib which is currently linking against a static lib using version 3.43.0 for linux x64

See create See tests