Last active
August 29, 2015 14:14
-
-
Save khibino/0c40b465f6deb822ca1a to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Model where | |
import Data.Int (Int32) | |
import Data.Time | |
import Database.HDBC.Record.Persistable () | |
import Database.Relational.Query (defaultConfig) | |
import Database.Relational.Query.TH (defineTableDefault) | |
$(defineTableDefault defaultConfig "TEST" "person" | |
[ ("name", [t| String |]) | |
, ("nickname", [t| String |]) | |
, ("day" , [t| Day |]) | |
, ("sex" , [t| Int32 |]) | |
] [] [0] $ Just 0) |
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
module OrPlaceholders where | |
import Data.String (IsString) | |
import Language.SQL.Keyword (Keyword (LIKE)) | |
import qualified Language.SQL.Keyword as SQL | |
import Database.Relational.Query | |
import Model (Person, person) | |
import qualified Model as Person | |
like :: (SqlProjectable p, ProjectableShowSql p, IsString a) | |
=> p a -> p b -> p (Maybe Bool) | |
like = unsafeBinOp (SQL.defineBinOp LIKE) | |
findOr :: Relation (String, String) Person | |
findOr = relation' $ do | |
p <- query person | |
(ph, ()) <- placeholder $ \pph -> wheres | |
$ p ! Person.name' .=. pph ! fst' `or'` p ! Person.nickname' .=. pph ! snd' | |
return (ph, p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment