X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Wiki.hs;h=d7ce7bcd912305223137ad8a72f141f255cfb165;hb=4f0ceb93a3cf4cc64f0809445e3b05beffcaf8ce;hp=c41effa9d481e63e5c7b41aa1aa5569504475287;hpb=ab35c3fcc01e43f9aea657f4c1c35bd66de0aafb;p=yawbih.git diff --git a/Wiki.hs b/Wiki.hs index c41effa..d7ce7bc 100644 --- a/Wiki.hs +++ b/Wiki.hs @@ -5,36 +5,46 @@ module Wiki ( ) where import Dbconnect +import Data.Char class WB a where --Keyword -> (Full text,date) getCurrent :: a -> String -> IO (String,String) --Keyword -> [(id,date)] - getList :: a -> String -> IO [(String, String)] + getList :: a -> String -> IO [(String, String, String, String)] --Keyword -> id -> Full text get :: a -> String -> String -> IO String --Keyword -> id -> () - setCurrent :: a -> String -> String -> IO () + setCurrent :: a -> String -> String -> IO Int --Keyword -> Full text -> id addNew :: a -> String -> String -> IO String data PGB = PGB DBService -createPGP host database user password = let db = createDBService host database "" user password Nothing in return (PGB db) +createPGB :: String -> String -> String -> String -> IO PGB +createPGB host database user password = let db = createDBService host database "" user password Nothing in return (PGB db) +testDB = createPGB "wave" "wiki" "wiki" "12wiki34db" + instance WB PGB where - getCurrent (PGB db) key = return ("","") + getCurrent (PGB db) key = do + [[text,date]] <- selectReturnTuples db $ "SELECT fulltext,timestamp FROM curtexts where keyword='"++(escapeQuery key)++"'" + return (text,date) - getList (PGB db) key = return [("","")] + getList (PGB db) key = do + list <- selectReturnTuples db $ "SELECT id, timestamp, author, comment from fulltexts where keyword = '"++(escapeQuery key)++"'" + return $ map (\[id,date,author,comment] -> (id,date,author,comment)) list get (PGB db) key id = return "" - setCurrent (PGB db) key id = return () + setCurrent (PGB db) key id = + execute db $ "UPDATE current SET id = '"++(escapeQuery id)++"' where keyword = '"++(escapeQuery key)++"'" addNew (PGB db) key text = return "" +