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
[i ?sql`,`:sql``, sql`${sql(column) }${ order ==='desc'?sql`desc`:sql`asc`}`]
357
+
)
358
+
}
359
+
`
360
+
```
361
+
341
362
### SQL functions
342
363
Using keywords or calling functions dynamically is also possible by using ``` sql`` ``` fragments.
343
364
```js
@@ -564,6 +585,8 @@ If you know what you're doing, you can use `unsafe` to pass any string you'd lik
564
585
sql.unsafe('select '+ danger +' from users where id = '+ dragons)
565
586
```
566
587
588
+
By default, `sql.unsafe` assumes the `query` string is sufficiently dynamic that prepared statements do not make sense, and so defaults them to off. If you'd like to re-enable prepared statements, you can pass `{ prepare: true }`.
589
+
567
590
You can also nest `sql.unsafe` within a safe `sql` expression. This is useful if only part of your fraction has unsafe elements.
568
591
569
592
```js
@@ -1121,20 +1144,25 @@ It is also possible to connect to the database without a connection string or an
1121
1144
constsql=postgres()
1122
1145
```
1123
1146
1124
-
| Option | Environment Variables |
1125
-
| ----------------- | ------------------------ |
1126
-
|`host`|`PGHOST`|
1127
-
|`port`|`PGPORT`|
1128
-
|`database`|`PGDATABASE`|
1129
-
|`username`|`PGUSERNAME` or `PGUSER`|
1130
-
|`password`|`PGPASSWORD`|
1131
-
|`idle_timeout`|`PGIDLE_TIMEOUT`|
1132
-
|`connect_timeout`|`PGCONNECT_TIMEOUT`|
1147
+
| Option | Environment Variables |
1148
+
| ------------------ | ------------------------ |
1149
+
|`host`|`PGHOST`|
1150
+
|`port`|`PGPORT`|
1151
+
|`database`|`PGDATABASE`|
1152
+
|`username`|`PGUSERNAME` or `PGUSER`|
1153
+
|`password`|`PGPASSWORD`|
1154
+
|`application_name`|`PGAPPNAME`|
1155
+
|`idle_timeout`|`PGIDLE_TIMEOUT`|
1156
+
|`connect_timeout`|`PGCONNECT_TIMEOUT`|
1133
1157
1134
1158
### Prepared statements
1135
1159
1136
1160
Prepared statements will automatically be created for any queries where it can be inferred that the query is static. This can be disabled by using the `prepare: false` option. For instance — this is useful when [using PGBouncer in `transaction mode`](https://github.com/porsager/postgres/issues/93#issuecomment-656290493).
You can add ergonomic support for custom types, or simply use `sql.typed(value, type)` inline, where type is the PostgreSQL `oid` for the type and the correctly serialized string. _(`oid` values for types can be found in the `pg_catalog.pg_type` table.)_
@@ -1294,8 +1322,8 @@ This error is thrown if the user has called [`sql.end()`](#teardown--cleanup) an
1294
1322
1295
1323
This error is thrown for any queries that were pending when the timeout to [`sql.end({ timeout: X })`](#teardown--cleanup) was reached.
1296
1324
1297
-
##### CONNECTION_CONNECT_TIMEOUT
1298
-
> write CONNECTION_CONNECT_TIMEOUT host:port
1325
+
##### CONNECT_TIMEOUT
1326
+
> write CONNECT_TIMEOUT host:port
1299
1327
1300
1328
This error is thrown if the startup phase of the connection (tcp, protocol negotiation, and auth) took more than the default 30 seconds or what was specified using `connect_timeout` or `PGCONNECT_TIMEOUT`.
0 commit comments