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