From 2ee07a473ff94a41b0e3163ab543d0897e30f67d Mon Sep 17 00:00:00 2001 From: Jesse Rittner Date: Fri, 4 Jan 2019 18:54:34 -0500 Subject: [PATCH 1/2] adding additional info to FAQ about in-memory databases --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 51b7e90..d93b9cf 100644 --- a/README.md +++ b/README.md @@ -459,12 +459,16 @@ For an example see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatial 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:?mode=memory&cache=shared". Every - connection to this string will point to the same in-memory database. + 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. + + Note that if the last database connection in the pool closes, the in-memory database is deleted. Make sure the [max idle connection limit](https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns) is > 0, and the [connection lifetime](https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime) is infinite. For more information see * [#204](https://github.com/mattn/go-sqlite3/issues/204) * [#511](https://github.com/mattn/go-sqlite3/issues/511) + * https://www.sqlite.org/sharedcache.html#shared_cache_and_in_memory_databases + * https://www.sqlite.org/inmemorydb.html#sharedmemdb - Reading from database with large amount of goroutines fails on OSX. From 062811fcbdca58aa7caadb3fa31c312ac0d5132b Mon Sep 17 00:00:00 2001 From: Jesse Rittner Date: Fri, 4 Jan 2019 18:57:33 -0500 Subject: [PATCH 2/2] more code formatting --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d93b9cf..b1bc610 100644 --- a/README.md +++ b/README.md @@ -456,9 +456,9 @@ For an example see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatial Why is it racy if I use a `sql.Open("sqlite3", ":memory:")` database? - Each connection to :memory: opens a brand new in-memory sql database, so if + 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 + 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.