]> ruin.nu Git - yawbih.git/blob - Wiki.hs
getCurrent and getList done
[yawbih.git] / Wiki.hs
1 module Wiki (
2         WB
3         ,PGB
4
5 ) where
6
7 import Dbconnect
8
9 class WB a where
10         --Keyword -> (Full text,date)
11         getCurrent :: a -> String -> IO (String,String)
12
13         --Keyword -> [(id,date)]
14         getList :: a -> String -> IO [(String, String, String, String)]
15
16         --Keyword -> id -> Full text
17         get :: a -> String -> String -> IO String
18
19         --Keyword -> id -> ()
20         setCurrent :: a -> String -> String -> IO ()
21
22         --Keyword -> Full text -> id
23         addNew :: a -> String -> String -> IO String
24
25 data PGB = PGB DBService
26
27 createPGB :: String -> String -> String -> String -> IO PGB
28 createPGB host database user password = let db = createDBService host database "" user password Nothing in return (PGB db)
29
30
31 testDB = createPGB "wave" "wiki" "wiki" "12wiki34db"
32
33 instance WB PGB where
34
35         getCurrent (PGB db) key = do 
36                 [[text,date]] <- selectReturnTuples db $ "SELECT fulltext,timestamp FROM curtexts where keyword='"++key++"'"
37                 return (text,date)
38
39         getList (PGB db) key = do
40                 list <- selectReturnTuples db $ "SELECT id, timestamp, author, comment from fulltexts where keyword = '"++key++"'"
41                 return $ map (\[id,date,author,comment] -> (id,date,author,comment)) list
42
43         get (PGB db) key id = return ""
44
45         setCurrent (PGB db) key id = return ()
46
47         addNew (PGB db) key text = return ""
48