rusqlite-patterns

Standardize Tauri rusqlite connection lifecycle and SQL primitives.

2|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/jonaseck2/slaktforskning --skill rusqlite-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rusqlite-patterns
Source: https://github.com/jonaseck2/slaktforskning/tree/main/.claude/skills/rusqlite-patterns
Command: npx skills add https://github.com/jonaseck2/slaktforskning --skill rusqlite-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents broken or inconsistent SQLite/Rust database layer changes by documenting the exact Tauri + rusqlite connection lifecycle, SQL command primitives, parameter binding rules, and where new logic should live.

Core Features & Use Cases

  • Connection lifecycle & safety model: how the single global SQLite connection is opened, guarded by a Mutex, switched between DB files, and closed.
  • SQL primitive contract: how the renderer-side db-shim calls the five generic Rust commands (db_batch, db_run, db_run_changes, db_get, db_all) and what shapes return.
  • Correct SQL binding & transactions: positional parameter binding via ? placeholders, supported JSON-to-SQL coercions, and the recommended transaction pattern using BEGIN IMMEDIATE/COMMIT/ROLLBACK.
  • Guidance on code placement: decision criteria for adding logic to src/api/ versus introducing new #[tauri::command] functions in Rust.
  • Type marshalling expectations: how SQL row values are marshalled into JSON types, including defensive handling for BLOB columns.

Quick Start

When modifying src-tauri/src/db.rs, ask the AI to explain how to implement your new SQL helper consistently with the existing db_* primitives, including parameter binding, transactions, and whether the change should go in src/api/ or as a Rust command.

Frequently Asked Questions about rusqlite-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage the SQLite connection lifecycle in a Tauri desktop app using rusqlite?

To manage the SQLite connection lifecycle in a Tauri app, use a single global connection guarded by a Mutex<Option<Connection>>. This model standardizes how the database is opened, switched between files, and safely closed.

What is the correct way to bind SQL parameters in rusqlite for a Tauri application?

The correct way to bind SQL parameters in rusqlite is using positional `?` placeholders. You must follow specific parameter binding rules and supported JSON-to-SQL coercions when passing values to your generic Rust commands.

How do I decide whether to put new database logic in the TypeScript API layer or as a Rust command in Tauri?

Deciding where to place new database logic involves evaluating specific criteria for adding code to the TypeScript `src/api/` layer versus introducing new `#[tauri::command]` functions in Rust to maintain proper architecture.

What transaction pattern should I use for SQLite operations in a local-first Rust app?

The recommended transaction pattern for SQLite operations uses BEGIN IMMEDIATE, COMMIT, and ROLLBACK. This ensures safe concurrent access and data integrity when executing batch operations through the generic Rust SQL primitives.

How are SQL row values marshalled into JSON types when using rusqlite with Tauri?

SQL row values are marshalled into JSON types through specific return contracts defined by the generic db_run, db_get, and db_all commands. This includes defensive handling to properly process BLOB columns for the renderer.