File tree Expand file tree Collapse file tree 11 files changed +29
-28
lines changed
packages/dialect-wasm/src Expand file tree Collapse file tree 11 files changed +29
-28
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,8 @@ export class CrSqliteDriver extends BaseDriver {
15
15
? await this . config . database ( )
16
16
: this . config . database
17
17
this . connection = new CrSqliteConnection ( this . db )
18
- if ( this . config . onCreateConnection ) {
19
- await this . config . onCreateConnection ( this . connection )
20
- }
18
+
19
+ await this . config . onCreateConnection ?.( this . connection )
21
20
}
22
21
23
22
async destroy ( ) : Promise < void > {
Original file line number Diff line number Diff line change 1
1
import type { DatabaseConnection , Driver } from 'kysely'
2
2
import { BaseDialect } from '../baseDialect'
3
+ import type { Promisable } from '../util'
3
4
import { CrSqliteDriver } from './driver'
4
5
import type { CrSqliteDB } from './type'
5
6
6
7
export interface CrSqliteDialectConfig {
7
- database : CrSqliteDB | ( ( ) => Promise < CrSqliteDB > )
8
- onCreateConnection ?: ( connection : DatabaseConnection ) => Promise < void >
8
+ database : CrSqliteDB | ( ( ) => Promisable < CrSqliteDB > )
9
+ onCreateConnection ?: ( connection : DatabaseConnection ) => Promisable < void >
9
10
}
10
11
export class CrSqliteDialect extends BaseDialect {
11
12
#config: CrSqliteDialectConfig
Original file line number Diff line number Diff line change @@ -15,9 +15,8 @@ export class NodeWasmDriver extends BaseDriver {
15
15
? await this . #config. database ( )
16
16
: this . #config. database
17
17
this . connection = new NodeWasmConnection ( this . #db)
18
- if ( this . #config. onCreateConnection ) {
19
- await this . #config. onCreateConnection ( this . connection )
20
- }
18
+
19
+ await this . #config. onCreateConnection ?.( this . connection )
21
20
}
22
21
23
22
async destroy ( ) : Promise < void > {
Original file line number Diff line number Diff line change 1
1
import type { DatabaseConnection , Driver } from 'kysely'
2
2
import { BaseDialect } from '../baseDialect'
3
+ import type { Promisable } from '../util'
3
4
import type { NodeWasmDataBase } from './type'
4
5
import { NodeWasmDriver } from './driver'
5
6
6
7
export interface NodeWasmDialectConfig {
7
- database : NodeWasmDataBase | ( ( ) => Promise < NodeWasmDataBase > )
8
- onCreateConnection ?: ( connection : DatabaseConnection ) => Promise < void >
8
+ database : NodeWasmDataBase | ( ( ) => Promisable < NodeWasmDataBase > )
9
+ onCreateConnection ?: ( connection : DatabaseConnection ) => Promisable < void >
9
10
}
10
11
11
12
export class NodeWasmDialect extends BaseDialect {
Original file line number Diff line number Diff line change @@ -15,9 +15,8 @@ export class OfficialWasmDriver extends BaseDriver {
15
15
? await this . config . database ( )
16
16
: this . config . database
17
17
this . connection = new OfficailSqliteWasmConnection ( this . db )
18
- if ( this . config . onCreateConnection ) {
19
- await this . config . onCreateConnection ( this . connection )
20
- }
18
+
19
+ await this . config . onCreateConnection ?.( this . connection )
21
20
}
22
21
23
22
async destroy ( ) : Promise < void > {
Original file line number Diff line number Diff line change 1
1
import type { DatabaseConnection } from 'kysely'
2
2
import { BaseDialect } from '../baseDialect'
3
+ import type { Promisable } from '../util'
3
4
import { OfficialWasmDriver } from './driver'
4
5
import type { OfficialWasmDB } from './type'
5
6
6
7
export interface OfficialWasmDialectConfig {
7
- database : OfficialWasmDB | ( ( ) => Promise < OfficialWasmDB > )
8
- onCreateConnection ?: ( connection : DatabaseConnection ) => Promise < void >
8
+ database : OfficialWasmDB | ( ( ) => Promisable < OfficialWasmDB > )
9
+ onCreateConnection ?: ( connection : DatabaseConnection ) => Promisable < void >
9
10
}
10
11
11
12
export class OfficialWasmDialect extends BaseDialect {
Original file line number Diff line number Diff line change @@ -85,9 +85,7 @@ export class SqlJsDriver extends BaseDriver {
85
85
this . config . onWrite ?. delay ,
86
86
)
87
87
88
- if ( this . config . onCreateConnection ) {
89
- await this . config . onCreateConnection ( this . connection )
90
- }
88
+ await this . config . onCreateConnection ?.( this . connection )
91
89
}
92
90
93
91
async beginTransaction ( connection : SqlJsConnection ) : Promise < void > {
Original file line number Diff line number Diff line change 1
1
import type { DatabaseConnection , Driver } from 'kysely'
2
2
import { BaseDialect } from '../baseDialect'
3
+ import type { Promisable } from '../util'
3
4
import { SqlJsDriver } from './driver'
4
5
import type { SqlJSDB } from './type'
5
6
6
7
export interface SqlJsDialectConfig {
7
- database : SqlJSDB | ( ( ) => Promise < SqlJSDB > )
8
+ database : SqlJSDB | ( ( ) => Promisable < SqlJSDB > )
8
9
onWrite ?: {
9
10
func : ( buffer : Uint8Array ) => void
10
11
/**
@@ -20,7 +21,7 @@ export interface SqlJsDialectConfig {
20
21
*/
21
22
maxCalls ?: number
22
23
}
23
- onCreateConnection ?: ( connection : DatabaseConnection ) => Promise < void >
24
+ onCreateConnection ?: ( connection : DatabaseConnection ) => Promisable < void >
24
25
}
25
26
export class SqlJsDialect extends BaseDialect {
26
27
readonly #config: SqlJsDialectConfig
Original file line number Diff line number Diff line change @@ -15,8 +15,10 @@ import { CompiledQuery } from 'kysely'
15
15
*/
16
16
export async function optimzePragma ( conn : DatabaseConnection , cacheSize = 4096 , pageSize = 32 * 1024 ) : Promise < void > {
17
17
await conn . executeQuery ( CompiledQuery . raw ( `PRAGMA cache_size = ${ cacheSize } ;` ) )
18
- await conn . executeQuery ( CompiledQuery . raw ( 'PRAGMA journal_mode = MEMORY;' ) )
19
- await conn . executeQuery ( CompiledQuery . raw ( 'PRAGMA locking_mode = MEMORY;' ) )
20
- await conn . executeQuery ( CompiledQuery . raw ( 'PRAGMA temp_store = 2;' ) )
18
+ await conn . executeQuery ( CompiledQuery . raw ( 'PRAGMA journal_mode = WAL;' ) )
19
+ await conn . executeQuery ( CompiledQuery . raw ( 'PRAGMA temp_store = MEMORY;' ) )
21
20
await conn . executeQuery ( CompiledQuery . raw ( `PRAGMA page_size = ${ pageSize } ;` ) )
21
+ await conn . executeQuery ( CompiledQuery . raw ( 'PRAGMA synchronous = NORMAL;' ) )
22
22
}
23
+
24
+ export type Promisable < T > = T | Promise < T >
Original file line number Diff line number Diff line change @@ -15,9 +15,8 @@ export class WaSqliteDriver extends BaseDriver {
15
15
? await this . config . database ( )
16
16
: this . config . database
17
17
this . connection = new WaSqliteConnection ( this . db )
18
- if ( this . config . onCreateConnection ) {
19
- await this . config . onCreateConnection ( this . connection )
20
- }
18
+
19
+ await this . config . onCreateConnection ?.( this . connection )
21
20
}
22
21
23
22
async destroy ( ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments