@tauri-apps/plugin-sql 2.0.0-alpha.0 → 2.0.0-alpha.1
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 +32 -1
- package/dist-js/index.d.ts +25 -0
- package/dist-js/index.min.js +25 -0
- package/dist-js/index.mjs +25 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
1
|
+

|
|
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
|
|
|
@@ -74,6 +74,37 @@ const db = await Database.load("postgres://postgres:password@localhost/test");
|
|
|
74
74
|
await db.execute("INSERT INTO ...");
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
## Syntax
|
|
78
|
+
|
|
79
|
+
We use sqlx as our underlying library, adopting their query syntax:
|
|
80
|
+
|
|
81
|
+
- sqlite and postgres use the "$#" syntax when substituting query data
|
|
82
|
+
- mysql uses "?" when substituting query data
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
// INSERT and UPDATE examples for sqlite and postgres
|
|
86
|
+
const result = await db.execute(
|
|
87
|
+
"INSERT into todos (id, title, status) VALUES ($1, $2, $3)",
|
|
88
|
+
[todos.id, todos.title, todos.status],
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const result = await db.execute(
|
|
92
|
+
"UPDATE todos SET title = $1, completed = $2 WHERE id = $3",
|
|
93
|
+
[todos.title, todos.status, todos.id],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// INSERT and UPDATE examples for mysql
|
|
97
|
+
const result = await db.execute(
|
|
98
|
+
"INSERT into todos (id, title, status) VALUES (?, ?, ?)",
|
|
99
|
+
[todos.id, todos.title, todos.status],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const result = await db.execute(
|
|
103
|
+
"UPDATE todos SET title = ?, completed = ? WHERE id = ?",
|
|
104
|
+
[todos.title, todos.status, todos.id],
|
|
105
|
+
);
|
|
106
|
+
```
|
|
107
|
+
|
|
77
108
|
## Contributing
|
|
78
109
|
|
|
79
110
|
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
package/dist-js/index.d.ts
CHANGED
|
@@ -65,10 +65,29 @@ export default class Database {
|
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
67
|
* ```ts
|
|
68
|
+
* // for sqlite & postgres
|
|
69
|
+
* // INSERT example
|
|
70
|
+
* const result = await db.execute(
|
|
71
|
+
* "INSERT into todos (id, title, status) VALUES ($1, $2, $3)",
|
|
72
|
+
* [ todos.id, todos.title, todos.status ]
|
|
73
|
+
* );
|
|
74
|
+
* // UPDATE example
|
|
68
75
|
* const result = await db.execute(
|
|
69
76
|
* "UPDATE todos SET title = $1, completed = $2 WHERE id = $3",
|
|
70
77
|
* [ todos.title, todos.status, todos.id ]
|
|
71
78
|
* );
|
|
79
|
+
*
|
|
80
|
+
* // for mysql
|
|
81
|
+
* // INSERT example
|
|
82
|
+
* const result = await db.execute(
|
|
83
|
+
* "INSERT into todos (id, title, status) VALUES (?, ?, ?)",
|
|
84
|
+
* [ todos.id, todos.title, todos.status ]
|
|
85
|
+
* );
|
|
86
|
+
* // UPDATE example
|
|
87
|
+
* const result = await db.execute(
|
|
88
|
+
* "UPDATE todos SET title = ?, completed = ? WHERE id = ?",
|
|
89
|
+
* [ todos.title, todos.status, todos.id ]
|
|
90
|
+
* );
|
|
72
91
|
* ```
|
|
73
92
|
*/
|
|
74
93
|
execute(query: string, bindValues?: unknown[]): Promise<QueryResult>;
|
|
@@ -79,9 +98,15 @@ export default class Database {
|
|
|
79
98
|
*
|
|
80
99
|
* @example
|
|
81
100
|
* ```ts
|
|
101
|
+
* // for sqlite & postgres
|
|
82
102
|
* const result = await db.select(
|
|
83
103
|
* "SELECT * from todos WHERE id = $1", id
|
|
84
104
|
* );
|
|
105
|
+
*
|
|
106
|
+
* // for mysql
|
|
107
|
+
* const result = await db.select(
|
|
108
|
+
* "SELECT * from todos WHERE id = ?", id
|
|
109
|
+
* );
|
|
85
110
|
* ```
|
|
86
111
|
*/
|
|
87
112
|
select<T>(query: string, bindValues?: unknown[]): Promise<T>;
|
package/dist-js/index.min.js
CHANGED
|
@@ -58,10 +58,29 @@ class Database {
|
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* ```ts
|
|
61
|
+
* // for sqlite & postgres
|
|
62
|
+
* // INSERT example
|
|
63
|
+
* const result = await db.execute(
|
|
64
|
+
* "INSERT into todos (id, title, status) VALUES ($1, $2, $3)",
|
|
65
|
+
* [ todos.id, todos.title, todos.status ]
|
|
66
|
+
* );
|
|
67
|
+
* // UPDATE example
|
|
61
68
|
* const result = await db.execute(
|
|
62
69
|
* "UPDATE todos SET title = $1, completed = $2 WHERE id = $3",
|
|
63
70
|
* [ todos.title, todos.status, todos.id ]
|
|
64
71
|
* );
|
|
72
|
+
*
|
|
73
|
+
* // for mysql
|
|
74
|
+
* // INSERT example
|
|
75
|
+
* const result = await db.execute(
|
|
76
|
+
* "INSERT into todos (id, title, status) VALUES (?, ?, ?)",
|
|
77
|
+
* [ todos.id, todos.title, todos.status ]
|
|
78
|
+
* );
|
|
79
|
+
* // UPDATE example
|
|
80
|
+
* const result = await db.execute(
|
|
81
|
+
* "UPDATE todos SET title = ?, completed = ? WHERE id = ?",
|
|
82
|
+
* [ todos.title, todos.status, todos.id ]
|
|
83
|
+
* );
|
|
65
84
|
* ```
|
|
66
85
|
*/
|
|
67
86
|
async execute(query, bindValues) {
|
|
@@ -82,9 +101,15 @@ class Database {
|
|
|
82
101
|
*
|
|
83
102
|
* @example
|
|
84
103
|
* ```ts
|
|
104
|
+
* // for sqlite & postgres
|
|
85
105
|
* const result = await db.select(
|
|
86
106
|
* "SELECT * from todos WHERE id = $1", id
|
|
87
107
|
* );
|
|
108
|
+
*
|
|
109
|
+
* // for mysql
|
|
110
|
+
* const result = await db.select(
|
|
111
|
+
* "SELECT * from todos WHERE id = ?", id
|
|
112
|
+
* );
|
|
88
113
|
* ```
|
|
89
114
|
*/
|
|
90
115
|
async select(query, bindValues) {
|
package/dist-js/index.mjs
CHANGED
|
@@ -58,10 +58,29 @@ class Database {
|
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* ```ts
|
|
61
|
+
* // for sqlite & postgres
|
|
62
|
+
* // INSERT example
|
|
63
|
+
* const result = await db.execute(
|
|
64
|
+
* "INSERT into todos (id, title, status) VALUES ($1, $2, $3)",
|
|
65
|
+
* [ todos.id, todos.title, todos.status ]
|
|
66
|
+
* );
|
|
67
|
+
* // UPDATE example
|
|
61
68
|
* const result = await db.execute(
|
|
62
69
|
* "UPDATE todos SET title = $1, completed = $2 WHERE id = $3",
|
|
63
70
|
* [ todos.title, todos.status, todos.id ]
|
|
64
71
|
* );
|
|
72
|
+
*
|
|
73
|
+
* // for mysql
|
|
74
|
+
* // INSERT example
|
|
75
|
+
* const result = await db.execute(
|
|
76
|
+
* "INSERT into todos (id, title, status) VALUES (?, ?, ?)",
|
|
77
|
+
* [ todos.id, todos.title, todos.status ]
|
|
78
|
+
* );
|
|
79
|
+
* // UPDATE example
|
|
80
|
+
* const result = await db.execute(
|
|
81
|
+
* "UPDATE todos SET title = ?, completed = ? WHERE id = ?",
|
|
82
|
+
* [ todos.title, todos.status, todos.id ]
|
|
83
|
+
* );
|
|
65
84
|
* ```
|
|
66
85
|
*/
|
|
67
86
|
async execute(query, bindValues) {
|
|
@@ -82,9 +101,15 @@ class Database {
|
|
|
82
101
|
*
|
|
83
102
|
* @example
|
|
84
103
|
* ```ts
|
|
104
|
+
* // for sqlite & postgres
|
|
85
105
|
* const result = await db.select(
|
|
86
106
|
* "SELECT * from todos WHERE id = $1", id
|
|
87
107
|
* );
|
|
108
|
+
*
|
|
109
|
+
* // for mysql
|
|
110
|
+
* const result = await db.select(
|
|
111
|
+
* "SELECT * from todos WHERE id = ?", id
|
|
112
|
+
* );
|
|
88
113
|
* ```
|
|
89
114
|
*/
|
|
90
115
|
async select(query, bindValues) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-sql",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"description": "Interface with SQL databases",
|
|
5
5
|
"license": "MIT or APACHE-2.0",
|
|
6
6
|
"authors": [
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"LICENSE"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"tslib": "
|
|
25
|
+
"tslib": "2.6.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tauri-apps/api": "2.0.0-alpha.
|
|
28
|
+
"@tauri-apps/api": "2.0.0-alpha.6"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "rollup -c"
|