You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a step is used for a type which doesn't support that step class, the type could offer a function to attempt to coerce the step to a compatible type.
Discord user @box received Query planning error: $record.record is not a function because they attempted to use the result of object({sessionToken: withPgClientTransaction(...)).get('sessionToken') for a built in type SessionToken which expects to represent a Postgres type, and thus should use the PgSelectSingleStep or PgClassExpressionStep step classes.
However, we should be able to take an arbirary object and assume it's the right type, and convert it to a PgSelectSingleStep by piping it through json_populate_record or similar. For example:
functionpgSelectSingleFromObject(resource: PgResource,$obj: ExecutableStep): PgSelectSingle{const$records=pgSelect({identifiers: [],
resource,from: (r)=>sql`json_populate_record(null::${resource.codec.sqlType}, ${r.placeholder})`,args: [{step: $obj,pgCodec: TYPES.json}],});return$records.single();}// ...constsessionTokenCodec=build.input.pgRegistry.pgCodecs.session_token;constresource=build.pgTableResource(sessionTokenCodec,false);SessionTokenType.extensions.grafast.coerceStep=($step)=>{if($stepinstanceofPgSelectSingleStep||$stepinstanceofPgClassExpressionStep){// No co-ercion needed; we already support these typesreturn$step;}else{// Attempt to convertreturnpgSelectSingleFromObject(resource,$step);}}
The text was updated successfully, but these errors were encountered:
Feature description
When a step is used for a type which doesn't support that step class, the type could offer a function to attempt to coerce the step to a compatible type.
Motivating example
https://discord.com/channels/489127045289476126/498852330754801666/1209806376595882014
Discord user
@box
receivedQuery planning error: $record.record is not a function
because they attempted to use the result ofobject({sessionToken: withPgClientTransaction(...)).get('sessionToken')
for a built in typeSessionToken
which expects to represent a Postgres type, and thus should use thePgSelectSingleStep
orPgClassExpressionStep
step classes.However, we should be able to take an arbirary object and assume it's the right type, and convert it to a
PgSelectSingleStep
by piping it throughjson_populate_record
or similar. For example:The text was updated successfully, but these errors were encountered: