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
Copy file name to clipboardExpand all lines: deno/README.md
+29-1
Original file line number
Diff line number
Diff line change
@@ -228,6 +228,21 @@ sql`
228
228
update users set "name"= $1, "age"= $2 where user_id = $3
229
229
```
230
230
231
+
### Multiple updates in one query
232
+
It's possible to create multiple udpates in a single query. It's necessary to use arrays intead of objects to ensure the order of the items so that these correspond with the column names.
233
+
```js
234
+
constusers= [
235
+
[1, 'John', 34],
236
+
[2, 'Jane', 27],
237
+
]
238
+
239
+
sql`
240
+
update users set name =update_data.name, age =update_data.age
241
+
from (values${sql(users)}) as update_data (id, name, age)
242
+
whereusers.id=update_data.id
243
+
`
244
+
```
245
+
231
246
### Dynamic values and `where in`
232
247
Value lists can also be created dynamically, making `where in` queries simple too.
233
248
```js
@@ -320,6 +335,17 @@ sql`
320
335
select "id" from "users"
321
336
```
322
337
338
+
### Quick primer on interpolation
339
+
340
+
Here's a quick oversight over all the ways to do interpolation in a query template string:
341
+
342
+
| Interpolation syntax | Usage | Example |
343
+
| ------------- | ------------- | ------------- |
344
+
|`${ sql`` }`| for keywords or sql fragments |``sql`SELECT * FROM users ${sql`order by age desc` }` ``|
345
+
|`${ sql(string) }`| for identifiers |``sql`SELECT * FROM ${sql('table_name')` ``|
346
+
|`${ sql([] or {}, ...) }`| for helpers |``sql`INSERT INTO users ${sql({ name: 'Peter'})}` ``|
347
+
|`${ 'somevalue' }`| for values |``sql`SELECT * FROM users WHERE age = ${42}` ``|
Rather than executing a given query, `.describe` will return information utilized in the query process. This information can include the query identifier, column types, etc.
399
425
@@ -585,6 +611,8 @@ Built in transformation functions are:
585
611
* For PascalCase - `postgres.pascal`, `postgres.toPascal`, `postgres.fromPascal`
586
612
* For Kebab-Case - `postgres.kebab`, `postgres.toKebab`, `postgres.fromKebab`
587
613
614
+
These built in transformations will only convert to/from snake_case. For example, using `{ transform: postgres.toCamel }` will convert the column names to camelCase only if the column names are in snake_case to begin with. `{ transform: postgres.fromCamel }` will convert camelCase only to snake_case.
615
+
588
616
By default, using `postgres.camel`, `postgres.pascal` and `postgres.kebab` will perform a two-way transformation - both the data passed to the query and the data returned by the query will be transformed:
0 commit comments