go-pg is in a maintenance mode and only critical issues are addressed. New development happens in Bun repo which offers similar functionality but works with PostgreSQL, MySQL, and SQLite.
- Removed references to deprecated
io/ioutil
(#2001) - Added password environment variable for easier testing (#1996)
- Bumped google.golang.org/protobuf from 1.25.0 to 1.33.0 (#2000)
- Bumped golang.org/x/net from 0.17.0 to 0.23.0 (#2002)
Thank you @DarrylWong and @testwill
- Fixed invalid pointer dereference when accessing results (#1990)
- Updated minimum Golang version to v1.19.0 + go.mod cleanup (#1992)
- Bumped golang.org/x/net from 0.10.0 to 0.17.0 (#1993)
- Bumped gopkg.in/yaml.v3 from 3.0.0-20200313102051-9f266ea9e77c to 3.0.0 (#1994)
Thank you @fernandez14
- Improved memory allocation when working with multi-byte characters in
appendRune
(#1988) - Added
ToURL
to*Options
(#1934)
Thank you @dillonstreator and @MateusVeloso!
- Fixed bug with how cancelled contexts are handled in SingleConnPool connections (#1981)
Thank you @xin-tsla!
- Updated dependency
mellium.im/sasl
from 0.2.1 to 0.3.1. (#1969)
- Fixed race condition in notify listener.
- Add shortcut
WhereInOr
. - Fixed bug in sending cancel request to terminate long running query.
- Updated OpenTelemetry to v1.0.0.
-
Removed extra OpenTelemetry spans from go-pg core. Now go-pg instrumentation only adds a single span with a SQL query (instead of 4 spans). There are multiple reasons behind this decision:
- Traces become smaller and less noisy.
- Bun can't support the same level of instrumentation and it is nice to keep projects synced.
- It may be costly to process those 3 extra spans for each query.
Eventually we hope to replace the information that we no longer collect with OpenTelemetry Metrics.
- To make updating easier, extra modules now have the same version as go-pg does. That means that you need to update your imports:
github.com/go-pg/pg/extra/pgdebug -> github.com/go-pg/pg/extra/pgdebug/v10
github.com/go-pg/pg/extra/pgotel -> github.com/go-pg/pg/extra/pgotel/v10
github.com/go-pg/pg/extra/pgsegment -> github.com/go-pg/pg/extra/pgsegment/v10
- Exported
pg.Query
which should be used instead oform.Query
. - Added
pg.DBI
which is a DB interface implemented bypg.DB
andpg.Tx
.
- Docs at https://pg.uptrace.dev/ powered by mkdocs.
- RealWorld example application.
- Discord.
Select
,Insert
, andUpdate
supportmap[string]interface{}
.Select
also supports[]map[string]interface{}
.
var mm []map[string]interface{}
err := db.Model((*User)(nil)).Limit(10).Select(&mm)
- Columns that start with
_
are ignored if there is no destination field. - Optional faster json encoding.
- Added pgext.OpenTelemetryHook that adds OpenTelemetry instrumentation.
- Added pgext.DebugHook that logs failed queries.
- Added
db.Ping
to check if database is healthy.
- ORM relations are reworked and now require
rel
tag option (but existing code will continue working until v11). Supported options:pg:"rel:has-one"
- has one relation.pg:"rel:belongs-to"
- belongs to relation.pg:"rel:has-many"
- has many relation.pg:"many2many:book_genres"
- many to many relation.
- Changed
pg.QueryHook
to return temp byte slice to reduce memory usage. ,msgpack
struct tag marshals data in MessagePack format using https://github.com/vmihailenco/msgpack- Empty slices and maps are no longer marshaled as
NULL
. Nil slices and maps are still marshaled asNULL
. - Changed
UpdateNotZero
to include zero fields withpg:",use_zero"
tag. Consider usingModel(*map[string]interface{})
for inserts and updates. joinFK
is deprecated in favor ofjoin_fk
.partitionBy
is deprecated in favor ofpartition_by
.- ORM shortcuts are removed:
db.Select(model)
becomesdb.Model(model).WherePK().Select()
.db.Insert(model)
becomesdb.Model(model).Insert()
.db.Update(model)
becomesdb.Model(model).WherePK().Update()
.db.Delete(model)
becomesdb.Model(model).WherePK().Delete()
.
- Deprecated types and funcs are removed.
WhereStruct
is removed.
pg:",notnull"
is reworked. Now it means SQLNOT NULL
constraint and nothing more.- Added
pg:",use_zero"
to prevent go-pg from converting Go zero values to SQLNULL
. - UpdateNotNull is renamed to UpdateNotZero. As previously it omits zero Go values, but it does not take in account if field is nullable or not.
- ORM supports DistinctOn.
- Hooks accept and return context.
- Client respects Context.Deadline when setting net.Conn deadline.
- Client listens on Context.Done while waiting for a connection from the pool and returns an error when context is cancelled.
Query.Column
does not accept relation name any more. UseQuery.Relation
instead which returns an error if relation does not exist.- urlvalues package is removed in favor of https://github.com/go-pg/urlstruct. You can also use
struct based filters via
Query.WhereStruct
. NewModel
andAddModel
methods ofHooklessModel
interface were renamed toNextColumnScanner
andAddColumnScanner
respectively.types.F
andpg.F
are deprecated in favor ofpg.Ident
.types.Q
is deprecated in favor ofpg.Safe
.pg.Q
is deprecated in favor ofpg.SafeQuery
.TableName
field is deprecated in favor oftableName
.- Always use
pg:"..."
struct field tag instead ofsql:"..."
. pg:",override"
is deprecated in favor ofpg:",inherit"
.
- Added
QueryContext
,ExecContext
, andModelContext
which acceptcontext.Context
. Queries are cancelled when context is cancelled. - Model hooks are changed to accept
context.Context
as first argument. - Fixed array and hstore parsers to handle multiple single quotes (#1235).
- DB.OnQueryProcessed is replaced with DB.AddQueryHook.
- Added WhereStruct.
- orm.Pager is moved to urlvalues.Pager. Pager.FromURLValues returns an error if page or limit params can't be parsed.
- Read buffer is re-worked. Default read buffer is increased to 65kb.
- Added Options.MinIdleConns.
- Options.MaxAge renamed to Options.MaxConnAge.
- PoolStats.FreeConns is renamed to PoolStats.IdleConns.
- New hook BeforeSelectQuery.
,override
is renamed to,inherit
.- Dialer.KeepAlive is set to 5 minutes by default.
- Added support "scram-sha-256" authentication.
- Fields ignored with
sql:"-"
tag are no longer considered by ORM relation detector.
Insert
,Update
, andDelete
can returnpg.ErrNoRows
andpg.ErrMultiRows
whenReturning
is used and model expects single row.
db.Model(&strct).Update()
anddb.Model(&strct).Delete()
no longer adds WHERE condition based on primary key when there are no conditions. Instead you should usedb.Update(&strct)
ordb.Model(&strct).WherePK().Update()
.
?Columns
is renamed to?TableColumns
.?Columns
is changed to produce column names without table alias.
pg:"fk"
tag now accepts SQL names instead of Go names, e.g.pg:"fk:ParentId"
becomespg:"fk:parent_id"
. Old code should continue working in most cases, but it is strongly advised to start using new convention.- uint and uint64 SQL type is changed from decimal to bigint according to the lesser of two evils
principle. Use
sql:"type:decimal"
to get old behavior.
CreateTable
no longer adds ON DELETE hook by default. To get old behavior users should addsql:"on_delete:CASCADE"
tag on foreign key field.
types.Result
is renamed toorm.Result
.- Added
OnQueryProcessed
event that can be used to log / report queries timing. Query logger is removed. orm.URLValues
is renamed toorm.URLFilters
. It no longer adds ORDER clause.orm.Pager
is renamed toorm.Pagination
.- Support for net.IP and net.IPNet.
- Support for context.Context.
- Bulk/multi updates.
- Query.WhereGroup for enclosing conditions in parentheses.
- All fields are nullable by default.
,null
tag is replaced with,notnull
. Result.Affected
renamed toResult.RowsAffected
.- Added
Result.RowsReturned
. Create
renamed toInsert
,BeforeCreate
toBeforeInsert
,AfterCreate
toAfterInsert
.- Indexed placeholders support, e.g.
db.Exec("SELECT ?0 + ?0", 1)
. - Named placeholders are evaluated when query is executed.
- Added Update and Delete hooks.
- Order reworked to quote column names. OrderExpr added to bypass Order quoting restrictions.
- Group reworked to quote column names. GroupExpr added to bypass Group quoting restrictions.
Options.Host
andOptions.Port
merged intoOptions.Addr
.- Added
Options.MaxRetries
. Now queries are not retried by default. LoadInto
renamed toScan
,ColumnLoader
renamed toColumnScanner
, LoadColumn renamed to ScanColumn,NewRecord() interface{}
changed toNewModel() ColumnScanner
,AppendQuery(dst []byte) []byte
changed toAppendValue(dst []byte, quote bool) ([]byte, error)
.- Structs, maps and slices are marshalled to JSON by default.
- Added support for scanning slices, .e.g. scanning
[]int
. - Added object relational mapping.