diff options
| author | mattn <mattn.jp@gmail.com> | 2013-08-23 13:58:54 +0900 |
|---|---|---|
| committer | mattn <mattn.jp@gmail.com> | 2013-08-23 13:58:54 +0900 |
| commit | e6850435ffb1700c672f08d73ea6ccb7f7b78287 (patch) | |
| tree | 33ee113ffadb120f25db3b8ff235c4bd089e90f2 /sqlite3.go | |
| parent | Add example for sqlite3 extension (diff) | |
| download | golite-e6850435ffb1700c672f08d73ea6ccb7f7b78287.tar.gz golite-e6850435ffb1700c672f08d73ea6ccb7f7b78287.tar.xz | |
Possible to register custom driver
Diffstat (limited to 'sqlite3.go')
| -rw-r--r-- | sqlite3.go | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -72,13 +72,13 @@ var SQLiteTimestampFormats = []string{ } func init() { - sql.Register("sqlite3", &SQLiteDriver{false}) - sql.Register("sqlite3_with_extensions", &SQLiteDriver{true}) + sql.Register("sqlite3", &SQLiteDriver{false, nil}) } // Driver struct. type SQLiteDriver struct { - enableLoadExtentions bool + EnableLoadExtentions bool + ConnectHook func(*SQLiteConn) } // Conn struct. @@ -179,7 +179,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } enableLoadExtentions := 0 - if d.enableLoadExtentions { + if d.EnableLoadExtentions { enableLoadExtentions = 1 } rv = C.sqlite3_enable_load_extension(db, C.int(enableLoadExtentions)) @@ -187,7 +187,13 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { return nil, errors.New(C.GoString(C.sqlite3_errmsg(db))) } - return &SQLiteConn{db}, nil + conn := &SQLiteConn{db} + + if d.ConnectHook != nil { + d.ConnectHook(conn) + } + + return conn, nil } // Close the connection. |
