Created
January 1, 2016 22:36
-
-
Save krisajenkins/71d878d284cc4cfe918f to your computer and use it in GitHub Desktop.
A couple of Haskell/SQL examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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