Skip to content

Commit 92e27da

Browse files
committed
chore: add kysely test example for transaction with raw sql
1 parent 8cc1524 commit 92e27da

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/kysely-driver/tests/sqlite/db.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
22
import * as SUT from '../../src/sqlite/db';
3-
import { Kysely } from 'kysely';
3+
import { Kysely, sql } from 'kysely';
44
import { getPowerSyncDb } from '../setup/db';
55
import { AbstractPowerSyncDatabase } from '@powersync/common';
6-
import { Database } from '../setup/types';
6+
import { Database, UsersTable } from '../setup/types';
77

88
describe('CRUD operations', () => {
99
let powerSyncDb: AbstractPowerSyncDatabase;
@@ -50,4 +50,15 @@ describe('CRUD operations', () => {
5050

5151
expect(result.name).toEqual('James Smith');
5252
});
53+
54+
55+
it('should insert a user and update that user within a transaction when raw sql is used', async () => {
56+
await db.transaction().execute(async (transaction) => {
57+
await sql`INSERT INTO users (id, name) VALUES ('4', 'James');`.execute(transaction)
58+
await transaction.updateTable('users').where('name', '=', 'James').set('name', 'James Smith').execute();
59+
});
60+
const result = await db.selectFrom('users').select('name').executeTakeFirstOrThrow();
61+
62+
expect(result.name).toEqual('James Smith');
63+
});
5364
});

0 commit comments

Comments
 (0)