23 ms·
SQLite is great. I've also recently settled on it as a key-value store, after considering a few purpose-built key-value solutions. Turns out that it's really ea
by imiric 3y ago
SQLite is great. I've also recently settled on it as a key-value store, after considering a few purpose-built key-value solutions. Turns out that it's really easy to make SQLite work as a key-value store, but very difficult to make key-value stores relational, if you ever need to.
Just be careful with `:memory:` databases. From the mattn/go-sqlite3 FAQ[1]:
> Each connection to ":memory:" opens a brand new in-memory sql database, so if the stdlib's sql engine happens to open another connection and you've only specified ":memory:", that connection will see a brand new database. A workaround is to use "file::memory:?cache=shared" (or "file:foobar?mode=memory&cache=shared"). Every connection to this string will point to the same in-memory database.
I noticed strange behaviors with just `:memory:` where tables would disappear at random, and this workaround helped. Make sure to use a unique filename as the `file:` value, especially if using this in tests.
[1]: https://github.com/mattn/go-sqlite3#faq https://github.com/mattn/go-sqlite3#faq
- wilsonehusin 3y agoOP here — that's interesting, thank you for sharing! I use http://modernc.org/sqlite http://modernc.org/sqlite for easier static compilation and haven't observed unexpected behaviors, but will keep that in mind! I agree with the key-value store too — there are some instances where I wish for a columnar database, but settling to use SQLite with key-value store ended up pretty okay.
- imiric 3y agoI use the modernc driver as well, which is where I ran into this. AFAIU this is not a driver issue, but a SQLite one. See https://www.sqlite.org/inmemorydb.html https://www.sqlite.org/inmemorydb.html