@tauri-apps/plugin-sql 3.0.0-alpha.2 → 3.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-js/index.cjs CHANGED
@@ -51,14 +51,17 @@ class Database {
51
51
  * ```typescript
52
52
  * import Database from '@tauri-apps/plugin-sql'
53
53
  * const db = await Database.load('sqlite:test.db')
54
+ * const existingDb = await Database.load('sqlite:test.db', { autoCreate: false })
54
55
  * ```
55
56
  *
56
- * @param path The database connection string, such as `sqlite:test.db`. The database is created if it does not exist yet, and any migration registered for it on the Rust side is run.
57
+ * @param path The database connection string, such as `sqlite:test.db`. The database is created if it does not exist yet (unless `options.autoCreate` is `false`), and any migration registered for it on the Rust side is run.
58
+ * @param options Configuration options for connecting to the database.
57
59
  * @returns A promise resolving to a `Database` instance connected to the given database.
58
60
  */
59
- static async load(path) {
61
+ static async load(path, options) {
60
62
  const _path = await core.invoke('plugin:sql|load', {
61
- db: path
63
+ db: path,
64
+ options
62
65
  });
63
66
  return new Database(_path);
64
67
  }
@@ -14,6 +14,18 @@ export interface QueryResult {
14
14
  */
15
15
  lastInsertId?: number;
16
16
  }
17
+ /**
18
+ * Options for loading a database.
19
+ *
20
+ * @since 2.6.0
21
+ */
22
+ export interface LoadOptions {
23
+ /**
24
+ * Whether to automatically create the database if it does not exist yet.
25
+ * Defaults to `true`.
26
+ */
27
+ autoCreate?: boolean;
28
+ }
17
29
  /**
18
30
  * **Database**
19
31
  *
@@ -57,12 +69,14 @@ export default class Database {
57
69
  * ```typescript
58
70
  * import Database from '@tauri-apps/plugin-sql'
59
71
  * const db = await Database.load('sqlite:test.db')
72
+ * const existingDb = await Database.load('sqlite:test.db', { autoCreate: false })
60
73
  * ```
61
74
  *
62
- * @param path The database connection string, such as `sqlite:test.db`. The database is created if it does not exist yet, and any migration registered for it on the Rust side is run.
75
+ * @param path The database connection string, such as `sqlite:test.db`. The database is created if it does not exist yet (unless `options.autoCreate` is `false`), and any migration registered for it on the Rust side is run.
76
+ * @param options Configuration options for connecting to the database.
63
77
  * @returns A promise resolving to a `Database` instance connected to the given database.
64
78
  */
65
- static load(path: string): Promise<Database>;
79
+ static load(path: string, options?: LoadOptions): Promise<Database>;
66
80
  /**
67
81
  * **get**
68
82
  *
package/dist-js/index.js CHANGED
@@ -49,14 +49,17 @@ class Database {
49
49
  * ```typescript
50
50
  * import Database from '@tauri-apps/plugin-sql'
51
51
  * const db = await Database.load('sqlite:test.db')
52
+ * const existingDb = await Database.load('sqlite:test.db', { autoCreate: false })
52
53
  * ```
53
54
  *
54
- * @param path The database connection string, such as `sqlite:test.db`. The database is created if it does not exist yet, and any migration registered for it on the Rust side is run.
55
+ * @param path The database connection string, such as `sqlite:test.db`. The database is created if it does not exist yet (unless `options.autoCreate` is `false`), and any migration registered for it on the Rust side is run.
56
+ * @param options Configuration options for connecting to the database.
55
57
  * @returns A promise resolving to a `Database` instance connected to the given database.
56
58
  */
57
- static async load(path) {
59
+ static async load(path, options) {
58
60
  const _path = await invoke('plugin:sql|load', {
59
- db: path
61
+ db: path,
62
+ options
60
63
  });
61
64
  return new Database(_path);
62
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-sql",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.3",
4
4
  "description": "Interface with SQL databases",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "authors": [
@@ -25,6 +25,6 @@
25
25
  "LICENSE"
26
26
  ],
27
27
  "dependencies": {
28
- "@tauri-apps/api": "^3.0.0-alpha.1"
28
+ "@tauri-apps/api": "^3.0.0-alpha.2"
29
29
  }
30
30
  }