Skip to content

Commit b7bf68c

Browse files
committed
feat(dialect-wasqlite-worker): upgrade wasqlite and fix url
1 parent 50d82a2 commit b7bf68c

File tree

12 files changed

+58
-42
lines changed

12 files changed

+58
-42
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export default defineEslintConfig({
55
overrideRules: {
66
'prefer-template': 'off',
77
},
8+
vue: true,
89
})

packages/dialect-wasqlite-worker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
"zen-mitt": "^0.3.0"
5858
},
5959
"devDependencies": {
60-
"@subframe7536/sqlite-wasm": "^0.2.2"
60+
"@subframe7536/sqlite-wasm": "^0.3.0-beta.1"
6161
}
6262
}

packages/dialect-wasqlite-worker/src/driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class WaSqliteWorkerConnection implements DatabaseConnection {
125125
}
126126

127127
streamQuery<R>(): AsyncIterableIterator<QueryResult<R>> {
128-
throw new Error('SQLite driver doesn\'t support streaming')
128+
throw new Error('wa-sqlite worker driver doesn\'t support streaming')
129129
}
130130

131131
async executeQuery<R>(compiledQuery: CompiledQuery<unknown>): Promise<QueryResult<R>> {

packages/dialect-wasqlite-worker/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from 'kysely'
33
import { WaSqliteWorkerDriver } from './driver'
44
import type { Promisable } from './type'
55

6+
export { isIdbSupported, isOpfsSupported, isModuleWorkerSupport } from '@subframe7536/sqlite-wasm'
7+
68
export interface WaSqliteWorkerDialectConfig {
79
/**
810
* db file name
@@ -41,15 +43,13 @@ export interface WaSqliteWorkerDialectConfig {
4143
* import { useDefaultWasmURL } from 'kysely-wasqlite-worker'
4244
* @example
4345
* (useAsyncWasm) => useAsyncWasm
44-
* ? 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v0.9.9/dist/wa-sqlite-async.wasm'
46+
* ? 'https://cdn.jsdelivr.net/gh/rhashimoto/wa-sqlite@v1.0.0/dist/wa-sqlite-async.wasm'
4547
* : new URL('kysely-wasqlite-worker/wasm-sync', import.meta.url).href
4648
*/
4749
url?: string | ((useAsyncWasm: boolean) => string)
4850
onCreateConnection?: (connection: DatabaseConnection) => Promisable<void>
4951
}
5052

51-
export { isIdbSupported, isOpfsSupported, isModuleWorkerSupport } from '@subframe7536/sqlite-wasm'
52-
5353
export class WaSqliteWorkerDialect implements Dialect {
5454
private config: WaSqliteWorkerDialectConfig
5555

packages/dialect-wasqlite-worker/src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { MainMsg, WorkerMsg } from './type'
55

66
let db: SQLiteDB
77

8-
async function init(url: string, fileName: string, useOPFS: boolean) {
8+
async function init(fileName: string, url: string, useOPFS: boolean) {
99
db = await initSQLite(
1010
(
1111
useOPFS

packages/sqlite-builder/src/schema/parseExist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type ParsedColumnProperty = {
2525
* @todo support extra constraints
2626
*/
2727
export function parseCreateTableSQL(definition: string): ParsedCreateTableSQL {
28+
// eslint-disable-next-line regexp/no-super-linear-backtracking
2829
const baseRegex = /create table (?:if not exist)?\s*"([^"]+)".*?\((.*)\)/i
2930
const columnRegex = /"([^"]+)"\s+(\w+)\s?(not null)?/gi
3031
const [, tableName, cols] = definition.replace(/\r?\n/g, '').match(baseRegex)!

packages/sqlite-utils/src/soft-delete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export function basicExecutorFn<DB extends Record<string, any>>(db: () => Kysely
4848
export function createSoftDeleteExecutorFn<DB extends Record<string, any>>(
4949
deleteColumnName = 'isDeleted',
5050
): SqliteExecutorFn<DB, {
51-
withoutDelete: <W extends WhereInterface<DB, keyof DB>>(qb: W) => WhereInterface<DB, keyof DB>
52-
}> {
51+
withoutDelete: <W extends WhereInterface<DB, keyof DB>>(qb: W) => WhereInterface<DB, keyof DB>
52+
}> {
5353
return (db: () => Kysely<DB>) => {
5454
return {
5555
selectFrom: <T extends keyof DB & string>(

playground/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
},
99
"dependencies": {
1010
"@subframe7536/sqlite-wasm": "^0.2.2",
11-
"kysely-sqlite-builder": "workspace:*",
11+
"kysely-sqlite-builder": "^0.8.7",
1212
"kysely-wasm": "workspace:*",
1313
"kysely-wasqlite-worker": "workspace:*",
14-
"vue": "^3.4.27"
14+
"vue": "^3.4.31"
1515
},
1616
"devDependencies": {
17-
"@vitejs/plugin-vue": "^5.0.4"
17+
"@vitejs/plugin-vue": "^5.0.5"
1818
}
1919
}

playground/src/App.vue

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import OfficialWorker from './modules/officialWasmWorker?worker'
55
import { useWaSqliteWorker } from './modules/wasqliteWorker'
66
import { deleteFile } from './modules/indexeddb'
77
8-
// import { testCRSqlite } from './modules/crsqlite'
9-
108
const sqljsWorker = new SqljsWorker()
119
const { result, run } = useDB()
1210
const officialWorker = new OfficialWorker()
@@ -56,7 +54,10 @@ async function clear() {
5654
<h3>see worker result in console</h3>
5755
<h3>
5856
you can explore
59-
<a href="https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API#origin_private_file_system" target="_blank">
57+
<a
58+
href="https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API#origin_private_file_system"
59+
target="_blank"
60+
>
6061
OPFS
6162
</a>
6263
file using
@@ -95,31 +96,41 @@ async function clear() {
9596
</template>
9697

9798
<style>
98-
button, a {
99+
button,
100+
a {
99101
font-family: sans-serif;
100102
}
103+
101104
button {
102105
margin: 0 10px 10px;
103106
padding: 4px 8px;
104107
border-radius: 4px;
105108
}
109+
106110
button:hover {
107111
background-color: lightblue;
108112
transition: 0.2s;
109113
}
110-
h1, h3 {
114+
115+
h1,
116+
h3 {
111117
text-align: center;
112118
}
119+
113120
h1 {
114121
margin-bottom: 0;
115122
}
116-
div, pre {
123+
124+
div,
125+
pre {
117126
width: fit-content;
118127
margin: 0 auto 20px;
119128
}
129+
120130
.buttons {
121131
display: flex;
122132
}
133+
123134
pre {
124135
padding: 0 20px;
125136
border: 2px solid lightblue;
@@ -128,11 +139,13 @@ pre {
128139
width: 380px;
129140
overflow-y: scroll;
130141
}
131-
::-webkit-scrollbar{
142+
143+
::-webkit-scrollbar {
132144
width: 6px;
133145
height: 6px;
134146
}
135-
::-webkit-scrollbar-thumb{
147+
148+
::-webkit-scrollbar-thumb {
136149
width: 6px;
137150
border-radius: 6px;
138151
background-color: gray;

playground/src/modules/utils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { Dialect } from 'kysely'
22
import { SqliteBuilder } from 'kysely-sqlite-builder'
33
import type { InferDatabase } from 'kysely-sqlite-builder/schema'
4-
import { defineTable, useSchema } from 'kysely-sqlite-builder/schema'
4+
import { column, defineTable, useSchema } from 'kysely-sqlite-builder/schema'
55

66
const tables = {
77
test: defineTable({
8-
id: { type: 'increments' },
9-
name: { type: 'string' },
10-
blobtest: { type: 'blob' },
11-
}, {
8+
columns: {
9+
id: column.increments(),
10+
name: column.string(),
11+
blobtest: column.blob(),
12+
},
1213
timeTrigger: { create: true, update: true },
1314
}),
1415
}
@@ -23,7 +24,7 @@ export async function testDB(dialect: Dialect) {
2324
if (!result.ready) {
2425
throw result.error
2526
}
26-
console.log(await db.raw(`PRAGMA table_info('test')`))
27+
console.log(await db.execute(`PRAGMA table_info('test')`))
2728

2829
for (let i = 0; i < 10; i++) {
2930
await db.transaction(async () => {
@@ -32,18 +33,17 @@ export async function testDB(dialect: Dialect) {
3233
console.log('test rollback')
3334
throw new Error('test rollback')
3435
}
35-
await db.execute(d => d
36-
.insertInto('test')
36+
await db.insertInto('test')
3737
.values({
3838
name: `test at ${Date.now()}`,
3939
blobtest: Uint8Array.from([2, 3, 4, 5, 6, 7, 8]),
40-
}),
41-
)
40+
})
41+
.execute()
4242
})
4343
})
4444
}
4545

46-
return db.execute(db => db.selectFrom('test').selectAll()).then(async (data) => {
46+
return db.selectFrom('test').selectAll().execute().then(async (data) => {
4747
await db.destroy()
4848
console.log(data)
4949
return data

0 commit comments

Comments
 (0)