default
이 콘텐츠는 아직 번역되지 않았습니다.
Module @netwiv/api/plugins/sql · Kind Class
import { default } from '@netwiv/api/plugins/sql';Database
The Database class serves as the primary interface for
communicating with the rust side of the sql plugin.
Constructor
Section titled “Constructor”new default(path: string)Static members
Section titled “Static members”get(path: string): Databaseget
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
Section titled “Sqlite”The path is relative to tauri::path::BaseDirectory::App and must start with sqlite:.
Example
const db = Database.get("sqlite:test.db");load(path: string): Promise<Database>load
A static initializer which connects to the underlying database and
returns a Database instance once a connection to the database is established.
Sqlite
Section titled “Sqlite”The path is relative to tauri::path::BaseDirectory::App and must start with sqlite:.
Example
const db = await Database.load("sqlite:test.db");Instance members
Section titled “Instance members”close(db?: string | undefined): Promise<boolean>close
Closes the database connection pool.
Example
const success = await db.close()execute
Section titled “execute”execute(query: string, bindValues?: unknown[] | undefined): Promise<QueryResult>execute
Passes a SQL expression to the database for execution.
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 ]);path: stringselect
Section titled “select”select<T>(query: string, bindValues?: unknown[] | undefined): Promise<T>select
Passes in a SELECT query to the database for execution.
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 ]);Descriptions come from the pinned @tauri-apps/plugin-sql@2.4.1 declarations (MIT OR Apache-2.0); imports are shown with @netwiv/api paths.