@tauri-apps/plugin-sql
Classes
default
Database
The Database
class serves as the primary interface for
communicating with the rust side of the sql plugin.
Constructors
new default()
new default(path): default
Parameters
Parameter | Type |
---|---|
path | string |
Returns
Source: undefined
Properties
Property | Type | Defined in |
---|---|---|
path | string | Source: undefined |
Methods
close()
close(db?): Promise<boolean>
close
Closes the database connection pool.
Parameters
Parameter | Type | Description |
---|---|---|
db ? | string | Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope. |
Returns
Promise
<boolean
>
Example
const success = await db.close()
Source: undefined
execute()
execute(query, bindValues?): Promise<QueryResult>
execute
Passes a SQL expression to the database for execution.
Parameters
Parameter | Type |
---|---|
query | string |
bindValues ? | unknown [] |
Returns
Example
// for sqlite & postgres// INSERT exampleconst result = await db.execute( "INSERT into todos (id, title, status) VALUES ($1, $2, $3)", [ todos.id, todos.title, todos.status ]);// UPDATE exampleconst result = await db.execute( "UPDATE todos SET title = $1, completed = $2 WHERE id = $3", [ todos.title, todos.status, todos.id ]);
// for mysql// INSERT exampleconst result = await db.execute( "INSERT into todos (id, title, status) VALUES (?, ?, ?)", [ todos.id, todos.title, todos.status ]);// UPDATE exampleconst result = await db.execute( "UPDATE todos SET title = ?, completed = ? WHERE id = ?", [ todos.title, todos.status, todos.id ]);
Source: undefined
select()
select<T>(query, bindValues?): Promise<T>
select
Passes in a SELECT query to the database for execution.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
query | string |
bindValues ? | unknown [] |
Returns
Promise
<T
>
Example
// for sqlite & postgresconst result = await db.select( "SELECT * from todos WHERE id = $1", [ id ]);
// for mysqlconst result = await db.select( "SELECT * from todos WHERE id = ?", [ id ]);
Source: undefined
get()
static get(path): default
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:
.
Parameters
Parameter | Type |
---|---|
path | string |
Returns
Example
const db = Database.get("sqlite:test.db");
Source: undefined
load()
static load(path): Promise<default>
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:
.
Parameters
Parameter | Type |
---|---|
path | string |
Returns
Example
const db = await Database.load("sqlite:test.db");
Source: undefined
Interfaces
QueryResult
Properties
Tauri 中文网 - 粤ICP备13048890号