Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kysely-mapper

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kysely-mapper - npm Package Compare versions

Comparing version 0.4.14 to 0.4.15

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc