mirror of
https://github.com/xiaoqidun/entps
synced 2024-09-08 09:58:03 +08:00
32 lines
567 B
Go
32 lines
567 B
Go
package entps
|
|
|
|
import (
|
|
"database/sql"
|
|
"database/sql/driver"
|
|
"modernc.org/sqlite"
|
|
)
|
|
|
|
type sqlite3Driver struct {
|
|
*sqlite.Driver
|
|
}
|
|
|
|
type sqlite3DriverConn interface {
|
|
Exec(string, []driver.Value) (driver.Result, error)
|
|
}
|
|
|
|
func (d sqlite3Driver) Open(name string) (conn driver.Conn, err error) {
|
|
conn, err = d.Driver.Open(name)
|
|
if err != nil {
|
|
return
|
|
}
|
|
_, err = conn.(sqlite3DriverConn).Exec("PRAGMA foreign_keys = ON;", nil)
|
|
if err != nil {
|
|
_ = conn.Close()
|
|
}
|
|
return
|
|
}
|
|
|
|
func init() {
|
|
sql.Register("sqlite3", sqlite3Driver{Driver: &sqlite.Driver{}})
|
|
}
|