sqlite_skim is a Rust-based SQLite loadable extension that provides a fuzzy matching scoring function, skim_score, powered by the skim-rs library.
This allows you to integrate powerful fuzzy string matching into your SQL queries, enabling features like search ranking and intelligent sorting of results.
skim_score(query_string, choice_string): Returns an integer score representing how wellchoice_stringmatchesquery_stringusing theskim-rsfuzzy matching algorithm.
- Rustup (for managing Rust toolchains)
- Rust
nightlytoolchain - SQLite
To build the sqlite_skim extension, follow these steps:
-
Clone the repository:
git clone https://github.com/your-repo/sqlite_skim.git cd sqlite_skim/sqlite_skim(Replace
https://github.com/your-repo/sqlite_skim.gitwith the actual repository URL once available) -
Set the Rust toolchain to nightly: This project requires the nightly Rust toolchain due to dependencies within
skim-rs.rustup override set nightly-2026-02-11 -
Build in release mode:
cargo build --release
This will produce the loadable SQLite extension library. The path to the library will typically be:
- Linux:
target/release/libsqlite_skim.so - macOS:
target/release/libsqlite_skim.dylib - Windows:
target/release/sqlite_skim.dll
- Linux:
Once the extension library is built, you can load it into your SQLite environment and start using the skim_score function.
-
Load the extension in SQLite:
Open the SQLite CLI or integrate into your application's SQLite connection:
SELECT load_extension('/path/to/your/sqlite_skim/target/release/libsqlite_skim.so');
Replace
/path/to/your/sqlite_skim/target/release/libsqlite_skim.sowith the actual absolute path to the compiled library file. -
Using the
skim_scorefunction:The
skim_scorefunction takes two string arguments: thequery_stringand thechoice_string.SELECT skim_score('query', 'choice string');
Examples:
-- Basic fuzzy matching SELECT skim_score('apple', 'I like apples'); SELECT skim_score('data', 'database management'); SELECT skim_score('db', 'database'); -- No match will return 0 SELECT skim_score('xyz', 'abc');
-
Sorting results with
skim_score:You can use
skim_scorein yourORDER BYclause to sort results based on their relevance to a query.Imagine a table
productswith anamecolumn:CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT); INSERT INTO products (name) VALUES ('Apple MacBook Pro'), ('Banana Smoothie Maker'), ('Red Delicious Apples'), ('Pineapple Slicer'); SELECT name, skim_score('apple', name) AS score FROM products ORDER BY score DESC;
This query would return products related to 'apple', with the most relevant (highest score) first.