Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
"crates/sqlx-sqlite-observer",
"crates/sqlx-sqlite-toolkit",
]
exclude = ["examples/observer-demo/src-tauri"]
exclude = ["examples/observer-demo/src-tauri", "examples/pagination-demo/src-tauri"]

[package]
name = "tauri-plugin-sqlite"
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn main() {
"transaction_read",
"fetch_all",
"fetch_one",
"fetch_page",
"close",
"close_all",
"remove",
Expand Down
13 changes: 13 additions & 0 deletions permissions/autogenerated/commands/fetch_page.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-fetch-page"
description = "Enables the fetch_page command without any pre-configured scope."
commands.allow = ["fetch_page"]

[[permission]]
identifier = "deny-fetch-page"
description = "Denies the fetch_page command without any pre-configured scope."
commands.deny = ["fetch_page"]
27 changes: 27 additions & 0 deletions permissions/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Default permissions for the sqlite plugin - allows all database operations
- `allow-transaction-read`
- `allow-fetch-all`
- `allow-fetch-one`
- `allow-fetch-page`
- `allow-close`
- `allow-close-all`
- `allow-remove`
Expand Down Expand Up @@ -215,6 +216,32 @@ Denies the fetch_one command without any pre-configured scope.
<tr>
<td>

`sqlite:allow-fetch-page`

</td>
<td>

Enables the fetch_page command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`sqlite:deny-fetch-page`

</td>
<td>

Denies the fetch_page command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`sqlite:allow-get-migration-events`

</td>
Expand Down
1 change: 1 addition & 0 deletions permissions/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ permissions = [
"allow-transaction-read",
"allow-fetch-all",
"allow-fetch-one",
"allow-fetch-page",
"allow-close",
"allow-close-all",
"allow-remove",
Expand Down
16 changes: 14 additions & 2 deletions permissions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@
"const": "deny-fetch-one",
"markdownDescription": "Denies the fetch_one command without any pre-configured scope."
},
{
"description": "Enables the fetch_page command without any pre-configured scope.",
"type": "string",
"const": "allow-fetch-page",
"markdownDescription": "Enables the fetch_page command without any pre-configured scope."
},
{
"description": "Denies the fetch_page command without any pre-configured scope.",
"type": "string",
"const": "deny-fetch-page",
"markdownDescription": "Denies the fetch_page command without any pre-configured scope."
},
{
"description": "Enables the get_migration_events command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -499,10 +511,10 @@
"markdownDescription": "Denies the unsubscribe command without any pre-configured scope."
},
{
"description": "Default permissions for the sqlite plugin - allows all database operations\n#### This default permission set includes:\n\n- `allow-load`\n- `allow-execute`\n- `allow-execute-transaction`\n- `allow-begin-interruptible-transaction`\n- `allow-transaction-continue`\n- `allow-transaction-read`\n- `allow-fetch-all`\n- `allow-fetch-one`\n- `allow-close`\n- `allow-close-all`\n- `allow-remove`\n- `allow-get-migration-events`\n- `allow-observe`\n- `allow-subscribe`\n- `allow-unsubscribe`\n- `allow-unobserve`",
"description": "Default permissions for the sqlite plugin - allows all database operations\n#### This default permission set includes:\n\n- `allow-load`\n- `allow-execute`\n- `allow-execute-transaction`\n- `allow-begin-interruptible-transaction`\n- `allow-transaction-continue`\n- `allow-transaction-read`\n- `allow-fetch-all`\n- `allow-fetch-one`\n- `allow-fetch-page`\n- `allow-close`\n- `allow-close-all`\n- `allow-remove`\n- `allow-get-migration-events`\n- `allow-observe`\n- `allow-subscribe`\n- `allow-unsubscribe`\n- `allow-unobserve`",
"type": "string",
"const": "default",
"markdownDescription": "Default permissions for the sqlite plugin - allows all database operations\n#### This default permission set includes:\n\n- `allow-load`\n- `allow-execute`\n- `allow-execute-transaction`\n- `allow-begin-interruptible-transaction`\n- `allow-transaction-continue`\n- `allow-transaction-read`\n- `allow-fetch-all`\n- `allow-fetch-one`\n- `allow-close`\n- `allow-close-all`\n- `allow-remove`\n- `allow-get-migration-events`\n- `allow-observe`\n- `allow-subscribe`\n- `allow-unsubscribe`\n- `allow-unobserve`"
"markdownDescription": "Default permissions for the sqlite plugin - allows all database operations\n#### This default permission set includes:\n\n- `allow-load`\n- `allow-execute`\n- `allow-execute-transaction`\n- `allow-begin-interruptible-transaction`\n- `allow-transaction-continue`\n- `allow-transaction-read`\n- `allow-fetch-all`\n- `allow-fetch-one`\n- `allow-fetch-page`\n- `allow-close`\n- `allow-close-all`\n- `allow-remove`\n- `allow-get-migration-events`\n- `allow-observe`\n- `allow-subscribe`\n- `allow-unsubscribe`\n- `allow-unobserve`"
}
]
}
Expand Down
44 changes: 44 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,50 @@ pub async fn fetch_one(
Ok(result)
}

/// Execute a paginated SELECT query using keyset (cursor-based) pagination
#[allow(clippy::too_many_arguments)]
#[tauri::command]
pub async fn fetch_page(
db_instances: State<'_, DbInstances>,
db: String,
query: String,
values: Vec<JsonValue>,
keyset: Vec<sqlx_sqlite_toolkit::KeysetColumn>,
page_size: usize,
after: Option<Vec<JsonValue>>,
before: Option<Vec<JsonValue>>,
attached: Option<Vec<AttachedDatabaseSpec>>,
) -> Result<sqlx_sqlite_toolkit::KeysetPage> {
if after.is_some() && before.is_some() {
return Err(Error::Toolkit(
sqlx_sqlite_toolkit::Error::ConflictingCursors,
));
}

let instances = db_instances.0.read().await;

let wrapper = instances
.get(&db)
.ok_or_else(|| Error::DatabaseNotLoaded(db.clone()))?;

let mut builder = wrapper.fetch_page(query, values, keyset, page_size);

if let Some(cursor_values) = after {
builder = builder.after(cursor_values);
} else if let Some(cursor_values) = before {
builder = builder.before(cursor_values);
}

if let Some(specs) = attached {
let resolved_specs = resolve_attached_specs(specs, &instances)?;
builder = builder.attach(resolved_specs);
}

let result = builder.execute().await?;

Ok(result)
}

/// Close a specific database connection
///
/// Returns `true` if the database was loaded and successfully closed.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl Builder {
commands::transaction_read,
commands::fetch_all,
commands::fetch_one,
commands::fetch_page,
commands::close,
commands::close_all,
commands::remove,
Expand Down