aboutsummaryrefslogtreecommitdiffstats
path: root/Database.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2016-11-04 23:42:34 +0100
committertv <tv@krebsco.de>2016-11-04 23:42:34 +0100
commitd63a423abbfa2789024ddec4d3585d154610c958 (patch)
tree515f41c96fe5d36065db155a79291c1a3e14a6e1 /Database.hs
Diffstat (limited to 'Database.hs')
-rw-r--r--Database.hs53
1 files changed, 53 insertions, 0 deletions
diff --git a/Database.hs b/Database.hs
new file mode 100644
index 0000000..87670c4
--- /dev/null
+++ b/Database.hs
@@ -0,0 +1,53 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Database
+ ( Database(..)
+ , lookup
+ , readFile
+ )
+ where
+
+import Prelude hiding (lookup,readFile)
+import qualified Prelude (readFile)
+
+import Data.Data
+import Data.IxSet.Typed
+import Network.DNS.Types
+
+deriving instance Data OData
+deriving instance Data Question
+deriving instance Data RData
+deriving instance Data ResourceRecord
+deriving instance Data TYPE
+deriving instance Ord Question
+deriving instance Ord ResourceRecord
+deriving instance Ord TYPE
+deriving instance Read OData
+deriving instance Read Question
+deriving instance Read RData
+deriving instance Read ResourceRecord
+
+type ResourceRecordIxs = '[Domain, TYPE]
+type IxResourceRecord = IxSet ResourceRecordIxs ResourceRecord
+data Database = Database
+ { recordSet :: IxResourceRecord
+ }
+ deriving (Read,Show)
+
+instance Indexable ResourceRecordIxs ResourceRecord where
+ indices = ixList
+ (ixGen (Proxy :: Proxy Domain))
+ (ixGen (Proxy :: Proxy TYPE))
+
+lookup :: Question -> Database -> [ResourceRecord]
+lookup Question{..} (Database ix) =
+ toList (ix @= qname @= qtype)
+
+readFile :: FilePath -> IO Database
+readFile path =
+ read <$> Prelude.readFile path