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 <cursoragent@cursor.com>
This commit is contained in:
2026-06-29 17:47:56 -07:00
parent a303e025b2
commit 8053aafa6f
5 changed files with 30 additions and 40 deletions
+8 -9
View File
@@ -3,7 +3,6 @@ package dbx
import ( import (
"reflect" "reflect"
"github.com/go-jet/jet/v2/mysql"
"golang.org/x/exp/constraints" "golang.org/x/exp/constraints"
) )
@@ -19,8 +18,8 @@ type ApplyInterface[T any] interface {
func ApplyPtr[T constraints.Float | constraints.Integer | string | bool]( func ApplyPtr[T constraints.Float | constraints.Integer | string | bool](
existing *T, existing *T,
newVal *T, newVal *T,
updatedColumns *mysql.ColumnList, updatedColumns *ColumnList,
targetColumn mysql.Column, targetColumn Column,
) *T { ) *T {
if newVal == nil { if newVal == nil {
return existing return existing
@@ -46,8 +45,8 @@ func ApplyComplexPtr[
]( ](
existing *Existing, existing *Existing,
newVal *New, newVal *New,
updatedColumns *mysql.ColumnList, updatedColumns *ColumnList,
targetColumn mysql.Column, targetColumn Column,
) *Existing { ) *Existing {
if newVal == nil { if newVal == nil {
return existing return existing
@@ -73,8 +72,8 @@ func ApplyComplexPtr[
func ApplyInterfacePtr[T ApplyInterface[T]]( func ApplyInterfacePtr[T ApplyInterface[T]](
existing *T, existing *T,
newVal *T, newVal *T,
updatedColumns *mysql.ColumnList, updatedColumns *ColumnList,
targetColumn mysql.Column, targetColumn Column,
) *T { ) *T {
if newVal == nil { if newVal == nil {
return existing return existing
@@ -98,8 +97,8 @@ func ApplyInterfacePtr[T ApplyInterface[T]](
func ApplyVal[T constraints.Float | constraints.Integer | string | bool]( func ApplyVal[T constraints.Float | constraints.Integer | string | bool](
existing T, existing T,
newVal *T, newVal *T,
updatedColumns *mysql.ColumnList, updatedColumns *ColumnList,
targetColumn mysql.Column, targetColumn Column,
) T { ) T {
if newVal == nil { if newVal == nil {
return existing return existing
+1 -1
View File
@@ -13,7 +13,7 @@
// //
// # Jet column utilities // # 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]). // lists ([NormalCols]) and expression building ([ExprValues]).
// //
// Partial-update helpers ([ApplyPtr], [ApplyVal]) track changed fields for // Partial-update helpers ([ApplyPtr], [ApplyVal]) track changed fields for
+5 -5
View File
@@ -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 // NormalCols processes a list of columns and strips out any that implement any of
// ColumnTimestamp, ColumnTime, or ColumnDate. // ColumnTimestamp, ColumnTime, or ColumnDate.
func NormalCols[CL ColumnList](cols ...Column) CL { func NormalCols(cols ...Column) ColumnList {
res := make(CL, 0) res := make(ColumnList, 0)
for _, col := range cols { for _, col := range cols {
switch col.(type) { switch col.(type) {
case mysql.ColumnTimestamp, // = postgres.ColumnTimestamp case mysql.ColumnTimestamp,
mysql.ColumnTime, // = postgres.ColumnTime mysql.ColumnTime,
mysql.ColumnDate: // = postgres.ColumnDate mysql.ColumnDate:
default: default:
res = append(res, col) res = append(res, col)
} }
+6 -6
View File
@@ -6,19 +6,19 @@ import (
"github.com/go-jet/jet/v2/mysql" "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). // 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 { func ExprValues[T any](values []T, f func(T) Expression) []Expression {
expressions := make([]mysql.Expression, len(values)) expressions := make([]Expression, len(values))
for i, v := range values { for i, v := range values {
expressions[i] = f(v) expressions[i] = f(v)
} }
return expressions return expressions
} }
// ExprStringers converts a list of fmt.Stringers to a list of mysql.Expression values. // ExprStringers converts a list of fmt.Stringers to a list of Expression values.
func ExprStringers(values []fmt.Stringer) []mysql.Expression { func ExprStringers(values []fmt.Stringer) []Expression {
expressions := make([]mysql.Expression, len(values)) expressions := make([]Expression, len(values))
for i, v := range values { for i, v := range values {
expressions[i] = mysql.String(v.String()) expressions[i] = mysql.String(v.String())
} }
+10 -19
View File
@@ -1,24 +1,15 @@
package dbx package dbx
import ( import "github.com/go-jet/jet/v2/mysql"
"github.com/go-jet/jet/v2/mysql"
"github.com/go-jet/jet/v2/postgres"
)
// Column is a union type for mysql.Column and postgres.Column // Column is a dialect-neutral alias for Jet column expressions.
type Column interface { type Column = mysql.Column
mysql.Column
postgres.Column
}
// ColumnList is a union type for mysql.ColumnList and postgres.ColumnList // ColumnList is a dialect-neutral alias for Jet column lists.
type ColumnList interface { type ColumnList = mysql.ColumnList
mysql.ColumnList
postgres.ColumnList
}
// BoolExpression is a union type for mysql.BoolExpression and postgres.BoolExpression // Expression is a dialect-neutral alias for Jet SQL expressions.
type BoolExpression interface { type Expression = mysql.Expression
mysql.BoolExpression
postgres.BoolExpression // BoolExpression is a dialect-neutral alias for Jet boolean expressions.
} type BoolExpression = mysql.BoolExpression