Hi, thanks for this great library.
I found a mismatch between documentation and runtime behavior for .then.val().
Summary
The README says .then.val() returns the first item (or undefined), but in practice it returns an Actionable object (query expression helpers), not the first element of the executed query result.
Documentation reference
Reproduction
Environment:
- surqlize: 0.1.0
- surrealdb: 2.0.3
- runtime: bun
Minimal script:
const user = await db.select("user").then.val();
const users = await db.select("user");
console.log(user, users[0]);
Actual behavior
- user is an Actionable-like object (contains methods like eq, contains, at, val, etc.)
- users[0] is the actual first record object
Expected behavior
- user should be the first record (or undefined), consistent with README
Likely root cause
In source, val delegates to at(0), and at returns a databaseFunction expression (Actionable), not a resolved JS array element:
- val implementation:
|
): Actionable<C, OptionType<T>>; |
|
function val<C extends WorkableContext, T extends AbstractType>( |
|
this: Workable<C, ArrayType<T>>, |
|
) { |
|
// Call at() with literal 0 to get the first element |
|
// Type assertion is safe as we're calling the at() function with correct parameters |
|
type AtFunction = ( |
|
this: Workable<C, ArrayType<T>>, |
|
n: IntoWorkable<C, LiteralType<0>>, |
|
) => unknown; |
|
return (at as AtFunction).call( |
|
this, |
|
intoWorkable(this[__ctx], t.literal(0), 0), |
|
); |
|
} |
- at implementation in same file returns array::at expression
Also, Query.then returns a function merged with actionable helpers, so .then.val() appears to bind to query-expression functions rather than resolved result-array helpers.
Hi, thanks for this great library.
I found a mismatch between documentation and runtime behavior for .then.val().
Summary
The README says .then.val() returns the first item (or undefined), but in practice it returns an Actionable object (query expression helpers), not the first element of the executed query result.
Documentation reference
Reproduction
Environment:
Minimal script:
Actual behavior
Expected behavior
Likely root cause
In source, val delegates to at(0), and at returns a databaseFunction expression (Actionable), not a resolved JS array element:
surqlize/src/functions/types/array.ts
Lines 833 to 847 in 9d989b6
Also, Query.then returns a function merged with actionable helpers, so .then.val() appears to bind to query-expression functions rather than resolved result-array helpers.