@tauri-apps/plugin-sql 2.0.0-rc.1 → 2.0.0
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 +29 -21
- package/dist-js/index.cjs +9 -9
- package/dist-js/index.js +9 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Interface with SQL databases through [sqlx](https://github.com/launchbadge/sqlx). It supports the `sqlite`, `mysql` and `postgres` drivers, enabled by a Cargo feature.
|
|
4
4
|
|
|
5
|
+
| Platform | Supported |
|
|
6
|
+
| -------- | --------- |
|
|
7
|
+
| Linux | ✓ |
|
|
8
|
+
| Windows | ✓ |
|
|
9
|
+
| macOS | ✓ |
|
|
10
|
+
| Android | ✓ |
|
|
11
|
+
| iOS | x |
|
|
12
|
+
|
|
5
13
|
## Install
|
|
6
14
|
|
|
7
|
-
_This plugin requires a Rust version of at least **1.
|
|
15
|
+
_This plugin requires a Rust version of at least **1.78**_
|
|
8
16
|
|
|
9
17
|
There are three general methods of installation that we can recommend.
|
|
10
18
|
|
|
@@ -19,7 +27,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
|
|
|
19
27
|
```toml
|
|
20
28
|
[dependencies.tauri-plugin-sql]
|
|
21
29
|
features = ["sqlite"] # or "postgres", or "mysql"
|
|
22
|
-
version = "2.0.0
|
|
30
|
+
version = "2.0.0"
|
|
23
31
|
# alternatively with Git
|
|
24
32
|
git = "https://github.com/tauri-apps/plugins-workspace"
|
|
25
33
|
branch = "v2"
|
|
@@ -62,16 +70,16 @@ fn main() {
|
|
|
62
70
|
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
|
63
71
|
|
|
64
72
|
```javascript
|
|
65
|
-
import Database from
|
|
73
|
+
import Database from '@tauri-apps/plugin-sql'
|
|
66
74
|
|
|
67
75
|
// sqlite. The path is relative to `tauri::api::path::BaseDirectory::AppConfig`.
|
|
68
|
-
const db = await Database.load(
|
|
76
|
+
const db = await Database.load('sqlite:test.db')
|
|
69
77
|
// mysql
|
|
70
|
-
const db = await Database.load(
|
|
78
|
+
const db = await Database.load('mysql://user:pass@host/database')
|
|
71
79
|
// postgres
|
|
72
|
-
const db = await Database.load(
|
|
80
|
+
const db = await Database.load('postgres://postgres:password@localhost/test')
|
|
73
81
|
|
|
74
|
-
await db.execute(
|
|
82
|
+
await db.execute('INSERT INTO ...')
|
|
75
83
|
```
|
|
76
84
|
|
|
77
85
|
## Syntax
|
|
@@ -84,25 +92,25 @@ We use sqlx as our underlying library, adopting their query syntax:
|
|
|
84
92
|
```javascript
|
|
85
93
|
// INSERT and UPDATE examples for sqlite and postgres
|
|
86
94
|
const result = await db.execute(
|
|
87
|
-
|
|
88
|
-
[todos.id, todos.title, todos.status]
|
|
89
|
-
)
|
|
95
|
+
'INSERT into todos (id, title, status) VALUES ($1, $2, $3)',
|
|
96
|
+
[todos.id, todos.title, todos.status]
|
|
97
|
+
)
|
|
90
98
|
|
|
91
99
|
const result = await db.execute(
|
|
92
|
-
|
|
93
|
-
[todos.title, todos.status, todos.id]
|
|
94
|
-
)
|
|
100
|
+
'UPDATE todos SET title = $1, status = $2 WHERE id = $3',
|
|
101
|
+
[todos.title, todos.status, todos.id]
|
|
102
|
+
)
|
|
95
103
|
|
|
96
104
|
// INSERT and UPDATE examples for mysql
|
|
97
105
|
const result = await db.execute(
|
|
98
|
-
|
|
99
|
-
[todos.id, todos.title, todos.status]
|
|
100
|
-
)
|
|
106
|
+
'INSERT into todos (id, title, status) VALUES (?, ?, ?)',
|
|
107
|
+
[todos.id, todos.title, todos.status]
|
|
108
|
+
)
|
|
101
109
|
|
|
102
110
|
const result = await db.execute(
|
|
103
|
-
|
|
104
|
-
[todos.title, todos.status, todos.id]
|
|
105
|
-
)
|
|
111
|
+
'UPDATE todos SET title = ?, status = ? WHERE id = ?',
|
|
112
|
+
[todos.title, todos.status, todos.id]
|
|
113
|
+
)
|
|
106
114
|
```
|
|
107
115
|
|
|
108
116
|
## Migrations
|
|
@@ -173,8 +181,8 @@ To apply the migrations when the plugin is initialized, add the connection strin
|
|
|
173
181
|
Alternatively, the client side `load()` also runs the migrations for a given connection string:
|
|
174
182
|
|
|
175
183
|
```ts
|
|
176
|
-
import Database from
|
|
177
|
-
const db = await Database.load(
|
|
184
|
+
import Database from '@tauri-apps/plugin-sql'
|
|
185
|
+
const db = await Database.load('sqlite:mydatabase.db')
|
|
178
186
|
```
|
|
179
187
|
|
|
180
188
|
Ensure that the migrations are defined in the correct order and are safe to run multiple times.
|
package/dist-js/index.cjs
CHANGED
|
@@ -31,8 +31,8 @@ class Database {
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
static async load(path) {
|
|
34
|
-
const _path = await core.invoke(
|
|
35
|
-
db: path
|
|
34
|
+
const _path = await core.invoke('plugin:sql|load', {
|
|
35
|
+
db: path
|
|
36
36
|
});
|
|
37
37
|
return new Database(_path);
|
|
38
38
|
}
|
|
@@ -88,14 +88,14 @@ class Database {
|
|
|
88
88
|
* ```
|
|
89
89
|
*/
|
|
90
90
|
async execute(query, bindValues) {
|
|
91
|
-
const [rowsAffected, lastInsertId] = await core.invoke(
|
|
91
|
+
const [rowsAffected, lastInsertId] = await core.invoke('plugin:sql|execute', {
|
|
92
92
|
db: this.path,
|
|
93
93
|
query,
|
|
94
|
-
values: bindValues ?? []
|
|
94
|
+
values: bindValues ?? []
|
|
95
95
|
});
|
|
96
96
|
return {
|
|
97
97
|
lastInsertId,
|
|
98
|
-
rowsAffected
|
|
98
|
+
rowsAffected
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
@@ -117,10 +117,10 @@ class Database {
|
|
|
117
117
|
* ```
|
|
118
118
|
*/
|
|
119
119
|
async select(query, bindValues) {
|
|
120
|
-
const result = await core.invoke(
|
|
120
|
+
const result = await core.invoke('plugin:sql|select', {
|
|
121
121
|
db: this.path,
|
|
122
122
|
query,
|
|
123
|
-
values: bindValues ?? []
|
|
123
|
+
values: bindValues ?? []
|
|
124
124
|
});
|
|
125
125
|
return result;
|
|
126
126
|
}
|
|
@@ -136,8 +136,8 @@ class Database {
|
|
|
136
136
|
* @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
|
|
137
137
|
*/
|
|
138
138
|
async close(db) {
|
|
139
|
-
const success = await core.invoke(
|
|
140
|
-
db
|
|
139
|
+
const success = await core.invoke('plugin:sql|close', {
|
|
140
|
+
db
|
|
141
141
|
});
|
|
142
142
|
return success;
|
|
143
143
|
}
|
package/dist-js/index.js
CHANGED
|
@@ -29,8 +29,8 @@ class Database {
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
static async load(path) {
|
|
32
|
-
const _path = await invoke(
|
|
33
|
-
db: path
|
|
32
|
+
const _path = await invoke('plugin:sql|load', {
|
|
33
|
+
db: path
|
|
34
34
|
});
|
|
35
35
|
return new Database(_path);
|
|
36
36
|
}
|
|
@@ -86,14 +86,14 @@ class Database {
|
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
88
|
async execute(query, bindValues) {
|
|
89
|
-
const [rowsAffected, lastInsertId] = await invoke(
|
|
89
|
+
const [rowsAffected, lastInsertId] = await invoke('plugin:sql|execute', {
|
|
90
90
|
db: this.path,
|
|
91
91
|
query,
|
|
92
|
-
values: bindValues ?? []
|
|
92
|
+
values: bindValues ?? []
|
|
93
93
|
});
|
|
94
94
|
return {
|
|
95
95
|
lastInsertId,
|
|
96
|
-
rowsAffected
|
|
96
|
+
rowsAffected
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
@@ -115,10 +115,10 @@ class Database {
|
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
117
|
async select(query, bindValues) {
|
|
118
|
-
const result = await invoke(
|
|
118
|
+
const result = await invoke('plugin:sql|select', {
|
|
119
119
|
db: this.path,
|
|
120
120
|
query,
|
|
121
|
-
values: bindValues ?? []
|
|
121
|
+
values: bindValues ?? []
|
|
122
122
|
});
|
|
123
123
|
return result;
|
|
124
124
|
}
|
|
@@ -134,8 +134,8 @@ class Database {
|
|
|
134
134
|
* @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
|
|
135
135
|
*/
|
|
136
136
|
async close(db) {
|
|
137
|
-
const success = await invoke(
|
|
138
|
-
db
|
|
137
|
+
const success = await invoke('plugin:sql|close', {
|
|
138
|
+
db
|
|
139
139
|
});
|
|
140
140
|
return success;
|
|
141
141
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-sql",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Interface with SQL databases",
|
|
5
|
-
"license": "MIT
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"authors": [
|
|
7
7
|
"Tauri Programme within The Commons Conservancy"
|
|
8
8
|
],
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tauri-apps/api": "^2.0.0
|
|
28
|
+
"@tauri-apps/api": "^2.0.0"
|
|
29
29
|
}
|
|
30
30
|
}
|