packages feed

hesql 0.2 → 0.3

raw patch · 5 files changed

+21/−16 lines, 5 files

Files

HESQL/Parser.hs view
@@ -48,13 +48,13 @@  selectStatement = do   opts <- selectVariant-  cols <- sepBy1 column (symbol ",")-  reserved "from"-  tab <- table+  cols <- sepBy1 sqlExp (symbol ",")+  tab <- optionMaybe (reserved "from" >> table)   wh <- optionMaybe whereCondition   ord <- optionMaybe order-  return $ SELECT opts (ExplicitColumns cols) tab-            wh ord Nothing+  return $ SELECT opts +             (ExplicitColumns $ map (flip (,) Nothing) cols) tab+             wh ord Nothing  order = do   reserved "order"@@ -124,7 +124,7 @@ sqlExp = sqlCompare   sqlCompare = buildExpressionParser table sqlTerm-   where table = [ [prefix "not" SqlNot]+   where table = [ [prefix (reserved "not") SqlNot]                  , [binary "+" SqlPlus AssocLeft, binary "-" SqlMinus AssocLeft]                  , [binary "*" SqlMult AssocLeft, binary "/" SqlDiv AssocLeft]                  , [binary "is" SqlIs AssocRight]@@ -206,5 +206,5 @@                                  return $ \ e1 e2 -> SqlInfixApp e1 fun e2)                               assoc -prefix name fun = Prefix (do reservedOp name; return fun)+prefix p fun = Prefix (do p >> return fun) postfix names fun = Prefix (do forM_ names reservedOp; return fun)
HESQL/Syntax.hs view
@@ -18,7 +18,7 @@     , declSQL  :: SQL    } deriving Show -data SQL = SELECT [SelectOption] SelectColumns From +data SQL = SELECT [SelectOption] SelectColumns (Maybe From)               (Maybe SqlExp)  (Maybe SqlOrder) (Maybe Group)          | INSERT TableName InsertColumns [SqlExp]          | UPDATE TableName [(ColName, SqlExp)] (Maybe SqlExp)@@ -67,7 +67,7 @@ sqlToString :: SQL -> String sqlToString DummySQL = "" sqlToString (SELECT _ cols from wh order group) = -      "select " ++ showColumns cols ++ " from " ++ showFrom from+      "select " ++ showColumns cols ++ showFrom from                 ++ showWhere wh ++ showOrder order -- TODO where order group sqlToString (INSERT tab spec vals) =@@ -87,10 +87,11 @@   showColumns :: SelectColumns -> String-showColumns (ExplicitColumns cols) = comaSepList $ map fst cols -- TODO Alias+showColumns (ExplicitColumns cols) = comaSepList $ map (showSqlExp . fst) cols -- TODO Alias showColumns _ = todo "showColumns" -showFrom  table = table+showFrom Nothing = ""+showFrom (Just table) = "from " ++ table  showWhere Nothing = "" showWhere (Just sqlExp) = " where " ++ showSqlExp sqlExp@@ -126,7 +127,7 @@ todo s = error ("TODO " ++ s)           data SelectOption = Strict | ReturnMaybe deriving (Show, Eq)-data SelectColumns = AllColumns | ExplicitColumns [(ColName, Maybe ColAlias)] deriving Show+data SelectColumns = AllColumns | ExplicitColumns [(SqlExp, Maybe ColAlias)] deriving Show -- data From = FromSubQuery SQL | FromTables [(TableName, TableAlias)] deriving Show type From = TableName  type InsertColumns = [ColName]
HESQL/Translator.hs view
@@ -98,8 +98,12 @@           lvar i = HsIdent $ "v" ++ show i           convVar v = hsapp "fromSql" (HsVar (UnQual  v)) +placeHolderCols AllColumns = []+placeHolderCols (ExplicitColumns cols) =+    concatMap placeHoldersExp $ map fst cols+ placeHoldersSql (SELECT _ cols from wh ord grp) =-    maybe [] placeHoldersExp wh+    placeHolderCols cols ++ maybe [] placeHoldersExp wh  placeHoldersSql (INSERT _ _ vals) =    concatMap placeHoldersExp vals
README view
@@ -42,9 +42,9 @@ verifyLogin login' password' =   select1' Accountid, Login, RealName, Email from Account      where (password is null or password  = md5(password')) and Lower(Login) = login'-           and not Locked+           and not Locked; -will generate code for a Haskell-Funktion with the type:+will generate code for a Haskell-function with the type:  verifyLogin :: Stmts -> String -> String -> IO (Maybe (Int, String, String, String)) 
hesql.cabal view
@@ -1,5 +1,5 @@ Name: hesql-Version: 0.2+Version: 0.3 Author: Christoph Bauer <ich@christoph-bauer.net> Maintainer: Christoph Bauer <ich@christoph-bauer.net> Cabal-Version: >= 1.2