packages feed

ribbit 0.2.0.1 → 0.2.1.0

raw patch · 3 files changed

+116/−18 lines, 3 files

Files

README.md view
@@ -5,7 +5,7 @@         - [Current Features](#current-features)             - [Basic @Select .. From ..](#basic-select--from-)             - [Cross product](#cross-product)-            - [Limited Conditionals](#limited-conditionals)+            - [Conditionals](#conditionals)     - [Roadmap](#roadmap)         - [More conditional operatores.](#more-conditional-operatores)         - [`CREATE TABLE` support.](#create-table-support)@@ -64,26 +64,29 @@  type MyQuery = Select '["t1.field1", "t2.field2"] `From` MyTable1 `As` "t1" `X` MyTable2 `As` "t2" -#### Limited Conditionals+#### Conditionals  We support queries of the form: -> type MyQuery = Select '["field1", "field2"] `From` MyTable `Where` <condition>+> type MyQuery = Select '["field1", "field2"] `From` MyTable `Where` \<condition\> -Where <condition> can include:+Where ```<condition>``` can include: -- a `And` b: Basic intersection.-- a `Or` b: Basic union.-- "field" `Equals` (?): Test for equality. This introduces a query parameter that must be supplied at runtime.-- "field1" `Equals` "field2": Test the equality of two fields (that both must exist in the schema)+- ```a `And` b```: Basic intersection.+- ```a `Or` b```: Basic union.+- ```"field" `Equals` (?)```: Test for equality. This introduces a query parameter that must be supplied at runtime.+- ```"field1" `Equals` "field2"```: Test the equality of two fields (that both must exist in the schema)+- ```a `Lt` b```: Less than operator.+- ```a `Lte` b```: Less than or equal to operator.+- ```a `Gt` b```: Greater than operator.+- ```a `Gte` b```: Greater than or equal to operator.+- ```Not a```: Not operator.+- ```"field" `NotEquals` (?)```: Test for inequality against a query parameter.+- ```"field1" `NotEquals` "field2"```: Test for inequality between two fields.  ## Roadmap  This is what I plan to work on next:--### More conditional operatores.--I want to fill in the conditional operators with the usual suspects (`<`, `<=`, `>`, `>=`, `!=`, etc.).  ### `CREATE TABLE` support. 
ribbit.cabal view
@@ -1,6 +1,6 @@  name:                ribbit-version:             0.2.0.1+version:             0.2.1.0 synopsis:            ribbit -- description:          homepage:            https://github.com/owensmurray/ribbit
src/Database/Ribbit.hs view
@@ -43,6 +43,12 @@   And,   Or,   Equals,+  NotEquals,+  Gt,+  Gte,+  Lt,+  Lte,+  Not,    -- ** Query Parameters   type (?),@@ -176,6 +182,31 @@ infix 9 `Equals`  +{- | "!=" combinator for conditions. -}+data NotEquals l r+infix 9 `NotEquals`+++{- | "<" combinator for conditions. -}+data Lt l r+infix 9 `Lt`+++{- | "<=" combinator for conditions. -}+data Lte l r+infix 9 `Lte`+++{- | ">" combinator for conditions. -}+data Gt l r+infix 9 `Gt`+++{- | ">=" combinator for conditions. -}+data Gte l r+infix 9 `Gte`++ {- | "AND" combinator for conditions. -} data And l r infixr 8 `And`@@ -196,6 +227,10 @@ infix 8 `As`  +{- | NOT conditional combinator. -}+data Not a++ {- | "?" combinator, used to indicate the presence of a query parameter. -} data (?) @@ -216,6 +251,7 @@  data Expr a + type family ProjectionType proj schema where   ProjectionType '[name] schema =     LookupType name schema schema@@ -287,15 +323,32 @@     StripUnit (Flatten (ArgsType (schema, a) :> ArgsType (schema, b)))   ArgsType (schema, Or a b) =     StripUnit (Flatten (ArgsType (schema, a) :> ArgsType (schema, b)))-  ArgsType (schema, Equals field (?)) =+  ArgsType (schema, Condition field (?)) =     ProjectionType '[field] schema-  ArgsType (schema, Equals field expr) =+  ArgsType (schema, Condition (?) field) =+    ProjectionType '[field] schema+  ArgsType (schema, Condition l r) =     If-      (ValidField expr schema)-      (If (ValidField field schema) () (NotInSchema field schema))-      (NotInSchema expr schema)+      (ValidField r schema)+      (If (ValidField l schema) () (NotInSchema l schema))+      (NotInSchema r schema)+  ArgsType (schema, Equals l r) = ArgsType (schema, Condition l r)+  ArgsType (schema, NotEquals l r) = ArgsType (schema, Condition l r)+  ArgsType (schema, Lt l r) = ArgsType (schema, Condition l r)+  ArgsType (schema, Lte l r) = ArgsType (schema, Condition l r)+  ArgsType (schema, Gt l r) = ArgsType (schema, Condition l r)+  ArgsType (schema, Gte l r) = ArgsType (schema, Condition l r)+  ArgsType (schema, Not a) = ArgsType (schema, a)   ArgsType _ = () ++{- |+  Helper for 'ArgsType'. Reduces the number of equations required, because+  'ArgsType' doesn't actually care about which condition it is inspecting.+-}+data Condition l r++ type family NotInSchema field schema where   NotInSchema field schema =     TypeError (@@ -375,6 +428,48 @@   render _proxy =     render (Proxy @(Expr l))     <> " = "+    <> render (Proxy @(Expr r))++{- Not Equals -}+instance (Render (Expr l), Render (Expr r)) => Render (NotEquals l r) where+  render _proxy =+    render (Proxy @(Expr l))+    <> " != "+    <> render (Proxy @(Expr r))++{- Not -}+instance (Render a) => Render (Not a) where+  render _proxy =+    "not ("+    <> render (Proxy @a)+    <> ")"++{- Gt -}+instance (Render (Expr l), Render (Expr r)) => Render (Gt l r) where+  render _proxy =+    render (Proxy @(Expr l))+    <> " > "+    <> render (Proxy @(Expr r))++{- Gte -}+instance (Render (Expr l), Render (Expr r)) => Render (Gte l r) where+  render _proxy =+    render (Proxy @(Expr l))+    <> " >= "+    <> render (Proxy @(Expr r))++{- Lt -}+instance (Render (Expr l), Render (Expr r)) => Render (Lt l r) where+  render _proxy =+    render (Proxy @(Expr l))+    <> " < "+    <> render (Proxy @(Expr r))++{- Lte -}+instance (Render (Expr l), Render (Expr r)) => Render (Lte l r) where+  render _proxy =+    render (Proxy @(Expr l))+    <> " <= "     <> render (Proxy @(Expr r))  {- AND -}