diff --git a/db/db.go b/db/db.go index 55855150a..7cbaf3035 100644 --- a/db/db.go +++ b/db/db.go @@ -101,6 +101,18 @@ func New(path, dsnQuery string, memory bool) (*DB, error) { }, nil } +func (d *DB) ConnectWithHook(connectHook func(*sqlite3.SQLiteConn) error) (*Conn, error) { + drv := sqlite3.SQLiteDriver{ConnectHook: connectHook} + c, err := drv.Open(d.fqdsn) + if err != nil { + return nil, err + } + + return &Conn{ + sqlite: c.(*sqlite3.SQLiteConn), + }, nil +} + // Connect returns a connection to the database. func (d *DB) Connect() (*Conn, error) { drv := sqlite3.SQLiteDriver{} diff --git a/hooks/django/django.go b/hooks/django/django.go index 41c1f0f57..10b430bed 100644 --- a/hooks/django/django.go +++ b/hooks/django/django.go @@ -54,7 +54,7 @@ func _sqlite_datetime_extract(lookup_type string, dt time.Time) int { func _sqlite_datetime_trunc(lookup_type string, dt time.Time) string { switch lookup_type { case "year": - return fmt.Sprintf("%d-01-01", dt.Year) + return fmt.Sprintf("%d-01-01", dt.Year()) case "quarter": month := int(dt.Month()) month_quarter := month - (month-1)%3 @@ -64,7 +64,7 @@ func _sqlite_datetime_trunc(lookup_type string, dt time.Time) string { case "day": return fmt.Sprintf("%d-%02d-%02d", dt.Year(), dt.Month(), dt.Day()) case "hour": - return fmt.Sprintf("%02d:%00:00", dt.Hour()) + return fmt.Sprintf("%02d:00:00", dt.Hour()) case "minute": return fmt.Sprintf("%02d:%02d:00", dt.Hour(), dt.Minute()) case "second": diff --git a/store/store.go b/store/store.go index 6f4e39eb6..65c0a5f9f 100644 --- a/store/store.go +++ b/store/store.go @@ -23,6 +23,7 @@ import ( "github.com/hashicorp/raft" "github.com/hashicorp/raft-boltdb" sdb "github.com/rqlite/rqlite/db" + djhooks "github.com/rqlite/rqlite/hooks/django" ) var ( @@ -261,7 +262,7 @@ func (s *Store) Open(enableSingle bool) error { } // Get utility connection to database. - conn, err := s.db.Connect() + conn, err := s.db.ConnectWithHook(djhooks.ConnectHook) if err != nil { return err }