-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2895c64
commit 908ed10
Showing
6 changed files
with
78 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package pkg | ||
|
||
import ( | ||
"database/sql" | ||
"os" | ||
"time" | ||
|
||
_ "github.com/glebarez/go-sqlite" // nolint: revive | ||
) | ||
|
||
func InitDB(dbName string) (*sql.DB, error) { | ||
db, err := sql.Open("sqlite", dbName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = db.Exec(` | ||
CREATE TABLE IF NOT EXISTS state ( | ||
key TEXT PRIMARY KEY, | ||
value INTEGER | ||
) | ||
`) | ||
if err != nil { | ||
return nil, err | ||
} | ||
db.SetMaxOpenConns(5) | ||
db.SetMaxIdleConns(5) | ||
db.SetConnMaxLifetime(time.Hour) | ||
|
||
return db, nil | ||
} | ||
func Vacuum(dbName string) error { | ||
if _, err := os.Stat(dbName); err == nil { | ||
if err := os.Remove(dbName); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters