study_xxqg/model/model.go

41 lines
655 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"database/sql"
_ "modernc.org/sqlite"
log "github.com/sirupsen/logrus"
)
var (
db *sql.DB
)
func init() {
var err error
db, err = sql.Open("sqlite", "./config/user.db")
if err != nil {
log.Errorln("用户数据库打开失败请检查config目录权限")
log.Panicln(err.Error())
}
_, _ = db.Exec(`create table user
(
nick TEXT,
uid TEXT not null
constraint user_pk
primary key,
token TEXT not null,
login_time integer not null,
push_id TEXT
);
`)
}
func ping() {
err := db.Ping()
if err != nil {
log.Errorln("数据库断开了连接")
}
}