Files
mayfly-go/server/internal/db/dbm/sqlite/meta.go

29 lines
696 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 sqlite
import (
"database/sql"
"errors"
"mayfly-go/internal/db/dbm/dbi"
"os"
)
func init() {
dbi.Register(dbi.DbTypeSqlite, new(SqliteMeta))
}
type SqliteMeta struct {
}
func (md *SqliteMeta) GetSqlDb(d *dbi.DbInfo) (*sql.DB, error) {
// 用host字段来存sqlite的文件路径
// 检查文件是否存在,否则报错基于sqlite会自动创建文件为了服务器文件安全所以先确定文件存在再连接不自动创建
if _, err := os.Stat(d.Host); err != nil {
return nil, errors.New("数据库文件不存在")
}
return sql.Open("sqlite", d.Host)
}
func (md *SqliteMeta) GetDialect(conn *dbi.DbConn) dbi.Dialect {
return &SqliteDialect{conn}
}