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
direnvand ashell.nixfile to easily get a development environment,pandoc --to markdownto remove any metadata block (an alternative is--to plain,- SQLite's
readilefunction 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 INTOcopying the data would have worked too, since that database is only used for reading), - Scotty to write a small Haskell script,
sqlite-simpleto 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.