Skip to content

Commit 8d33359

Browse files
committed
feat(dialect-tauri)!: drop support for MySQL and PostgreSQL
1 parent a58a538 commit 8d33359

File tree

3 files changed

+22
-45
lines changed

3 files changed

+22
-45
lines changed

packages/dialect-tauri/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# kysely-dialect-tauri
22

3-
[kysely](https://github.com/kysely-org/kysely) dialect for [`Tauri`](https://tauri.app/), using [official sql plugin](https://github.com/tauri-apps/plugins-workspace/tree/dev/plugins/sql), support MySQL, PostgreSQL and SQLite
3+
[kysely](https://github.com/kysely-org/kysely) dialect for [`Tauri`](https://tauri.app/) with SQLite, using [official sql plugin](https://github.com/tauri-apps/plugins-workspace/tree/dev/plugins/sql)
44

55
## Install
66

@@ -17,7 +17,6 @@ import { appDataDir } from '@tauri-apps/api/path'
1717

1818
const kysely = new Kysely<DB>({
1919
dialect: new TauriSqlDialect({
20-
type: 'sqlite',
2120
database: prefix => Database.load(`${prefix}${await appDataDir()}test.db`)
2221
}),
2322
})
@@ -26,9 +25,13 @@ const kysely = new Kysely<DB>({
2625
## Config
2726

2827
```ts
29-
export interface TauriSqlDialectConfig<T extends 'sqlite' | 'mysql' | 'postgres'> {
30-
database: Promisable<TauriSqlDB> | ((prefix: T extends 'sqlite' ? `${T}:` : `${T}://`) => Promisable<TauriSqlDB>)
31-
type: T
28+
export interface TauriSqliteDialectConfig {
29+
database: Promisable<TauriSqlDB> | ((prefix: 'sqlite:') => Promisable<TauriSqlDB>)
30+
/**
31+
* Called once when the first query is executed.
32+
*
33+
* This is a Kysely specific feature and does not come from the `better-sqlite3` module.
34+
*/
3235
onCreateConnection?: (connection: DatabaseConnection) => Promisable<void>
3336
}
3437
```

packages/dialect-tauri/src/driver.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import type { DatabaseConnection, QueryResult } from 'kysely'
22
import { CompiledQuery, SelectQueryNode } from 'kysely'
33
import type { TauriSqlDB } from './type'
4-
import type { TauriSqlDialectConfig } from '.'
4+
import type { TauriSqliteDialectConfig } from '.'
55

6-
export class TaruiSqlDriver<T extends 'sqlite' | 'mysql' | 'postgres'> {
7-
private config: TauriSqlDialectConfig<T>
6+
export class TaruiSqlDriver {
7+
private config: TauriSqliteDialectConfig
88
private db?: TauriSqlDB
99
private connectionMutex = new ConnectionMutex()
1010
private connection?: DatabaseConnection
11-
constructor(config: TauriSqlDialectConfig<T>) {
11+
constructor(config: TauriSqliteDialectConfig) {
1212
this.config = config
1313
}
1414

1515
async init(): Promise<void> {
1616
this.db = typeof this.config.database === 'function'
17-
? await this.config.database(this.config.type + this.config.type === 'sqlite' ? ':' : '://' as any)
17+
? await this.config.database('sqlite:' as any)
1818
: await this.config.database
1919
this.connection = new TauriSqlConnection(this.db)
2020

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { DatabaseConnection, DatabaseIntrospector, DialectAdapter, Driver, Kysely, QueryCompiler } from 'kysely'
2-
import { MysqlAdapter, MysqlIntrospector, MysqlQueryCompiler, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from 'kysely'
2+
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler } from 'kysely'
33
import { TaruiSqlDriver } from './driver'
44
import type { Promisable, TauriSqlDB } from './type'
55

6-
export interface TauriSqlDialectConfig<T extends 'sqlite' | 'mysql' | 'postgres'> {
6+
export interface TauriSqliteDialectConfig {
77
/**
88
* Tauri database instance.
99
*
@@ -14,17 +14,12 @@ export interface TauriSqlDialectConfig<T extends 'sqlite' | 'mysql' | 'postgres'
1414
*
1515
* const kysely = new Kysely<DB>({
1616
* dialect: new TauriSqlDialect({
17-
* type: 'sqlite',
1817
* database: prefix => Database.load(`${prefix}${await appDataDir()}test.db`)
1918
* }),
2019
* })
2120
* ```
2221
*/
23-
database: Promisable<TauriSqlDB> | ((prefix: T extends 'sqlite' ? `${T}:` : `${T}://`) => Promisable<TauriSqlDB>)
24-
/**
25-
* database type
26-
*/
27-
type: T
22+
database: Promisable<TauriSqlDB> | ((prefix: 'sqlite:') => Promisable<TauriSqlDB>)
2823
/**
2924
* Called once when the first query is executed.
3025
*
@@ -35,14 +30,14 @@ export interface TauriSqlDialectConfig<T extends 'sqlite' | 'mysql' | 'postgres'
3530
/**
3631
* https://github.com/tauri-apps/plugins-workspace/tree/dev/plugins/sql
3732
*/
38-
export class TauriSqlDialect<T extends 'sqlite' | 'mysql' | 'postgres'> {
39-
private config: TauriSqlDialectConfig<T>
33+
export class TauriSqliteDialect {
34+
private config: TauriSqliteDialectConfig
4035
/**
4136
* dialect for Tauri,
4237
* using [official sql plugin](https://github.com/tauri-apps/plugins-workspace/tree/dev/plugins/sql),
4338
* support MySQL, PostgreSQL and SQLite
4439
*/
45-
constructor(config: TauriSqlDialectConfig<T>) {
40+
constructor(config: TauriSqliteDialectConfig) {
4641
this.config = config
4742
}
4843

@@ -51,35 +46,14 @@ export class TauriSqlDialect<T extends 'sqlite' | 'mysql' | 'postgres'> {
5146
}
5247

5348
createQueryCompiler(): QueryCompiler {
54-
switch (this.config.type) {
55-
case 'mysql':
56-
return new MysqlQueryCompiler()
57-
case 'postgres':
58-
return new PostgresQueryCompiler()
59-
default:
60-
return new SqliteQueryCompiler()
61-
}
49+
return new SqliteQueryCompiler()
6250
}
6351

6452
createAdapter(): DialectAdapter {
65-
switch (this.config.type) {
66-
case 'mysql':
67-
return new MysqlAdapter()
68-
case 'postgres':
69-
return new PostgresAdapter()
70-
default:
71-
return new SqliteAdapter()
72-
}
53+
return new SqliteAdapter()
7354
}
7455

7556
createIntrospector(db: Kysely<any>): DatabaseIntrospector {
76-
switch (this.config.type) {
77-
case 'mysql':
78-
return new MysqlIntrospector(db)
79-
case 'postgres':
80-
return new PostgresIntrospector(db)
81-
default:
82-
return new SqliteIntrospector(db)
83-
}
57+
return new SqliteIntrospector(db)
8458
}
8559
}

0 commit comments

Comments
 (0)