From 4733ed277381a57e68e24faeb714484c47108f65 Mon Sep 17 00:00:00 2001 From: Yassine R Date: Wed, 24 Aug 2022 17:00:53 +0200 Subject: [PATCH] docs: add doc for json columns --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 6bf42ef0..09177a76 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,30 @@ const [{ a, b, c }] => await sql` ` ``` +### Update jsonb columns +If you want to update a jsonb column, you have to use "sql.json()" +```js +const user = { + id: 1, + location: { + city: "Toronto", + street: "1st michel avenue", + country: "Canada" + } + name: 'Murray', +} + +sql` + update users set location = ${ + sql.json(user.location) + } + where user_id = ${ user.id } +` + +// Which results in: +update users set "location" = $1 where user_id = $2 +``` + ## Building queries Postgres.js features a simple dynamic query builder by conditionally appending/omitting query fragments.