a712ccc38f
Adds StringKSUIDExpr and BinaryKSUIDExpr for use with ExprValues, plus Expr() methods on both types. Removes ExprStringKSUIDs and BinExpr. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package dbx
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/go-jet/jet/v2/mysql"
|
|
)
|
|
|
|
// 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) 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 Expression values.
|
|
func ExprStringers(values []fmt.Stringer) []Expression {
|
|
expressions := make([]Expression, len(values))
|
|
for i, v := range values {
|
|
expressions[i] = mysql.String(v.String())
|
|
}
|
|
return expressions
|
|
}
|
|
|
|
// StringKSUIDExpr returns a Jet expression for a string-encoded KSUID column.
|
|
func StringKSUIDExpr(id StringKSUID) Expression {
|
|
if id.IsNil() {
|
|
return mysql.StringExp(mysql.NULL)
|
|
}
|
|
return mysql.String(id.String())
|
|
}
|
|
|
|
// BinaryKSUIDExpr returns a Jet expression for a binary-encoded KSUID column.
|
|
func BinaryKSUIDExpr(id BinaryKSUID) Expression {
|
|
if id.IsNil() {
|
|
return mysql.StringExp(mysql.NULL)
|
|
}
|
|
return mysql.String(string(id.Bytes()))
|
|
}
|