Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 070b17a

Browse files
authored
Merge pull request mattn#680 from rittneje/improve-faq-in-memory-shared-cache
improve FAQ re: in-memory databases
2 parents afa0250 + 062811f commit 070b17a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

‎README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,19 @@ For an example see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatial
456456

457457
Why is it racy if I use a `sql.Open("sqlite3", ":memory:")` database?
458458

459-
Each connection to :memory: opens a brand new in-memory sql database, so if
459+
Each connection to `":memory:"` opens a brand new in-memory sql database, so if
460460
the stdlib's sql engine happens to open another connection and you've only
461-
specified ":memory:", that connection will see a brand new database. A
462-
workaround is to use "file::memory:?mode=memory&cache=shared". Every
463-
connection to this string will point to the same in-memory database.
461+
specified `":memory:"`, that connection will see a brand new database. A
462+
workaround is to use `"file::memory:?cache=shared"` (or `"file:foobar?mode=memory&cache=shared"`). Every
463+
connection to this string will point to the same in-memory database.
464+
465+
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.
464466

465467
For more information see
466468
* [#204](https://github.com/mattn/go-sqlite3/issues/204)
467469
* [#511](https://github.com/mattn/go-sqlite3/issues/511)
470+
* https://www.sqlite.org/sharedcache.html#shared_cache_and_in_memory_databases
471+
* https://www.sqlite.org/inmemorydb.html#sharedmemdb
468472

469473
- Reading from database with large amount of goroutines fails on OSX.
470474

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /