|
1 | 1 | import { invariant, lowerCaseFirst } from '@zenstackhq/common-helpers'; |
2 | | -import type { QueryExecutor, SqliteDialectConfig } from 'kysely'; |
| 2 | +import type { QueryExecutor } from 'kysely'; |
3 | 3 | import { |
4 | 4 | CompiledQuery, |
5 | 5 | DefaultConnectionProvider, |
6 | 6 | DefaultQueryExecutor, |
7 | 7 | Kysely, |
8 | 8 | Log, |
9 | | - PostgresDialect, |
10 | 9 | sql, |
11 | | - SqliteDialect, |
12 | 10 | type KyselyProps, |
13 | | - type PostgresDialectConfig, |
14 | 11 | } from 'kysely'; |
15 | | -import { match } from 'ts-pattern'; |
16 | 12 | import type { GetModels, ProcedureDef, SchemaDef } from '../schema'; |
17 | 13 | import type { AuthType } from '../schema/auth'; |
18 | 14 | import type { UnwrapTuplePromises } from '../utils/type-utils'; |
@@ -88,18 +84,17 @@ export class ClientImpl<Schema extends SchemaDef> { |
88 | 84 | this.kyselyRaw = baseClient.kyselyRaw; |
89 | 85 | this.auth = baseClient.auth; |
90 | 86 | } else { |
91 | | - const dialect = this.getKyselyDialect(); |
92 | | - const driver = new ZenStackDriver(dialect.createDriver(), new Log(this.$options.log ?? [])); |
93 | | - const compiler = dialect.createQueryCompiler(); |
94 | | - const adapter = dialect.createAdapter(); |
| 87 | + const driver = new ZenStackDriver(options.dialect.createDriver(), new Log(this.$options.log ?? [])); |
| 88 | + const compiler = options.dialect.createQueryCompiler(); |
| 89 | + const adapter = options.dialect.createAdapter(); |
95 | 90 | const connectionProvider = new DefaultConnectionProvider(driver); |
96 | 91 |
|
97 | 92 | this.kyselyProps = { |
98 | 93 | config: { |
99 | | - dialect, |
| 94 | + dialect: options.dialect, |
100 | 95 | log: this.$options.log, |
101 | 96 | }, |
102 | | - dialect, |
| 97 | + dialect: options.dialect, |
103 | 98 | driver, |
104 | 99 | executor: executor ?? new ZenStackQueryExecutor(this, driver, compiler, adapter, connectionProvider), |
105 | 100 | }; |
@@ -135,21 +130,6 @@ export class ClientImpl<Schema extends SchemaDef> { |
135 | 130 | return new ClientImpl(this.schema, this.$options, this, executor); |
136 | 131 | } |
137 | 132 |
|
138 | | - private getKyselyDialect() { |
139 | | - return match(this.schema.provider.type) |
140 | | - .with('sqlite', () => this.makeSqliteKyselyDialect()) |
141 | | - .with('postgresql', () => this.makePostgresKyselyDialect()) |
142 | | - .exhaustive(); |
143 | | - } |
144 | | - |
145 | | - private makePostgresKyselyDialect(): PostgresDialect { |
146 | | - return new PostgresDialect(this.options.dialectConfig as PostgresDialectConfig); |
147 | | - } |
148 | | - |
149 | | - private makeSqliteKyselyDialect(): SqliteDialect { |
150 | | - return new SqliteDialect(this.options.dialectConfig as SqliteDialectConfig); |
151 | | - } |
152 | | - |
153 | 133 | // overload for interactive transaction |
154 | 134 | $transaction<T>( |
155 | 135 | callback: (tx: ClientContract<Schema>) => Promise<T>, |
|
0 commit comments