Timeouts per query. If a timeout occurs, then the query will be cancelled through
pg_cancel_backend
err := DB.Select("SELECT pg_sleep(1)").Timeout(1 * time.Millisecond).Exec()
err == dat.ErrTimedout
- Caching - caching with Redis or (in-memory for testing)
- LogQueriesThreshold - log slow queries
- dat.Null* creators
- fix resource cleanup
- fix duplicate error logging
- include RFC339Nano in NullTime parsing
- HUGE BUG in remapPlaceholders
-
Original dat moved to legacy branch.
-
Move to gopkg.in for API stability.
-
Legacy
Connection
renamed toDB
to be consistent withdatabase/sql
-
Connection
is now the interface forDB
andTx
. UseConnection
to receive either aDB
orTx
. -
Support for nested transactions. Needs user testing and feedback.
In a nested transaction only the top-most commit commits to the database if it has not been rollbacked. Any rollback in nested funtion results in entire transaction being rollbacked and leaves the transaction in
tx.IsRollbacked()
state.
func nested(conn runner.Connection) error {
tx, err := conn.Begin()
if err != nil {
return err
}
defer tx.AutoRollback()
_, err := tx.SQL('...').Exec()
if err != nil {
return err
}
return tx.Commit()
}
func fromDB() error {
return nested(DB)
}
func fromTx() error {
tx, err := DB.Begin()
if err != nil {
return err
}
defer tx.AutoRollback()
err := nested(tx)
if err ! = nil {
return logger.Error("Failed in nested", err)
}
// if Rollback was called, Commit returns an error
return tx.Commit()
}
SelectDoc.HasMany
andSelectDoc.HasOne
renamed toMany
andOne
for retrieving hierarchical JSON documents. BTW,SelectDoc
itself can be used inMany
andOne
to build N-deep hierarchies.
DB.SelectDoc("id", "user_name", "avatar").
Many("recent_comments", `SELECT id, title FROM comments WHERE id = users.id LIMIT 10`).
Many("recent_posts", `SELECT id, title FROM posts WHERE author_id = users.id LIMIT 10`).
One("account", `SELECT balance FROM accounts WHERE user_id = users.id`).
From("users").
Where("id = $1", 4).
QueryStruct(&obj) // obj must be agreeable with json.Unmarshal()
-
Session obsoleted. Go's db library does not support transaction-less sessions. Use
Tx
if you need a session, otherwise useDB
directly. -
Fixes to dat.NullTime to properly work with JSON timestamps from HTTP handlers and
timestamptz
.