Cursor Rules for
SQLite

This rule explains SQLite database design patterns and performance considerations.
Back to rules
Type
Database
Stats
224 views
10 copies
14 downloads
sqlite.mdc
---
description: This rule explains SQLite database design patterns and performance considerations.
globs: **/*.sql
alwaysApply: false
---

# SQLite rules

- Use appropriate data types for columns (INTEGER, TEXT, REAL, BLOB, NULL)
- Create indexes for frequently queried columns
- Enable foreign key support with `PRAGMA foreign_keys = ON`
- Use transactions for multiple operations
- Use prepared statements to prevent SQL injection
- Use EXPLAIN QUERY PLAN to analyze query performance
- Consider using WAL journal mode for better concurrency
- Use VACUUM periodically to optimize database size

This rule provides guidance on SQLite database design patterns and performance considerations to help you write efficient, secure SQL queries and properly structure your databases. It offers best practices that can be automatically suggested when working with SQL files in Cursor.

What this rule does

The SQLite rule in Cursor provides expert guidance on working with SQLite databases. It focuses on optimizing database design, query performance, and security practices. When active, this rule instructs the AI assistant to suggest appropriate data types, recommend indexing strategies, encourage proper transaction handling, and offer other SQLite-specific best practices.

Key SQLite practices included

Data type selection

The rule encourages using appropriate data types (INTEGER, TEXT, REAL, BLOB, NULL) for your database columns. Proper data type selection helps with:

  • Storage efficiency
  • Query performance
  • Data integrity

Performance optimization

Several performance-focused recommendations are included:

  • Creating indexes for frequently queried columns to speed up searches
  • Using EXPLAIN QUERY PLAN to analyze and improve query performance
  • Implementing WAL (Write-Ahead Logging) journal mode for better concurrency
  • Running the VACUUM command periodically to optimize database size

Security and integrity

The rule emphasizes important security practices:

-- Enable foreign key constraints
PRAGMA foreign_keys = ON;

It also recommends using prepared statements to prevent SQL injection attacks, which is crucial for any database that processes user input.

Transaction management

The rule advocates for using transactions when performing multiple database operations, which helps maintain data integrity and can improve performance.

Using SQLite in Cursor

This rule (sqlite.mdc) is designed to automatically activate when you're working with SQL files in your project. The glob pattern **/*.sql means Cursor will apply this rule's context whenever you're editing any SQL file in your project directory structure.

When activated, the AI will have access to these SQLite best practices and can:

  • Provide suggestions that follow SQLite best practices
  • Help you optimize your database schema and queries
  • Offer relevant code completions incorporating these principles
  • Answer questions with SQLite-specific knowledge in mind

You don't need to manually invoke this rule when working with SQL files. However, if you want to explicitly activate it in other contexts, you can type @sqlite in the chat or Command-K interface.

Usage tips

Practical application

When designing a new SQLite database schema, let the AI assist you with proper table definitions including appropriate data types and constraints:

CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    username TEXT NOT NULL UNIQUE,
    email TEXT NOT NULL UNIQUE,
    created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
);

-- Create an index for frequently queried columns
CREATE INDEX idx_users_username ON users(username);

Combining with other rules

This SQLite rule works well alongside more general programming rules you might have in your Cursor setup. For instance, if you have rules for code documentation standards, the AI can help you write well-documented SQL that also follows SQLite best practices.

When to invoke manually

While the rule automatically applies to SQL files, you might want to manually invoke it with @sqlite when:

  • Writing SQL strings within other programming languages
  • Discussing database design in comments or documentation
  • Getting recommendations for optimizing an existing database
Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later