diff --git a/adapter/cockroachdb/cockroachdb.go b/adapter/cockroachdb/cockroachdb.go index 1ef4e616..18b1e3ce 100644 --- a/adapter/cockroachdb/cockroachdb.go +++ b/adapter/cockroachdb/cockroachdb.go @@ -35,17 +35,17 @@ const Adapter = `cockroachdb` var registeredAdapter = sqladapter.RegisterAdapter(Adapter, &database{}) // Open establishes a connection to the database server and returns a -// db.Session instance (which is compatible with db.Session). +// [sqladapter.Session] instance (which is compatible with [db.Session]). func Open(connURL db.ConnectionURL) (db.Session, error) { return registeredAdapter.OpenDSN(connURL) } -// NewTx creates a sqlbuilder.Tx instance by wrapping a *sql.Tx value. +// NewTx creates a [sqlbuilder.Tx] instance by wrapping a *[sql.Tx] value. func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error) { return registeredAdapter.NewTx(sqlTx) } -// New creates a sqlbuilder.Sesion instance by wrapping a *sql.DB value. +// New creates a [sqlbuilder.Sesion] instance by wrapping a *[sql.DB] value. func New(sqlDB *sql.DB) (db.Session, error) { return registeredAdapter.New(sqlDB) } diff --git a/adapter/cockroachdb/collection.go b/adapter/cockroachdb/collection.go index 222d7a0b..41e135cc 100644 --- a/adapter/cockroachdb/collection.go +++ b/adapter/cockroachdb/collection.go @@ -29,7 +29,7 @@ import ( type collectionAdapter struct { } -func (*collectionAdapter) Insert(col sqladapter.Collection, item interface{}) (interface{}, error) { +func (*collectionAdapter) Insert(col sqladapter.Collection, item any) (any, error) { pKey, err := col.PrimaryKeys() if err != nil { return nil, err diff --git a/adapter/cockroachdb/custom_types.go b/adapter/cockroachdb/custom_types.go index 6f246e10..70fd4244 100644 --- a/adapter/cockroachdb/custom_types.go +++ b/adapter/cockroachdb/custom_types.go @@ -32,61 +32,79 @@ import ( ) // JSONBMap represents a map of interfaces with string keys -// (`map[string]interface{}`) that is compatible with PostgreSQL's JSONB type. -// JSONBMap satisfies sqlbuilder.ScannerValuer. -type JSONBMap map[string]interface{} +// (`map[string]any`) that is compatible with PostgreSQL's JSONB type. +// JSONBMap satisfies [sqlbuilder.ScannerValuer]. +// +// Deprecated: This type is simply an alias of [JSONBMapOf][any]. +// +//go:fix inline +type JSONBMap = JSONBMapOf[any] + +// JSONBMapOf represents a map of any type T with string keys (`map[string]T`) +// that is compatible with PostgreSQL's JSONB type. JSONBMapOf satisfies +// [sqlbuilder.ScannerValuer]. +type JSONBMapOf[T any] map[string]T -// Value satisfies the driver.Valuer interface. -func (m JSONBMap) Value() (driver.Value, error) { +// Value satisfies the [driver.Valuer] interface. +func (m JSONBMapOf[T]) Value() (driver.Value, error) { return JSONBValue(m) } -// Scan satisfies the sql.Scanner interface. -func (m *JSONBMap) Scan(src interface{}) error { - *m = map[string]interface{}(nil) +// Scan satisfies the [sql.Scanner] interface. +func (m *JSONBMapOf[T]) Scan(src any) error { + *m = map[string]T(nil) return ScanJSONB(m, src) } -// JSONBArray represents an array of any type (`[]interface{}`) that is +// JSONBArray represents an array of any type (`[]any`) that is // compatible with PostgreSQL's JSONB type. JSONBArray satisfies -// sqlbuilder.ScannerValuer. -type JSONBArray []interface{} +// [sqlbuilder.ScannerValuer]. +// +// Deprecated: This type is simply an alias of [JSONBArrayOf][any]. +// +//go:fix inline +type JSONBArray = JSONBArrayOf[any] + +// JSONBArrayOf represents an array of any type (`[]any`) that is +// compatible with PostgreSQL's JSONB type. JSONBArrayOf satisfies +// [sqlbuilder.ScannerValuer]. +type JSONBArrayOf[T any] []T -// Value satisfies the driver.Valuer interface. -func (a JSONBArray) Value() (driver.Value, error) { +// Value satisfies the [driver.Valuer] interface. +func (a JSONBArrayOf[T]) Value() (driver.Value, error) { return JSONBValue(a) } -// Scan satisfies the sql.Scanner interface. -func (a *JSONBArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (a *JSONBArrayOf[T]) Scan(src any) error { return ScanJSONB(a, src) } -// JSONBValue takes an interface and provides a driver.Value that can be +// JSONBValue takes an interface and provides a [driver.Value] that can be // stored as a JSONB column. -func JSONBValue(i interface{}) (driver.Value, error) { +func JSONBValue(i any) (driver.Value, error) { v := JSONB{i} return v.Value() } // ScanJSONB decodes a JSON byte stream into the passed dst value. -func ScanJSONB(dst interface{}, src interface{}) error { +func ScanJSONB(dst any, src any) error { v := JSONB{dst} return v.Scan(src) } // EncodeJSONB is deprecated and going to be removed. Use ScanJSONB instead. -func EncodeJSONB(i interface{}) (driver.Value, error) { +func EncodeJSONB(i any) (driver.Value, error) { return JSONBValue(i) } // DecodeJSONB is deprecated and going to be removed. Use JSONBValue instead. -func DecodeJSONB(dst interface{}, src interface{}) error { +func DecodeJSONB(dst any, src any) error { return ScanJSONB(dst, src) } // JSONBConverter provides a helper method WrapValue that satisfies -// sqlbuilder.ValueWrapper, can be used to encode Go structs into JSONB +// [sqlbuilder.ValueWrapper], can be used to encode Go structs into JSONB // PostgreSQL types and vice versa. // // Example: @@ -100,7 +118,7 @@ func DecodeJSONB(dst interface{}, src interface{}) error { type JSONBConverter struct { } -func (*JSONBConverter) ConvertValue(src interface{}) interface { +func (*JSONBConverter) ConvertValue(src any) interface { sql.Scanner driver.Valuer } { @@ -119,7 +137,7 @@ func (t timeWrapper) Value() (driver.Value, error) { return nil, nil } -func (t *timeWrapper) Scan(src interface{}) error { +func (t *timeWrapper) Scan(src any) error { if src == nil { nilTime := (*time.Time)(nil) if t.v == nil { @@ -144,7 +162,7 @@ func (t *timeWrapper) Scan(src interface{}) error { return nil } -func (d *database) ConvertValueContext(ctx context.Context, in interface{}) interface{} { +func (d *database) ConvertValueContext(ctx context.Context, in any) any { tz, _ := ctx.Value(db.ContextKey("timezone")).(*time.Location) switch v := in.(type) { @@ -163,6 +181,6 @@ var ( _ sqlbuilder.ScannerValuer = &Int64Array{} _ sqlbuilder.ScannerValuer = &Float64Array{} _ sqlbuilder.ScannerValuer = &BoolArray{} - _ sqlbuilder.ScannerValuer = &JSONBMap{} - _ sqlbuilder.ScannerValuer = &JSONBArray{} + _ sqlbuilder.ScannerValuer = &JSONBMapOf[struct{}]{} + _ sqlbuilder.ScannerValuer = &JSONBArrayOf[struct{}]{} ) diff --git a/adapter/cockroachdb/custom_types_pgx.go b/adapter/cockroachdb/custom_types_pgx.go index 2d969580..cd22b775 100644 --- a/adapter/cockroachdb/custom_types_pgx.go +++ b/adapter/cockroachdb/custom_types_pgx.go @@ -30,11 +30,12 @@ import ( "github.com/jackc/pgtype" ) -// JSONB represents a PostgreSQL's JSONB value: -// https://www.postgresql.org/docs/9.6/static/datatype-json.html. JSONB -// satisfies sqlbuilder.ScannerValuer. +// JSONB represents a [PostgreSQL's JSONB] value. JSONB satisfies +// [sqlbuilder.ScannerValuer]. +// +// [PostgreSQL's JSONB]: https://www.postgresql.org/docs/current/static/datatype-json.html type JSONB struct { - Data interface{} + Data any } // MarshalJSON encodes the wrapper value as JSON. @@ -62,8 +63,8 @@ func (j *JSONB) UnmarshalJSON(b []byte) error { return nil } -// Scan satisfies the sql.Scanner interface. -func (j *JSONB) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (j *JSONB) Scan(src any) error { t := &pgtype.JSONB{} if err := t.Scan(src); err != nil { return err @@ -78,7 +79,7 @@ func (j *JSONB) Scan(src interface{}) error { return nil } -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (j JSONB) Value() (driver.Value, error) { t := &pgtype.JSONB{} if err := t.Set(j.Data); err != nil { @@ -89,10 +90,10 @@ func (j JSONB) Value() (driver.Value, error) { // StringArray represents a one-dimensional array of strings (`[]string{}`) // that is compatible with PostgreSQL's text array (`text[]`). StringArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type StringArray []string -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (a StringArray) Value() (driver.Value, error) { t := pgtype.TextArray{} if err := t.Set(a); err != nil { @@ -101,8 +102,8 @@ func (a StringArray) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (sa *StringArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (sa *StringArray) Scan(src any) error { d := []string{} t := pgtype.TextArray{} if err := t.Scan(src); err != nil { @@ -125,7 +126,7 @@ func (b Bytea) Value() (driver.Value, error) { return t.Value() } -func (b *Bytea) Scan(src interface{}) error { +func (b *Bytea) Scan(src any) error { d := []byte{} t := pgtype.Bytea{} if err := t.Scan(src); err != nil { @@ -140,10 +141,10 @@ func (b *Bytea) Scan(src interface{}) error { // ByteaArray represents a one-dimensional array of strings (`[]string{}`) // that is compatible with PostgreSQL's text array (`text[]`). ByteaArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type ByteaArray [][]byte -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (a ByteaArray) Value() (driver.Value, error) { t := pgtype.ByteaArray{} if err := t.Set(a); err != nil { @@ -152,8 +153,8 @@ func (a ByteaArray) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (ba *ByteaArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (ba *ByteaArray) Scan(src any) error { d := [][]byte{} t := pgtype.ByteaArray{} if err := t.Scan(src); err != nil { @@ -168,10 +169,10 @@ func (ba *ByteaArray) Scan(src interface{}) error { // Int64Array represents a one-dimensional array of int64s (`[]int64{}`) that // is compatible with PostgreSQL's integer array (`integer[]`). Int64Array -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type Int64Array []int64 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (i64a Int64Array) Value() (driver.Value, error) { t := pgtype.Int8Array{} if err := t.Set(i64a); err != nil { @@ -180,8 +181,8 @@ func (i64a Int64Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (i64a *Int64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (i64a *Int64Array) Scan(src any) error { d := []int64{} t := pgtype.Int8Array{} if err := t.Scan(src); err != nil { @@ -196,10 +197,10 @@ func (i64a *Int64Array) Scan(src interface{}) error { // Int32Array represents a one-dimensional array of int32s (`[]int32{}`) that // is compatible with PostgreSQL's integer array (`integer[]`). Int32Array -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type Int32Array []int32 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (i32a Int32Array) Value() (driver.Value, error) { t := pgtype.Int4Array{} if err := t.Set(i32a); err != nil { @@ -208,8 +209,8 @@ func (i32a Int32Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (i32a *Int32Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (i32a *Int32Array) Scan(src any) error { d := []int32{} t := pgtype.Int4Array{} if err := t.Scan(src); err != nil { @@ -224,10 +225,10 @@ func (i32a *Int32Array) Scan(src interface{}) error { // Float64Array represents a one-dimensional array of float64s (`[]float64{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float64Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float64Array satisfies [sqlbuilder.ScannerValuer]. type Float64Array []float64 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f64a Float64Array) Value() (driver.Value, error) { t := pgtype.Float8Array{} if err := t.Set(f64a); err != nil { @@ -236,8 +237,8 @@ func (f64a Float64Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (f64a *Float64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f64a *Float64Array) Scan(src any) error { d := []float64{} t := pgtype.Float8Array{} if err := t.Scan(src); err != nil { @@ -252,10 +253,10 @@ func (f64a *Float64Array) Scan(src interface{}) error { // Float32Array represents a one-dimensional array of float32s (`[]float32{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float32Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float32Array satisfies [sqlbuilder.ScannerValuer]. type Float32Array []float32 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f32a Float32Array) Value() (driver.Value, error) { t := pgtype.Float8Array{} if err := t.Set(f32a); err != nil { @@ -264,8 +265,8 @@ func (f32a Float32Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (f32a *Float32Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f32a *Float32Array) Scan(src any) error { d := []float32{} t := pgtype.Float8Array{} if err := t.Scan(src); err != nil { @@ -280,10 +281,10 @@ func (f32a *Float32Array) Scan(src interface{}) error { // BoolArray represents a one-dimensional array of int64s (`[]bool{}`) that // is compatible with PostgreSQL's boolean type (`boolean[]`). BoolArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type BoolArray []bool -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (ba BoolArray) Value() (driver.Value, error) { t := pgtype.BoolArray{} if err := t.Set(ba); err != nil { @@ -292,8 +293,8 @@ func (ba BoolArray) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (ba *BoolArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (ba *BoolArray) Scan(src any) error { d := []bool{} t := pgtype.BoolArray{} if err := t.Scan(src); err != nil { diff --git a/adapter/cockroachdb/custom_types_pq.go b/adapter/cockroachdb/custom_types_pq.go index 92cdd7b3..c8e2c03d 100644 --- a/adapter/cockroachdb/custom_types_pq.go +++ b/adapter/cockroachdb/custom_types_pq.go @@ -38,11 +38,12 @@ import ( "github.com/lib/pq" ) -// JSONB represents a PostgreSQL's JSONB value: -// https://www.postgresql.org/docs/9.6/static/datatype-json.html. JSONB -// satisfies sqlbuilder.ScannerValuer. +// JSONB represents a [PostgreSQL's JSONB] value. JSONB satisfies +// [sqlbuilder.ScannerValuer]. +// +// [PostgreSQL's JSONB]: https://www.postgresql.org/docs/current/static/datatype-json.html type JSONB struct { - Data interface{} + Data any } // MarshalJSON encodes the wrapper value as JSON. @@ -52,7 +53,7 @@ func (j JSONB) MarshalJSON() ([]byte, error) { // UnmarshalJSON decodes the given JSON into the wrapped value. func (j *JSONB) UnmarshalJSON(b []byte) error { - var v interface{} + var v any if err := json.Unmarshal(b, &v); err != nil { return err } @@ -60,8 +61,8 @@ func (j *JSONB) UnmarshalJSON(b []byte) error { return nil } -// Scan satisfies the sql.Scanner interface. -func (j *JSONB) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (j *JSONB) Scan(src any) error { if j.Data == nil { return nil } @@ -82,7 +83,7 @@ func (j *JSONB) Scan(src interface{}) error { return nil } -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (j JSONB) Value() (driver.Value, error) { // See https://github.com/lib/pq/issues/528#issuecomment-257197239 on why are // we returning string instead of []byte. @@ -101,16 +102,16 @@ func (j JSONB) Value() (driver.Value, error) { // StringArray represents a one-dimensional array of strings (`[]string{}`) // that is compatible with PostgreSQL's text array (`text[]`). StringArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type StringArray pq.StringArray -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (a StringArray) Value() (driver.Value, error) { return pq.StringArray(a).Value() } -// Scan satisfies the sql.Scanner interface. -func (a *StringArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (a *StringArray) Scan(src any) error { s := pq.StringArray(*a) if err := s.Scan(src); err != nil { return err @@ -121,16 +122,16 @@ func (a *StringArray) Scan(src interface{}) error { // Int64Array represents a one-dimensional array of int64s (`[]int64{}`) that // is compatible with PostgreSQL's integer array (`integer[]`). Int64Array -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type Int64Array pq.Int64Array -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (i Int64Array) Value() (driver.Value, error) { return pq.Int64Array(i).Value() } -// Scan satisfies the sql.Scanner interface. -func (i *Int64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (i *Int64Array) Scan(src any) error { s := pq.Int64Array(*i) if err := s.Scan(src); err != nil { return err @@ -141,16 +142,16 @@ func (i *Int64Array) Scan(src interface{}) error { // Float64Array represents a one-dimensional array of float64s (`[]float64{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float64Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float64Array satisfies [sqlbuilder.ScannerValuer]. type Float64Array pq.Float64Array -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f Float64Array) Value() (driver.Value, error) { return pq.Float64Array(f).Value() } -// Scan satisfies the sql.Scanner interface. -func (f *Float64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f *Float64Array) Scan(src any) error { s := pq.Float64Array(*f) if err := s.Scan(src); err != nil { return err @@ -161,16 +162,16 @@ func (f *Float64Array) Scan(src interface{}) error { // Float32Array represents a one-dimensional array of float32s (`[]float32{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float32Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float32Array satisfies [sqlbuilder.ScannerValuer]. type Float32Array pq.Float32Array -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f Float32Array) Value() (driver.Value, error) { return pq.Float32Array(f).Value() } -// Scan satisfies the sql.Scanner interface. -func (f *Float32Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f *Float32Array) Scan(src any) error { s := pq.Float32Array(*f) if err := s.Scan(src); err != nil { return err @@ -181,16 +182,16 @@ func (f *Float32Array) Scan(src interface{}) error { // BoolArray represents a one-dimensional array of int64s (`[]bool{}`) that // is compatible with PostgreSQL's boolean type (`boolean[]`). BoolArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type BoolArray pq.BoolArray -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (b BoolArray) Value() (driver.Value, error) { return pq.BoolArray(b).Value() } -// Scan satisfies the sql.Scanner interface. -func (b *BoolArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (b *BoolArray) Scan(src any) error { s := pq.BoolArray(*b) if err := s.Scan(src); err != nil { return err @@ -201,8 +202,8 @@ func (b *BoolArray) Scan(src interface{}) error { type Bytea []byte -// Scan satisfies the sql.Scanner interface. -func (b *Bytea) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (b *Bytea) Scan(src any) error { decoded, err := parseBytea(src.([]byte)) if err != nil { return err diff --git a/adapter/cockroachdb/custom_types_test.go b/adapter/cockroachdb/custom_types_test.go index 57274be6..59674088 100644 --- a/adapter/cockroachdb/custom_types_test.go +++ b/adapter/cockroachdb/custom_types_test.go @@ -10,7 +10,7 @@ import ( type testStruct struct { X int `json:"x"` Z string `json:"z"` - V interface{} `json:"v"` + V any `json:"v"` } func TestScanJSONB(t *testing.T) { diff --git a/adapter/cockroachdb/database.go b/adapter/cockroachdb/database.go index b2414f16..040915f4 100644 --- a/adapter/cockroachdb/database.go +++ b/adapter/cockroachdb/database.go @@ -19,9 +19,9 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// Package cockroachdb wraps the github.com/lib/pq driver and provides a +// Package cockroachdb wraps the github.com/jackc/pgx driver and provides a // compatibility later with CockroachDB. See -// https://github.com/upper/db/adapter/cockroachdb for documentation, +// See https://upper.io/v4/adapter/cockroachdb for documentation, // particularities and usage examples. package cockroachdb @@ -69,7 +69,7 @@ func (*database) Collections(sess sqladapter.Session) (collections []string, err return collections, nil } -func (*database) ConvertValue(in interface{}) interface{} { +func (*database) ConvertValue(in any) any { switch v := in.(type) { case *[]int64: @@ -80,8 +80,8 @@ func (*database) ConvertValue(in interface{}) interface{} { return (*Float64Array)(v) case *[]bool: return (*BoolArray)(v) - case *map[string]interface{}: - return (*JSONBMap)(v) + case *map[string]any: + return (*JSONBMapOf[any])(v) case []int64: return (*Int64Array)(&v) @@ -91,8 +91,8 @@ func (*database) ConvertValue(in interface{}) interface{} { return (*Float64Array)(&v) case []bool: return (*BoolArray)(&v) - case map[string]interface{}: - return (*JSONBMap)(&v) + case map[string]any: + return (*JSONBMapOf[any])(&v) case sql.Scanner, driver.Valuer: return v @@ -122,7 +122,7 @@ func (*database) ConvertValue(in interface{}) interface{} { return in } -func (*database) CompileStatement(sess sqladapter.Session, stmt *exql.Statement, args []interface{}) (string, []interface{}, error) { +func (*database) CompileStatement(sess sqladapter.Session, stmt *exql.Statement, args []any) (string, []any, error) { compiled, err := stmt.Compile(template) if err != nil { return "", nil, err diff --git a/adapter/cockroachdb/template_test.go b/adapter/cockroachdb/template_test.go index 74bdbb86..e23418d8 100644 --- a/adapter/cockroachdb/template_test.go +++ b/adapter/cockroachdb/template_test.go @@ -187,7 +187,7 @@ func TestTemplateInsert(t *testing.T) { assert.Equal( `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`, - b.InsertInto("artist").Values(map[string]interface{}{"name": "Chavela Vargas", "id": 12}).String(), + b.InsertInto("artist").Values(map[string]any{"name": "Chavela Vargas", "id": 12}).String(), ) assert.Equal( diff --git a/adapter/postgresql/collection.go b/adapter/postgresql/collection.go index 04c5005d..4a54eb8a 100644 --- a/adapter/postgresql/collection.go +++ b/adapter/postgresql/collection.go @@ -29,7 +29,7 @@ import ( type collectionAdapter struct { } -func (*collectionAdapter) Insert(col sqladapter.Collection, item interface{}) (interface{}, error) { +func (*collectionAdapter) Insert(col sqladapter.Collection, item any) (any, error) { pKey, err := col.PrimaryKeys() if err != nil { return nil, err diff --git a/adapter/postgresql/connection.go b/adapter/postgresql/connection.go index 35f0eb46..7a3fd4d8 100644 --- a/adapter/postgresql/connection.go +++ b/adapter/postgresql/connection.go @@ -243,14 +243,14 @@ func newScanner(s string) *scanner { return &scanner{[]rune(s), 0} } -// ParseURL no longer needs to be used by clients of this library since supplying a URL as a -// connection string to sql.Open() is now supported: +// parseURL no longer needs to be used by clients of this library since supplying a URL as a +// connection string to [sql.Open]() is now supported: // // sql.Open("postgres", "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full") // // It remains exported here for backwards-compatibility. // -// ParseURL converts a url to a connection string for driver.Open. +// parseURL converts a url to a connection string for [driver.Open]. // Example: // // "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full" @@ -263,7 +263,7 @@ func newScanner(s string) *scanner { // // "postgres://" // -// # This will be blank, causing driver.Open to use all of the defaults +// # This will be blank, causing [driver.Open] to use all of the defaults // // NOTE: vendored/copied from github.com/lib/pq func parseURL(uri string) (string, error) { diff --git a/adapter/postgresql/custom_types.go b/adapter/postgresql/custom_types.go index ff178552..6a1e8c55 100644 --- a/adapter/postgresql/custom_types.go +++ b/adapter/postgresql/custom_types.go @@ -32,45 +32,63 @@ import ( ) // JSONBMap represents a map of interfaces with string keys -// (`map[string]interface{}`) that is compatible with PostgreSQL's JSONB type. -// JSONBMap satisfies sqlbuilder.ScannerValuer. -type JSONBMap map[string]interface{} +// (`map[string]any`) that is compatible with PostgreSQL's JSONB type. +// JSONBMap satisfies [sqlbuilder.ScannerValuer]. +// +// Deprecated: This type is simply an alias of [JSONBMapOf][any]. +// +//go:fix inline +type JSONBMap = JSONBMapOf[any] + +// JSONBMapOf represents a map of any type T with string keys (`map[string]T`) +// that is compatible with PostgreSQL's JSONB type. JSONBMapOf satisfies +// [sqlbuilder.ScannerValuer]. +type JSONBMapOf[T any] map[string]T -// Value satisfies the driver.Valuer interface. -func (m JSONBMap) Value() (driver.Value, error) { +// Value satisfies the [driver.Valuer] interface. +func (m JSONBMapOf[T]) Value() (driver.Value, error) { return JSONBValue(m) } -// Scan satisfies the sql.Scanner interface. -func (m *JSONBMap) Scan(src interface{}) error { - *m = map[string]interface{}(nil) +// Scan satisfies the [sql.Scanner] interface. +func (m *JSONBMapOf[T]) Scan(src any) error { + *m = map[string]T(nil) return ScanJSONB(m, src) } -// JSONBArray represents an array of any type (`[]interface{}`) that is +// JSONBArray represents an array of any type (`[]any`) that is // compatible with PostgreSQL's JSONB type. JSONBArray satisfies -// sqlbuilder.ScannerValuer. -type JSONBArray []interface{} +// [sqlbuilder.ScannerValuer]. +// +// Deprecated: This type is simply an alias of [JSONBArrayOf][any]. +// +//go:fix inline +type JSONBArray = JSONBArrayOf[any] + +// JSONBArrayOf represents an array of any type T (`[]T`) that is +// compatible with PostgreSQL's JSONB type. JSONBArrayOf satisfies +// [sqlbuilder.ScannerValuer]. +type JSONBArrayOf[T any] []T -// Value satisfies the driver.Valuer interface. -func (a JSONBArray) Value() (driver.Value, error) { +// Value satisfies the [driver.Valuer] interface. +func (a JSONBArrayOf[T]) Value() (driver.Value, error) { return JSONBValue(a) } -// Scan satisfies the sql.Scanner interface. -func (a *JSONBArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (a *JSONBArrayOf[T]) Scan(src any) error { return ScanJSONB(a, src) } -// JSONBValue takes an interface and provides a driver.Value that can be +// JSONBValue takes an interface and provides a [driver.Value] that can be // stored as a JSONB column. -func JSONBValue(i interface{}) (driver.Value, error) { +func JSONBValue(i any) (driver.Value, error) { v := JSONB{i} return v.Value() } // ScanJSONB decodes a JSON byte stream into the passed dst value. -func ScanJSONB(dst interface{}, src interface{}) error { +func ScanJSONB(dst any, src any) error { v := JSONB{dst} return v.Scan(src) } @@ -78,7 +96,7 @@ func ScanJSONB(dst interface{}, src interface{}) error { type JSONBConverter struct { } -func (*JSONBConverter) ConvertValue(in interface{}) interface { +func (*JSONBConverter) ConvertValue(in any) interface { sql.Scanner driver.Valuer } { @@ -97,7 +115,7 @@ func (t timeWrapper) Value() (driver.Value, error) { return nil, nil } -func (t *timeWrapper) Scan(src interface{}) error { +func (t *timeWrapper) Scan(src any) error { if src == nil { nilTime := (*time.Time)(nil) if t.v == nil { @@ -122,7 +140,7 @@ func (t *timeWrapper) Scan(src interface{}) error { return nil } -func (d *database) ConvertValueContext(ctx context.Context, in interface{}) interface{} { +func (d *database) ConvertValueContext(ctx context.Context, in any) any { tz, _ := ctx.Value(db.ContextKey("timezone")).(*time.Location) switch v := in.(type) { @@ -142,7 +160,7 @@ var ( _ sqlbuilder.ScannerValuer = &Float64Array{} _ sqlbuilder.ScannerValuer = &Float32Array{} _ sqlbuilder.ScannerValuer = &BoolArray{} - _ sqlbuilder.ScannerValuer = &JSONBMap{} - _ sqlbuilder.ScannerValuer = &JSONBArray{} + _ sqlbuilder.ScannerValuer = &JSONBMapOf[struct{}]{} + _ sqlbuilder.ScannerValuer = &JSONBArrayOf[struct{}]{} _ sqlbuilder.ScannerValuer = &JSONB{} ) diff --git a/adapter/postgresql/custom_types_pgx.go b/adapter/postgresql/custom_types_pgx.go index 2a0b6583..3bd90598 100644 --- a/adapter/postgresql/custom_types_pgx.go +++ b/adapter/postgresql/custom_types_pgx.go @@ -30,11 +30,12 @@ import ( "github.com/jackc/pgtype" ) -// JSONB represents a PostgreSQL's JSONB value: -// https://www.postgresql.org/docs/9.6/static/datatype-json.html. JSONB -// satisfies sqlbuilder.ScannerValuer. +// JSONB represents a [PostgreSQL's JSONB] value. JSONB satisfies +// [sqlbuilder.ScannerValuer]. +// +// [PostgreSQL's JSONB]: https://www.postgresql.org/docs/current/static/datatype-json.html type JSONB struct { - Data interface{} + Data any } // MarshalJSON encodes the wrapper value as JSON. @@ -62,8 +63,8 @@ func (j *JSONB) UnmarshalJSON(b []byte) error { return nil } -// Scan satisfies the sql.Scanner interface. -func (j *JSONB) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (j *JSONB) Scan(src any) error { t := &pgtype.JSONB{} if err := t.Scan(src); err != nil { return err @@ -78,7 +79,7 @@ func (j *JSONB) Scan(src interface{}) error { return nil } -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (j JSONB) Value() (driver.Value, error) { t := &pgtype.JSONB{} if err := t.Set(j.Data); err != nil { @@ -89,10 +90,10 @@ func (j JSONB) Value() (driver.Value, error) { // StringArray represents a one-dimensional array of strings (`[]string{}`) // that is compatible with PostgreSQL's text array (`text[]`). StringArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type StringArray []string -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (a StringArray) Value() (driver.Value, error) { t := pgtype.TextArray{} if err := t.Set(a); err != nil { @@ -101,8 +102,8 @@ func (a StringArray) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (sa *StringArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (sa *StringArray) Scan(src any) error { d := []string{} t := pgtype.TextArray{} if err := t.Scan(src); err != nil { @@ -125,7 +126,7 @@ func (b Bytea) Value() (driver.Value, error) { return t.Value() } -func (b *Bytea) Scan(src interface{}) error { +func (b *Bytea) Scan(src any) error { d := []byte{} t := pgtype.Bytea{} if err := t.Scan(src); err != nil { @@ -140,10 +141,10 @@ func (b *Bytea) Scan(src interface{}) error { // ByteaArray represents a one-dimensional array of strings (`[]string{}`) // that is compatible with PostgreSQL's text array (`text[]`). ByteaArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type ByteaArray [][]byte -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (a ByteaArray) Value() (driver.Value, error) { t := pgtype.ByteaArray{} if err := t.Set(a); err != nil { @@ -152,8 +153,8 @@ func (a ByteaArray) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (ba *ByteaArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (ba *ByteaArray) Scan(src any) error { d := [][]byte{} t := pgtype.ByteaArray{} if err := t.Scan(src); err != nil { @@ -168,10 +169,10 @@ func (ba *ByteaArray) Scan(src interface{}) error { // Int64Array represents a one-dimensional array of int64s (`[]int64{}`) that // is compatible with PostgreSQL's integer array (`integer[]`). Int64Array -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type Int64Array []int64 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (i64a Int64Array) Value() (driver.Value, error) { t := pgtype.Int8Array{} if err := t.Set(i64a); err != nil { @@ -180,8 +181,8 @@ func (i64a Int64Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (i64a *Int64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (i64a *Int64Array) Scan(src any) error { d := []int64{} t := pgtype.Int8Array{} if err := t.Scan(src); err != nil { @@ -196,10 +197,10 @@ func (i64a *Int64Array) Scan(src interface{}) error { // Int32Array represents a one-dimensional array of int32s (`[]int32{}`) that // is compatible with PostgreSQL's integer array (`integer[]`). Int32Array -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type Int32Array []int32 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (i32a Int32Array) Value() (driver.Value, error) { t := pgtype.Int4Array{} if err := t.Set(i32a); err != nil { @@ -208,8 +209,8 @@ func (i32a Int32Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (i32a *Int32Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (i32a *Int32Array) Scan(src any) error { d := []int32{} t := pgtype.Int4Array{} if err := t.Scan(src); err != nil { @@ -224,10 +225,10 @@ func (i32a *Int32Array) Scan(src interface{}) error { // Float64Array represents a one-dimensional array of float64s (`[]float64{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float64Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float64Array satisfies [sqlbuilder.ScannerValuer]. type Float64Array []float64 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f64a Float64Array) Value() (driver.Value, error) { t := pgtype.Float8Array{} if err := t.Set(f64a); err != nil { @@ -236,8 +237,8 @@ func (f64a Float64Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (f64a *Float64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f64a *Float64Array) Scan(src any) error { d := []float64{} t := pgtype.Float8Array{} if err := t.Scan(src); err != nil { @@ -252,10 +253,10 @@ func (f64a *Float64Array) Scan(src interface{}) error { // Float32Array represents a one-dimensional array of float32s (`[]float32{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float32Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float32Array satisfies [sqlbuilder.ScannerValuer]. type Float32Array []float32 -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f32a Float32Array) Value() (driver.Value, error) { t := pgtype.Float8Array{} if err := t.Set(f32a); err != nil { @@ -264,8 +265,8 @@ func (f32a Float32Array) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (f32a *Float32Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f32a *Float32Array) Scan(src any) error { d := []float32{} t := pgtype.Float8Array{} if err := t.Scan(src); err != nil { @@ -280,10 +281,10 @@ func (f32a *Float32Array) Scan(src interface{}) error { // BoolArray represents a one-dimensional array of int64s (`[]bool{}`) that // is compatible with PostgreSQL's boolean type (`boolean[]`). BoolArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type BoolArray []bool -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (ba BoolArray) Value() (driver.Value, error) { t := pgtype.BoolArray{} if err := t.Set(ba); err != nil { @@ -292,8 +293,8 @@ func (ba BoolArray) Value() (driver.Value, error) { return t.Value() } -// Scan satisfies the sql.Scanner interface. -func (ba *BoolArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (ba *BoolArray) Scan(src any) error { d := []bool{} t := pgtype.BoolArray{} if err := t.Scan(src); err != nil { diff --git a/adapter/postgresql/custom_types_pq.go b/adapter/postgresql/custom_types_pq.go index 0ffdeb3d..68eb2a5e 100644 --- a/adapter/postgresql/custom_types_pq.go +++ b/adapter/postgresql/custom_types_pq.go @@ -38,11 +38,12 @@ import ( "github.com/lib/pq" ) -// JSONB represents a PostgreSQL's JSONB value: -// https://www.postgresql.org/docs/9.6/static/datatype-json.html. JSONB -// satisfies sqlbuilder.ScannerValuer. +// JSONB represents a [PostgreSQL's JSONB] value. JSONB satisfies +// [sqlbuilder.ScannerValuer]. +// +// [PostgreSQL's JSONB]: https://www.postgresql.org/docs/current/static/datatype-json.html type JSONB struct { - Data interface{} + Data any } // MarshalJSON encodes the wrapper value as JSON. @@ -52,7 +53,7 @@ func (j JSONB) MarshalJSON() ([]byte, error) { // UnmarshalJSON decodes the given JSON into the wrapped value. func (j *JSONB) UnmarshalJSON(b []byte) error { - var v interface{} + var v any if err := json.Unmarshal(b, &v); err != nil { return err } @@ -60,8 +61,8 @@ func (j *JSONB) UnmarshalJSON(b []byte) error { return nil } -// Scan satisfies the sql.Scanner interface. -func (j *JSONB) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (j *JSONB) Scan(src any) error { if j.Data == nil { return nil } @@ -82,7 +83,7 @@ func (j *JSONB) Scan(src interface{}) error { return nil } -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (j JSONB) Value() (driver.Value, error) { // See https://github.com/lib/pq/issues/528#issuecomment-257197239 on why are // we returning string instead of []byte. @@ -101,16 +102,16 @@ func (j JSONB) Value() (driver.Value, error) { // StringArray represents a one-dimensional array of strings (`[]string{}`) // that is compatible with PostgreSQL's text array (`text[]`). StringArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type StringArray pq.StringArray -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (a StringArray) Value() (driver.Value, error) { return pq.StringArray(a).Value() } -// Scan satisfies the sql.Scanner interface. -func (a *StringArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (a *StringArray) Scan(src any) error { s := pq.StringArray(*a) if err := s.Scan(src); err != nil { return err @@ -121,16 +122,16 @@ func (a *StringArray) Scan(src interface{}) error { // Int64Array represents a one-dimensional array of int64s (`[]int64{}`) that // is compatible with PostgreSQL's integer array (`integer[]`). Int64Array -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type Int64Array pq.Int64Array -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (i Int64Array) Value() (driver.Value, error) { return pq.Int64Array(i).Value() } -// Scan satisfies the sql.Scanner interface. -func (i *Int64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (i *Int64Array) Scan(src any) error { s := pq.Int64Array(*i) if err := s.Scan(src); err != nil { return err @@ -141,16 +142,16 @@ func (i *Int64Array) Scan(src interface{}) error { // Float64Array represents a one-dimensional array of float64s (`[]float64{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float64Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float64Array satisfies [sqlbuilder.ScannerValuer]. type Float64Array pq.Float64Array -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f Float64Array) Value() (driver.Value, error) { return pq.Float64Array(f).Value() } -// Scan satisfies the sql.Scanner interface. -func (f *Float64Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f *Float64Array) Scan(src any) error { s := pq.Float64Array(*f) if err := s.Scan(src); err != nil { return err @@ -161,16 +162,16 @@ func (f *Float64Array) Scan(src interface{}) error { // Float32Array represents a one-dimensional array of float32s (`[]float32{}`) // that is compatible with PostgreSQL's double precision array (`double -// precision[]`). Float32Array satisfies sqlbuilder.ScannerValuer. +// precision[]`). Float32Array satisfies [sqlbuilder.ScannerValuer]. type Float32Array pq.Float32Array -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (f Float32Array) Value() (driver.Value, error) { return pq.Float32Array(f).Value() } -// Scan satisfies the sql.Scanner interface. -func (f *Float32Array) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (f *Float32Array) Scan(src any) error { s := pq.Float32Array(*f) if err := s.Scan(src); err != nil { return err @@ -181,16 +182,16 @@ func (f *Float32Array) Scan(src interface{}) error { // BoolArray represents a one-dimensional array of int64s (`[]bool{}`) that // is compatible with PostgreSQL's boolean type (`boolean[]`). BoolArray -// satisfies sqlbuilder.ScannerValuer. +// satisfies [sqlbuilder.ScannerValuer]. type BoolArray pq.BoolArray -// Value satisfies the driver.Valuer interface. +// Value satisfies the [driver.Valuer] interface. func (b BoolArray) Value() (driver.Value, error) { return pq.BoolArray(b).Value() } -// Scan satisfies the sql.Scanner interface. -func (b *BoolArray) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (b *BoolArray) Scan(src any) error { s := pq.BoolArray(*b) if err := s.Scan(src); err != nil { return err @@ -201,8 +202,8 @@ func (b *BoolArray) Scan(src interface{}) error { type Bytea []byte -// Scan satisfies the sql.Scanner interface. -func (b *Bytea) Scan(src interface{}) error { +// Scan satisfies the [sql.Scanner] interface. +func (b *Bytea) Scan(src any) error { decoded, err := parseBytea(src.([]byte)) if err != nil { return err diff --git a/adapter/postgresql/custom_types_test.go b/adapter/postgresql/custom_types_test.go index 8624fda6..1e589244 100644 --- a/adapter/postgresql/custom_types_test.go +++ b/adapter/postgresql/custom_types_test.go @@ -10,7 +10,7 @@ import ( type testStruct struct { X int `json:"x"` Z string `json:"z"` - V interface{} `json:"v"` + V any `json:"v"` } func TestScanJSONB(t *testing.T) { diff --git a/adapter/postgresql/database.go b/adapter/postgresql/database.go index cea7da2e..2e608937 100644 --- a/adapter/postgresql/database.go +++ b/adapter/postgresql/database.go @@ -20,7 +20,7 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // Package postgresql provides an adapter for PostgreSQL. -// See https://github.com/upper/db/adapter/postgresql for documentation, +// See https://upper.io/v4/adapter/postgresql for documentation, // particularities and usage examples. package postgresql @@ -64,7 +64,7 @@ func (*database) Collections(sess sqladapter.Session) (collections []string, err return collections, nil } -func (*database) ConvertValue(in interface{}) interface{} { +func (*database) ConvertValue(in any) any { switch v := in.(type) { case *[]int64: return (*Int64Array)(v) @@ -74,8 +74,8 @@ func (*database) ConvertValue(in interface{}) interface{} { return (*Float64Array)(v) case *[]bool: return (*BoolArray)(v) - case *map[string]interface{}: - return (*JSONBMap)(v) + case *map[string]any: + return (*JSONBMapOf[any])(v) case []int64: return (*Int64Array)(&v) @@ -85,14 +85,14 @@ func (*database) ConvertValue(in interface{}) interface{} { return (*Float64Array)(&v) case []bool: return (*BoolArray)(&v) - case map[string]interface{}: - return (*JSONBMap)(&v) + case map[string]any: + return (*JSONBMapOf[any])(&v) } return in } -func (*database) CompileStatement(sess sqladapter.Session, stmt *exql.Statement, args []interface{}) (string, []interface{}, error) { +func (*database) CompileStatement(sess sqladapter.Session, stmt *exql.Statement, args []any) (string, []any, error) { compiled, err := stmt.Compile(template) if err != nil { return "", nil, err diff --git a/adapter/postgresql/postgresql.go b/adapter/postgresql/postgresql.go index 577f4af1..34f11bd0 100644 --- a/adapter/postgresql/postgresql.go +++ b/adapter/postgresql/postgresql.go @@ -35,17 +35,17 @@ const Adapter = "postgresql" var registeredAdapter = sqladapter.RegisterAdapter(Adapter, &database{}) // Open establishes a connection to the database server and returns a -// sqlbuilder.Session instance (which is compatible with db.Session). +// [sqladapter.Session] instance (which is compatible with [db.Session]). func Open(connURL db.ConnectionURL) (db.Session, error) { return registeredAdapter.OpenDSN(connURL) } -// NewTx creates a sqlbuilder.Tx instance by wrapping a *sql.Tx value. +// NewTx creates a [sqlbuilder.Tx] instance by wrapping a *[sql.Tx] value. func NewTx(sqlTx *sql.Tx) (sqlbuilder.Tx, error) { return registeredAdapter.NewTx(sqlTx) } -// New creates a sqlbuilder.Sesion instance by wrapping a *sql.DB value. +// New creates a [sqlbuilder.Sesion] instance by wrapping a *[sql.DB] value. func New(sqlDB *sql.DB) (db.Session, error) { return registeredAdapter.New(sqlDB) } diff --git a/adapter/postgresql/template_test.go b/adapter/postgresql/template_test.go index 22ddbaef..b80be4bc 100644 --- a/adapter/postgresql/template_test.go +++ b/adapter/postgresql/template_test.go @@ -187,7 +187,7 @@ func TestTemplateInsert(t *testing.T) { assert.Equal( `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`, - b.InsertInto("artist").Values(map[string]interface{}{"name": "Chavela Vargas", "id": 12}).String(), + b.InsertInto("artist").Values(map[string]any{"name": "Chavela Vargas", "id": 12}).String(), ) assert.Equal( diff --git a/tests/cockroachdb/cockroachdb.go b/tests/cockroachdb/cockroachdb.go index 63dba03a..3dd095d3 100644 --- a/tests/cockroachdb/cockroachdb.go +++ b/tests/cockroachdb/cockroachdb.go @@ -22,7 +22,7 @@ import ( type customJSONBObjectArray []customJSONB -func (customJSONBObjectArray) ConvertValue(in interface{}) interface { +func (customJSONBObjectArray) ConvertValue(in any) interface { sql.Scanner driver.Valuer } { @@ -35,7 +35,7 @@ func (c customJSONBObjectMap) Value() (driver.Value, error) { return cockroachdb.JSONBValue(c) } -func (c *customJSONBObjectMap) Scan(src interface{}) error { +func (c *customJSONBObjectMap) Scan(src any) error { return cockroachdb.ScanJSONB(c, src) } @@ -64,7 +64,7 @@ func (ua uint8CompatArray) Value() (driver.Value, error) { return v, nil } -func (ua *uint8CompatArray) Scan(src interface{}) error { +func (ua *uint8CompatArray) Scan(src any) error { decoded := cockroachdb.Bytea{} if err := decoded.Scan(src); err != nil { return nil @@ -80,7 +80,7 @@ func (ua *uint8CompatArray) Scan(src interface{}) error { return nil } -func (u *int64Compat) Scan(src interface{}) error { +func (u *int64Compat) Scan(src any) error { if src != nil { switch v := src.(type) { case int64: @@ -108,7 +108,7 @@ func (i64a int64CompatArray) Value() (driver.Value, error) { return v.Value() } -func (i64a *int64CompatArray) Scan(src interface{}) error { +func (i64a *int64CompatArray) Scan(src any) error { s := cockroachdb.Int64Array{} if err := s.Scan(src); err != nil { return err @@ -204,17 +204,17 @@ func (s *AdapterTests) SkipTest_Issue469_BadConnection() { func testPostgreSQLTypes(t *testing.T, sess db.Session) { type PGTypeInline struct { - IntegerArrayPtr *cockroachdb.Int64Array `db:"integer_array_ptr,omitempty"` - StringArrayPtr *cockroachdb.StringArray `db:"string_array_ptr,omitempty"` - JSONBMapPtr *cockroachdb.JSONBMap `db:"jsonb_map_ptr,omitempty"` + IntegerArrayPtr *cockroachdb.Int64Array `db:"integer_array_ptr,omitempty"` + StringArrayPtr *cockroachdb.StringArray `db:"string_array_ptr,omitempty"` + JSONBMapPtr *cockroachdb.JSONBMapOf[any] `db:"jsonb_map_ptr,omitempty"` } type PGTypeAutoInline struct { - AutoIntegerArray []int64 `db:"auto_integer_array"` - AutoStringArray []string `db:"auto_string_array"` - AutoJSONBMap map[string]interface{} `db:"auto_jsonb_map"` - AutoJSONBMapString map[string]interface{} `db:"auto_jsonb_map_string"` - AutoJSONBMapInteger map[string]interface{} `db:"auto_jsonb_map_integer"` + AutoIntegerArray []int64 `db:"auto_integer_array"` + AutoStringArray []string `db:"auto_string_array"` + AutoJSONBMap map[string]any `db:"auto_jsonb_map"` + AutoJSONBMapString map[string]any `db:"auto_jsonb_map_string"` + AutoJSONBMapInteger map[string]any `db:"auto_jsonb_map_integer"` } type PGType struct { @@ -226,16 +226,16 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { Int64Value int64Compat `db:"int64_value"` Int64ValueArray *int64CompatArray `db:"int64_value_array"` - IntegerArray cockroachdb.Int64Array `db:"integer_array"` - StringArray cockroachdb.StringArray `db:"string_array,stringarray"` - JSONBMap cockroachdb.JSONBMap `db:"jsonb_map"` + IntegerArray cockroachdb.Int64Array `db:"integer_array"` + StringArray cockroachdb.StringArray `db:"string_array,stringarray"` + JSONBMap cockroachdb.JSONBMapOf[any] `db:"jsonb_map"` PGTypeInline `db:",inline"` PGTypeAutoInline `db:",inline"` - JSONBObject cockroachdb.JSONB `db:"jsonb_object"` - JSONBArray cockroachdb.JSONBArray `db:"jsonb_array"` + JSONBObject cockroachdb.JSONB `db:"jsonb_object"` + JSONBArray cockroachdb.JSONBArrayOf[any] `db:"jsonb_array"` CustomJSONBObject customJSONB `db:"custom_jsonb_object"` AutoCustomJSONBObject customJSONB `db:"auto_custom_jsonb_object"` @@ -255,9 +255,9 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { UIntCompatValue uintCompat `db:"uinteger_compat_value"` StringCompatValue stringCompat `db:"string_compat_value"` - Int64CompatValueJSONBArray cockroachdb.JSONBArray `db:"integer_compat_value_jsonb_array"` - UIntCompatValueJSONBArray cockroachdb.JSONBArray `db:"uinteger_compat_value_jsonb_array"` - StringCompatValueJSONBArray cockroachdb.JSONBArray `db:"string_compat_value_jsonb_array"` + Int64CompatValueJSONBArray cockroachdb.JSONBArrayOf[any] `db:"integer_compat_value_jsonb_array"` + UIntCompatValueJSONBArray cockroachdb.JSONBArrayOf[any] `db:"uinteger_compat_value_jsonb_array"` + StringCompatValueJSONBArray cockroachdb.JSONBArrayOf[any] `db:"string_compat_value_jsonb_array"` StringValuePtr *string `db:"string_value_ptr,omitempty"` IntegerValuePtr *int64 `db:"integer_value_ptr,omitempty"` @@ -275,7 +275,7 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { integerArrayValue := cockroachdb.Int64Array{1, 2, 3, 4} stringArrayValue := cockroachdb.StringArray{"a", "b", "c"} - jsonbMapValue := cockroachdb.JSONBMap{"Hello": "World"} + jsonbMapValue := cockroachdb.JSONBMapOf[any]{"Hello": "World"} testValue := "Hello world!" @@ -312,22 +312,22 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { StringCompatValue: "abc", }, PGType{ - Int64CompatValueJSONBArray: cockroachdb.JSONBArray{1.0, -2.0, 3.0, -4.0}, - UIntCompatValueJSONBArray: cockroachdb.JSONBArray{1.0, 2.0, 3.0, 4.0}, - StringCompatValueJSONBArray: cockroachdb.JSONBArray{"a", "b", "", "c"}, + Int64CompatValueJSONBArray: cockroachdb.JSONBArrayOf[any]{1.0, -2.0, 3.0, -4.0}, + UIntCompatValueJSONBArray: cockroachdb.JSONBArrayOf[any]{1.0, 2.0, 3.0, 4.0}, + StringCompatValueJSONBArray: cockroachdb.JSONBArrayOf[any]{"a", "b", "", "c"}, }, PGType{ - Int64CompatValueJSONBArray: cockroachdb.JSONBArray(nil), - UIntCompatValueJSONBArray: cockroachdb.JSONBArray(nil), - StringCompatValueJSONBArray: cockroachdb.JSONBArray(nil), + Int64CompatValueJSONBArray: cockroachdb.JSONBArrayOf[any](nil), + UIntCompatValueJSONBArray: cockroachdb.JSONBArrayOf[any](nil), + StringCompatValueJSONBArray: cockroachdb.JSONBArrayOf[any](nil), }, PGType{ IntegerValuePtr: &integerValue, StringValuePtr: &stringValue, DecimalValuePtr: &decimalValue, PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMapString: map[string]interface{}{"a": "x", "b": "67"}, - AutoJSONBMapInteger: map[string]interface{}{"a": 12.0, "b": 13.0}, + AutoJSONBMapString: map[string]any{"a": "x", "b": "67"}, + AutoJSONBMapInteger: map[string]any{"a": 12.0, "b": 13.0}, }, }, PGType{ @@ -362,12 +362,12 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { }, }, PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}{ + AutoJSONBMap: map[string]any{ "Hello": "world", "Roses": "red", }, }, - JSONBArray: cockroachdb.JSONBArray{float64(1), float64(2), float64(3), float64(4)}, + JSONBArray: cockroachdb.JSONBArrayOf[any]{float64(1), float64(2), float64(3), float64(4)}, }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ @@ -376,15 +376,15 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}{}, + AutoJSONBMap: map[string]any{}, }, - JSONBArray: cockroachdb.JSONBArray{}, + JSONBArray: cockroachdb.JSONBArrayOf[any]{}, }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}(nil), + AutoJSONBMap: map[string]any(nil), }, - JSONBArray: cockroachdb.JSONBArray(nil), + JSONBArray: cockroachdb.JSONBArrayOf[any](nil), }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ @@ -398,7 +398,7 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}{"hello": "world!"}, + AutoJSONBMap: map[string]any{"hello": "world!"}, }, }, PGType{ @@ -589,17 +589,17 @@ func (s *AdapterTests) TestOptionTypes() { // A struct with wrapped option types defined in the struct tags // for postgres string array and jsonb types type optionType struct { - ID int64 `db:"id,omitempty"` - Name string `db:"name"` - Tags []string `db:"tags"` - Settings map[string]interface{} `db:"settings"` + ID int64 `db:"id,omitempty"` + Name string `db:"name"` + Tags []string `db:"tags"` + Settings map[string]any `db:"settings"` } // Item 1 item1 := optionType{ Name: "Food", Tags: []string{"toronto", "pizza"}, - Settings: map[string]interface{}{"a": 1, "b": 2}, + Settings: map[string]any{"a": 1, "b": 2}, } record, err := optionTypes.Insert(item1) @@ -620,7 +620,7 @@ func (s *AdapterTests) TestOptionTypes() { item1b := &optionType{ Name: "Golang", Tags: []string{"love", "it"}, - Settings: map[string]interface{}{"go": 1, "lang": 2}, + Settings: map[string]any{"go": 1, "lang": 2}, } record, err = optionTypes.Insert(item1b) @@ -639,7 +639,7 @@ func (s *AdapterTests) TestOptionTypes() { // Item 1 C item1c := &optionType{ - Name: "Sup", Tags: []string{}, Settings: map[string]interface{}{}, + Name: "Sup", Tags: []string{}, Settings: map[string]any{}, } record, err = optionTypes.Insert(item1c) @@ -658,10 +658,10 @@ func (s *AdapterTests) TestOptionTypes() { // An option type to pointer jsonb field type optionType2 struct { - ID int64 `db:"id,omitempty"` - Name string `db:"name"` - Tags cockroachdb.StringArray `db:"tags"` - Settings *cockroachdb.JSONBMap `db:"settings"` + ID int64 `db:"id,omitempty"` + Name string `db:"name"` + Tags cockroachdb.StringArray `db:"tags"` + Settings *cockroachdb.JSONBMapOf[any] `db:"settings"` } item2 := optionType2{ @@ -688,7 +688,7 @@ func (s *AdapterTests) TestOptionTypes() { s.Equal(len(item2Chk.Tags), len(item2.Tags)) // Update the value - m := cockroachdb.JSONBMap{} + m := cockroachdb.JSONBMapOf[any]{} m["lang"] = "javascript" m["num"] = 31337 item2.Settings = &m @@ -704,16 +704,16 @@ func (s *AdapterTests) TestOptionTypes() { // An option type to pointer string array field type optionType3 struct { - ID int64 `db:"id,omitempty"` - Name string `db:"name"` - Tags *cockroachdb.StringArray `db:"tags"` - Settings cockroachdb.JSONBMap `db:"settings"` + ID int64 `db:"id,omitempty"` + Name string `db:"name"` + Tags *cockroachdb.StringArray `db:"tags"` + Settings cockroachdb.JSONBMapOf[any] `db:"settings"` } item3 := optionType3{ Name: "Julia", Tags: nil, - Settings: cockroachdb.JSONBMap{"girl": true, "lang": true}, + Settings: cockroachdb.JSONBMapOf[any]{"girl": true, "lang": true}, } record, err = optionTypes.Insert(item3) @@ -733,7 +733,7 @@ type Settings struct { Num int64 `json:"num"` } -func (s *Settings) Scan(src interface{}) error { +func (s *Settings) Scan(src any) error { return cockroachdb.ScanJSONB(s, src) } func (s Settings) Value() (driver.Value, error) { @@ -951,7 +951,7 @@ func (s *AdapterTests) Test_Issue409_TxOptions() { err := sess.TxContext(context.Background(), func(tx db.Session) error { col := tx.Collection("publication") - row := map[string]interface{}{ + row := map[string]any{ "title": "foo", "author_id": 1, } diff --git a/tests/postgresql/postgresql.go b/tests/postgresql/postgresql.go index 441d0a1d..d2a3b06f 100644 --- a/tests/postgresql/postgresql.go +++ b/tests/postgresql/postgresql.go @@ -23,7 +23,7 @@ import ( type customJSONBObjectArray []customJSONB -func (customJSONBObjectArray) ConvertValue(in interface{}) interface { +func (customJSONBObjectArray) ConvertValue(in any) interface { sql.Scanner driver.Valuer } { @@ -36,7 +36,7 @@ func (c customJSONBObjectMap) Value() (driver.Value, error) { return postgresql.JSONBValue(c) } -func (c *customJSONBObjectMap) Scan(src interface{}) error { +func (c *customJSONBObjectMap) Scan(src any) error { return postgresql.ScanJSONB(c, src) } @@ -65,7 +65,7 @@ func (ua uint8CompatArray) Value() (driver.Value, error) { return v, nil } -func (ua *uint8CompatArray) Scan(src interface{}) error { +func (ua *uint8CompatArray) Scan(src any) error { decoded := postgresql.Bytea{} if err := decoded.Scan(src); err != nil { return nil @@ -91,7 +91,7 @@ func (i64a int64CompatArray) Value() (driver.Value, error) { return v.Value() } -func (i64a *int64CompatArray) Scan(src interface{}) error { +func (i64a *int64CompatArray) Scan(src any) error { s := postgresql.Int64Array{} if err := s.Scan(src); err != nil { return err @@ -185,17 +185,17 @@ func (s *AdapterTests) Test_Issue469_BadConnection() { func testPostgreSQLTypes(t *testing.T, sess db.Session) { type PGTypeInline struct { - IntegerArrayPtr *postgresql.Int64Array `db:"integer_array_ptr,omitempty"` - StringArrayPtr *postgresql.StringArray `db:"string_array_ptr,omitempty"` - JSONBMapPtr *postgresql.JSONBMap `db:"jsonb_map_ptr,omitempty"` + IntegerArrayPtr *postgresql.Int64Array `db:"integer_array_ptr,omitempty"` + StringArrayPtr *postgresql.StringArray `db:"string_array_ptr,omitempty"` + JSONBMapPtr *postgresql.JSONBMapOf[any] `db:"jsonb_map_ptr,omitempty"` } type PGTypeAutoInline struct { - AutoIntegerArray []int64 `db:"auto_integer_array"` - AutoStringArray []string `db:"auto_string_array"` - AutoJSONBMap map[string]interface{} `db:"auto_jsonb_map"` - AutoJSONBMapString map[string]interface{} `db:"auto_jsonb_map_string"` - AutoJSONBMapInteger map[string]interface{} `db:"auto_jsonb_map_integer"` + AutoIntegerArray []int64 `db:"auto_integer_array"` + AutoStringArray []string `db:"auto_string_array"` + AutoJSONBMap map[string]any `db:"auto_jsonb_map"` + AutoJSONBMapString map[string]any `db:"auto_jsonb_map_string"` + AutoJSONBMapInteger map[string]any `db:"auto_jsonb_map_integer"` } type PGType struct { @@ -207,9 +207,9 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { Int64Value int64Compat `db:"int64_value"` Int64ValueArray *int64CompatArray `db:"int64_value_array"` - IntegerArray postgresql.Int64Array `db:"integer_array"` - StringArray postgresql.StringArray `db:"string_array,stringarray"` - JSONBMap postgresql.JSONBMap `db:"jsonb_map"` + IntegerArray postgresql.Int64Array `db:"integer_array"` + StringArray postgresql.StringArray `db:"string_array,stringarray"` + JSONBMap postgresql.JSONBMapOf[any] `db:"jsonb_map"` RawJSONBMap *json.RawMessage `db:"raw_jsonb_map,omitempty"` RawJSONBText *json.RawMessage `db:"raw_jsonb_text,omitempty"` @@ -218,8 +218,8 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { PGTypeAutoInline `db:",inline"` - JSONBObject postgresql.JSONB `db:"jsonb_object"` - JSONBArray postgresql.JSONBArray `db:"jsonb_array"` + JSONBObject postgresql.JSONB `db:"jsonb_object"` + JSONBArray postgresql.JSONBArrayOf[any] `db:"jsonb_array"` CustomJSONBObject customJSONB `db:"custom_jsonb_object"` AutoCustomJSONBObject customJSONB `db:"auto_custom_jsonb_object"` @@ -239,9 +239,9 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { UIntCompatValue uintCompat `db:"uinteger_compat_value"` StringCompatValue stringCompat `db:"string_compat_value"` - Int64CompatValueJSONBArray postgresql.JSONBArray `db:"integer_compat_value_jsonb_array"` - UIntCompatValueJSONBArray postgresql.JSONBArray `db:"uinteger_compat_value_jsonb_array"` - StringCompatValueJSONBArray postgresql.JSONBArray `db:"string_compat_value_jsonb_array"` + Int64CompatValueJSONBArray postgresql.JSONBArrayOf[any] `db:"integer_compat_value_jsonb_array"` + UIntCompatValueJSONBArray postgresql.JSONBArrayOf[any] `db:"uinteger_compat_value_jsonb_array"` + StringCompatValueJSONBArray postgresql.JSONBArrayOf[any] `db:"string_compat_value_jsonb_array"` StringValuePtr *string `db:"string_value_ptr,omitempty"` IntegerValuePtr *int64 `db:"integer_value_ptr,omitempty"` @@ -261,7 +261,7 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { integerArrayValue := postgresql.Int64Array{1, 2, 3, 4} stringArrayValue := postgresql.StringArray{"a", "b", "c"} - jsonbMapValue := postgresql.JSONBMap{"Hello": "World"} + jsonbMapValue := postgresql.JSONBMapOf[any]{"Hello": "World"} rawJSONBMap := json.RawMessage(`{"foo": "bar"}`) rawJSONBText := json.RawMessage(`{"age": [{">": "1h"}]}`) @@ -300,22 +300,22 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { StringCompatValue: "abc", }, PGType{ - Int64CompatValueJSONBArray: postgresql.JSONBArray{1.0, -2.0, 3.0, -4.0}, - UIntCompatValueJSONBArray: postgresql.JSONBArray{1.0, 2.0, 3.0, 4.0}, - StringCompatValueJSONBArray: postgresql.JSONBArray{"a", "b", "", "c"}, + Int64CompatValueJSONBArray: postgresql.JSONBArrayOf[any]{1.0, -2.0, 3.0, -4.0}, + UIntCompatValueJSONBArray: postgresql.JSONBArrayOf[any]{1.0, 2.0, 3.0, 4.0}, + StringCompatValueJSONBArray: postgresql.JSONBArrayOf[any]{"a", "b", "", "c"}, }, PGType{ - Int64CompatValueJSONBArray: postgresql.JSONBArray(nil), - UIntCompatValueJSONBArray: postgresql.JSONBArray(nil), - StringCompatValueJSONBArray: postgresql.JSONBArray(nil), + Int64CompatValueJSONBArray: postgresql.JSONBArrayOf[any](nil), + UIntCompatValueJSONBArray: postgresql.JSONBArrayOf[any](nil), + StringCompatValueJSONBArray: postgresql.JSONBArrayOf[any](nil), }, PGType{ IntegerValuePtr: &integerValue, StringValuePtr: &stringValue, DecimalValuePtr: &decimalValue, PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMapString: map[string]interface{}{"a": "x", "b": "67"}, - AutoJSONBMapInteger: map[string]interface{}{"a": 12.0, "b": 13.0}, + AutoJSONBMapString: map[string]any{"a": "x", "b": "67"}, + AutoJSONBMapInteger: map[string]any{"a": 12.0, "b": 13.0}, }, }, PGType{ @@ -354,12 +354,12 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { }, }, PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}{ + AutoJSONBMap: map[string]any{ "Hello": "world", "Roses": "red", }, }, - JSONBArray: postgresql.JSONBArray{float64(1), float64(2), float64(3), float64(4)}, + JSONBArray: postgresql.JSONBArrayOf[any]{float64(1), float64(2), float64(3), float64(4)}, }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ @@ -368,15 +368,15 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}{}, + AutoJSONBMap: map[string]any{}, }, - JSONBArray: postgresql.JSONBArray{}, + JSONBArray: postgresql.JSONBArrayOf[any]{}, }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}(nil), + AutoJSONBMap: map[string]any(nil), }, - JSONBArray: postgresql.JSONBArray(nil), + JSONBArray: postgresql.JSONBArrayOf[any](nil), }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ @@ -390,7 +390,7 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) { }, PGType{ PGTypeAutoInline: PGTypeAutoInline{ - AutoJSONBMap: map[string]interface{}{"hello": "world!"}, + AutoJSONBMap: map[string]any{"hello": "world!"}, }, }, PGType{ @@ -582,17 +582,17 @@ func (s *AdapterTests) TestOptionTypes() { // A struct with wrapped option types defined in the struct tags // for postgres string array and jsonb types type optionType struct { - ID int64 `db:"id,omitempty"` - Name string `db:"name"` - Tags []string `db:"tags"` - Settings map[string]interface{} `db:"settings"` + ID int64 `db:"id,omitempty"` + Name string `db:"name"` + Tags []string `db:"tags"` + Settings map[string]any `db:"settings"` } // Item 1 item1 := optionType{ Name: "Food", Tags: []string{"toronto", "pizza"}, - Settings: map[string]interface{}{"a": 1, "b": 2}, + Settings: map[string]any{"a": 1, "b": 2}, } record, err := optionTypes.Insert(item1) @@ -613,7 +613,7 @@ func (s *AdapterTests) TestOptionTypes() { item1b := &optionType{ Name: "Golang", Tags: []string{"love", "it"}, - Settings: map[string]interface{}{"go": 1, "lang": 2}, + Settings: map[string]any{"go": 1, "lang": 2}, } record, err = optionTypes.Insert(item1b) @@ -632,7 +632,7 @@ func (s *AdapterTests) TestOptionTypes() { // Item 1 C item1c := &optionType{ - Name: "Sup", Tags: []string{}, Settings: map[string]interface{}{}, + Name: "Sup", Tags: []string{}, Settings: map[string]any{}, } record, err = optionTypes.Insert(item1c) @@ -651,10 +651,10 @@ func (s *AdapterTests) TestOptionTypes() { // An option type to pointer jsonb field type optionType2 struct { - ID int64 `db:"id,omitempty"` - Name string `db:"name"` - Tags postgresql.StringArray `db:"tags"` - Settings *postgresql.JSONBMap `db:"settings"` + ID int64 `db:"id,omitempty"` + Name string `db:"name"` + Tags postgresql.StringArray `db:"tags"` + Settings *postgresql.JSONBMapOf[any] `db:"settings"` } item2 := optionType2{ @@ -681,7 +681,7 @@ func (s *AdapterTests) TestOptionTypes() { s.Equal(len(item2Chk.Tags), len(item2.Tags)) // Update the value - m := postgresql.JSONBMap{} + m := postgresql.JSONBMapOf[any]{} m["lang"] = "javascript" m["num"] = 31337 item2.Settings = &m @@ -697,16 +697,16 @@ func (s *AdapterTests) TestOptionTypes() { // An option type to pointer string array field type optionType3 struct { - ID int64 `db:"id,omitempty"` - Name string `db:"name"` - Tags *postgresql.StringArray `db:"tags"` - Settings postgresql.JSONBMap `db:"settings"` + ID int64 `db:"id,omitempty"` + Name string `db:"name"` + Tags *postgresql.StringArray `db:"tags"` + Settings postgresql.JSONBMapOf[any] `db:"settings"` } item3 := optionType3{ Name: "Julia", Tags: nil, - Settings: postgresql.JSONBMap{"girl": true, "lang": true}, + Settings: postgresql.JSONBMapOf[any]{"girl": true, "lang": true}, } record, err = optionTypes.Insert(item3) @@ -726,7 +726,7 @@ type Settings struct { Num int64 `json:"num"` } -func (s *Settings) Scan(src interface{}) error { +func (s *Settings) Scan(src any) error { return postgresql.ScanJSONB(s, src) } func (s Settings) Value() (driver.Value, error) { @@ -1038,7 +1038,7 @@ func (s *AdapterTests) Test_Issue409_TxOptions() { err := sess.TxContext(context.Background(), func(tx db.Session) error { col := tx.Collection("publication") - row := map[string]interface{}{ + row := map[string]any{ "title": "foo", "author_id": 1, } @@ -1383,7 +1383,7 @@ func (s *AdapterTests) TestNonTrivialSubqueries() { } func (s *AdapterTests) Test_Issue601_ErrorCarrying() { - var items []interface{} + var items []any var err error sess := s.Session()