Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ sql.notify('news', JSON.stringify({ no: 'this', is: 'news' }))

This also means you cannot write dynamic queries or concat queries together by simple string manipulation. To enable dynamic queries in a safe way, the `sql` function doubles as a regular function which escapes any value properly. It also includes overloads for common cases of inserting, selecting, updating and querying.

## Dynamic query helpers `sql() inside tagged template`
## Dynamic query helpers - `sql()` inside tagged template

Postgres.js has a safe, ergonomic way to aid you in writing queries. This makes it easier to write dynamic inserts, selects, updates and where queries.
Postgres.js has a safe, ergonomic way to aid you in writing queries. This makes it easier to write dynamic `insert`, `select` and `update` queries, and pass `where` parameters.

#### Insert

Expand Down Expand Up @@ -272,7 +272,6 @@ sql`
sql(users, 'name', 'age')
}
`

```

#### Update
Expand Down Expand Up @@ -312,6 +311,20 @@ sql`
select name, age from users
```

#### Dynamic table name

```js

const table = 'users'

sql`
select id from ${sql(table)}
`

// Is translated into this query:
select id from users
```

#### Arrays `sql.array(Array)`

PostgreSQL has a native array type which is similar to js arrays, but only allows the same type and shape for nested items. This method automatically infers the item type and serializes js arrays into PostgreSQL arrays.
Expand Down