Skip to content
Projets

À propos

my database and the web apps that use it

Développement web et applicatif

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
+1
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

I'm Derek Sivers @ https://sive.rs/

This is my database and the web apps that use it. My data is private but code is public. See LICENSE.

Master code repository is on my private server, but mirrors to:

These are only mirrors. I don't monitor these sites or take pull requests.

tables.sql

This is the heart of it. Start there. Read that.
Foreign keys can be added using awk after data is loaded.

reset.sh

All functions - (except for a few at the top of tables.sql) - are in schemas.
Schemas can be dropped and reloaded without losing the data in the tables.
Run reset.sh every time a function has changed, to reload them all.
This also creates a database for testing. More on that, below.

o/*.sql

Functions used by multiple web apps. Schema name: o.
One file per function except TRIGGERS.sql

*/test/*.sql

For each function, tests in the test/ directory, in a file with the same name.
Tests use pgTAP. See https://pgtap.org/
Tests are run on the test database (siverstest) a clone of the live database.
Minimal data is inserted for testing just this function.
This makes it easier to understand without keeping anything else in mind.
To run a test, boilerplate and psql env vars are in a script called tap.
It's in scripts/tap here, but put it in your $PATH so you can always do ...
tap thatfile.sql
... to run that file's tests with nice output and rollback.
Or to run all tests:
for f in *.sql ; do tap $f ; done

scripts/

Hands-on or cron, shell scripts are here.

HTML in PostgreSQL?

Typical db-driven web apps get values from db, then merge into HTML templates.
Aiming for simplicity - less coupling - I do that step directly in PostgreSQL.
Mustache HTML templates are stored only in templates table, not on disk.
Router calls PostgreSQL functions and gets a full HTML response.
Pass it directly to HTTP or write it to disk.

HTTP headers in PostgreSQL?

What about when I need a value to be handled outside of the HTML body?
It usually results in an HTTP header: 404, Set-Cookie then 303 redirect, etc.
So the function creates the HTTP headers when needed to override the default.
All PostgreSQL web functions return just two values: head text, body text.
head is null? Stick with defaults. (Status 200, text/html, etc.)
head first line is 3 digits? Use that to override HTTP status. (404, 303)
head lines otherwise should override defaults.
I so far only set one cookie, so Set-Cookie is treated like any other.

web functions

These two PostgreSQL web app return values (head text, body text) are unified,
so we can make the handling code shorter with two sugar functions:
Call handler gets row 0 of select head, body from {schema}.{function}(params)
Response handler converts that PostgreSQL row to an HTTP response.

*/*.go

Go HTTP servers parse requests, send to PostgreSQL, and return responses.
The internal/xx/ directory is for Go shared modules.
I keep everything possible in PostgreSQL, and as little as possible in Go.
Go is needed for HTTP, SMTP, ActivityPub, Telegram, and PostgreSQL listeners.
It's very likely I'll swap Go for some other programming language someday.
For now, Go HTTP servers are behind nginx which passes X-Real-IP.

app schemas

Directories keep the functions and tests related to different web apps:

dir site
ding/ network listeners
me/ sive.rs
mynow/ my.nownownow.com
nnn/ nownownow.com
peep/ people / email
st0re/ sive.rs/store
stork/ store keeper

st0re/ and peep/ are unfinished so ignore them for now.

OpenBSD server setup

Run scripts/setup-*.sh

and occasional maintenance of Go, updating to newest version:

go mod edit -go=1.27.1
go get -u -t ./...
go mod tidy
go test ./...

questions? comments?

I love talking about programming. Email me any time. I reply to every one.
Contact me here: https://sive.rs/contact

— Derek

Explorer des projets similaires

Chargement…