Back to Blog

SQLite Debugging in Tauri: Verify CRUD with CLI & println! | Rust Desktop App Tutorial

Sandy LaneSandy Lane

Video: SQLite Debugging in Tauri: Verify CRUD with CLI & println! | Rust Desktop App Tutorial by Taught by Celeste AI - AI Coding Coach

Watch full page →

SQLite Debugging in Tauri: Verify CRUD with CLI & println!

Debugging SQLite databases in Tauri apps is crucial to ensure your CRUD operations work correctly. This guide shows you how to locate your database file on any platform, inspect and query it using the sqlite3 CLI, and add Rust println! statements to trace backend operations effectively.

Code

// Example Rust functions with println! debugging for SQLite CRUD operations

// Add a new article to the database
fn add_article(title: &str, content: &str, author: &str) {
  println!("add_article called");
  println!("Title: {}, Content length: {}, Author: {}", title, content.len(), author);
  // Insert SQL logic here to add article to SQLite database
}

// Retrieve all articles from the database
fn get_articles() {
  println!("get_articles called");
  // Query SQLite database and fetch articles
}

// Delete an article by id
fn delete_article(article_id: i32) {
  println!("delete_article called with id: {}", article_id);
  // Execute delete SQL command on SQLite database
}

// Example usage of sqlite3 CLI commands for debugging:
//
// Open the database file:
// $ sqlite3 path/to/your/app/articles.db
//
// List tables:
// sqlite>.tables
//
// Show schema of articles table:
// sqlite>.schema articles
//
// Query all articles:
// sqlite> SELECT * FROM articles;
//
// Count articles:
// sqlite> SELECT COUNT(*) FROM articles;
//
// Filter articles by author:
// sqlite> SELECT * FROM articles WHERE author LIKE '%John%';
//
// Check database integrity:
// sqlite> PRAGMA integrity_check;

Key Points

  • Locate your SQLite database in the platform-specific app data directory for direct access.
  • Use the sqlite3 CLI to inspect tables, run queries, and verify data outside the app.
  • Add println! statements in Rust backend functions to trace CRUD operations during runtime.
  • Verify each frontend CRUD action by checking CLI query results and printed debug output.
  • Use PRAGMA integrity_check and delete the database file to troubleshoot and reset your data.