-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathindex.ts
More file actions
70 lines (62 loc) · 1.98 KB
/
Copy pathindex.ts
File metadata and controls
70 lines (62 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { CompiledQuery, Dialect, Driver, QueryResult } from 'kysely'
import type { connections } from '~/drizzle'
import { DummyDriver, MysqlAdapter, MysqlQueryCompiler } from 'kysely'
import { logSql } from '../../sql'
function execute(connection: typeof connections.$inferSelect, compiledQuery: CompiledQuery) {
if (!window.electron) {
throw new Error('Electron is not available')
}
const promise = window.electron.query.mysql({
connectionString: connection.connectionString,
sql: compiledQuery.sql,
values: compiledQuery.parameters as unknown[],
})
logSql(connection, promise, {
sql: compiledQuery.sql,
values: compiledQuery.parameters as unknown[],
})
return promise
}
function createDriver(connection: typeof connections.$inferSelect) {
return {
async init() {},
async acquireConnection() {
return {
executeQuery: async <R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>> => {
const { result } = await execute(connection, compiledQuery)
return {
rows: result as R[],
}
},
streamQuery() {
throw new Error('Not implemented')
},
}
},
async beginTransaction() {},
async commitTransaction() {},
async rollbackTransaction() {},
async releaseConnection() {},
async destroy() {},
} satisfies Driver
}
export function mysqlDialect(connection: typeof connections.$inferSelect) {
return {
createDriver: () => createDriver(connection),
createQueryCompiler: () => new MysqlQueryCompiler(),
createAdapter: () => new MysqlAdapter(),
createIntrospector: () => {
throw new Error('Not implemented')
},
} satisfies Dialect
}
export function mysqlColdDialect() {
return {
createDriver: () => new DummyDriver(),
createQueryCompiler: () => new MysqlQueryCompiler(),
createAdapter: () => new MysqlAdapter(),
createIntrospector: () => {
throw new Error('Not implemented')
},
} satisfies Dialect
}