---
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.
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.
The rule encourages using appropriate data types (INTEGER, TEXT, REAL, BLOB, NULL) for your database columns. Proper data type selection helps with:
Several performance-focused recommendations are included:
EXPLAIN QUERY PLAN
to analyze and improve query performanceVACUUM
command periodically to optimize database sizeThe 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.
The rule advocates for using transactions when performing multiple database operations, which helps maintain data integrity and can improve performance.
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:
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.
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);
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.
While the rule automatically applies to SQL files, you might want to manually invoke it with @sqlite
when: