mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-11-05 06:03:57 +03:00
add db
This commit is contained in:
parent
33cb1e23db
commit
41a46c7c6c
1 changed files with 42 additions and 0 deletions
42
functions/database.go
Normal file
42
functions/database.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package functions
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func Database() {
|
||||
db, openErr := sql.Open("sqlite3", "EveryNasa.db")
|
||||
if openErr != nil {
|
||||
panic(openErr)
|
||||
}
|
||||
|
||||
var exists bool
|
||||
QueryErr := db.QueryRow("SELECT EXISTS(SELECT name FROM sqlite_master WHERE type='table' AND name='settings')").Scan(&exists)
|
||||
if QueryErr != nil {
|
||||
panic(QueryErr)
|
||||
}
|
||||
|
||||
if exists == false {
|
||||
sqlTable := `
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
lang TEXT DEFAULT 'en',
|
||||
autostart INTEGER DEFAULT 0,
|
||||
autoupdate INTEGER DEFAULT 0
|
||||
);`
|
||||
_, CreateTableErr := db.Exec(sqlTable)
|
||||
if CreateTableErr != nil {
|
||||
panic(CreateTableErr)
|
||||
}
|
||||
|
||||
stmt, InsertErr := db.Prepare("INSERT INTO settings(lang, autostart, autoupdate) values(?,?,?)")
|
||||
if InsertErr != nil {
|
||||
panic(InsertErr)
|
||||
}
|
||||
|
||||
_, ExecErr := stmt.Exec("en", 0, 0)
|
||||
if ExecErr != nil {
|
||||
panic(ExecErr)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue