fastn
Note: This document is about querying PostgreSQL Database. You can also query
SQLite using fastn
.
pg
processor allows you to execute SQL queries against a PostgreSQL database.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.CREATE TABLE users (
id SERIAL,
name TEXT,
department TEXT
);
INSERT INTO "users" (name, department) VALUES ('jack', 'design');
INSERT INTO "users" (name, department) VALUES ('jill', 'engineering');
fastn
about your databasefastn
about your PostgreSQL
database credentials.export FASTN_PG_URL=postgres://username:password@db-host/db-name
FASTN_PG_URL
must contain a valid connection
string..env
file is properly setup you can fetch data from the SQLite database
using pg
processor:-- import: fastn/processors as pr
-- person list people:
$processor$: pr.pg
SELECT * FROM users;
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$
:-- show-person: $p
for: $p in $people
FASTN_PG_URL
The FASTN_PG_URL
must contain a valid connection
string.
FASTN_PG_DANGER_DISABLE_SSL
By default fastn
connects to PostgreSQL over a secure connection. You can set
FASTN_PG_DANGER_DISABLE_SSL
to false
if you want to connect to a insecure
connection.
FASTN_PG_SSL_MODE
fastn
can connect to a PostgreSQL in a few different secure mode. See
PostgreSQL official documentation on SSL Mode
Descriptions.
FASTN_PG_SSL_MODE=require
is default and recommended for production.
FASTN_PG_SSL_MODE=prefer
is allowed but not recommended for production as it
offers no benefits of encryption (is suseptible to MITM attack).
verify-ca
and verify-full
are both better than require
, but we do not
support them yet because the underlying we are using, deadpool, does not support
it yet.
We have created a tracking issue for
this.FASTN_PG_DANGER_ALLOW_UNVERIFIED_CERTIFICATE
fastn
can ignore invalid ceritificates when connecting to PostgreSQL if you
set FASTN_PG_DANGER_ALLOW_UNVERIFIED_CERTIFICATE
to true
. This is not
recommended for production.FASTN_PG_CERTIFICATE
If you have access to root certificate of the certificate authority who issued the certificate used by PostgreSQL.
Note that this is not working right now when tested with Supabase.
Since this is not working, the only way to connect is by usingFASTN_PG_DANGER_ALLOW_UNVERIFIED_CERTIFICATE=true
right now.