govote/store/db.go

27 lines
456 B
Go
Raw Normal View History

2024-05-12 22:47:24 +00:00
package store
import (
2024-05-13 08:45:38 +00:00
"database/sql"
_ "github.com/mattn/go-sqlite3"
2024-05-12 22:47:24 +00:00
)
2024-05-14 08:26:48 +00:00
// file points the the sqlite file.
2024-05-12 22:47:24 +00:00
const file = "./govote.db"
2024-05-14 08:26:48 +00:00
// db references the initialized sqlite connection.
2024-05-12 22:47:24 +00:00
var db *sql.DB
2024-05-14 08:26:48 +00:00
// init initialized the database layer
2024-05-12 22:47:24 +00:00
func init() {
2024-05-13 08:45:38 +00:00
var err error
if db, err = sql.Open("sqlite3", file); err != nil {
panic(err)
}
2024-05-12 22:47:24 +00:00
2024-05-14 08:26:48 +00:00
// initialize the sql schema
2024-05-13 08:45:38 +00:00
initCreateTables(db)
2024-05-14 08:26:48 +00:00
// initialize all prepared statements
2024-05-13 08:45:38 +00:00
initStmts(db)
2024-05-12 22:47:24 +00:00
}