From d63a423abbfa2789024ddec4d3585d154610c958 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 4 Nov 2016 23:42:34 +0100 Subject: initial commit --- Database.hs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Database.hs (limited to 'Database.hs') 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 -- cgit v1.2.3