File: current-time.hs

package info (click to toggle)
haskelldb 0.9.cvs.601-13
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 680 kB
  • ctags: 33
  • sloc: haskell: 4,392; sh: 1,900; makefile: 130
file content (35 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- Nasty hack, demonstatrates how to use HaskellDB's internals to
-- access non-standard database features.

import Database.HaskellDB
import Database.HaskellDB.DBLayout
import Database.HaskellDB.Database
import Database.HaskellDB.Query
import Database.HaskellDB.PrimQuery
import Database.HaskellDB.Sql hiding (tables)

import TestConnect

import Data.Maybe
import System.Time

now :: Expr CalendarTime
now = Expr (ConstExpr (OtherLit "NOW()"))

data Timefield = Timefield
instance FieldTag Timefield where fieldName _ = "timefield"
timefield = mkAttr Timefield :: Attr Timefield CalendarTime

q = project (timefield << now)

getTime :: Database -> IO CalendarTime
getTime db = do
	     (r:_) <- query db q
	     return (r!timefield)

printTime db = do
	       putStrLn $ show $ showSql q
	       t <- getTime db
	       putStrLn $ calendarTimeToString t

main = argConnect printTime