feat(jet): add ExprPtrs for pointer slice expressions

ExprPtrs dereferences []*T values, skips nil entries, and maps survivors
through a converter.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-29 18:48:32 -07:00
parent a712ccc38f
commit 7e30272020
5 changed files with 30 additions and 3 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
- `Query`, `MustQuery`, and `UpdateOne` helpers (+ Context variants).
- `WithTxValue` for transactional functions that return a value.
- `QueryCount`, `BuildQueryCountFn`, and `CountResult` for pagination counts.
- `StringKSUIDExpr`, `BinaryKSUIDExpr`, and flexible `Parse*Any` KSUID parsers.
- `StringKSUIDExpr`, `BinaryKSUIDExpr`, `ExprPtrs`, and flexible `Parse*Any` KSUID parsers.
- `MarshalUint64` and `UnmarshalUint64` for JS-safe GraphQL uint64 scalars.
- Context-aware variants for all query and mutation helpers.
- `Delete`, `DeleteAffected`, `WithTx`, `ContainsCol`, and `CurrentDialect()`.
+1 -1
View File
@@ -45,7 +45,7 @@ For Postgres, use `dbx.DialectPostgres` and blank-import `dbxp` instead of `dbxm
| Query | `Fetch`, `MustFetch`, `FetchOne`, `MustFetchOne`, `Query`, `MustQuery` (+ `*Context` variants) |
| Mutations | `Insert`, `InsertReturning`, `Update`, `UpdateAffected`, `UpdateOne`, `UpdateReturning`, `Delete`, `DeleteAffected` (+ `*Context` variants) |
| Transactions | `WithTx`, `WithTxValue` |
| Columns | `NormalCols`, `ContainsCol`, `ExprValues`, `ExprStringers`, `StringKSUIDExpr`, `BinaryKSUIDExpr`, `QueryCount`, `BuildQueryCountFn` |
| Columns | `NormalCols`, `ContainsCol`, `ExprValues`, `ExprPtrs`, `ExprStringers`, `StringKSUIDExpr`, `BinaryKSUIDExpr`, `QueryCount`, `BuildQueryCountFn` |
| Partial update | `ApplyPtr`, `ApplyComplexPtr`, `ApplyInterfacePtr`, `ApplyVal` |
| Pointers | `Ptr`, `Val`, `NowPtr`, `TrimPtr`, `TrimPtrToNil`, `IsZero` |
| Types | `StringKSUID`, `BinaryKSUID`, `JSONB` |
+1 -1
View File
@@ -17,7 +17,7 @@
//
// Dialect-neutral type aliases ([Column], [ColumnList]) and helpers for column
// lists ([NormalCols], [ContainsCol]) and expression building ([ExprValues],
// [StringKSUIDExpr], [BinaryKSUIDExpr]).
// [ExprPtrs], [StringKSUIDExpr], [BinaryKSUIDExpr]).
// [QueryCount] and [BuildQueryCountFn] support pagination total counts.
//
// Partial-update helpers ([ApplyPtr], [ApplyVal]) track changed fields for
+13
View File
@@ -16,6 +16,19 @@ func ExprValues[T any](values []T, f func(T) Expression) []Expression {
return expressions
}
// ExprPtrs converts a list of pointers to Expression values, skipping nil
// entries. Function f receives the dereferenced value.
func ExprPtrs[T any](values []*T, f func(T) Expression) []Expression {
expressions := make([]Expression, 0, len(values))
for _, v := range values {
if v == nil {
continue
}
expressions = append(expressions, 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))
+14
View File
@@ -29,6 +29,20 @@ func TestBinaryKSUIDExpr(t *testing.T) {
assert.Equal(t, nilExpr, NilBinaryKSUID.Expr())
}
func TestExprPtrs_StringKSUID(t *testing.T) {
a := NewStringKSUID()
b := NewStringKSUID()
exprs := ExprPtrs([]*StringKSUID{&a, nil, &b}, StringKSUIDExpr)
require.Len(t, exprs, 2)
}
func TestExprPtrs_BinaryKSUID(t *testing.T) {
a := NewBinaryKSUID()
exprs := ExprPtrs([]*BinaryKSUID{&a, nil}, BinaryKSUIDExpr)
require.Len(t, exprs, 1)
assert.NotNil(t, exprs[0])
}
func TestExprValues_StringKSUID(t *testing.T) {
a := NewStringKSUID()
b := NewStringKSUID()