@geekmidas/testkit 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{Factory-Bm44VKa-.d.cts → Factory-D7P3bKKb.d.mts} +2 -2
- package/dist/{Factory-tjCDNgUK.d.mts → Factory-pNV7ZQ7-.d.cts} +2 -2
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/{KyselyFactory-BoPDDitt.d.cts → KyselyFactory-72P98y5I.d.mts} +3 -3
- package/dist/{KyselyFactory-C3Bc3p4L.mjs → KyselyFactory-BcYkC0t2.mjs} +1 -1
- package/dist/{KyselyFactory-CXtfmMfK.cjs → KyselyFactory-Cf0o2YxO.cjs} +1 -1
- package/dist/{KyselyFactory-D82j74t9.d.mts → KyselyFactory-DLBrYWxU.d.cts} +3 -3
- package/dist/KyselyFactory.cjs +1 -1
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/KyselyFactory.mjs +1 -1
- package/dist/{ObjectionFactory-qIICOph3.mjs → ObjectionFactory-8hebmnai.mjs} +20 -4
- package/dist/{ObjectionFactory-BWMTXsxH.d.cts → ObjectionFactory-B40NQWSe.d.mts} +2 -2
- package/dist/{ObjectionFactory-DxIxJagq.cjs → ObjectionFactory-CDriunkS.cjs} +20 -4
- package/dist/{ObjectionFactory-CEG5qUrm.d.mts → ObjectionFactory-D3l1VuyX.d.cts} +2 -2
- package/dist/ObjectionFactory.cjs +1 -1
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/ObjectionFactory.mjs +1 -1
- package/dist/{VitestKyselyTransactionIsolator-ClCazkBO.d.mts → VitestKyselyTransactionIsolator-CnxpE9cH.d.mts} +2 -1
- package/dist/{VitestKyselyTransactionIsolator-UE1J-UoP.d.cts → VitestKyselyTransactionIsolator-DYUYVEh9.d.cts} +2 -1
- package/dist/{VitestKyselyTransactionIsolator-BKGT9nEG.mjs → VitestKyselyTransactionIsolator-Dq4Oeh-Y.mjs} +4 -1
- package/dist/{VitestKyselyTransactionIsolator-CIlpIO78.cjs → VitestKyselyTransactionIsolator-Dqy3qNoJ.cjs} +4 -1
- package/dist/VitestKyselyTransactionIsolator.cjs +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +2 -2
- package/dist/{VitestObjectionTransactionIsolator-CO2nTi9r.d.cts → VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts} +3 -2
- package/dist/{VitestObjectionTransactionIsolator-D264iuPy.d.mts → VitestObjectionTransactionIsolator-DIM79dCq.d.mts} +3 -2
- package/dist/{VitestObjectionTransactionIsolator-BPoLUFop.mjs → VitestObjectionTransactionIsolator-DVtJG2F3.mjs} +6 -3
- package/dist/{VitestObjectionTransactionIsolator-DyqLp_in.cjs → VitestObjectionTransactionIsolator-LP4B0cqW.cjs} +6 -3
- package/dist/VitestObjectionTransactionIsolator.cjs +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +2 -2
- package/dist/{VitestTransactionIsolator-CruLTRRi.cjs → VitestTransactionIsolator-BQ5FpLtC.cjs} +5 -2
- package/dist/{VitestTransactionIsolator-BWwK-ca6.mjs → VitestTransactionIsolator-CskiiJbW.mjs} +5 -2
- package/dist/{VitestTransactionIsolator-DHf2MxmC.d.cts → VitestTransactionIsolator-DdLNODZg.d.cts} +8 -5
- package/dist/{VitestTransactionIsolator-Xqyjlmw6.d.mts → VitestTransactionIsolator-zdyiS_SY.d.mts} +8 -5
- package/dist/VitestTransactionIsolator.cjs +1 -1
- package/dist/VitestTransactionIsolator.d.cts +2 -2
- package/dist/VitestTransactionIsolator.d.mts +2 -2
- package/dist/VitestTransactionIsolator.mjs +1 -1
- package/dist/__tests__/KyselyFactory.spec.cjs +6 -6
- package/dist/__tests__/KyselyFactory.spec.mjs +6 -6
- package/dist/__tests__/ObjectionFactory.spec.cjs +288 -450
- package/dist/__tests__/ObjectionFactory.spec.mjs +289 -451
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +397 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +1 -0
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +396 -0
- package/dist/__tests__/PostgresMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +1 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +1 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +7 -16
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +7 -16
- package/dist/__tests__/integration.spec.cjs +6 -6
- package/dist/__tests__/integration.spec.mjs +6 -6
- package/dist/{faker-km9UhOS6.d.cts → faker-BSH1EMtg.d.cts} +2 -2
- package/dist/{faker-ChuHaYMR.d.mts → faker-C-Iuk_R1.d.mts} +2 -2
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/{helpers-BEmjyUVE.mjs → helpers-B4TXg3Wp.mjs} +11 -36
- package/dist/{helpers-CNMBePuj.cjs → helpers-Bf0nXhbu.cjs} +10 -41
- package/dist/{kysely-Cx_1pZYc.mjs → kysely-BsDbvw3r.mjs} +4 -4
- package/dist/{kysely-CBfCXxUn.cjs → kysely-CP1iJMvq.cjs} +4 -4
- package/dist/kysely.cjs +4 -4
- package/dist/kysely.d.cts +6 -6
- package/dist/kysely.d.mts +6 -6
- package/dist/kysely.mjs +4 -4
- package/dist/{objection-lsMgM5gP.mjs → objection-BEPk9h-g.mjs} +5 -5
- package/dist/{objection-CCD8fMLj.cjs → objection-Di7JSist.cjs} +5 -5
- package/dist/objection.cjs +4 -4
- package/dist/objection.d.cts +7 -7
- package/dist/objection.d.mts +7 -7
- package/dist/objection.mjs +4 -4
- package/package.json +3 -3
- package/src/Factory.ts +4 -1
- package/src/KyselyFactory.ts +6 -2
- package/src/ObjectionFactory.ts +34 -4
- package/src/VitestKyselyTransactionIsolator.ts +3 -0
- package/src/VitestObjectionTransactionIsolator.ts +5 -2
- package/src/VitestTransactionIsolator.ts +11 -8
- package/src/__tests__/KyselyFactory.spec.ts +1 -1
- package/src/__tests__/ObjectionFactory.spec.ts +423 -542
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +690 -0
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +1 -10
- package/src/__tests__/integration.spec.ts +1 -1
- package/src/kysely.ts +6 -3
- package/src/objection.ts +7 -4
- package/test/helpers.ts +13 -21
- package/dist/example.cjs +0 -22
- package/dist/example.d.cts +0 -26
- package/dist/example.d.mts +0 -26
- package/dist/example.mjs +0 -22
- package/src/example.ts +0 -45
|
@@ -12,8 +12,6 @@ class User extends Model {
|
|
|
12
12
|
|
|
13
13
|
id!: number;
|
|
14
14
|
name!: string;
|
|
15
|
-
email!: string;
|
|
16
|
-
role?: string;
|
|
17
15
|
createdAt!: Date;
|
|
18
16
|
updatedAt?: Date;
|
|
19
17
|
|
|
@@ -108,13 +106,9 @@ class Comment extends Model {
|
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
// Create database connection
|
|
111
|
-
const knex = createKnexDb();
|
|
112
|
-
|
|
113
|
-
// Bind models to Knex instance
|
|
114
|
-
Model.knex(knex);
|
|
115
109
|
|
|
116
110
|
// Create wrapped test with transaction isolation
|
|
117
|
-
const it = wrapVitestObjectionTransaction(base,
|
|
111
|
+
const it = wrapVitestObjectionTransaction(base, createKnexDb, async (trx) => {
|
|
118
112
|
// Create tables in the transaction
|
|
119
113
|
await createTestTablesKnex(trx);
|
|
120
114
|
});
|
|
@@ -125,8 +119,6 @@ describe('VitestObjectionTransactionIsolator', () => {
|
|
|
125
119
|
// Create a user within the transaction
|
|
126
120
|
const user = await User.query(trx).insert({
|
|
127
121
|
name: 'Test User',
|
|
128
|
-
email: 'test@example.com',
|
|
129
|
-
role: 'user',
|
|
130
122
|
});
|
|
131
123
|
|
|
132
124
|
expect(user).toBeDefined();
|
|
@@ -136,7 +128,6 @@ describe('VitestObjectionTransactionIsolator', () => {
|
|
|
136
128
|
// Verify user exists in transaction
|
|
137
129
|
const foundUser = await User.query(trx).findById(user.id);
|
|
138
130
|
expect(foundUser).toBeDefined();
|
|
139
|
-
expect(foundUser?.email).toBe(user.email);
|
|
140
131
|
|
|
141
132
|
// Data will be rolled back after this test
|
|
142
133
|
});
|
|
@@ -5,7 +5,7 @@ import { KyselyFactory } from '../KyselyFactory';
|
|
|
5
5
|
import { createKyselyDb } from '../helpers';
|
|
6
6
|
import { wrapVitestKyselyTransaction } from '../kysely';
|
|
7
7
|
|
|
8
|
-
const db = createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
|
|
8
|
+
const db = () => createKyselyDb<TestDatabase>(TEST_DATABASE_CONFIG);
|
|
9
9
|
const it = wrapVitestKyselyTransaction<TestDatabase>(
|
|
10
10
|
base,
|
|
11
11
|
db,
|
package/src/kysely.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Kysely, Transaction } from 'kysely';
|
|
2
2
|
import type { TestAPI } from 'vitest';
|
|
3
3
|
import { VitestKyselyTransactionIsolator } from './VitestKyselyTransactionIsolator';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type DatabaseConnection,
|
|
6
|
+
IsolationLevel,
|
|
7
|
+
} from './VitestTransactionIsolator';
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Kysely-specific exports for test utilities.
|
|
@@ -71,11 +74,11 @@ export { IsolationLevel } from './VitestTransactionIsolator';
|
|
|
71
74
|
*/
|
|
72
75
|
export function wrapVitestKyselyTransaction<Database>(
|
|
73
76
|
api: TestAPI,
|
|
74
|
-
|
|
77
|
+
connection: DatabaseConnection<Kysely<Database>>,
|
|
75
78
|
setup?: (trx: Transaction<Database>) => Promise<void>,
|
|
76
79
|
level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
|
|
77
80
|
) {
|
|
78
81
|
const wrapper = new VitestKyselyTransactionIsolator<Database>(api);
|
|
79
82
|
|
|
80
|
-
return wrapper.wrapVitestWithTransaction(
|
|
83
|
+
return wrapper.wrapVitestWithTransaction(connection, setup, level);
|
|
81
84
|
}
|
package/src/objection.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
import type { TestAPI } from 'vitest';
|
|
3
3
|
import { VitestObjectionTransactionIsolator } from './VitestObjectionTransactionIsolator';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type DatabaseConnection,
|
|
6
|
+
IsolationLevel,
|
|
7
|
+
} from './VitestTransactionIsolator';
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Objection.js-specific exports for test utilities.
|
|
@@ -20,7 +23,7 @@ export { PostgresObjectionMigrator } from './PostgresObjectionMigrator';
|
|
|
20
23
|
* This ensures tests don't affect each other's data and run faster than truncating tables.
|
|
21
24
|
*
|
|
22
25
|
* @param api - The Vitest test API (usually `test` from vitest)
|
|
23
|
-
* @param
|
|
26
|
+
* @param conn - The Knex database connection instance
|
|
24
27
|
* @param setup - Optional setup function to run before each test in the transaction
|
|
25
28
|
* @param level - Transaction isolation level (defaults to REPEATABLE_READ)
|
|
26
29
|
* @returns A wrapped test API that provides transaction isolation
|
|
@@ -87,11 +90,11 @@ export { PostgresObjectionMigrator } from './PostgresObjectionMigrator';
|
|
|
87
90
|
*/
|
|
88
91
|
export function wrapVitestObjectionTransaction(
|
|
89
92
|
api: TestAPI,
|
|
90
|
-
|
|
93
|
+
conn: DatabaseConnection<Knex>,
|
|
91
94
|
setup?: (trx: Knex.Transaction) => Promise<void>,
|
|
92
95
|
level: IsolationLevel = IsolationLevel.REPEATABLE_READ,
|
|
93
96
|
) {
|
|
94
97
|
const wrapper = new VitestObjectionTransactionIsolator(api);
|
|
95
98
|
|
|
96
|
-
return wrapper.wrapVitestWithTransaction(
|
|
99
|
+
return wrapper.wrapVitestWithTransaction(conn, setup, level);
|
|
97
100
|
}
|
package/test/helpers.ts
CHANGED
|
@@ -165,49 +165,41 @@ export async function createTestTables(
|
|
|
165
165
|
export async function createTestTablesKnex(
|
|
166
166
|
trx: Knex.Transaction,
|
|
167
167
|
): Promise<void> {
|
|
168
|
-
// Create users table
|
|
169
|
-
await trx.
|
|
170
|
-
|
|
168
|
+
// Create simple users table for testing factory
|
|
169
|
+
await trx.raw(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
|
170
|
+
await trx.schema.createTableIfNotExists('users', (table) => {
|
|
171
|
+
table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
|
|
171
172
|
table.string('name').notNullable();
|
|
172
|
-
table.string('email').notNullable().unique();
|
|
173
|
-
table.string('role').defaultTo('user');
|
|
174
|
-
table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
|
|
175
|
-
table.timestamp('updated_at').defaultTo(trx.fn.now()).notNullable();
|
|
176
173
|
});
|
|
177
174
|
|
|
178
|
-
// Create posts table
|
|
179
|
-
await trx.schema.
|
|
180
|
-
table.
|
|
175
|
+
// Create simple posts table for testing factory
|
|
176
|
+
await trx.schema.createTableIfNotExists('posts', (table) => {
|
|
177
|
+
table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
|
|
181
178
|
table.string('title').notNullable();
|
|
182
|
-
table.text('content').notNullable();
|
|
183
179
|
table
|
|
184
|
-
.
|
|
180
|
+
.uuid('user_id')
|
|
185
181
|
.notNullable()
|
|
186
182
|
.references('id')
|
|
187
183
|
.inTable('users')
|
|
188
184
|
.onDelete('cascade');
|
|
189
|
-
table.boolean('published').defaultTo(false);
|
|
190
|
-
table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
|
|
191
|
-
table.timestamp('updated_at').defaultTo(trx.fn.now()).notNullable();
|
|
192
185
|
});
|
|
193
186
|
|
|
194
|
-
// Create comments table
|
|
195
|
-
await trx.schema.
|
|
196
|
-
table.
|
|
187
|
+
// Create simple comments table for testing factory
|
|
188
|
+
await trx.schema.createTableIfNotExists('comments', (table) => {
|
|
189
|
+
table.uuid('id').primary().defaultTo(trx.raw('uuid_generate_v4()'));
|
|
197
190
|
table.text('content').notNullable();
|
|
198
191
|
table
|
|
199
|
-
.
|
|
192
|
+
.uuid('post_id')
|
|
200
193
|
.notNullable()
|
|
201
194
|
.references('id')
|
|
202
195
|
.inTable('posts')
|
|
203
196
|
.onDelete('cascade');
|
|
204
197
|
table
|
|
205
|
-
.
|
|
198
|
+
.uuid('user_id')
|
|
206
199
|
.notNullable()
|
|
207
200
|
.references('id')
|
|
208
201
|
.inTable('users')
|
|
209
202
|
.onDelete('cascade');
|
|
210
|
-
table.timestamp('created_at').defaultTo(trx.fn.now()).notNullable();
|
|
211
203
|
});
|
|
212
204
|
}
|
|
213
205
|
|
package/dist/example.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require('./Factory-WMhTNZ9S.cjs');
|
|
2
|
-
require('./faker-B14IEMIN.cjs');
|
|
3
|
-
const require_KyselyFactory = require('./KyselyFactory-CXtfmMfK.cjs');
|
|
4
|
-
|
|
5
|
-
//#region src/example.ts
|
|
6
|
-
const userBuilder = require_KyselyFactory.KyselyFactory.createBuilder({
|
|
7
|
-
table: "users",
|
|
8
|
-
defaults: async (attrs) => ({
|
|
9
|
-
name: "John Doe",
|
|
10
|
-
email: `user${Date.now()}@example.com`,
|
|
11
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
const builders = { user: userBuilder };
|
|
15
|
-
const factory = new require_KyselyFactory.KyselyFactory(builders, {}, {});
|
|
16
|
-
factory.insert("user", {
|
|
17
|
-
name: "Jane Doe",
|
|
18
|
-
email: `user${Date.now()}@example.com`,
|
|
19
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
//#endregion
|
package/dist/example.d.cts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { FakerFactory } from "./faker-km9UhOS6.cjs";
|
|
2
|
-
import * as kysely0 from "kysely";
|
|
3
|
-
|
|
4
|
-
//#region src/example.d.ts
|
|
5
|
-
interface Database {
|
|
6
|
-
users: {
|
|
7
|
-
id: number;
|
|
8
|
-
name: string;
|
|
9
|
-
email: string;
|
|
10
|
-
createdAt: Date;
|
|
11
|
-
};
|
|
12
|
-
posts: {
|
|
13
|
-
id: number;
|
|
14
|
-
title: string;
|
|
15
|
-
content: string;
|
|
16
|
-
userId: number;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
declare const builders: {
|
|
21
|
-
user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
|
|
22
|
-
};
|
|
23
|
-
type Builders = typeof builders;
|
|
24
|
-
type Seeds = Record<string, any>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { Builders, Seeds };
|
package/dist/example.d.mts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { FakerFactory } from "./faker-ChuHaYMR.mjs";
|
|
2
|
-
import * as kysely0 from "kysely";
|
|
3
|
-
|
|
4
|
-
//#region src/example.d.ts
|
|
5
|
-
interface Database {
|
|
6
|
-
users: {
|
|
7
|
-
id: number;
|
|
8
|
-
name: string;
|
|
9
|
-
email: string;
|
|
10
|
-
createdAt: Date;
|
|
11
|
-
};
|
|
12
|
-
posts: {
|
|
13
|
-
id: number;
|
|
14
|
-
title: string;
|
|
15
|
-
content: string;
|
|
16
|
-
userId: number;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
declare const builders: {
|
|
21
|
-
user: (attrs: Partial<kysely0.Insertable<DB[TableName]>>, factory: any, db: kysely0.Kysely<Database>, faker: FakerFactory) => Promise<kysely0.Selectable<DB[TableName]>>;
|
|
22
|
-
};
|
|
23
|
-
type Builders = typeof builders;
|
|
24
|
-
type Seeds = Record<string, any>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { Builders, Seeds };
|
package/dist/example.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import "./Factory-z2m01hMj.mjs";
|
|
2
|
-
import "./faker-BGKYFoCT.mjs";
|
|
3
|
-
import { KyselyFactory } from "./KyselyFactory-C3Bc3p4L.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/example.ts
|
|
6
|
-
const userBuilder = KyselyFactory.createBuilder({
|
|
7
|
-
table: "users",
|
|
8
|
-
defaults: async (attrs) => ({
|
|
9
|
-
name: "John Doe",
|
|
10
|
-
email: `user${Date.now()}@example.com`,
|
|
11
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
const builders = { user: userBuilder };
|
|
15
|
-
const factory = new KyselyFactory(builders, {}, {});
|
|
16
|
-
factory.insert("user", {
|
|
17
|
-
name: "Jane Doe",
|
|
18
|
-
email: `user${Date.now()}@example.com`,
|
|
19
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
//#endregion
|
package/src/example.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { KyselyFactory } from './KyselyFactory';
|
|
2
|
-
|
|
3
|
-
interface Database {
|
|
4
|
-
users: {
|
|
5
|
-
id: number;
|
|
6
|
-
name: string;
|
|
7
|
-
email: string;
|
|
8
|
-
createdAt: Date;
|
|
9
|
-
};
|
|
10
|
-
posts: {
|
|
11
|
-
id: number;
|
|
12
|
-
title: string;
|
|
13
|
-
content: string;
|
|
14
|
-
userId: number;
|
|
15
|
-
createdAt: Date;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const userBuilder = KyselyFactory.createBuilder<Database, 'users'>({
|
|
20
|
-
table: 'users',
|
|
21
|
-
defaults: async (attrs) => ({
|
|
22
|
-
name: 'John Doe',
|
|
23
|
-
email: `user${Date.now()}@example.com`,
|
|
24
|
-
createdAt: new Date(),
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const builders = {
|
|
29
|
-
user: userBuilder,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type Builders = typeof builders;
|
|
33
|
-
export type Seeds = Record<string, any>;
|
|
34
|
-
|
|
35
|
-
const factory = new KyselyFactory<Database, Builders, Seeds>(
|
|
36
|
-
builders,
|
|
37
|
-
{},
|
|
38
|
-
{} as any,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
factory.insert('user', {
|
|
42
|
-
name: 'Jane Doe',
|
|
43
|
-
email: `user${Date.now()}@example.com`,
|
|
44
|
-
createdAt: new Date(),
|
|
45
|
-
});
|