mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-01 12:08:06 +02:00
chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)
* chore: adjust prettier config, .gitignore and use taplo to format toml files This brings the plugins-workspace repository to the same code style of the main tauri repo * format toml * ignore examples gen dir * add .vscode/extensions.json * remove packageManager field * fmt * fix audit * taplo ignore permissions autogenerated files * remove create dummy dist * fix prettier workflow * install fmt in prettier workflow --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
@@ -1 +0,0 @@
|
||||
node_modules
|
||||
@@ -11,11 +11,11 @@ links = "tauri-plugin-sql"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["sqlite"]
|
||||
rustc-args = [ "--cfg", "docsrs" ]
|
||||
rustdoc-args = [ "--cfg", "docsrs" ]
|
||||
rustc-args = ["--cfg", "docsrs"]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-plugin = { workspace = true, features = [ "build" ] }
|
||||
tauri-plugin = { workspace = true, features = ["build"] }
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true }
|
||||
|
||||
+19
-19
@@ -62,16 +62,16 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import Database from "@tauri-apps/plugin-sql";
|
||||
import Database from '@tauri-apps/plugin-sql'
|
||||
|
||||
// sqlite. The path is relative to `tauri::api::path::BaseDirectory::AppConfig`.
|
||||
const db = await Database.load("sqlite:test.db");
|
||||
const db = await Database.load('sqlite:test.db')
|
||||
// mysql
|
||||
const db = await Database.load("mysql://user:pass@host/database");
|
||||
const db = await Database.load('mysql://user:pass@host/database')
|
||||
// postgres
|
||||
const db = await Database.load("postgres://postgres:password@localhost/test");
|
||||
const db = await Database.load('postgres://postgres:password@localhost/test')
|
||||
|
||||
await db.execute("INSERT INTO ...");
|
||||
await db.execute('INSERT INTO ...')
|
||||
```
|
||||
|
||||
## Syntax
|
||||
@@ -84,25 +84,25 @@ We use sqlx as our underlying library, adopting their query syntax:
|
||||
```javascript
|
||||
// INSERT and UPDATE examples for sqlite and postgres
|
||||
const result = await db.execute(
|
||||
"INSERT into todos (id, title, status) VALUES ($1, $2, $3)",
|
||||
[todos.id, todos.title, todos.status],
|
||||
);
|
||||
'INSERT into todos (id, title, status) VALUES ($1, $2, $3)',
|
||||
[todos.id, todos.title, todos.status]
|
||||
)
|
||||
|
||||
const result = await db.execute(
|
||||
"UPDATE todos SET title = $1, status = $2 WHERE id = $3",
|
||||
[todos.title, todos.status, todos.id],
|
||||
);
|
||||
'UPDATE todos SET title = $1, status = $2 WHERE id = $3',
|
||||
[todos.title, todos.status, todos.id]
|
||||
)
|
||||
|
||||
// INSERT and UPDATE examples for mysql
|
||||
const result = await db.execute(
|
||||
"INSERT into todos (id, title, status) VALUES (?, ?, ?)",
|
||||
[todos.id, todos.title, todos.status],
|
||||
);
|
||||
'INSERT into todos (id, title, status) VALUES (?, ?, ?)',
|
||||
[todos.id, todos.title, todos.status]
|
||||
)
|
||||
|
||||
const result = await db.execute(
|
||||
"UPDATE todos SET title = ?, status = ? WHERE id = ?",
|
||||
[todos.title, todos.status, todos.id],
|
||||
);
|
||||
'UPDATE todos SET title = ?, status = ? WHERE id = ?',
|
||||
[todos.title, todos.status, todos.id]
|
||||
)
|
||||
```
|
||||
|
||||
## Migrations
|
||||
@@ -173,8 +173,8 @@ To apply the migrations when the plugin is initialized, add the connection strin
|
||||
Alternatively, the client side `load()` also runs the migrations for a given connection string:
|
||||
|
||||
```ts
|
||||
import Database from "@tauri-apps/plugin-sql";
|
||||
const db = await Database.load("sqlite:mydatabase.db");
|
||||
import Database from '@tauri-apps/plugin-sql'
|
||||
const db = await Database.load('sqlite:mydatabase.db')
|
||||
```
|
||||
|
||||
Ensure that the migrations are defined in the correct order and are safe to run multiple times.
|
||||
|
||||
@@ -20,4 +20,4 @@ We prefer to receive reports in English.
|
||||
|
||||
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
|
||||
|
||||
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
|
||||
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export interface QueryResult {
|
||||
/** The number of rows affected by the query. */
|
||||
rowsAffected: number;
|
||||
rowsAffected: number
|
||||
/**
|
||||
* The last inserted `id`.
|
||||
*
|
||||
@@ -15,7 +15,7 @@ export interface QueryResult {
|
||||
* must be used, with a `RETURNING` clause
|
||||
* (`INSERT INTO todos (title) VALUES ($1) RETURNING id`).
|
||||
*/
|
||||
lastInsertId: number;
|
||||
lastInsertId: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,9 +25,9 @@ export interface QueryResult {
|
||||
* communicating with the rust side of the sql plugin.
|
||||
*/
|
||||
export default class Database {
|
||||
path: string;
|
||||
path: string
|
||||
constructor(path: string) {
|
||||
this.path = path;
|
||||
this.path = path
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,11 +46,11 @@ export default class Database {
|
||||
* ```
|
||||
*/
|
||||
static async load(path: string): Promise<Database> {
|
||||
const _path = await invoke<string>("plugin:sql|load", {
|
||||
db: path,
|
||||
});
|
||||
const _path = await invoke<string>('plugin:sql|load', {
|
||||
db: path
|
||||
})
|
||||
|
||||
return new Database(_path);
|
||||
return new Database(_path)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ export default class Database {
|
||||
* ```
|
||||
*/
|
||||
static get(path: string): Database {
|
||||
return new Database(path);
|
||||
return new Database(path)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,17 +107,17 @@ export default class Database {
|
||||
*/
|
||||
async execute(query: string, bindValues?: unknown[]): Promise<QueryResult> {
|
||||
const [rowsAffected, lastInsertId] = await invoke<[number, number]>(
|
||||
"plugin:sql|execute",
|
||||
'plugin:sql|execute',
|
||||
{
|
||||
db: this.path,
|
||||
query,
|
||||
values: bindValues ?? [],
|
||||
},
|
||||
);
|
||||
values: bindValues ?? []
|
||||
}
|
||||
)
|
||||
return {
|
||||
lastInsertId,
|
||||
rowsAffected,
|
||||
};
|
||||
rowsAffected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,13 +139,13 @@ export default class Database {
|
||||
* ```
|
||||
*/
|
||||
async select<T>(query: string, bindValues?: unknown[]): Promise<T> {
|
||||
const result = await invoke<T>("plugin:sql|select", {
|
||||
const result = await invoke<T>('plugin:sql|select', {
|
||||
db: this.path,
|
||||
query,
|
||||
values: bindValues ?? [],
|
||||
});
|
||||
values: bindValues ?? []
|
||||
})
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,9 +160,9 @@ export default class Database {
|
||||
* @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
|
||||
*/
|
||||
async close(db?: string): Promise<boolean> {
|
||||
const success = await invoke<boolean>("plugin:sql|close", {
|
||||
db,
|
||||
});
|
||||
return success;
|
||||
const success = await invoke<boolean>('plugin:sql|close', {
|
||||
db
|
||||
})
|
||||
return success
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,4 @@ All reading related operations are enabled.
|
||||
Also allows to load or close a connection.
|
||||
|
||||
"""
|
||||
permissions = [
|
||||
"allow-close",
|
||||
"allow-load",
|
||||
"allow-select",
|
||||
]
|
||||
permissions = ["allow-close", "allow-load", "allow-select"]
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { createConfig } from "../../shared/rollup.config.js";
|
||||
import { createConfig } from '../../shared/rollup.config.js'
|
||||
|
||||
export default createConfig();
|
||||
export default createConfig()
|
||||
|
||||
Reference in New Issue
Block a user