Skip to content

Commit

Permalink
Only use a single DB connection (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
minhducsun2002 authored Jun 26, 2020
1 parent 07d35e3 commit 692cda1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type DB struct {

// New creates a new DB object from the given filename.
func New(filename string) (*DB, error) {
dsn := fmt.Sprintf("%s?_fk=1&mode=rw", filename)
dsn := fmt.Sprintf("%s?_fk=1&mode=rw&cache=shared&_journal=WAL", filename)
sqlxdb, err := sqlx.Open("sqlite3", dsn)
if err != nil {
return nil, errors.WithStack(err)
Expand All @@ -43,6 +43,7 @@ func New(filename string) (*DB, error) {
DB: sqlxdb,
PersistentConn: conn.(*sqlite3.SQLiteConn),
}
db.SetMaxOpenConns(1)
// Perform migrations, if needed.
if err := db.migrate(); err != nil {
return nil, err
Expand Down

0 comments on commit 692cda1

Please sign in to comment.