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:
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
- `Query`, `MustQuery`, and `UpdateOne` helpers (+ Context variants).
|
- `Query`, `MustQuery`, and `UpdateOne` helpers (+ Context variants).
|
||||||
- `WithTxValue` for transactional functions that return a value.
|
- `WithTxValue` for transactional functions that return a value.
|
||||||
- `QueryCount`, `BuildQueryCountFn`, and `CountResult` for pagination counts.
|
- `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.
|
- `MarshalUint64` and `UnmarshalUint64` for JS-safe GraphQL uint64 scalars.
|
||||||
- Context-aware variants for all query and mutation helpers.
|
- Context-aware variants for all query and mutation helpers.
|
||||||
- `Delete`, `DeleteAffected`, `WithTx`, `ContainsCol`, and `CurrentDialect()`.
|
- `Delete`, `DeleteAffected`, `WithTx`, `ContainsCol`, and `CurrentDialect()`.
|
||||||
|
|||||||
@@ -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) |
|
| Query | `Fetch`, `MustFetch`, `FetchOne`, `MustFetchOne`, `Query`, `MustQuery` (+ `*Context` variants) |
|
||||||
| Mutations | `Insert`, `InsertReturning`, `Update`, `UpdateAffected`, `UpdateOne`, `UpdateReturning`, `Delete`, `DeleteAffected` (+ `*Context` variants) |
|
| Mutations | `Insert`, `InsertReturning`, `Update`, `UpdateAffected`, `UpdateOne`, `UpdateReturning`, `Delete`, `DeleteAffected` (+ `*Context` variants) |
|
||||||
| Transactions | `WithTx`, `WithTxValue` |
|
| 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` |
|
| Partial update | `ApplyPtr`, `ApplyComplexPtr`, `ApplyInterfacePtr`, `ApplyVal` |
|
||||||
| Pointers | `Ptr`, `Val`, `NowPtr`, `TrimPtr`, `TrimPtrToNil`, `IsZero` |
|
| Pointers | `Ptr`, `Val`, `NowPtr`, `TrimPtr`, `TrimPtrToNil`, `IsZero` |
|
||||||
| Types | `StringKSUID`, `BinaryKSUID`, `JSONB` |
|
| Types | `StringKSUID`, `BinaryKSUID`, `JSONB` |
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
//
|
//
|
||||||
// Dialect-neutral type aliases ([Column], [ColumnList]) and helpers for column
|
// Dialect-neutral type aliases ([Column], [ColumnList]) and helpers for column
|
||||||
// lists ([NormalCols], [ContainsCol]) and expression building ([ExprValues],
|
// lists ([NormalCols], [ContainsCol]) and expression building ([ExprValues],
|
||||||
// [StringKSUIDExpr], [BinaryKSUIDExpr]).
|
// [ExprPtrs], [StringKSUIDExpr], [BinaryKSUIDExpr]).
|
||||||
// [QueryCount] and [BuildQueryCountFn] support pagination total counts.
|
// [QueryCount] and [BuildQueryCountFn] support pagination total counts.
|
||||||
//
|
//
|
||||||
// Partial-update helpers ([ApplyPtr], [ApplyVal]) track changed fields for
|
// Partial-update helpers ([ApplyPtr], [ApplyVal]) track changed fields for
|
||||||
|
|||||||
+13
@@ -16,6 +16,19 @@ func ExprValues[T any](values []T, f func(T) Expression) []Expression {
|
|||||||
return expressions
|
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.
|
// ExprStringers converts a list of fmt.Stringers to a list of Expression values.
|
||||||
func ExprStringers(values []fmt.Stringer) []Expression {
|
func ExprStringers(values []fmt.Stringer) []Expression {
|
||||||
expressions := make([]Expression, len(values))
|
expressions := make([]Expression, len(values))
|
||||||
|
|||||||
@@ -29,6 +29,20 @@ func TestBinaryKSUIDExpr(t *testing.T) {
|
|||||||
assert.Equal(t, nilExpr, NilBinaryKSUID.Expr())
|
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) {
|
func TestExprValues_StringKSUID(t *testing.T) {
|
||||||
a := NewStringKSUID()
|
a := NewStringKSUID()
|
||||||
b := NewStringKSUID()
|
b := NewStringKSUID()
|
||||||
|
|||||||
Reference in New Issue
Block a user