zombiezen / go-sqlite

Low-level Go interface to SQLite 3
https://pkg.go.dev/zombiezen.com/go/sqlite
ISC License
699 stars 16 forks source link

file:memory does not appear to work #92

Closed dkotik closed 2 months ago

dkotik commented 2 months ago

Dear maintainer,

I use the sqlitex.Pool for simulating in-memory testing connections, but it does not appear to work when using file:memory?mode=memory with multiple connections as described below:

func NewPool(uri string, opts PoolOptions) (pool *Pool, err error) {
    if uri == ":memory:" {
        return nil, strerror{msg: `sqlite: ":memory:" does not work with multiple connections, use "file::memory:?mode=memory"`}
    }
       // ...
}

I care about this, because my authorization code occasionally may make a database call, which will block the Pool, making this impossible to test. I can work around this by writing my own wrapper around the Pool and returning the same connection when in `file:memory:" mode, but I want to know if I am doing something wrong here, or may be there is a better way. Thank you!

zombiezen commented 2 months ago

You will also need to pass in OpenSharedCache (not on by default) in order for a pool of in-memory connections to work as you expect.

edit: I believe adding &cache=shared will also work. If that's the case, the error message should probably be amended to include that to avoid future confusion.

dkotik commented 2 months ago

edit: I believe adding &cache=shared will also work. If that's the case, the error message should probably be amended to include that to avoid future confusion.

This worked perfectly! You are amazing!

dkotik commented 2 months ago

I will gladly submit a documentation PR - would you like me to? I write ok docs.

zombiezen commented 2 months ago

Sure, sounds good. 👍