Agent skill
how-to-store-sqlite-as-nosql-store
Discover how to leverage SQLite's JSON support to build a NoSQL-like document store, complete with TTL-based expiration, within this powerful embedded database.
Install this agent skill to your Project
npx add-skill https://github.com/rodydavis/skills/tree/main/skills/sqlite_no-sql
Metadata
Additional technical details for this skill
- last modified
- Tue, 03 Feb 2026 20:04:37 GMT
SKILL.md
How to store SQLite as NoSQL Store
SQLite is a very capable edge database that can store various shapes of data.
NoSQL databases are very popular due to the schema-less nature of storing of the data but it is totally possible to store these documents in SQLite.
SQLite actually has great JSON support and even supports JSONB.
Create the table
To store JSON documents we need to create a table to store the values as strings.
CREATE TABLE documents (
path TEXT NOT NULL PRIMARY KEY,
data TEXT,
ttl INTEGER,
created INTEGER NOT NULL,
updated INTEGER NOT NULL,
UNIQUE(path)
);
path
data
ttl
created
updated
/posts/1
{"id":1}
NULL
0
0
/posts/2
{"id":2}
NULL
0
0
/users/1
{"id":1}
NULL
0
0
The basic idea is to store a JSON object and an unique path.
There is an optional TTL to automatically delete rows when they reach the stale date.
Save a document
To save a document we can encode our JSON as a string or binary and save in in the table with a unique path.
INSERT OR REPLACE
INTO documents (path, data, ttl, created, updated)
VALUES (:path, :data, :ttl, :created, :updated)
RETURNING *;
You can also use JSON functions to save the Object to a valid JSON string.
INSERT OR REPLACE
INTO documents (path, data, ttl, created, updated)
VALUES ("/posts/1", json('{"id" 1}'), NULL, 0, 0)
RETURNING *;
path
data
ttl
created
updated
/posts/1
{"id":1}
NULL
0
0
Reading a document
To read a document we just need the path. If a TTL is set we can calculate if the current date is greater than the offset and not return the document.
SELECT * FROM documents
WHERE path = :path
AND (
(ttl IS NOT NULL AND ttl + updated < unixepoch())
OR
ttl IS NULL
);
path
data
ttl
created
updated
/posts/1
{"id":1}
NULL
0
0
Get documents for a collection
We can query all the docs for a given collection using some built-in functions and a path prefix:
SELECT *
FROM documents
WHERE (
path LIKE :prefix
AND
(LENGTH(path) - LENGTH(REPLACE(path, '/', ''))) = (LENGTH(:prefix) - LENGTH(REPLACE(:prefix, '/', '')))
)
AND (
(ttl IS NOT NULL AND ttl + updated < unixepoch())
OR
ttl IS NULL
)
ORDER BY created;
It is expected to search for a :prefix with the /% at the end:
"/my/path/%" // search for /my/path
Deleting expired documents
Using the TTL field we can delete all expired documents:
DELETE FROM documents
WHERE ttl IS NOT NULL
AND ttl + updated < unixepoch();
Demo
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
how-to-do-offline-recommendations-with-sqlite-and-gemini
Learn how to enhance your CMS like PocketBase with AI-powered content recommendations using text embeddings, SQLite, and k-nearest neighbor search for efficient and scalable related content suggestions.
how-to-build-a-webrtc-signal-server-with-pocketbase
Learn how to build a simple WebRTC video call application using PocketBase as a signaling server, enabling peer-to-peer communication with SQLite on the server and realtime updates via Server Sent Events.
flutter-terminal-cheat-sheet
This post provides a handy collection of Flutter commands and scripts for web development, package creation, troubleshooting, testing, and more, streamlining your Flutter workflow.
how-to-print-multiple-objects-to-the-console-with-print-in-dart
Learn how to print multiple objects to the console in Dart using Records, offering a similar experience to JavaScript's `console.log()` functionality.
flutter-input-output-preview
Build responsive Flutter apps with a reusable `TwoPane` widget and an `InputOutputPreview` component for side-by-side code and preview display on both mobile and desktop.
displaying-html-in-flutter
Easily display and interact with HTML content in your Flutter app using the `easy_web_view` package, which supports both web and mobile platforms.
Didn't find tool you were looking for?