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
**pg-client-helper** manages your database connection by utilizing connection pooling. It also supports connections to AWS RDS via IAM using AWS Signer.
143
144
145
+
If you want to use transactions, please use the following approach:
146
+
147
+
```ts
148
+
import*asPGfrom"pg-client-helper";
149
+
150
+
asyncfunction myfunc() {
151
+
const client:any=PG.beginTransaction(); // begins the transaction and returns a client to be used for ALL
152
+
153
+
try {
154
+
// 1st query
155
+
const $id_mytable1 =awaitPG.query(
156
+
`INSERT INTO mytable1 (val1) VALUES 'foo' RETURNING id_mytable1`
157
+
);
158
+
159
+
// 2nd query
160
+
const $id_mytable2 =awaitPG.query(
161
+
`INSERT INTO mytable2 (id_mytable1, val2) VALUES ($id_mytable1, 'bar')`,
162
+
{ $id_mytable1 }
163
+
);
164
+
165
+
// 3rd query
166
+
awaitPG.query(
167
+
`UPDATE mytable3 SET val3 = 'baz' WHERE id_mytable1 = $id_mytable1 AND id_mytable2 = $id_mytable2`,
168
+
{ $id_mytable1, $id_mytable2 }
169
+
);
170
+
171
+
awaitPG.commitTransaction(client); // commits all changes made since beginTransaction
172
+
} catch (error) {
173
+
if (client) {
174
+
awaitPG.rollbackTransaction(client); // we faced an error after beginTransaction, roll back all changes since then
0 commit comments