Skip to content

Instantly share code, notes, and snippets.

@reddec
Created January 7, 2023 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reddec/70cbde11fbf048a2df8d5b63a18fa6cd to your computer and use it in GitHub Desktop.
Save reddec/70cbde11fbf048a2df8d5b63a18fa6cd to your computer and use it in GitHub Desktop.
SQLite document
-- https://www.sqlite.org/json1.html
CREATE TABLE stat
(
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
started_at TIMESTAMP NOT NULL DEFAULT current_timestamp,
finished_at TIMESTAMP NOT NULL DEFAULT current_timestamp,
meta JSON NOT NULL DEFAULT '{}' -- JSON!
);
CREATE INDEX stat_meta_project ON stat (meta ->> 'project');
INSERT INTO stat(meta)
VALUES ('{
"project": "hello",
"workspace": "default",
"method": "POST"
}'),
('{
"project": "help",
"workspace": "default",
"method": "POST"
}');
SELECT *
FROM stat;
SELECT *
FROM stat
WHERE meta ->> 'project' = 'hello';
EXPLAIN QUERY PLAN
SELECT *
FROM stat
WHERE meta ->> 'project' = 'hello';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment