packages feed

hesql 0.0 → 0.1

raw patch · 6 files changed

+44/−15 lines, 6 files

Files

HESQL/Parser.hs view
@@ -50,8 +50,20 @@   reserved "from"   tab <- table   wh <- optionMaybe whereCondition+  ord <- optionMaybe order   return $ SELECT opts (ExplicitColumns cols) tab-            wh Nothing Nothing+            wh ord Nothing++order = do+  reserved "order"+  reserved "by"+  sepBy1 orderCol (symbol ",")+ where orderCol = do+          e   <- sqlExp+          ord <- optionMaybe orderDir+          return (e, ord)+       orderDir = (reserved "asc" >> return ASC)<|>+                  (reserved "desc" >> return DESC)  selectVariant =      select "1'" [Strict, ReturnMaybe] <|>
HESQL/Syntax.hs view
@@ -19,14 +19,12 @@   } deriving Show  data SQL = SELECT [SelectOption] SelectColumns From -              (Maybe SqlExp)  (Maybe Order) (Maybe Group)+              (Maybe SqlExp)  (Maybe SqlOrder) (Maybe Group)          | INSERT TableName InsertColumns [SqlExp]          | UPDATE TableName [(ColName, SqlExp)] (Maybe SqlExp)          | DELETE TableName (Maybe SqlExp)          | DummySQL -instance Show SQL where-    show = sqlToString   data SqlExp =      SqlFunApp FunName [SqlExp] | @@ -41,6 +39,17 @@                   SqlPlus | SqlMult | SqlMinus | SqlDiv   deriving Show ++data SqlOrderDirection = ASC | DESC+   deriving Show++type SqlOrder = [(SqlExp, Maybe SqlOrderDirection)]+++instance Show SQL where+    show = sqlToString ++ infixPrio SqlEqual = 3 infixPrio SqlLike = 3 infixPrio SqlLess = 3@@ -58,7 +67,7 @@ sqlToString DummySQL = "" sqlToString (SELECT _ cols from wh order group) =        "select " ++ showColumns cols ++ " from " ++ showFrom from-                ++ showWhere wh+                ++ showWhere wh ++ showOrder order -- TODO where order group sqlToString (INSERT tab spec vals) =     "insert into " ++ tab ++ " " ++ @@ -67,7 +76,7 @@          (withParens $ comaSepList $ map showSqlExp vals)  sqlToString (UPDATE tab updates wh) =-    "update " ++ tab ++ " " ++ +    "update " ++ tab ++ " set " ++           (comaSepList $ map updateStr updates) ++          showWhere wh     where updateStr (col, e) = col ++ " = " ++ showSqlExp e@@ -85,6 +94,12 @@ showWhere Nothing = "" showWhere (Just sqlExp) = " where " ++ showSqlExp sqlExp +showOrder Nothing = ""+showOrder (Just sqlOrder) = " order by " +++                   (comaSepList $ map orderStr sqlOrder)+               where orderStr (sqlExp, Nothing) = showSqlExp sqlExp+                     orderStr (sqlExp, Just order) = showSqlExp sqlExp ++ " " ++ show order+ showSqlExp = showSqlExp' 5  showSqlExp' p (SqlColumn n) = n@@ -115,7 +130,6 @@  type TableAlias = String -type Order = () type Group = ()  
Makefile view
@@ -14,4 +14,7 @@ install: all 	./Setup install -.PHONY: all clean install+dist: Setup+	./Setup sdist++.PHONY: all clean install dist
README view
@@ -46,20 +46,20 @@  will generate code for a Haskell-Funktion with the type: -verifyLogin :: Stmts -> String -> String -> Maybe (Int, String, String, String)+verifyLogin :: Stmts -> String -> String -> IO (Maybe (Int, String, String, String))  (To be honest, the type is simplified by me. hesql won't write any type annotation.)  Each module will have a function -init :: Connection -> Stmts+init :: Connection -> IO Stmts  it prepares each statement for the later use.   TODO   - add a separate TODO file-  - parse group by, order, having, column/table aliases, subselects+  - parse group by, having, column/table aliases, subselects   - verify table and column names   - resolve column names in SELECT * FROM ...   - fix command line argument parsing@@ -91,5 +91,5 @@     - HDBC with PostgreSQL backend     - haskell-src (to print the haskell code)     - parsec (for the SQL parser)-  +    - do we have to call finish on Maybe-Statements?   
example/Account.hesql view
@@ -4,13 +4,13 @@  verifyLogin login' password' =   select1' Accountid, Login, RealName, Email from Account-     where (password is null or password  = md5(password')) and Lower(Login) = login'+     where (password is null or password  = md5(password')) and Lower(Login) = Lower(login')            and not Locked  login accountid' =     update Account set LoggedIn = true where AccountID = accountid' -logout acountid' =+logout accountid' =    update Account       set LoggedIn = false,           LastLogout = Now()
hesql.cabal view
@@ -1,5 +1,5 @@ Name: hesql-Version: 0.0+Version: 0.1 Author: Christoph Bauer <ich@christoph-bauer.net> Maintainer: Christoph Bauer <ich@christoph-bauer.net> Cabal-Version: >= 1.2