mirror of
https://github.com/usememos/memos.git
synced 2024-12-27 15:42:51 +08:00
31 lines
416 B
Go
31 lines
416 B
Go
package store
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
var DB *sql.DB
|
|
|
|
func InitDBConn() {
|
|
db, err := sql.Open("sqlite3", "./resources/memos.db")
|
|
if err != nil {
|
|
fmt.Println("connect failed")
|
|
} else {
|
|
DB = db
|
|
fmt.Println("connect to sqlite succeed")
|
|
}
|
|
}
|
|
|
|
func FormatDBError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
|
|
switch err.Error() {
|
|
default:
|
|
return err
|
|
}
|
|
}
|