kysely-mapper
Advanced tools
Comparing version 0.4.14 to 0.4.15
{ | ||
"name": "kysely-mapper", | ||
"version": "0.4.14", | ||
"version": "0.4.15", | ||
"author": "Joseph T. Lapp <arachnojoe@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -19,2 +19,6 @@ # kysely-mapper | ||
## Updates | ||
- v**0.4.15** - Now supporting [transactions](https://github.com/jtlapp/kysely-mapper#transactions). | ||
## Installation | ||
@@ -431,2 +435,38 @@ | ||
## Transactions | ||
Because they Kysely [Transaction](https://kysely-org.github.io/kysely/classes/Transaction.html) class is an instance of the [Kysely](https://kysely-org.github.io/kysely/classes/Kysely.html) class, you can create a table mapper directly from a transaction. For example: | ||
```ts | ||
await db.transaction().execute(async (trx) => { | ||
const trxMapper = new TableMapper(trx, 'users', { | ||
keyColumns: ['id'], | ||
insertReturnColumns: ['id', 'modified'], | ||
updateReturnColumns: ['modified'], | ||
}); | ||
await trxMapper.insert().returnOne(user1); | ||
await trxMapper.insert().returnOne(user2); | ||
}); | ||
``` | ||
However, if you want to be able to use a single table mapper both outside transactions and within one or more transactions, you can create the table mapper as you normally would and call `forTransaction` on the table mapper. This provides an identically-configured mapper that operates only within the provided transaction. For example: | ||
```ts | ||
const table = new TableMapper(trx, 'users', { | ||
keyColumns: ['id'], | ||
insertReturnColumns: ['id', 'modified'], | ||
updateReturnColumns: ['modified'], | ||
}); | ||
await db.transaction().execute(async (trx) => { | ||
const trxMapper = table.forTransaction(trx); | ||
await trxMapper.insert().returnOne(user1); | ||
await trxMapper.insert().returnOne(user2); | ||
}); | ||
await db.transaction().execute(async (trx) => { | ||
const trxMapper = table.forTransaction(trx); | ||
await trxMapper.insert().returnOne(user3); | ||
await trxMapper.insert().returnOne(user4); | ||
}); | ||
``` | ||
## Compiling Queries | ||
@@ -433,0 +473,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1059303
767
0