Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
webda2l committed Oct 15, 2024
1 parent a1d54b8 commit b4426fc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,35 @@ const allUsersPaginated = await schemQl.all({
ORDER BY ${'@users.id'} ${s.sqlCond(data.query.dir === 'prev', 'DESC', 'ASC')}
LIMIT ${':limit'}
`)

// Automatically stringify JSON params 'metadata' (by schemQl if enabled)
// and get parsed JSON metadata, as well (if Zod preprocess set rightly)
const firstSession = await schemQl.firstOrThrow({
params: {
id: uuidv4(),
user_id: 'uuid-1',
metadata: {
account: 'credentials',
},
expiresAtAdd: 10000,
},
paramsSchema: z.object({
...zSessionDb.pick({ id: true, user_id: true, metadata: true }).shape,
expiresAtAdd: z.number().int(),
}),
resultSchema: zSessionDb,
})((s) => s.sql`
INSERT INTO
${{ sessions: ['id', 'user_id', 'metadata', 'expires_at'] }}
VALUES
(
${':id'}
, ${':user_id'}
, json(${':metadata'})
, strftime('%s', 'now') + ${':expiresAtAdd'}
)
RETURNING *
`)
```
</details>

Expand Down

0 comments on commit b4426fc

Please sign in to comment.