mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-11-06 06:13:57 +03:00
Refactoring the code and add new table, for favorite img
This commit is contained in:
parent
365caaeed0
commit
9abfd9f864
1 changed files with 38 additions and 8 deletions
|
@ -11,14 +11,7 @@ func Database() {
|
|||
Logger(err.Error())
|
||||
}
|
||||
|
||||
var existsSettings bool
|
||||
err = db.QueryRow("SELECT EXISTS(SELECT name FROM sqlite_master WHERE type='table' AND name='settings')").Scan(&existsSettings)
|
||||
|
||||
if err != nil {
|
||||
Logger(err.Error())
|
||||
}
|
||||
|
||||
if existsSettings == false {
|
||||
if !TableExists(db, "settings") {
|
||||
sqlTable := `
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
startup INTEGER DEFAULT 0,
|
||||
|
@ -42,4 +35,41 @@ func Database() {
|
|||
Logger(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if !TableExists(db, "favorite") {
|
||||
sqlTable := `
|
||||
CREATE TABLE IF NOT EXISTS favorite (
|
||||
title TEXT,
|
||||
explanation TEXT,
|
||||
copyright TEXT,
|
||||
date TEXT,
|
||||
url TEXT,
|
||||
hdurl TEXT,
|
||||
media_type TEXT
|
||||
);`
|
||||
|
||||
_, err = db.Exec(sqlTable)
|
||||
if err != nil {
|
||||
Logger(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetDatabase() *sql.DB {
|
||||
db, err := sql.Open("sqlite3", "EveryNasa.db")
|
||||
if err != nil {
|
||||
Logger(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 {
|
||||
Logger(err.Error())
|
||||
}
|
||||
|
||||
return exists
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue