matrix-development-lauge/modules/database/database.go

32 lines
431 B
Go
Executable File

package database
import (
"database/sql"
"log"
)
func InitDatabase() {
db := GetDatabase()
defer db.Close()
sqlStmt := `CREATE TABLE IF NOT EXISTS pages (page_id VARCHAR(255), page_title TEXT);`
_, err := db.Exec(sqlStmt)
if err != nil {
log.Printf("%q: %s\n", err, sqlStmt)
return
}
}
func GetDatabase() *sql.DB {
db, err := sql.Open("sqlite3", "./data.db")
if err != nil {
log.Fatal(err)
}
return db
}