Skip to content

Commit 5aa31f9

Browse files
committed
feat(dialect-tauri): add support for promise db instance
1 parent 4fde780 commit 5aa31f9

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

packages/dialect-tauri/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
using [Tauri official sqlite plugin](https://github.com/tauri-apps/plugins-workspace/tree/dev/plugins/sql)
44

5+
### usage
6+
7+
```ts
8+
const kysely = new Kysely<DB>({
9+
dialect: new TauriSqlDialect({
10+
database: Database.load(`sqlite:${await appDataDir()}test.db`)
11+
}),
12+
})
13+
```
14+
515
### type
616

717
```ts

packages/dialect-tauri/src/driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class TaruiSqlDriver {
1515
async init(): Promise<void> {
1616
this.db = typeof this.config.database === 'function'
1717
? await this.config.database()
18-
: this.config.database
18+
: await this.config.database
1919
this.connection = new TauriSqlConnection(this.db)
2020
if (this.config.onCreateConnection) {
2121
await this.config.onCreateConnection(this.connection)

packages/dialect-tauri/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ import type { TauriSqlDB } from './type'
55

66
export interface TauriSqlDialectConfig {
77
/**
8-
* The path is relative to `tauri::api::path::BaseDirectory::App`.
8+
* Tauri database instance.
9+
*
10+
* @example
11+
* ```ts
12+
* const kysely = new Kysely<DB>({
13+
* dialect: new TauriSqlDialect({
14+
* database: Database.load(`sqlite:${await appDataDir()}test.db`)
15+
* }),
16+
* })
17+
* ```
918
*/
10-
database: TauriSqlDB | (() => Promise<TauriSqlDB>)
19+
database: TauriSqlDB | Promise<TauriSqlDB> | (() => Promise<TauriSqlDB>)
1120
/**
1221
* Called once when the first query is executed.
1322
*

0 commit comments

Comments
 (0)