TastyBites/database/database.go
2024-05-05 17:53:48 +01:00

35 lines
537 B
Go

package database
import (
"database/sql"
"log"
"github.com/mattn/go-sqlite3"
)
var Conn *sql.DB
func Open() {
var err error
sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{})
Conn, err = sql.Open("sqlite3", "tastybites.db?_journal_mode=WAL")
if err != nil {
log.Fatal("Error opening connection: ", err)
}
//Set the connection to use WAL mode
_, err = Conn.Exec("PRAGMA journal_mode=WAL;")
if err != nil {
log.Fatal(err)
}
}
func Close() {
err := Conn.Close()
if err != nil {
log.Fatal(err)
}
}