From 8053aafa6f1de3928a13da89227af0efad3d29d1 Mon Sep 17 00:00:00 2001 From: Elijah Duffy Date: Mon, 29 Jun 2026 17:47:56 -0700 Subject: [PATCH] refactor: use dialect-neutral Jet type aliases Replace mysql/postgres intersection interfaces with mysql type aliases per go-jet/jet#555 and generalize Apply/Expr signatures. Co-authored-by: Cursor --- apply.go | 17 ++++++++--------- doc.go | 2 +- jet_columns.go | 10 +++++----- jet_expr.go | 12 ++++++------ jet_types.go | 29 ++++++++++------------------- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/apply.go b/apply.go index a40137d..7ddd9b1 100644 --- a/apply.go +++ b/apply.go @@ -3,7 +3,6 @@ package dbx import ( "reflect" - "github.com/go-jet/jet/v2/mysql" "golang.org/x/exp/constraints" ) @@ -19,8 +18,8 @@ type ApplyInterface[T any] interface { func ApplyPtr[T constraints.Float | constraints.Integer | string | bool]( existing *T, newVal *T, - updatedColumns *mysql.ColumnList, - targetColumn mysql.Column, + updatedColumns *ColumnList, + targetColumn Column, ) *T { if newVal == nil { return existing @@ -46,8 +45,8 @@ func ApplyComplexPtr[ ]( existing *Existing, newVal *New, - updatedColumns *mysql.ColumnList, - targetColumn mysql.Column, + updatedColumns *ColumnList, + targetColumn Column, ) *Existing { if newVal == nil { return existing @@ -73,8 +72,8 @@ func ApplyComplexPtr[ func ApplyInterfacePtr[T ApplyInterface[T]]( existing *T, newVal *T, - updatedColumns *mysql.ColumnList, - targetColumn mysql.Column, + updatedColumns *ColumnList, + targetColumn Column, ) *T { if newVal == nil { return existing @@ -98,8 +97,8 @@ func ApplyInterfacePtr[T ApplyInterface[T]]( func ApplyVal[T constraints.Float | constraints.Integer | string | bool]( existing T, newVal *T, - updatedColumns *mysql.ColumnList, - targetColumn mysql.Column, + updatedColumns *ColumnList, + targetColumn Column, ) T { if newVal == nil { return existing diff --git a/doc.go b/doc.go index b533d4c..ff93c15 100644 --- a/doc.go +++ b/doc.go @@ -13,7 +13,7 @@ // // # Jet column utilities // -// Dialect-neutral union types ([Column], [ColumnList]) and helpers for column +// Dialect-neutral type aliases ([Column], [ColumnList]) and helpers for column // lists ([NormalCols]) and expression building ([ExprValues]). // // Partial-update helpers ([ApplyPtr], [ApplyVal]) track changed fields for diff --git a/jet_columns.go b/jet_columns.go index 3f013db..73f89ec 100644 --- a/jet_columns.go +++ b/jet_columns.go @@ -4,14 +4,14 @@ import "github.com/go-jet/jet/v2/mysql" // NormalCols processes a list of columns and strips out any that implement any of // ColumnTimestamp, ColumnTime, or ColumnDate. -func NormalCols[CL ColumnList](cols ...Column) CL { - res := make(CL, 0) +func NormalCols(cols ...Column) ColumnList { + res := make(ColumnList, 0) for _, col := range cols { switch col.(type) { - case mysql.ColumnTimestamp, // = postgres.ColumnTimestamp - mysql.ColumnTime, // = postgres.ColumnTime - mysql.ColumnDate: // = postgres.ColumnDate + case mysql.ColumnTimestamp, + mysql.ColumnTime, + mysql.ColumnDate: default: res = append(res, col) } diff --git a/jet_expr.go b/jet_expr.go index 01146cf..81a5e07 100644 --- a/jet_expr.go +++ b/jet_expr.go @@ -6,19 +6,19 @@ import ( "github.com/go-jet/jet/v2/mysql" ) -// ExprValues converts a list of values to a list of mysql.Expression values using +// ExprValues converts a list of values to a list of Expression values using // function f to transform the values (mysql.String for strings, mysql.Uint64, etc). -func ExprValues[T any](values []T, f func(T) mysql.Expression) []mysql.Expression { - expressions := make([]mysql.Expression, len(values)) +func ExprValues[T any](values []T, f func(T) Expression) []Expression { + expressions := make([]Expression, len(values)) for i, v := range values { expressions[i] = f(v) } return expressions } -// ExprStringers converts a list of fmt.Stringers to a list of mysql.Expression values. -func ExprStringers(values []fmt.Stringer) []mysql.Expression { - expressions := make([]mysql.Expression, len(values)) +// ExprStringers converts a list of fmt.Stringers to a list of Expression values. +func ExprStringers(values []fmt.Stringer) []Expression { + expressions := make([]Expression, len(values)) for i, v := range values { expressions[i] = mysql.String(v.String()) } diff --git a/jet_types.go b/jet_types.go index 05d2fcb..5e0c85b 100644 --- a/jet_types.go +++ b/jet_types.go @@ -1,24 +1,15 @@ package dbx -import ( - "github.com/go-jet/jet/v2/mysql" - "github.com/go-jet/jet/v2/postgres" -) +import "github.com/go-jet/jet/v2/mysql" -// Column is a union type for mysql.Column and postgres.Column -type Column interface { - mysql.Column - postgres.Column -} +// Column is a dialect-neutral alias for Jet column expressions. +type Column = mysql.Column -// ColumnList is a union type for mysql.ColumnList and postgres.ColumnList -type ColumnList interface { - mysql.ColumnList - postgres.ColumnList -} +// ColumnList is a dialect-neutral alias for Jet column lists. +type ColumnList = mysql.ColumnList -// BoolExpression is a union type for mysql.BoolExpression and postgres.BoolExpression -type BoolExpression interface { - mysql.BoolExpression - postgres.BoolExpression -} +// Expression is a dialect-neutral alias for Jet SQL expressions. +type Expression = mysql.Expression + +// BoolExpression is a dialect-neutral alias for Jet boolean expressions. +type BoolExpression = mysql.BoolExpression