Skip to content

Commit

Permalink
docs: add doc for json columns
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine authored Aug 24, 2022
1 parent 65dcf0d commit 4733ed2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4733ed2

Please sign in to comment.