packages feed

dynamodb-simple 0.3.0.0 → 0.4.0.0

raw patch · 9 files changed

+37/−24 lines, 9 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Database.DynamoDB: qConsistentRead :: forall a_a150j hash_a150k range_a150l. Lens' (QueryOpts a_a150j hash_a150k range_a150l) Consistency
+ Database.DynamoDB: qConsistentRead :: forall a_a15F6 hash_a15F7 range_a15F8. Lens' (QueryOpts a_a15F6 hash_a15F7 range_a15F8) Consistency
- Database.DynamoDB: qDirection :: forall a_a150j hash_a150k range_a150l. Lens' (QueryOpts a_a150j hash_a150k range_a150l) Direction
+ Database.DynamoDB: qDirection :: forall a_a15F6 hash_a15F7 range_a15F8. Lens' (QueryOpts a_a15F6 hash_a15F7 range_a15F8) Direction
- Database.DynamoDB: qFilterCondition :: forall a_a150j hash_a150k range_a150l a_a152W. Lens (QueryOpts a_a150j hash_a150k range_a150l) (QueryOpts a_a152W hash_a150k range_a150l) (Maybe (FilterCondition a_a150j)) (Maybe (FilterCondition a_a152W))
+ Database.DynamoDB: qFilterCondition :: forall a_a15F6 hash_a15F7 range_a15F8 a_a15HJ. Lens (QueryOpts a_a15F6 hash_a15F7 range_a15F8) (QueryOpts a_a15HJ hash_a15F7 range_a15F8) (Maybe (FilterCondition a_a15F6)) (Maybe (FilterCondition a_a15HJ))
- Database.DynamoDB: qHashKey :: forall a_a150j hash_a150k range_a150l. Lens' (QueryOpts a_a150j hash_a150k range_a150l) hash_a150k
+ Database.DynamoDB: qHashKey :: forall a_a15F6 hash_a15F7 range_a15F8. Lens' (QueryOpts a_a15F6 hash_a15F7 range_a15F8) hash_a15F7
- Database.DynamoDB: qLimit :: forall a_a150j hash_a150k range_a150l. Lens' (QueryOpts a_a150j hash_a150k range_a150l) (Maybe Natural)
+ Database.DynamoDB: qLimit :: forall a_a15F6 hash_a15F7 range_a15F8. Lens' (QueryOpts a_a15F6 hash_a15F7 range_a15F8) (Maybe Natural)
- Database.DynamoDB: qRangeCondition :: forall a_a150j hash_a150k range_a150l. Lens' (QueryOpts a_a150j hash_a150k range_a150l) (Maybe (RangeOper range_a150l))
+ Database.DynamoDB: qRangeCondition :: forall a_a15F6 hash_a15F7 range_a15F8. Lens' (QueryOpts a_a15F6 hash_a15F7 range_a15F8) (Maybe (RangeOper range_a15F8))
- Database.DynamoDB: qStartKey :: forall a_a150j hash_a150k range_a150l. Lens' (QueryOpts a_a150j hash_a150k range_a150l) (Maybe (hash_a150k, range_a150l))
+ Database.DynamoDB: qStartKey :: forall a_a15F6 hash_a15F7 range_a15F8. Lens' (QueryOpts a_a15F6 hash_a15F7 range_a15F8) (Maybe (hash_a15F7, range_a15F8))
- Database.DynamoDB: sConsistentRead :: forall a_a154q r_a154r. Lens' (ScanOpts a_a154q r_a154r) Consistency
+ Database.DynamoDB: sConsistentRead :: forall a_a15Jd r_a15Je. Lens' (ScanOpts a_a15Jd r_a15Je) Consistency
- Database.DynamoDB: sFilterCondition :: forall a_a154q r_a154r. Lens' (ScanOpts a_a154q r_a154r) (Maybe (FilterCondition a_a154q))
+ Database.DynamoDB: sFilterCondition :: forall a_a15Jd r_a15Je. Lens' (ScanOpts a_a15Jd r_a15Je) (Maybe (FilterCondition a_a15Jd))
- Database.DynamoDB: sLimit :: forall a_a154q r_a154r. Lens' (ScanOpts a_a154q r_a154r) (Maybe Natural)
+ Database.DynamoDB: sLimit :: forall a_a15Jd r_a15Je. Lens' (ScanOpts a_a15Jd r_a15Je) (Maybe Natural)
- Database.DynamoDB: sParallel :: forall a_a154q r_a154r. Lens' (ScanOpts a_a154q r_a154r) (Maybe (Natural, Natural))
+ Database.DynamoDB: sParallel :: forall a_a15Jd r_a15Je. Lens' (ScanOpts a_a15Jd r_a15Je) (Maybe (Natural, Natural))
- Database.DynamoDB: sStartKey :: forall a_a154q r_a154r r_a15J7. Lens (ScanOpts a_a154q r_a154r) (ScanOpts a_a154q r_a15J7) (Maybe (PrimaryKey a_a154q r_a154r)) (Maybe (PrimaryKey a_a154q r_a15J7))
+ Database.DynamoDB: sStartKey :: forall a_a15Jd r_a15Je r_a16oc. Lens (ScanOpts a_a15Jd r_a15Je) (ScanOpts a_a15Jd r_a16oc) (Maybe (PrimaryKey a_a15Jd r_a15Je)) (Maybe (PrimaryKey a_a15Jd r_a16oc))
- Database.DynamoDB.TH: tableConfig :: (Name, RangeType) -> [(Name, RangeType)] -> [Name] -> TableConfig
+ Database.DynamoDB.TH: tableConfig :: String -> (Name, RangeType) -> [(Name, RangeType)] -> [Name] -> TableConfig

