25 lines
450 B
Go
25 lines
450 B
Go
package db
|
|
|
|
import (
|
|
"github.com/jmoiron/sqlx"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func NewSQLiteDB(Path string) (db *sqlx.DB, rer error) {
|
|
db, rer = sqlx.Open("sqlite3", Path)
|
|
if rer != nil {
|
|
return
|
|
}
|
|
rer = db.Ping()
|
|
return
|
|
}
|
|
|
|
func IsDBInitialized(db *sqlx.DB) bool {
|
|
var count int
|
|
err := db.Get(&count, "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='localtions';")
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return count > 0
|
|
}
|