Custom database combinators
Furnace framework ยป Database library

Next:Low-level database protocol


Every database library requires some effort on the programmer's part to initialize and open a database. SQLite uses files on your harddisk, so a simple pathname is all the setup required. With PostgreSQL, you log in to a networked server as a user on a specific port.

Make a with- combinator to open and close a database so that resources are not leaked.

SQLite example combinator:
USING: db.sqlite db io.files io.files.temp ; : with-sqlite-db ( quot -- ) "my-database.db" temp-file <sqlite-db> swap with-db ; inline

PostgreSQL example combinator:
USING: db.postgresql db ; : with-postgresql-db ( quot -- ) <postgresql-db> "localhost" >>host 5432 >>port "erg" >>username "secrets?" >>password "factor-test" >>database swap with-db ; inline