diff options
-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) { |