Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

sqlite

БесплатноБез исполняемых скриптовНе проверен

SQLite is a serverless, zero-configuration embedded SQL database that keeps a whole database in one file. Use when creating or querying a .db file with the…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

SQLite

Overview

SQLite is an embedded relational database that stores everything in one file and needs no server process. It ships in Python's standard library and most operating systems. Checked against SQLite 3.54.1 (2026-10-16) and better-sqlite3 13.0.3; the schema, Node.js and Python code below were run (SQLite 3.45.1 with FTS5, Node 24, Python 3.12).

Instructions

Installation

# Debian/Ubuntu
sudo apt-get install sqlite3
# macOS ships a copy; Homebrew gives a newer one
brew install sqlite
# Node.js driver (version 13 requires Node.js 22 or newer)
npm install better-sqlite3
# Python: sqlite3 is in the standard library, nothing to install

CLI basics

sqlite3 myapp.db                                   # open or create, interactive
sqlite3 myapp.db "SELECT count(*) FROM users;"     # one-off query
sqlite3 myapp.db ".schema"                         # show DDL
sqlite3 myapp.db ".dump" > backup.sql              # SQL text export
sqlite3 myapp.db < schema.sql                      # run a script
sqlite3 -header -column myapp.db "SELECT * FROM users LIMIT 5;"

CSV import: with an existing table, --skip 1 drops the header row (without it the header is inserted as data):

sqlite3 myapp.db ".import --csv --skip 1 customers.csv users"

If the table does not exist, .import --csv customers.csv users creates it from the header row, with all columns as TEXT.

Schema

-- schema.sql
CREATE TABLE IF NOT EXISTS users (
  id INTEGER PRIMARY KEY,
  email TEXT NOT NULL UNIQUE,
  name TEXT NOT NULL,
  created_at TEXT NOT NULL DEFAULT (datetime('now'))
) STRICT;

CREATE TABLE IF NOT EXISTS posts (
  id INTEGER PRIMARY KEY,
  user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  title TEXT NOT NULL,
  body TEXT,
  published_at TEXT
) STRICT;

CREATE INDEX IF NOT EXISTS idx_posts_user_id ON posts(user_id);
CREATE INDEX IF NOT EXISTS idx_posts_published ON posts(published_at);

INTEGER PRIMARY KEY is already an alias of the rowid and auto-assigns ids; AUTOINCREMENT is rarely needed and slower. STRICT (3.37+) enforces column types, which SQLite otherwise does not (any value can go in any column). There are no native date or boolean types: store ISO-8601 text, or integer Unix seconds (unixepoch()).

Pragmas

PRAGMA journal_mode = WAL;     -- persists in the file
PRAGMA busy_timeout = 5000;    -- per connection: wait 5 s instead of failing with SQLITE_BUSY
PRAGMA synchronous = NORMAL;   -- per connection; safe with WAL
PRAGMA foreign_keys = ON;      -- per connection; OFF by default, so foreign keys are not enforced

Everything except journal_mode must be set on every new connection. WAL does not work over network filesystems, and it adds -wal and -shm files next to the database that must travel with it.

Node.js with better-sqlite3

// db.mjs
import Database from 'better-sqlite3'
import { readFileSync } from 'node:fs'

const db = new Database('myapp.db')
db.pragma('journal_mode = WAL')
db.pragma('busy_timeout = 5000')
db.pragma('synchronous = NORMAL')
db.pragma('foreign_keys = ON')
db.exec(readFileSync('schema.sql', 'utf8'))

const insertUser = db.prepare('INSERT INTO users (email, name) VALUES (@email, @name)')
const getUserByEmail = db.prepare('SELECT * FROM users WHERE email = ?')

// A transaction function: commits on return, rolls back if it throws
const insertMany = db.transaction((users) => {
  for (const user of users) insertUser.run(user)
})

insertMany([
  { email: '[email protected]', name: 'Maria' },
  { email: '[email protected]', name: 'Li' },
])
console.log(getUserByEmail.get('[email protected]'))

process.on('exit', () => db.close())

The API is synchronous. Use .get() for one row, .all() for an array, .run() for writes (returns changes and lastInsertRowid). Node.js also ships an experimental built-in node:sqlite module (release candidate in Node 24) with a similar DatabaseSync API; prefer better-sqlite3 for production until it is stable.

Python

import sqlite3
from contextlib import closing

def get_connection(db_path="myapp.db"):
    conn = sqlite3.connect(db_path, timeout=5)
    conn.row_factory = sqlite3.Row
    conn.execute("PRAGMA journal_mode=WAL")
    conn.execute("PRAGMA foreign_keys=ON")
    return conn

with closing(get_connection()) as conn:
    with conn:  # commits on success, rolls back on exception; does NOT close
        conn.execute("INSERT INTO users (email, name) VALUES (?, ?)",
                     ("[email protected]", "Maria"))
    for row in conn.execute("SELECT * FROM users LIMIT ?", (100,)):
        print(dict(row))

Always pass values as ? parameters, never with f-strings. with conn: only manages the transaction; closing(...) closes the connection.

Full-text search (FTS5)

An external-content index does not follow the base table by itself; keep it in sync with triggers (tested):

CREATE
Полный SKILL.md на GitHub

Установить sqlite в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл sqlite?

SQLite is a serverless, zero-configuration embedded SQL database that keeps a whole database in one file. Use when creating or querying a .db file with the sqlite3 shell, importing CSV, using SQLite from Node.js (better-sqlite3) or Python (sqlite3), turning on WAL mode and foreign keys, adding FTS5 full-text search, or taking a safe backup.

Как установить скилл sqlite?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл sqlite запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить sqlite с