diff options
author | mattn <mattn.jp@gmail.com> | 2019-05-29 17:43:13 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-29 17:43:13 +0900 |
commit | 070b17a2fdf5109d2dd54acb6bbfb507872115cf (patch) | |
tree | da1a5195018709808554da2b2b1be09134cddbf2 | |
parent | Create FUNDING.yml (diff) | |
parent | more code formatting (diff) | |
download | golite-070b17a2fdf5109d2dd54acb6bbfb507872115cf.tar.gz golite-070b17a2fdf5109d2dd54acb6bbfb507872115cf.tar.xz |
Merge pull request #680 from rittneje/improve-faq-in-memory-shared-cache
improve FAQ re: in-memory databases
-rw-r--r-- | README.md | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -456,15 +456,19 @@ 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 - workaround is to use "file::memory:?mode=memory&cache=shared". Every - connection to this string will point to the same in-memory database. + 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. + + 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. |