fastn
Note: This document is about querying SQLite Database that is part of your
fastn
package. You can also query PostgreSQL using fastn
.
package-query
processor allows you to execute SQL queries against SQLite
files that are part of your fastn
package.sql
processor, starting from version 0.3.81.fastn
in
static site mode, then how the page looked when fastn build
was
called will be shown to everyone. But if you are using dynamic
mode then this page would be regenerated on every page load.-- run `sqlite3 db.sqlite` in shell to create the database
-- and paste this
CREATE TABLE user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
department TEXT
);
INSERT INTO user (name, department) VALUES ("amit", "engineering");
INSERT INTO user (name, department) VALUES ("jack", "ops");
db.sqlite
, you can fetch data from the SQLite
database using package-query
processor:-- import: fastn/processors as pr
-- person list people:
$processor$: pr.package-query
db: db.sqlite
SELECT * FROM user;
SELECT *
, which will fetch all
three columns, id
, name
and department
, so your record will look something
like this:-- record person:
integer id:
string name:
string department:
Note that the type columns in query result must match the type of fields in the record. The order of fields of record must also match the order of columns in the query result.
Also note that since the result of this query can be multiple rows (or one or none), we have to read the result in aperson list
, so all data can be stored
in corresponding list.$loop$
: