mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-12-04 10:46:21 +03:00
Restored the file to its previous state
This commit is contained in:
parent
a13f735afd
commit
2c8cb2a644
1 changed files with 56 additions and 0 deletions
56
utils/data.go
Normal file
56
utils/data.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func CreateDatabase() {
|
||||
db, err := sql.Open("sqlite3", "EveryNasa.db")
|
||||
if err != nil {
|
||||
Log(err.Error())
|
||||
}
|
||||
|
||||
if !TableExists(db, "settings") {
|
||||
sqlTable := `
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
startup INTEGER DEFAULT 0,
|
||||
wallpaper INTEGER DEFAULT 0,
|
||||
save_logg INTEGER DEFAULT 1
|
||||
);`
|
||||
|
||||
_, err = db.Exec(sqlTable)
|
||||
if err != nil {
|
||||
Log(err.Error())
|
||||
}
|
||||
|
||||
stmt, err := db.Prepare("INSERT INTO settings(startup, wallpaper, save_logg) values(?,?,?)")
|
||||
if err != nil {
|
||||
Log(err.Error())
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(0, 0, 1)
|
||||
if err != nil {
|
||||
Log(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetDatabase() *sql.DB {
|
||||
db, err := sql.Open("sqlite3", "EveryNasa.db")
|
||||
if err != nil {
|
||||
Log(err.Error())
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
func TableExists(db *sql.DB, name string) bool {
|
||||
var exists bool
|
||||
err := db.QueryRow("SELECT EXISTS(SELECT name FROM sqlite_master WHERE type='table' AND name=?)", name).Scan(&exists)
|
||||
if err != nil {
|
||||
Log(err.Error())
|
||||
}
|
||||
|
||||
return exists
|
||||
}
|
Loading…
Add table
Reference in a new issue