Releases: upper/db
v4.9.0
v4.8.0
v4.7.0
Release v4.6.0-rc1
This release includes memory and speed optimizations.
Release v4.6.0
This release includes memory and speed optimizations.
Release v4.5.4
Merge pull request #652 from upper/with-context Refactor WithContext to make it work without cloning the session and add `ConnMaxIdleTime`
Release v4.5.3
Merge pull request #656 from upper/allow-select-from-db-result allow using db.Result as subquery
Release v4.5.2
Merge pull request #649 from upper/refactor-memory-and-speed-optimiza…
v4.5.0
Release notes
The github.com/lib/pq
package that we used as driver for PostgreSQL and CockroachDB went under maintenance mode, the package maintainers recommended users to switch to github.com/jackc/pgx
. We followed that recommendation, and this release uses github.com/jackc/pgx
as driver for both PostgreSQL and CockroachDB.
For some codebases, the update will be completely transparent, but others cases might require slight modifications to their code, specially if they're using custom field types. If you're upgrading to v4.5.0
make sure you're either using the special types with driver.Value
and sql.Scanner
methods provided by the github.com/upper/db/v4/adapter/postgresql
package, or provide your own ones.
If the change is too complicated, you'll be able to use github.com/lib/pq
for a while by including the pgx
build constraint along the other build tags. See:
go build -tags=pgx ...
however, this is a temporary solution, support for the github.com/lib/pq
driver is going to be definitely removed on February 28th 2022.
Upgrading your codebase
If you upgraded to v4.5.0
and your code doesn't compile anymore or if it throws runtime errors around conversions between Go types and database types you'll have to tweak it a bit. Basically, you'll have to make sure you're providing scanners and values for all your types. Basic Go types, like int
, string
, bool
or even a slice of basic types won't require any special handling, but some other types like *[]int
or []uint
will do.
For instance, if your struct looks like this:
type Foo struct {
ID uint64 `db:"id"`
Names *[]string `db:"names"`
}
you'll have to convert it into:
import (
"github.com/upper/db/v4/adapter/postgresql"
)
type Foo struct {
ID uint64 `db:"id"` // no need to be updated
Names *postgresql.StringArray `db:"names"` // changed
}
The table below has some of the most common equivalences between old types and new types:
instead of | use |
---|---|
*[]string |
*postgresql.StringArray |
*[]int64 |
*postgresql.Int64Array |
*[]float64 |
*postgresql.Float64Array |
*[]float32 |
*postgresql.Float32Array |
*[]bool |
*postgresql.BoolArray |
*map[string]interface{} |
*postgresql.JSONBMap |
*[]interface{} |
*postgresql.JSONBArray |
If you're using custom types that are not provided in the table above, like map[string]bool
, you'll have to provide your own driver.Value
and sql.Scanner
methods.
If the destination type is JSONB
you can use postgresql.JSONBValue
and postgresql.ScanJSONB
to make those conversions easier, see the example below:
package foo
import (
"github.com/upper/db/v4/adapter/postgresql"
)
type CustomJSONB map[string]bool
func (c CustomJSONB) Value() (driver.Value, error) {
return postgresql.JSONBValue(c)
}
func (c *CustomJSONB) Scan(src interface{}) error {
return postgresql.ScanJSONB(c, src)
}
You can also use the *postgresql.JSONBConverter
type to add automatic conversions to some types, like this:
package foo
import (
"github.com/upper/db/v4/adapter/postgresql"
)
type CustomJSONB struct {
N string `json:"name"`
V float64 `json:"value"`
*postgresql.JSONBConverter
}
type CustomJSONBObjectArray []postgresql.CustomJSONB
func (CustomJSONBObjectArray) ConvertValue(in interface{}) interface {
sql.Scanner
driver.Valuer
} {
return &postgresql.JSONB{in}
}
type CustomJSONBObjectMap map[string]CustomJSONB
func (c CustomJSONBObjectMap) Value() (driver.Value, error) {
return postgresql.JSONBValue(c)
}
func (c *CustomJSONBObjectMap) Scan(src interface{}) error {
return postgresql.ScanJSONB(c, src)
}
Thanks for using db/v4!
What's Changed
- Replace lib/pq with pgx by @xiam in #627
- Fix sqlite.New panic by @sdvcrx in #635
- Fix condition that forced the statement cache to be skipped by @xiam in #638
New Contributors
Acknowledgements
Special thanks to @pkieltyka and Horizon Blockchain Games for their continuos support over the years! Thank you very much
Full Changelog: v4.2.1...v4.5.0
v4.5.0-rc3
Merge pull request #644 from upper/cockroachdb-default-port cockroachdb: set default port