quaint icon indicating copy to clipboard operation
quaint copied to clipboard

The `Sqlite` connector always create in-memory databases.

Open timothee-haudebourg opened this issue 5 years ago • 3 comments

This is something I had to discover the hard way, since it is not documented.

Even while it takes a file path as parameter, Sqlite::new does not open the file but creates an in-memory database. The method attach_database seems to used to attach the file afterward? This is quite weird to be honest.

If Sqlite::new takes a file name, then it should use the given file as main schema. If you want to keep new to create in-memory database, I would advocate removing its input parameter and add a new Sqlite::open method to open an on-disk file.

Also the method attach_database should comply to the sqlite semantics: take a file name and a schema name, and bind them together.

timothee-haudebourg avatar May 24 '20 09:05 timothee-haudebourg

I agree this behaviour is not very obvious!

I stumbled upon this because I got no results from SELECT * FROM sqlite_master whereas querying the tables would work fine. Because of the ATTACH you instead need to SELECT * FROM quaint.sqlite_master, i.e. specify your db_name (quaint is the default for db_name which appears is not documented).

pixelspark avatar Jun 02 '20 18:06 pixelspark

https://github.com/prisma/quaint/pull/126 addresses this I think. I'll have another look at it tomorrow and try to get it merged.

tomhoule avatar Jun 02 '20 19:06 tomhoule

Awesome!

pixelspark avatar Jun 04 '20 09:06 pixelspark