diff options
author | Jordan <me@jordan.im> | 2023-12-16 17:38:17 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2023-12-16 17:38:17 -0700 |
commit | a3dac1a28fdc9e42d85c4686858c64597cf1a15b (patch) | |
tree | 0c04ede4751e923770d096bb11b1f98f586af882 | |
parent | 1958cc39ec416e9e7ceca8d0658914167eeafe22 (diff) | |
download | keep-a3dac1a28fdc9e42d85c4686858c64597cf1a15b.tar.gz keep-a3dac1a28fdc9e42d85c4686858c64597cf1a15b.zip |
db: limit shared cache connections to one; see mattn/go-sqlite3 #209
-rw-r--r-- | db.go | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -25,6 +25,7 @@ type Stats struct { func initDB(path string) *sql.DB { + var db *sql.DB if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) { file, err := os.Create(path) if err != nil { @@ -32,16 +33,17 @@ func initDB(path string) *sql.DB { } file.Close() - db, _ := sql.Open("sqlite3", path) + db, _ = sql.Open("sqlite3", "file:"+path+"?cache=shared") initTables(db) - return db } else { - db, err := sql.Open("sqlite3", path) + //db, err := sql.Open("sqlite3", path) + db, _ = sql.Open("sqlite3", "file:"+path+"?cache=shared") if err != nil { log.Fatal(err) } - return db } + db.SetMaxOpenConns(1) + return db } func initTables(db *sql.DB) { |