This is a Gist demonstrating how to populate a SQLite database with some content coming from a Markdown file, adding full-text search capability, and querying it with a small Scotty-based web server.
In particular, this uses
direnv
and ashell.nix
file to easily get a development environment,pandoc --to markdown
to remove any metadata block (an alternative is--to plain
,- SQLite's
readile
function to insert the content of a file in the database, - SQLite's FTS feature,
- a trigger to automatically insert data into the FTW table (an
INSERT INTO
copying the data would have worked too, since that database is only used for reading), - Scotty to write a small Haskell script,
sqlite-simple
to query the database from Haskell.
The content of the .direnv
file is:
NIX_PATH=nixpkgs=channel:nixos-unstable
use_nix
Creating the database is done using the init.sh
file, which prepares the text
content of the database, and then executes init.sql
to create the schema and
insert data.
There is also search.sh
script to perform the search query from the
command-line.