Skip to content

Commit f54061e

Browse files
committed
feat(workspace): separate kysely-sqlite-utils from kysely-sqlite-builder
1 parent b321487 commit f54061e

File tree

17 files changed

+388
-300
lines changed

17 files changed

+388
-300
lines changed

commitlint.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
'dialect-wasqlite-worker',
2020
'builder',
2121
'workspace',
22+
'utils',
2223
],
2324
markBreakingChangeMode: true,
2425
allowBreakingChanges: [

packages/sqlite-builder/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
},
4040
"dependencies": {
4141
"@subframe7536/type-utils": "^0.1.3",
42-
"kysely-plugin-serialize": "workspace:*"
42+
"kysely-plugin-serialize": "workspace:*",
43+
"kysely-sqlite-utils": "workspace:*"
4344
}
4445
}

packages/sqlite-builder/src/builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import type {
88
} from 'kysely'
99
import { CompiledQuery, Kysely } from 'kysely'
1010
import { SerializePlugin, defaultSerializer } from 'kysely-plugin-serialize'
11+
import type { QueryBuilderOutput } from 'kysely-sqlite-utils'
1112
import {
1213
createKyselyLogger,
1314
precompileQuery,
1415
checkIntegrity as runCheckIntegrity,
1516
savePoint,
16-
} from './utils'
17+
} from 'kysely-sqlite-utils'
1718
import type {
1819
AvailableBuilder,
1920
DBLogger,
20-
QueryBuilderOutput,
2121
SqliteBuilderOptions,
2222
StatusResult,
2323
SyncTableFn,
@@ -130,7 +130,7 @@ export class SqliteBuilder<DB extends Record<string, any>> {
130130
}
131131

132132
private getDB() {
133-
return this.trx || this.kysely
133+
return this.trxCount ? this.trx! : this.kysely
134134
}
135135

136136
private logError(e: unknown, errorMsg?: string) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './builder'
22
export type { DBLogger, SqliteBuilderOptions } from './types'
33
export * from './sync'
4-
export * from './utils'
4+
export * from 'kysely-sqlite-utils'

packages/sqlite-builder/src/sync/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Kysely, sql } from 'kysely'
2+
import { getOrSetDBVersion } from 'kysely-sqlite-utils'
23
import type { DBLogger } from '../types'
3-
import { getOrSetDBVersion } from '../utils'
44
import type { Columns, Schema, Table } from './types'
55
import {
66
parseColumnType,

packages/sqlite-builder/src/sync/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import type { Kysely } from 'kysely'
1+
import type { Kysely, MigrationProvider, MigratorProps } from 'kysely'
2+
import { Migrator } from 'kysely'
23
import type { DBLogger, SyncTableFn } from '../types'
34
import type { Schema } from './types'
45
import type { SyncOptions } from './core'
56
import { syncTables } from './core'
67

78
export * from './types'
9+
810
export { defineTable, defineLiteral, defineObject } from './define'
911

1012
/**
@@ -21,3 +23,17 @@ export function createAutoSyncSchemaFn<T extends Schema>(
2123
await syncTables(db, schema, options, log ? logger : undefined)
2224
}
2325
}
26+
27+
/**
28+
* migrate to latest
29+
*/
30+
31+
export function createMigrateFn(
32+
provider: MigrationProvider,
33+
options?: Omit<MigratorProps, 'db' | 'provider'>,
34+
): SyncTableFn {
35+
return async (db: Kysely<any>) => {
36+
const migrator = new Migrator({ db, provider, ...options })
37+
await migrator.migrateToLatest()
38+
}
39+
}

packages/sqlite-builder/src/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {
2-
Compilable,
32
DeleteQueryBuilder,
43
Dialect,
54
InsertQueryBuilder,
@@ -9,7 +8,7 @@ import type {
98
UpdateQueryBuilder,
109
} from 'kysely'
1110
import type { SerializePluginOptions } from 'kysely-plugin-serialize'
12-
import type { LoggerOptions } from './utils'
11+
import type { LoggerOptions } from 'kysely-sqlite-utils'
1312

1413
export interface SqliteBuilderOptions {
1514
dialect: Dialect
@@ -42,8 +41,6 @@ export type AvailableBuilder<DB, O> =
4241
| InsertQueryBuilder<DB, any, O>
4342
| DeleteQueryBuilder<DB, any, O>
4443

45-
export type QueryBuilderOutput<QB> = QB extends Compilable<infer O> ? O : never
46-
4744
export type StatusResult =
4845
| { ready: true }
4946
| { ready: false; error: unknown }

0 commit comments

Comments
 (0)