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

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/README.md CHANGED
@@ -12,7 +12,7 @@ Interface with SQL databases through [sqlx](https://github.com/launchbadge/sqlx)
12
12
 
13
13
  ## Install
14
14
 
15
- _This plugin requires a Rust version of at least **1.77.2**_
15
+ _This plugin requires a Rust version of at least **1.95**_
16
16
 
17
17
  There are three general methods of installation that we can recommend.
18
18
 
package/dist-js/index.cjs CHANGED
@@ -5,13 +5,35 @@ var core = require('@tauri-apps/api/core');
5
5
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
6
6
  // SPDX-License-Identifier: Apache-2.0
7
7
  // SPDX-License-Identifier: MIT
8
+ /**
9
+ * Interface with SQL databases through [sqlx](https://github.com/launchbadge/sqlx).
10
+ * Which database engines can be used depends on the drivers enabled on the Rust
11
+ * side of the plugin: SQLite, MySQL and PostgreSQL.
12
+ *
13
+ * @module
14
+ */
8
15
  /**
9
16
  * **Database**
10
17
  *
11
18
  * The `Database` class serves as the primary interface for
12
19
  * communicating with the rust side of the sql plugin.
20
+ *
21
+ * @since 2.0.0
13
22
  */
14
23
  class Database {
24
+ /**
25
+ * Creates a `Database` instance for the given connection string without
26
+ * opening a connection to it. Use {@link Database.load} to connect to the
27
+ * database, or {@link Database.get} for a database that is already loaded.
28
+ *
29
+ * @param path The database connection string, such as `sqlite:test.db`.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import Database from '@tauri-apps/plugin-sql'
34
+ * const db = new Database('sqlite:test.db')
35
+ * ```
36
+ */
15
37
  constructor(path) {
16
38
  this.path = path;
17
39
  }
@@ -26,9 +48,13 @@ class Database {
26
48
  * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
27
49
  *
28
50
  * @example
29
- * ```ts
30
- * const db = await Database.load("sqlite:test.db");
51
+ * ```typescript
52
+ * import Database from '@tauri-apps/plugin-sql'
53
+ * const db = await Database.load('sqlite:test.db')
31
54
  * ```
55
+ *
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
+ * @returns A promise resolving to a `Database` instance connected to the given database.
32
58
  */
33
59
  static async load(path) {
34
60
  const _path = await core.invoke('plugin:sql|load', {
@@ -48,9 +74,13 @@ class Database {
48
74
  * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
49
75
  *
50
76
  * @example
51
- * ```ts
52
- * const db = Database.get("sqlite:test.db");
77
+ * ```typescript
78
+ * import Database from '@tauri-apps/plugin-sql'
79
+ * const db = Database.get('sqlite:test.db')
53
80
  * ```
81
+ *
82
+ * @param path The database connection string, such as `sqlite:test.db`.
83
+ * @returns A `Database` instance bound to the given connection string.
54
84
  */
55
85
  static get(path) {
56
86
  return new Database(path);
@@ -61,7 +91,10 @@ class Database {
61
91
  * Passes a SQL expression to the database for execution.
62
92
  *
63
93
  * @example
64
- * ```ts
94
+ * ```typescript
95
+ * import Database from '@tauri-apps/plugin-sql'
96
+ * const db = await Database.load('sqlite:test.db')
97
+ *
65
98
  * // for sqlite & postgres
66
99
  * // INSERT example
67
100
  * const result = await db.execute(
@@ -86,6 +119,10 @@ class Database {
86
119
  * [ todos.title, todos.status, todos.id ]
87
120
  * );
88
121
  * ```
122
+ *
123
+ * @param query The SQL statement to run, using `$1`, `$2`, ... placeholders on SQLite and PostgreSQL and `?` placeholders on MySQL.
124
+ * @param bindValues The values bound to the query placeholders, in the order they appear in the statement. Defaults to no values.
125
+ * @returns A promise resolving to the number of rows affected by the statement and the last inserted id.
89
126
  */
90
127
  async execute(query, bindValues) {
91
128
  const [rowsAffected, lastInsertId] = await core.invoke('plugin:sql|execute', {
@@ -104,7 +141,10 @@ class Database {
104
141
  * Passes in a SELECT query to the database for execution.
105
142
  *
106
143
  * @example
107
- * ```ts
144
+ * ```typescript
145
+ * import Database from '@tauri-apps/plugin-sql'
146
+ * const db = await Database.load('sqlite:test.db')
147
+ *
108
148
  * // for sqlite & postgres
109
149
  * const result = await db.select(
110
150
  * "SELECT * from todos WHERE id = $1", [ id ]
@@ -115,6 +155,10 @@ class Database {
115
155
  * "SELECT * from todos WHERE id = ?", [ id ]
116
156
  * );
117
157
  * ```
158
+ *
159
+ * @param query The SQL query to run, using `$1`, `$2`, ... placeholders on SQLite and PostgreSQL and `?` placeholders on MySQL.
160
+ * @param bindValues The values bound to the query placeholders, in the order they appear in the query. Defaults to no values.
161
+ * @returns A promise resolving to the selected rows, each row being an object keyed by column name.
118
162
  */
119
163
  async select(query, bindValues) {
120
164
  const result = await core.invoke('plugin:sql|select', {
@@ -130,10 +174,14 @@ class Database {
130
174
  * Closes the database connection pool.
131
175
  *
132
176
  * @example
133
- * ```ts
177
+ * ```typescript
178
+ * import Database from '@tauri-apps/plugin-sql'
179
+ * const db = await Database.load('sqlite:test.db')
134
180
  * const success = await db.close()
135
181
  * ```
182
+ *
136
183
  * @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
184
+ * @returns A promise resolving to `true` once the matching connection pools have been closed.
137
185
  */
138
186
  async close(db) {
139
187
  const success = await core.invoke('plugin:sql|close', {
@@ -1,3 +1,6 @@
1
+ /**
2
+ * The outcome of a statement run through {@link Database.execute}.
3
+ */
1
4
  export interface QueryResult {
2
5
  /** The number of rows affected by the query. */
3
6
  rowsAffected: number;
@@ -16,9 +19,29 @@ export interface QueryResult {
16
19
  *
17
20
  * The `Database` class serves as the primary interface for
18
21
  * communicating with the rust side of the sql plugin.
22
+ *
23
+ * @since 2.0.0
19
24
  */
20
25
  export default class Database {
26
+ /**
27
+ * The connection string identifying the database on the Rust side,
28
+ * for instance `sqlite:test.db`, `mysql://user:pass@host/database`
29
+ * or `postgres://user:pass@host/database`.
30
+ */
21
31
  path: string;
32
+ /**
33
+ * Creates a `Database` instance for the given connection string without
34
+ * opening a connection to it. Use {@link Database.load} to connect to the
35
+ * database, or {@link Database.get} for a database that is already loaded.
36
+ *
37
+ * @param path The database connection string, such as `sqlite:test.db`.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * import Database from '@tauri-apps/plugin-sql'
42
+ * const db = new Database('sqlite:test.db')
43
+ * ```
44
+ */
22
45
  constructor(path: string);
23
46
  /**
24
47
  * **load**
@@ -31,9 +54,13 @@ export default class Database {
31
54
  * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
32
55
  *
33
56
  * @example
34
- * ```ts
35
- * const db = await Database.load("sqlite:test.db");
57
+ * ```typescript
58
+ * import Database from '@tauri-apps/plugin-sql'
59
+ * const db = await Database.load('sqlite:test.db')
36
60
  * ```
61
+ *
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.
63
+ * @returns A promise resolving to a `Database` instance connected to the given database.
37
64
  */
38
65
  static load(path: string): Promise<Database>;
39
66
  /**
@@ -48,9 +75,13 @@ export default class Database {
48
75
  * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
49
76
  *
50
77
  * @example
51
- * ```ts
52
- * const db = Database.get("sqlite:test.db");
78
+ * ```typescript
79
+ * import Database from '@tauri-apps/plugin-sql'
80
+ * const db = Database.get('sqlite:test.db')
53
81
  * ```
82
+ *
83
+ * @param path The database connection string, such as `sqlite:test.db`.
84
+ * @returns A `Database` instance bound to the given connection string.
54
85
  */
55
86
  static get(path: string): Database;
56
87
  /**
@@ -59,7 +90,10 @@ export default class Database {
59
90
  * Passes a SQL expression to the database for execution.
60
91
  *
61
92
  * @example
62
- * ```ts
93
+ * ```typescript
94
+ * import Database from '@tauri-apps/plugin-sql'
95
+ * const db = await Database.load('sqlite:test.db')
96
+ *
63
97
  * // for sqlite & postgres
64
98
  * // INSERT example
65
99
  * const result = await db.execute(
@@ -84,6 +118,10 @@ export default class Database {
84
118
  * [ todos.title, todos.status, todos.id ]
85
119
  * );
86
120
  * ```
121
+ *
122
+ * @param query The SQL statement to run, using `$1`, `$2`, ... placeholders on SQLite and PostgreSQL and `?` placeholders on MySQL.
123
+ * @param bindValues The values bound to the query placeholders, in the order they appear in the statement. Defaults to no values.
124
+ * @returns A promise resolving to the number of rows affected by the statement and the last inserted id.
87
125
  */
88
126
  execute(query: string, bindValues?: unknown[]): Promise<QueryResult>;
89
127
  /**
@@ -92,7 +130,10 @@ export default class Database {
92
130
  * Passes in a SELECT query to the database for execution.
93
131
  *
94
132
  * @example
95
- * ```ts
133
+ * ```typescript
134
+ * import Database from '@tauri-apps/plugin-sql'
135
+ * const db = await Database.load('sqlite:test.db')
136
+ *
96
137
  * // for sqlite & postgres
97
138
  * const result = await db.select(
98
139
  * "SELECT * from todos WHERE id = $1", [ id ]
@@ -103,6 +144,10 @@ export default class Database {
103
144
  * "SELECT * from todos WHERE id = ?", [ id ]
104
145
  * );
105
146
  * ```
147
+ *
148
+ * @param query The SQL query to run, using `$1`, `$2`, ... placeholders on SQLite and PostgreSQL and `?` placeholders on MySQL.
149
+ * @param bindValues The values bound to the query placeholders, in the order they appear in the query. Defaults to no values.
150
+ * @returns A promise resolving to the selected rows, each row being an object keyed by column name.
106
151
  */
107
152
  select<T>(query: string, bindValues?: unknown[]): Promise<T>;
108
153
  /**
@@ -111,10 +156,14 @@ export default class Database {
111
156
  * Closes the database connection pool.
112
157
  *
113
158
  * @example
114
- * ```ts
159
+ * ```typescript
160
+ * import Database from '@tauri-apps/plugin-sql'
161
+ * const db = await Database.load('sqlite:test.db')
115
162
  * const success = await db.close()
116
163
  * ```
164
+ *
117
165
  * @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
166
+ * @returns A promise resolving to `true` once the matching connection pools have been closed.
118
167
  */
119
168
  close(db?: string): Promise<boolean>;
120
169
  }
package/dist-js/index.js CHANGED
@@ -3,13 +3,35 @@ import { invoke } from '@tauri-apps/api/core';
3
3
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
4
4
  // SPDX-License-Identifier: Apache-2.0
5
5
  // SPDX-License-Identifier: MIT
6
+ /**
7
+ * Interface with SQL databases through [sqlx](https://github.com/launchbadge/sqlx).
8
+ * Which database engines can be used depends on the drivers enabled on the Rust
9
+ * side of the plugin: SQLite, MySQL and PostgreSQL.
10
+ *
11
+ * @module
12
+ */
6
13
  /**
7
14
  * **Database**
8
15
  *
9
16
  * The `Database` class serves as the primary interface for
10
17
  * communicating with the rust side of the sql plugin.
18
+ *
19
+ * @since 2.0.0
11
20
  */
12
21
  class Database {
22
+ /**
23
+ * Creates a `Database` instance for the given connection string without
24
+ * opening a connection to it. Use {@link Database.load} to connect to the
25
+ * database, or {@link Database.get} for a database that is already loaded.
26
+ *
27
+ * @param path The database connection string, such as `sqlite:test.db`.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * import Database from '@tauri-apps/plugin-sql'
32
+ * const db = new Database('sqlite:test.db')
33
+ * ```
34
+ */
13
35
  constructor(path) {
14
36
  this.path = path;
15
37
  }
@@ -24,9 +46,13 @@ class Database {
24
46
  * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
25
47
  *
26
48
  * @example
27
- * ```ts
28
- * const db = await Database.load("sqlite:test.db");
49
+ * ```typescript
50
+ * import Database from '@tauri-apps/plugin-sql'
51
+ * const db = await Database.load('sqlite:test.db')
29
52
  * ```
53
+ *
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
+ * @returns A promise resolving to a `Database` instance connected to the given database.
30
56
  */
31
57
  static async load(path) {
32
58
  const _path = await invoke('plugin:sql|load', {
@@ -46,9 +72,13 @@ class Database {
46
72
  * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
47
73
  *
48
74
  * @example
49
- * ```ts
50
- * const db = Database.get("sqlite:test.db");
75
+ * ```typescript
76
+ * import Database from '@tauri-apps/plugin-sql'
77
+ * const db = Database.get('sqlite:test.db')
51
78
  * ```
79
+ *
80
+ * @param path The database connection string, such as `sqlite:test.db`.
81
+ * @returns A `Database` instance bound to the given connection string.
52
82
  */
53
83
  static get(path) {
54
84
  return new Database(path);
@@ -59,7 +89,10 @@ class Database {
59
89
  * Passes a SQL expression to the database for execution.
60
90
  *
61
91
  * @example
62
- * ```ts
92
+ * ```typescript
93
+ * import Database from '@tauri-apps/plugin-sql'
94
+ * const db = await Database.load('sqlite:test.db')
95
+ *
63
96
  * // for sqlite & postgres
64
97
  * // INSERT example
65
98
  * const result = await db.execute(
@@ -84,6 +117,10 @@ class Database {
84
117
  * [ todos.title, todos.status, todos.id ]
85
118
  * );
86
119
  * ```
120
+ *
121
+ * @param query The SQL statement to run, using `$1`, `$2`, ... placeholders on SQLite and PostgreSQL and `?` placeholders on MySQL.
122
+ * @param bindValues The values bound to the query placeholders, in the order they appear in the statement. Defaults to no values.
123
+ * @returns A promise resolving to the number of rows affected by the statement and the last inserted id.
87
124
  */
88
125
  async execute(query, bindValues) {
89
126
  const [rowsAffected, lastInsertId] = await invoke('plugin:sql|execute', {
@@ -102,7 +139,10 @@ class Database {
102
139
  * Passes in a SELECT query to the database for execution.
103
140
  *
104
141
  * @example
105
- * ```ts
142
+ * ```typescript
143
+ * import Database from '@tauri-apps/plugin-sql'
144
+ * const db = await Database.load('sqlite:test.db')
145
+ *
106
146
  * // for sqlite & postgres
107
147
  * const result = await db.select(
108
148
  * "SELECT * from todos WHERE id = $1", [ id ]
@@ -113,6 +153,10 @@ class Database {
113
153
  * "SELECT * from todos WHERE id = ?", [ id ]
114
154
  * );
115
155
  * ```
156
+ *
157
+ * @param query The SQL query to run, using `$1`, `$2`, ... placeholders on SQLite and PostgreSQL and `?` placeholders on MySQL.
158
+ * @param bindValues The values bound to the query placeholders, in the order they appear in the query. Defaults to no values.
159
+ * @returns A promise resolving to the selected rows, each row being an object keyed by column name.
116
160
  */
117
161
  async select(query, bindValues) {
118
162
  const result = await invoke('plugin:sql|select', {
@@ -128,10 +172,14 @@ class Database {
128
172
  * Closes the database connection pool.
129
173
  *
130
174
  * @example
131
- * ```ts
175
+ * ```typescript
176
+ * import Database from '@tauri-apps/plugin-sql'
177
+ * const db = await Database.load('sqlite:test.db')
132
178
  * const success = await db.close()
133
179
  * ```
180
+ *
134
181
  * @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
182
+ * @returns A promise resolving to `true` once the matching connection pools have been closed.
135
183
  */
136
184
  async close(db) {
137
185
  const success = await invoke('plugin:sql|close', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-sql",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.2",
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": "^2.11.0"
28
+ "@tauri-apps/api": "^3.0.0-alpha.1"
29
29
  }
30
30
  }