Files

README.md view
@@ -15,7 +15,7 @@   , replies  :: Int } deriving (Show) -- Generate instances and category', user' etc. variables for queries/updates-mkTableDefs "migrate" (tableConfig (''Test, WithRange) [] [])+mkTableDefs "migrate" (tableConfig "" (''Test, WithRange) [] [])  test :: IO () test = do
changelog.md view
@@ -1,3 +1,7 @@+# 0.4.0.0+- Slightly changed TH API to allow table prefixing+- Better consistency settings detection for queryOverIndex+ # 0.3.0.0 - API changes regarding position of `Proxy` - Added index->table conversion functions
dynamodb-simple.cabal view
@@ -1,5 +1,5 @@ name:                dynamodb-simple-version:             0.3.0.0+version:             0.4.0.0 synopsis:            Typesafe library for working with DynamoDB database description:         Framework for accessing DynamoDB database. The majority of AWS API                      is available to the user in a convenient, simple and typesafe manner.
src/Database/DynamoDB.hs view
@@ -260,7 +260,7 @@ --   , messageid :: T.Text --   , subject :: T.Text -- } deriving (Show)--- mkTableDefs "migrate" (tableConfig (''Test, WithRange) [] [])+-- mkTableDefs "migrate" (tableConfig "" (''Test, WithRange) [] []) -- @ -- -- This code creates appropriate instances for the table and the columns. It creates@@ -315,7 +315,7 @@ --     i_category :: T.Text --   , i_messageid :: T.Text -- }--- mkTableDefs "migrate" (tableConfig (''Test, WithRange) [(''TestIndex, NoRange)] [])+-- mkTableDefs "migrate" (tableConfig "" (''Test, WithRange) [(''TestIndex, NoRange)] []) -- -- doWithTest :: Test -> ... -- doWithTest item = (item ^. category) ...
src/Database/DynamoDB/Class.hs view
@@ -182,6 +182,7 @@ -- | Class representing a Global Secondary Index class DynamoCollection a r 'IsIndex => DynamoIndex a parent (r :: RangeType) | a -> parent r where   indexName :: Proxy a -> T.Text+  indexIsLocal :: Proxy a -> Bool  class DynamoIndex a parent r => IndexCreate a parent (r :: RangeType) where   createGlobalIndex ::
src/Database/DynamoDB/QueryRequest.hs view
@@ -161,6 +161,10 @@  -- | Query an index, fetch primary key from the result and immediately read -- full items from the main table.+--+-- You cannot perform strongly consistent reads on Global indexes; if you set+-- the 'qConsistentRead' to 'Strongly', fetch from global indexes is still done+-- as eventually consistent. Queries on local indexes are performed according to the settings. queryOverIndex :: forall a t m v1 v2 hash r2 range rest parent.     (CanQuery a t hash range, MonadAWS m,      Code a ~ '[ hash ': range ': rest],@@ -169,12 +173,13 @@      DynamoScalar v1 hash, DynamoScalar v2 range)   => Proxy a -> QueryOpts a hash range -> Source m parent queryOverIndex p q =-   querySourceChunks p q =$= CL.mapFoldableM batchParent+   querySourceChunks p (q & setConsistency)+      =$= CL.mapFoldableM batchParent   where-    batchParent vals = do-      let keys = map dTableKey vals-      -- TODO: it would be nice if we could paginate requests from getItemBatch downstraem-      getItemBatch (q ^. qConsistentRead) keys+    setConsistency -- Strong consistent reads not supported on global indexes+      | indexIsLocal p = id+      | otherwise = qConsistentRead .~ Eventually+    batchParent vals = getItemBatch (q ^. qConsistentRead) (map dTableKey vals)  -- | Perform a simple, eventually consistent, query. --
src/Database/DynamoDB/TH.hs view
@@ -64,15 +64,16 @@  -- | Simple table configuration tableConfig ::-     (Name, RangeType)   -- ^ Table type name, primary key type+     String -- ^ Prefix for table and index names; dynamodb doesn't have namespaces, this is to remedy the problem.+  -> (Name, RangeType)   -- ^ Table type name, primary key type   -> [(Name, RangeType)] -- ^ Global secondary index records, index key type   -> [Name] -- ^ Local secondary index records   -> TableConfig-tableConfig (table, tbltype) globidx locidx =+tableConfig prefix (table, tbltype) globidx locidx =     TableConfig {-        tableSetup = (table, tbltype, nameToStr table)-      , globalIndexes = map (\(n,r) -> (n, r, nameToStr n)) globidx-      , localIndexes = map (\n -> (n, nameToStr n)) locidx+        tableSetup = (table, tbltype, prefix ++ nameToStr table)+      , globalIndexes = map (\(n,r) -> (n, r, prefix ++ nameToStr n)) globidx+      , localIndexes = map (\n -> (n, prefix ++ nameToStr n)) locidx       , translateField = defaultTranslate       , buildLens = True     }@@ -95,7 +96,7 @@ -- > data Test { _first :: Text, _second :: Text, _third :: Int } -- > data TestIndex { u_third :: Int, i_second :: T.Text} -- >--- > mkTableDefs (tableConfig (''Test, WithRange) [(''TestIndex, NoRange)] [])+-- > mkTableDefs (tableConfig "" (''Test, WithRange) [(''TestIndex, NoRange)] []) -- > -- > deriveGenericOnly ''Test -- > instance DynamoCollection Test WithRange IsTable@@ -131,7 +132,7 @@      tblFieldNames <- getFieldNames table translateField     buildColData tblFieldNames-    genBaseCollection table tblrange tblname Nothing translateField+    genBaseCollection table tblrange tblname Nothing translateField False      -- Check, that hash key name in locindexes == hash key in primary table     let tblHashName = fst (head tblFieldNames)@@ -142,9 +143,10 @@                   <> " is not equal to table hash key " <> show tblHashName)      -- Instances for indices-    let allindexes = globalIndexes ++ map (\(idx,name) -> (idx, WithRange, name)) localIndexes-    forM_ allindexes $ \(idx, idxrange, idxname) -> do-        genBaseCollection idx idxrange idxname (Just table) translateField+    let allindexes = map (\(idx, idxrange, idxname) -> (idx, idxrange, idxname, False)) globalIndexes+                    ++ map (\(idx,name) -> (idx, WithRange, name, True)) localIndexes+    forM_ allindexes $ \(idx, idxrange, idxname, islocal) -> do+        genBaseCollection idx idxrange idxname (Just table) translateField islocal         -- Check that all records from indices conform to main table and create instances         instfields <- getFieldNames idx translateField         let pkeytable = [True | _ <- [1..(pkeySize idxrange)] ] ++ repeat False@@ -180,8 +182,8 @@ pkeySize NoRange = 1  -- | Generate basic collection instances-genBaseCollection :: Name -> RangeType -> String -> Maybe Name -> (String -> String) -> WriterT [Dec] Q ()-genBaseCollection coll collrange tblname mparent translate = do+genBaseCollection :: Name -> RangeType -> String -> Maybe Name -> (String -> String) -> Bool -> WriterT [Dec] Q ()+genBaseCollection coll collrange tblname mparent translate isLocal = do     tblFieldNames <- getFieldNames coll translate     let fieldNames = map fst tblFieldNames     let fieldList = listE (map (appE (varE 'T.pack) . litE . StringL) fieldNames)@@ -210,6 +212,7 @@         lift [d|             instance DynamoIndex $(conT coll) $(conT parent) $(conT $ mrange collrange) where                 indexName _ = $(appE (varE 'T.pack) (litE (StringL tblname)))+                indexIsLocal _ = $(conE (if isLocal then 'True  else 'False))               |] >>= tell      -- Skip primary key, we cannot filter by it
test/BaseSpec.hs view
@@ -42,13 +42,13 @@   , iInt      :: Int   , iMText    :: Maybe T.Text } deriving (Show, Eq, Ord)-mkTableDefs "migrateTest" (tableConfig (''Test, WithRange) [] [])+mkTableDefs "migrateTest" (tableConfig "" (''Test, WithRange) [] [])  data TestSecond = TestSecond {     tHashKey :: T.Text   , tInt :: Int } deriving (Show, Eq)-mkTableDefs "migrateTest2" (tableConfig (''TestSecond, NoRange) [] [])+mkTableDefs "migrateTest2" (tableConfig "" (''TestSecond, NoRange) [] [])  withDb :: Example (IO b) => String -> AWS b -> SpecWith (Arg (IO b)) withDb msg code = it msg runcode
test/NestedSpec.hs view
@@ -55,7 +55,7 @@   , _iList     :: [Inner]   , _iMap      :: HashMap Name Inner } deriving (Show, Eq)-mkTableDefs "migrateTest" (tableConfig (''Test, WithRange) [] [])+mkTableDefs "migrateTest" (tableConfig "" (''Test, WithRange) [] [])  withDb :: Example (IO b) => String -> AWS b -> SpecWith (Arg (IO b)) withDb msg code = it msg runcode