mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2025-05-24 12:24:55 +00:00
Start building out the backend with database
This commit is contained in:
parent
17476d3f2c
commit
677b4277a6
11 changed files with 241 additions and 63 deletions
40
database/database.go
Normal file
40
database/database.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var Conn *sql.DB
|
||||
|
||||
func Open() {
|
||||
var err error
|
||||
|
||||
sql.Register("sqlite3_with_extensions",
|
||||
&sqlite3.SQLiteDriver{
|
||||
Extensions: []string{
|
||||
"sqlite3_mod_regexp",
|
||||
},
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue