Skip to content

Commit 3d09a5a

Browse files
committed
feat: add sqlite close method
1 parent 125a46d commit 3d09a5a

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tauri-plugin-sqlite-api",
33
"description": "A Tauri plugin for interface to SQLite",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"author": "lzdyes <[email protected]>",
66
"repository": {
77
"type": "git",

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ async fn open(state: State<'_, SqliteMap>, path: String) -> Result<bool> {
5757
Ok(true)
5858
}
5959

60+
#[command]
61+
async fn close(state: State<'_, SqliteMap>, path: String) -> Result<bool> {
62+
let mut map = state.0.lock().unwrap();
63+
let connection = map.get_mut(&path).ok_or(Error::DatabaseNotOpened(path.clone()))?;
64+
drop(connection);
65+
map.remove(&path);
66+
Ok(true)
67+
}
68+
6069
#[command]
6170
async fn execute(state: State<'_, SqliteMap>, path: String, sql: String) -> Result<bool> {
6271
let mut map = state.0.lock().unwrap();
@@ -148,7 +157,7 @@ async fn select(
148157

149158
pub fn init<R: Runtime>() -> TauriPlugin<R> {
150159
Builder::new("sqlite")
151-
.invoke_handler(tauri::generate_handler![open, execute, execute2, select])
160+
.invoke_handler(tauri::generate_handler![open, close, execute, execute2, select])
152161
.setup(|app| {
153162
app.manage(SqliteMap::default());
154163
Ok(())

webview-dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default class SQLite {
22
path: string;
33
constructor(path: string);
44
static open(path: string): Promise<SQLite>;
5+
close(): Promise<boolean>;
56
execute(sql: string, values?: unknown[]): Promise<boolean>;
67
select<T>(sql: string, values?: unknown[]): Promise<T>;
78
}

webview-dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export default class SQLite {
1111
return await invoke<string>('plugin:sqlite|open', { path }).then(() => new SQLite(path))
1212
}
1313

14+
async close(): Promise<boolean> {
15+
return invoke('plugin:sqlite|close', { path: this.path })
16+
}
17+
1418
async execute(sql: string, values?: unknown[]): Promise<boolean> {
1519
return values ? invoke('plugin:sqlite|execute2', { path: this.path, sql, values }) : invoke('plugin:sqlite|execute', { path: this.path, sql })
1620
}

0 commit comments

Comments
 (0)