prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
583 stars 61 forks source link

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

Open timothee-haudebourg opened 4 years ago

timothee-haudebourg commented 4 years ago

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.

pixelspark commented 4 years ago

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).

tomhoule commented 4 years ago

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.

pixelspark commented 4 years ago

Awesome!