Files
mayfly-go/server/internal/db/dbm/sqlite/meta.go
zongyangleo 9a59749763 !86 dbms支持sqlite和一些bug修复
* fix: 达梦数据库连接修复,以支持带特殊字符的密码和schema
* fix: oracle bug修复
* feat: dbms支持sqlite
* fix: dbms 修改字段名bug
2024-01-19 08:59:35 +00:00

39 lines
801 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"
_ "github.com/mattn/go-sqlite3"
"mayfly-go/internal/db/dbm/dbi"
"os"
"sync"
)
var (
meta dbi.Meta
once sync.Once
)
func GetMeta() dbi.Meta {
once.Do(func() {
meta = new(SqliteMeta)
})
return meta
}
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("sqlite3", d.Host)
}
func (md *SqliteMeta) GetDialect(conn *dbi.DbConn) dbi.Dialect {
return &SqliteDialect{conn}
}