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
Do note that you can often achieve the same result using [`WITH` queries (Common Table Expressions)](https://www.postgresql.org/docs/current/queries-with.html) instead of using transactions.
519
520
521
+
## Data Transformation
522
+
523
+
`postgres.js` comes with a number of built-in data transformation functions that can be used to transform the data returned from a query or when inserting data. They are available under `transformation` option in the `postgres()` function connection options.
524
+
525
+
Like - `postgres('connectionURL', { transformation: {...} })`
526
+
527
+
### Parameters
528
+
* `to`: The function to transform the outgoing query column name to, i.e ``SELECT ${sql('aName') }` to `SELECT a_name` when using `postgres.toCamel`.
529
+
*`from`: The function to transform the incoming query result column name to, see example below.
530
+
531
+
> Both parameters are optional, if not provided, the default transformation function will be used.
532
+
533
+
Built in transformation functions are:
534
+
* For camelCase - `postgres.toCamel` and `postgres.fromCamel`
535
+
* For PascalCase - `postgres.toPascal` and `postgres.fromPascal`
536
+
* For Kebab-Case - `postgres.toKebab` and `postgres.fromKebab`
537
+
538
+
These functions can be passed in as options when calling `postgres()`. For example -
539
+
```js
540
+
// this will tranform the column names to camel case back and forth
> Note that if a column name is originally registered as snake_case in the database then to tranform it from camelCase to snake_case when querying or inserting, the column camelCase name must be put in `sql('columnName')` as it's done in the above example.
552
+
520
553
## Listen & notify
521
554
522
555
When you call `.listen`, a dedicated connection will be created to ensure that you receive notifications instantly. This connection will be used for any further calls to `.listen`. The connection will automatically reconnect according to a backoff reconnection pattern to not overload the database server.
0 commit comments