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
* Update README.md (prepared statements)
- correct typo
- add link to the official docs
- change the subsection name to "PREPARE TRANSACTION" instead of "PREPARE" (because "PREPARE" is more associated with "prepared statements")
One thing that is still a bit confusing in this section is the final sentence "Do note that you can often achieve...". It seems like it is referring to the "PREPARE" subsection, but in reality it is referring to the initial "BEGIN / COMMIT" subsection, no?
* Update README.md
- moved "Do note that you can often achieve the same result" to the first subsection
- added a link to a question in dba.stackexchange.com that shows how to do it
- in the insert and update example with dynamic columns, clarify that the columns can be given as an array
* Update README.md
- remove example in stackoverflow
Copy file name to clipboardExpand all lines: README.md
+25-6
Original file line number
Diff line number
Diff line change
@@ -176,14 +176,23 @@ const user = {
176
176
age:68
177
177
}
178
178
179
-
sql`
179
+
awaitsql`
180
180
insert into users ${
181
181
sql(user, 'name', 'age')
182
182
}
183
183
`
184
184
185
185
// Which results in:
186
186
insert into users ("name", "age") values ($1, $2)
187
+
188
+
// The columns can also be given with an array
189
+
constcolumns= ['name', 'age']
190
+
191
+
awaitsql`
192
+
insert into users ${
193
+
sql(user, columns)
194
+
}
195
+
`
187
196
```
188
197
189
198
**You can omit column names and simply execute `sql(user)` to get all the fields from the object as columns**. Be careful not to allow users to supply columns that you do not want to be inserted.
@@ -223,7 +232,7 @@ const user = {
223
232
age:68
224
233
}
225
234
226
-
sql`
235
+
awaitsql`
227
236
update users set${
228
237
sql(user, 'name', 'age')
229
238
}
@@ -232,6 +241,16 @@ sql`
232
241
233
242
// Which results in:
234
243
update users set "name"= $1, "age"= $2 where user_id = $3
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.
619
+
599
620
It's also possible to pipeline the requests in a transaction if needed by returning an array with queries from the callback function like this:
Indicates that the transactions should be prepared using the `PREPARED TRANASCTION [NAME]` statement
667
+
Indicates that the transactions should be prepared using the [`PREPARE TRANSACTION [NAME]`](https://www.postgresql.org/docs/current/sql-prepare-transaction.html) statement
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.
664
-
665
684
## Data Transformation
666
685
667
686
Postgres.js allows for transformation of the data passed to or returned from a query by using the `transform` option.
0 commit comments