Skip to content

Commit

Permalink
changes to make use of django hooks from contrib
Browse files Browse the repository at this point in the history
this registers the extra functions required by the django backend
  • Loading branch information
sum12 committed Jul 13, 2018
1 parent 154fe0b commit abc2c5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 12 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
4 changes: 2 additions & 2 deletions hooks/django/django.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand Down
3 changes: 2 additions & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit abc2c5d

Please sign in to comment.