gorm/dialects/sqlite/sqlite.go

38 lines
662 B
Go
Raw Normal View History

2020-02-02 03:35:01 +03:00
package sqlite
import (
2020-02-03 05:40:03 +03:00
"database/sql"
2020-02-02 09:40:44 +03:00
"github.com/jinzhu/gorm"
2020-02-02 03:35:01 +03:00
"github.com/jinzhu/gorm/callbacks"
_ "github.com/mattn/go-sqlite3"
)
type Dialector struct {
2020-02-03 05:40:03 +03:00
DSN string
2020-02-02 03:35:01 +03:00
}
func Open(dsn string) gorm.Dialector {
2020-02-03 05:40:03 +03:00
return &Dialector{DSN: dsn}
2020-02-02 03:35:01 +03:00
}
2020-02-03 05:40:03 +03:00
func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
2020-02-02 03:35:01 +03:00
// register callbacks
callbacks.RegisterDefaultCallbacks(db)
2020-02-03 05:40:03 +03:00
db.DB, err = sql.Open("sqlite3", dialector.DSN)
return
2020-02-02 03:35:01 +03:00
}
func (Dialector) Migrator() gorm.Migrator {
return nil
}
2020-02-03 05:40:03 +03:00
func (Dialector) BindVar(stmt *gorm.Statement, v interface{}) string {
2020-02-02 03:35:01 +03:00
return "?"
}
2020-02-05 06:14:58 +03:00
func (Dialector) QuoteChars() [2]byte {
return [2]byte{'`', '`'} // `name`
}