We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b0d8c8f commit 26ee478Copy full SHA for 26ee478
README.md
@@ -342,6 +342,27 @@ select * from users
342
select * from users where user_id = $1
343
```
344
345
+### Dynamic ordering
346
+
347
+```js
348
+const id = 1
349
+const order = {
350
+ username: 'asc'
351
+ created_at: 'desc'
352
+}
353
+await sql`
354
+ select
355
+ *
356
+ from ticket
357
+ where account = ${ id }
358
+ order by ${
359
+ Object.entries(order).flatMap(([column, order], i) =>
360
+ [i ? sql`,` : sql``, sql`${ sql(column) } ${ order === 'desc' ? sql`desc` : sql`asc` }`]
361
+ )
362
+ }
363
+`
364
+```
365
366
### SQL functions
367
Using keywords or calling functions dynamically is also possible by using ``` sql`` ``` fragments.
368
```js
0 commit comments