purescript-selda is an SQL library (eDSL) which allows a user to write type-safe queries.
To declare a type for a SQL table (already created in the db) we write the following table definition:
people ∷ Table (id ∷ Int, name ∷ String, age ∷ Maybe Int)
people = Table { name: "people" }
Once we've defined the tables, we can write queries, e.g.
selectFrom people \{ id, name, age } → do
{ balance } ← leftJoin bankAccounts \b → id .== b.personId
restrict $ id .> lit 1
pure { id, balance }
Generated SQL for the above query:
SELECT people_0.id AS id, bank_accounts_1.balance AS balance
FROM people people_0
LEFT JOIN bank_accounts bank_accounts_1 ON ((people_0.id = bank_accounts_1.personId))
WHERE ((people_0.id > 1))
For a more gentle introduction and more examples please refer to the Step-by-Step Guide.
If you have any questions please don't hesitate to ask.
I'll be happy to help and provide any guidance if necessary.
Open an issue or hit me up directly (either on slack, forum or directly via email).
Install postgresql-client's dependencies
npm install pg decimal.js
litPG
, Any
, EForeign
, custom PG functions), more flexible table definitions (Source
, db schemas, set-returning functions) - unsafe escape hatchesTest.Common
, Test.PG
, Test.SQLite3
. To run the tests, docker-compose up -d
helps to prepare postgres database.Supported by Lambda Terms
Inspired by selda