@tauri-apps/plugin-sql
Advanced tools
| 'use strict'; | ||
| var primitives = require('@tauri-apps/api/primitives'); | ||
| // Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
| /** | ||
| * **Database** | ||
| * | ||
| * The `Database` class serves as the primary interface for | ||
| * communicating with the rust side of the sql plugin. | ||
| */ | ||
| class Database { | ||
| constructor(path) { | ||
| this.path = path; | ||
| } | ||
| /** | ||
| * **load** | ||
| * | ||
| * A static initializer which connects to the underlying database and | ||
| * returns a `Database` instance once a connection to the database is established. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = await Database.load("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static async load(path) { | ||
| const _path = await primitives.invoke("plugin:sql|load", { | ||
| db: path, | ||
| }); | ||
| return new Database(_path); | ||
| } | ||
| /** | ||
| * **get** | ||
| * | ||
| * A static initializer which synchronously returns an instance of | ||
| * the Database class while deferring the actual database connection | ||
| * until the first invocation or selection on the database. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = Database.get("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static get(path) { | ||
| return new Database(path); | ||
| } | ||
| /** | ||
| * **execute** | ||
| * | ||
| * Passes a SQL expression to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES ($1, $2, $3)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = $1, completed = $2 WHERE id = $3", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES (?, ?, ?)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = ?, completed = ? WHERE id = ?", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async execute(query, bindValues) { | ||
| const [rowsAffected, lastInsertId] = await primitives.invoke("plugin:sql|execute", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues ?? [], | ||
| }); | ||
| return { | ||
| lastInsertId, | ||
| rowsAffected, | ||
| }; | ||
| } | ||
| /** | ||
| * **select** | ||
| * | ||
| * Passes in a SELECT query to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = $1", id | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = ?", id | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async select(query, bindValues) { | ||
| const result = await primitives.invoke("plugin:sql|select", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues ?? [], | ||
| }); | ||
| return result; | ||
| } | ||
| /** | ||
| * **close** | ||
| * | ||
| * Closes the database connection pool. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const success = await db.close() | ||
| * ``` | ||
| * @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) { | ||
| const success = await primitives.invoke("plugin:sql|close", { | ||
| db, | ||
| }); | ||
| return success; | ||
| } | ||
| } | ||
| module.exports = Database; |
| 'use strict'; | ||
| var primitives = require('@tauri-apps/api/primitives'); | ||
| // Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
| /** | ||
| * **Database** | ||
| * | ||
| * The `Database` class serves as the primary interface for | ||
| * communicating with the rust side of the sql plugin. | ||
| */ | ||
| class Database { | ||
| constructor(path) { | ||
| this.path = path; | ||
| } | ||
| /** | ||
| * **load** | ||
| * | ||
| * A static initializer which connects to the underlying database and | ||
| * returns a `Database` instance once a connection to the database is established. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = await Database.load("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static async load(path) { | ||
| const _path = await primitives.invoke("plugin:sql|load", { | ||
| db: path, | ||
| }); | ||
| return new Database(_path); | ||
| } | ||
| /** | ||
| * **get** | ||
| * | ||
| * A static initializer which synchronously returns an instance of | ||
| * the Database class while deferring the actual database connection | ||
| * until the first invocation or selection on the database. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = Database.get("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static get(path) { | ||
| return new Database(path); | ||
| } | ||
| /** | ||
| * **execute** | ||
| * | ||
| * Passes a SQL expression to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES ($1, $2, $3)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = $1, completed = $2 WHERE id = $3", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES (?, ?, ?)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = ?, completed = ? WHERE id = ?", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async execute(query, bindValues) { | ||
| const [rowsAffected, lastInsertId] = await primitives.invoke("plugin:sql|execute", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues ?? [], | ||
| }); | ||
| return { | ||
| lastInsertId, | ||
| rowsAffected, | ||
| }; | ||
| } | ||
| /** | ||
| * **select** | ||
| * | ||
| * Passes in a SELECT query to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = $1", id | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = ?", id | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async select(query, bindValues) { | ||
| const result = await primitives.invoke("plugin:sql|select", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues ?? [], | ||
| }); | ||
| return result; | ||
| } | ||
| /** | ||
| * **close** | ||
| * | ||
| * Closes the database connection pool. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const success = await db.close() | ||
| * ``` | ||
| * @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) { | ||
| const success = await primitives.invoke("plugin:sql|close", { | ||
| db, | ||
| }); | ||
| return success; | ||
| } | ||
| } | ||
| module.exports = Database; |
+144
| import { invoke } from '@tauri-apps/api/primitives'; | ||
| // Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
| /** | ||
| * **Database** | ||
| * | ||
| * The `Database` class serves as the primary interface for | ||
| * communicating with the rust side of the sql plugin. | ||
| */ | ||
| class Database { | ||
| constructor(path) { | ||
| this.path = path; | ||
| } | ||
| /** | ||
| * **load** | ||
| * | ||
| * A static initializer which connects to the underlying database and | ||
| * returns a `Database` instance once a connection to the database is established. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = await Database.load("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static async load(path) { | ||
| const _path = await invoke("plugin:sql|load", { | ||
| db: path, | ||
| }); | ||
| return new Database(_path); | ||
| } | ||
| /** | ||
| * **get** | ||
| * | ||
| * A static initializer which synchronously returns an instance of | ||
| * the Database class while deferring the actual database connection | ||
| * until the first invocation or selection on the database. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = Database.get("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static get(path) { | ||
| return new Database(path); | ||
| } | ||
| /** | ||
| * **execute** | ||
| * | ||
| * Passes a SQL expression to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES ($1, $2, $3)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = $1, completed = $2 WHERE id = $3", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES (?, ?, ?)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = ?, completed = ? WHERE id = ?", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async execute(query, bindValues) { | ||
| const [rowsAffected, lastInsertId] = await invoke("plugin:sql|execute", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues ?? [], | ||
| }); | ||
| return { | ||
| lastInsertId, | ||
| rowsAffected, | ||
| }; | ||
| } | ||
| /** | ||
| * **select** | ||
| * | ||
| * Passes in a SELECT query to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = $1", id | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = ?", id | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async select(query, bindValues) { | ||
| const result = await invoke("plugin:sql|select", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues ?? [], | ||
| }); | ||
| return result; | ||
| } | ||
| /** | ||
| * **close** | ||
| * | ||
| * Closes the database connection pool. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const success = await db.close() | ||
| * ``` | ||
| * @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) { | ||
| const success = await invoke("plugin:sql|close", { | ||
| db, | ||
| }); | ||
| return success; | ||
| } | ||
| } | ||
| export { Database as default }; |
+7
-11
| { | ||
| "name": "@tauri-apps/plugin-sql", | ||
| "version": "2.0.0-alpha.3", | ||
| "version": "2.0.0-alpha.4", | ||
| "description": "Interface with SQL databases", | ||
@@ -10,21 +10,17 @@ "license": "MIT or APACHE-2.0", | ||
| "type": "module", | ||
| "browser": "dist-js/index.min.js", | ||
| "module": "dist-js/index.mjs", | ||
| "types": "dist-js/index.d.ts", | ||
| "types": "./dist-js/index.d.ts", | ||
| "main": "./dist-js/index.cjs", | ||
| "module": "./dist-js/index.js", | ||
| "exports": { | ||
| "import": "./dist-js/index.mjs", | ||
| "types": "./dist-js/index.d.ts", | ||
| "browser": "./dist-js/index.min.js" | ||
| "import": "./dist-js/index.js", | ||
| "require": "./dist-js/index.cjs" | ||
| }, | ||
| "files": [ | ||
| "dist-js", | ||
| "!dist-js/**/*.map", | ||
| "README.md", | ||
| "LICENSE" | ||
| ], | ||
| "devDependencies": { | ||
| "tslib": "2.6.0" | ||
| }, | ||
| "dependencies": { | ||
| "@tauri-apps/api": "2.0.0-alpha.11" | ||
| "@tauri-apps/api": "2.0.0-alpha.12" | ||
| }, | ||
@@ -31,0 +27,0 @@ "scripts": { |
+16
-0
@@ -112,2 +112,18 @@  | ||
| ## Partners | ||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td align="center" valign="middle"> | ||
| <a href="https://crabnebula.dev" target="_blank"> | ||
| <img src="https://github.com/tauri-apps/plugins-workspace/raw/v2/.github/sponsors/crabnebula.svg" alt="CrabNebula" width="283"> | ||
| </a> | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri). | ||
| ## License | ||
@@ -114,0 +130,0 @@ |
| /****************************************************************************** | ||
| Copyright (c) Microsoft Corporation. | ||
| Permission to use, copy, modify, and/or distribute this software for any | ||
| purpose with or without fee is hereby granted. | ||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
| REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
| INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
| LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
| OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
| PERFORMANCE OF THIS SOFTWARE. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise, SuppressedError, Symbol */ | ||
| typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
| var e = new Error(message); | ||
| return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
| }; | ||
| /** | ||
| * Sends a message to the backend. | ||
| * @example | ||
| * ```typescript | ||
| * import { invoke } from '@tauri-apps/api/primitives'; | ||
| * await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' }); | ||
| * ``` | ||
| * | ||
| * @param cmd The command name. | ||
| * @param args The optional arguments to pass to the command. | ||
| * @param options The request options. | ||
| * @return A promise resolving or rejecting to the backend response. | ||
| * | ||
| * @since 1.0.0 | ||
| */ | ||
| async function invoke(cmd, args = {}, options) { | ||
| return window.__TAURI_INTERNALS__.invoke(cmd, args, options); | ||
| } | ||
| // Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
| /** | ||
| * **Database** | ||
| * | ||
| * The `Database` class serves as the primary interface for | ||
| * communicating with the rust side of the sql plugin. | ||
| */ | ||
| class Database { | ||
| constructor(path) { | ||
| this.path = path; | ||
| } | ||
| /** | ||
| * **load** | ||
| * | ||
| * A static initializer which connects to the underlying database and | ||
| * returns a `Database` instance once a connection to the database is established. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = await Database.load("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static async load(path) { | ||
| const _path = await invoke("plugin:sql|load", { | ||
| db: path, | ||
| }); | ||
| return new Database(_path); | ||
| } | ||
| /** | ||
| * **get** | ||
| * | ||
| * A static initializer which synchronously returns an instance of | ||
| * the Database class while deferring the actual database connection | ||
| * until the first invocation or selection on the database. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = Database.get("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static get(path) { | ||
| return new Database(path); | ||
| } | ||
| /** | ||
| * **execute** | ||
| * | ||
| * Passes a SQL expression to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES ($1, $2, $3)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = $1, completed = $2 WHERE id = $3", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES (?, ?, ?)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = ?, completed = ? WHERE id = ?", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async execute(query, bindValues) { | ||
| const [rowsAffected, lastInsertId] = await invoke("plugin:sql|execute", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues !== null && bindValues !== void 0 ? bindValues : [], | ||
| }); | ||
| return { | ||
| lastInsertId, | ||
| rowsAffected, | ||
| }; | ||
| } | ||
| /** | ||
| * **select** | ||
| * | ||
| * Passes in a SELECT query to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = $1", id | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = ?", id | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async select(query, bindValues) { | ||
| const result = await invoke("plugin:sql|select", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues !== null && bindValues !== void 0 ? bindValues : [], | ||
| }); | ||
| return result; | ||
| } | ||
| /** | ||
| * **close** | ||
| * | ||
| * Closes the database connection pool. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const success = await db.close() | ||
| * ``` | ||
| * @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) { | ||
| const success = await invoke("plugin:sql|close", { | ||
| db, | ||
| }); | ||
| return success; | ||
| } | ||
| } | ||
| export { Database as default }; | ||
| //# sourceMappingURL=index.min.js.map |
| import { invoke } from '@tauri-apps/api/primitives'; | ||
| // Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
| /** | ||
| * **Database** | ||
| * | ||
| * The `Database` class serves as the primary interface for | ||
| * communicating with the rust side of the sql plugin. | ||
| */ | ||
| class Database { | ||
| constructor(path) { | ||
| this.path = path; | ||
| } | ||
| /** | ||
| * **load** | ||
| * | ||
| * A static initializer which connects to the underlying database and | ||
| * returns a `Database` instance once a connection to the database is established. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = await Database.load("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static async load(path) { | ||
| const _path = await invoke("plugin:sql|load", { | ||
| db: path, | ||
| }); | ||
| return new Database(_path); | ||
| } | ||
| /** | ||
| * **get** | ||
| * | ||
| * A static initializer which synchronously returns an instance of | ||
| * the Database class while deferring the actual database connection | ||
| * until the first invocation or selection on the database. | ||
| * | ||
| * # Sqlite | ||
| * | ||
| * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const db = Database.get("sqlite:test.db"); | ||
| * ``` | ||
| */ | ||
| static get(path) { | ||
| return new Database(path); | ||
| } | ||
| /** | ||
| * **execute** | ||
| * | ||
| * Passes a SQL expression to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES ($1, $2, $3)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = $1, completed = $2 WHERE id = $3", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * // INSERT example | ||
| * const result = await db.execute( | ||
| * "INSERT into todos (id, title, status) VALUES (?, ?, ?)", | ||
| * [ todos.id, todos.title, todos.status ] | ||
| * ); | ||
| * // UPDATE example | ||
| * const result = await db.execute( | ||
| * "UPDATE todos SET title = ?, completed = ? WHERE id = ?", | ||
| * [ todos.title, todos.status, todos.id ] | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async execute(query, bindValues) { | ||
| const [rowsAffected, lastInsertId] = await invoke("plugin:sql|execute", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues !== null && bindValues !== void 0 ? bindValues : [], | ||
| }); | ||
| return { | ||
| lastInsertId, | ||
| rowsAffected, | ||
| }; | ||
| } | ||
| /** | ||
| * **select** | ||
| * | ||
| * Passes in a SELECT query to the database for execution. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // for sqlite & postgres | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = $1", id | ||
| * ); | ||
| * | ||
| * // for mysql | ||
| * const result = await db.select( | ||
| * "SELECT * from todos WHERE id = ?", id | ||
| * ); | ||
| * ``` | ||
| */ | ||
| async select(query, bindValues) { | ||
| const result = await invoke("plugin:sql|select", { | ||
| db: this.path, | ||
| query, | ||
| values: bindValues !== null && bindValues !== void 0 ? bindValues : [], | ||
| }); | ||
| return result; | ||
| } | ||
| /** | ||
| * **close** | ||
| * | ||
| * Closes the database connection pool. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const success = await db.close() | ||
| * ``` | ||
| * @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) { | ||
| const success = await invoke("plugin:sql|close", { | ||
| db, | ||
| }); | ||
| return success; | ||
| } | ||
| } | ||
| export { Database as default }; | ||
| //# sourceMappingURL=index.mjs.map |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
LicensePackage contains multiple licenses.
Found 1 instance in 1 package
21082
14.03%0
-100%7
16.67%0
-100%548
24.55%133
13.68%1
Infinity%+ Added
- Removed