32 lines
431 B
Go
32 lines
431 B
Go
|
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
|
||
|
}
|