pkulchenko / fullmoon

Fast and minimalistic Redbean-based Lua web framework in one file.
MIT License
684 stars 30 forks source link

makeStorage support for in memory database #24

Closed ghost closed 1 year ago

ghost commented 1 year ago

Is there some reason makeStorage shouldn't support in memory databases?

I changed my makeStorage to use sqlite3.open_memory and my application appears to run fine without any changes. I'd like to use an in memory db when writing tests and be able to use the same interface as in the application code.

pkulchenko commented 1 year ago

It should support memory databases without issues; I use them myself. You don't need open_memory for that, as it's just a shortcut for open(":memory:"), so you should be able to use makeStorage(":memory:") to get the same result.

ghost commented 1 year ago

Thanks it does work. I tried it before but looking now see I forgot the second :.

pkulchenko commented 1 year ago

@johnmuhl, just to note, you can also use the URI version of it if you need to have multiple connections (within the same process) using the same in-memory DB: fm.makeStorage("file:/memdb1?vfs=memdb", sql, {OPEN_URI = true}). memdb1 would be the name of the DB to reference in this case. If this approach is not used, then each ":memory:" DB is unique per-connection.

ghost commented 1 year ago

Thanks for the pointer I’m sure it’ll come in handy.