S
Supanote
Sign in Sign up

SQLite FTS5 Full-Text Search Schema & Sync Triggers

plain (sql) 1 month ago · 35 lines · 271 views
Verified Blueprint SQLite

External content FTS5 virtual table with unicode61 tokenizer and insert, update, and delete synchronization triggers.

Quick Fetch
1-- High-Performance SQLite FTS5 External Content Virtual Table
2-- Synchronizes search index with the primary 'articles' table
3
4-- 1. Create FTS5 Virtual Table
5CREATE VIRTUAL TABLE IF NOT EXISTS articles_fts USING fts5(
6 title,
7 body,
8 content='articles',
9 content_rowid='id',
10 tokenize='unicode61 remove_diacritics 2'
11);
13-- 2. After Insert Trigger
14CREATE TRIGGER IF NOT EXISTS articles_ai AFTER INSERT ON articles
15BEGIN
16 INSERT INTO articles_fts(rowid, title, body)
17 VALUES (new.id, new.title, new.body);
18END;
20-- 3. After Delete Trigger
21CREATE TRIGGER IF NOT EXISTS articles_ad AFTER DELETE ON articles
22BEGIN
23 INSERT INTO articles_fts(articles_fts, rowid, title, body)
24 VALUES ('delete', old.id, old.title, old.body);
25END;
27-- 4. After Update Trigger
28CREATE TRIGGER IF NOT EXISTS articles_au AFTER UPDATE ON articles
29BEGIN
30 INSERT INTO articles_fts(articles_fts, rowid, title, body)
31 VALUES ('delete', old.id, old.title, old.body);
32 INSERT INTO articles_fts(rowid, title, body)
33 VALUES (new.id, new.title, new.body);
34END;

No replies yet

Every reply is a note. Start a discussion, ask a question, or attach a code snippet.

Related SQLite & Database, Cache & SQL Blueprints

Production-ready configurations and diagnostics from the verified Supanote library.

All Database, Cache & SQL →
Interactive Developer Workbench: .env, Log & API Key Secret Scanner

Detect and redact leaked AWS keys, JWTs, database URIs, private keys, and Bearer tokens before sharing.

Open Secret Scanner →

Share Note

Open
Download SVG
Social Card Preview
Open on mobile
Point your phone camera to open this note directly

Report this note

Notification