Skip to content

Instantly share code, notes, and snippets.

@codedmart
Created August 13, 2015 13:49
Show Gist options
  • Select an option

  • Save codedmart/7dce3300c3aac24e344e to your computer and use it in GitHub Desktop.

Select an option

Save codedmart/7dce3300c3aac24e344e to your computer and use it in GitHub Desktop.
-- | Per-query settings
data RunFlag =
ReadMode ReadModeOpt |
NoReply |
Durability Durability |
Profile |
ArrayLimit Int
data Durability = Hard | Soft
renderOption :: RunFlag -> (Text, Datum)
renderOption (ReadMode Majority) = "read_mode" .= ("majority" :: String)
renderOption (ReadMode Single) = "read_mode" .= ("single" :: String)
renderOption (ReadMode Outdated) = "read_mode" .= ("outdated" :: String)
renderOption NoReply = "noreply" .= True
renderOption (Durability Soft) = "durability" .= ("soft" :: String)
renderOption (Durability Hard) = "durability" .= ("hard" :: String)
renderOption Profile = "profile" .= True
renderOption (ArrayLimit n) = "array_limit" .= n
data ReadModeOpt = Majority | Single | Outdated
-- | State used to build a Term
data QuerySettings = QuerySettings {
queryToken :: Int64,
queryDefaultDatabase :: Database,
queryVarIndex :: Int,
-- queryUseOutdated :: Maybe Bool <- was this
queryReadMode :: Maybe ReadModeOpt
}
instance Expr Table where
expr (Table mdb name _) = withQuerySettings $ \QuerySettings {..} ->
op' TABLE (fromMaybe queryDefaultDatabase mdb, name) $ catMaybes [
-- fmap ("use_outdated" :=) queryUseOutdated ] <- was
fmap ("read_mode" :=) queryReadMode ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment