Package Query: Run SQL Queries

package-query processor allows you to execute SQL queries against SQLite files present in your fastn package.

Say you have a record and a variable like this:
-- record person:
integer id:
string name:
string department:
Lang:
ftd
And say you have an SQLite database file with table like this:
sqlite3 db.sqlite
CREATE TABLE user (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    department TEXT
);
Lang:
sql

Notice how the able and the record have matching fields.

Say you have inserted some data:
INSERT INTO user (name, department) VALUES ("amit", "engineering");
INSERT INTO user (name, department) VALUES ("jack", "ops");
Lang:
sql
Assuming the SQLite file is 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;
Lang:
ftd

The record we use must match with the result of the query, so if we would have individually selected columns, or used expressions in the SELECT clause, the type of expression must match with the record in which you are going to store the result.

You can then show the results in the FTD document, eg:
-- show-person: $p
$loop$: $people as $p
Lang:
ftd

db

The name of sqlite database file is provided by the key db.

Person

Name
amit
Department
engineering

Person

Name
jack
Department
ops

Support fastn!

Enjoying fastn? Please consider giving us a star ⭐️ on GitHub to show your support!

Getting Help

Have a question or need help?

Visit our GitHub Q&A discussion to get answers and subscribe to it to stay tuned.

Join our Discord channel and share your thoughts, suggestion, question etc.

Connect with our community!

Found an issue?

If you find some issue, please visit our GitHub issues to tell us about it.

Join us

We welcome you to join our Discord community today.

We are trying to create the language for human beings and we do not believe it would be possible without your support. We would love to hear from you.
Copyright © 2023 - FifthTry.com