Skip to content

Instantly share code, notes, and snippets.

@krisajenkins
Created January 1, 2016 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisajenkins/71d878d284cc4cfe918f to your computer and use it in GitHub Desktop.
Save krisajenkins/71d878d284cc4cfe918f to your computer and use it in GitHub Desktop.
A couple of Haskell/SQL examples.
-- Both of these functions do the same thing: return some that, if given a DB connection, will return a list of records.
-- No type-checking, but obvious equivalence to SQL.
getPerson :: UUID -> SqlPersistM [Entity Person]
getPerson uuid = rawSql
rawSql "SELECT ?? FROM person WHERE person_id = ?" [uuid]
-- More DSL-ish, but more compile-time guarantees.
getPerson2 :: UUID -> SqlPersistM [Entity Person]
getPerson2 uuid =
select $
from $
\person -> where_ (person ^. PersonPersonId ==. val uuid) return person
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment