Clojure DynamoDB client. This experimental project started from Faraday by Peter Taoussanis. Ref. https://github.com/ptaoussanis/faraday (Faraday), http://goo.gl/22QGA (DynamoDBv2 API)
Clojure DynamoDB client. This experimental project started from Faraday by Peter Taoussanis. Ref. https://github.com/ptaoussanis/faraday (Faraday), http://goo.gl/22QGA (DynamoDBv2 API)
(batch-get-item
client-opts
requests
&
{:keys [return-cc? span-reqs] :as opts :or {span-reqs {:max 5}}})
Retrieves a batch of items in a single request. Limits apply, Ref. http://goo.gl/Bj9TC.
(batch-get-item client-opts {:users {:prim-kvs {:name "alice"}} :posts {:prim-kvs {:id [1 2 3]} :attrs [:timestamp :subject] :consistent? true} :friends {:prim-kvs [{:catagory "favorites" :id [1 2 3]} {:catagory "recent" :id [7 8 9]}]}})
:span-reqs - {:max _ :throttle-ms _} allows a number of requests to automatically be stitched together (to exceed throughput limits, for example).
Retrieves a batch of items in a single request. Limits apply, Ref. http://goo.gl/Bj9TC. (batch-get-item client-opts {:users {:prim-kvs {:name "alice"}} :posts {:prim-kvs {:id [1 2 3]} :attrs [:timestamp :subject] :consistent? true} :friends {:prim-kvs [{:catagory "favorites" :id [1 2 3]} {:catagory "recent" :id [7 8 9]}]}}) :span-reqs - {:max _ :throttle-ms _} allows a number of requests to automatically be stitched together (to exceed throughput limits, for example).
(batch-write-item
client-opts
requests
&
{:keys [return-cc? span-reqs] :as opts :or {span-reqs {:max 5}}})
Executes a batch of Puts and/or Deletes in a single request. Limits apply, Ref. http://goo.gl/Bj9TC. No transaction guarantees are provided, nor conditional puts. Request execution order is undefined.
(batch-write-item client-opts {:users {:put [{:user-id 1 :username "sally"} {:user-id 2 :username "jane"}] :delete [{:user-id [3 4 5]}]}})
:span-reqs - {:max _ :throttle-ms _} allows a number of requests to automatically be stitched together (to exceed throughput limits, for example).
Executes a batch of Puts and/or Deletes in a single request. Limits apply, Ref. http://goo.gl/Bj9TC. No transaction guarantees are provided, nor conditional puts. Request execution order is undefined. (batch-write-item client-opts {:users {:put [{:user-id 1 :username "sally"} {:user-id 2 :username "jane"}] :delete [{:user-id [3 4 5]}]}}) :span-reqs - {:max _ :throttle-ms _} allows a number of requests to automatically be stitched together (to exceed throughput limits, for example).
(create-table client-opts
table-name
hash-keydef
&
{:keys [range-keydef throughput lsindexes gsindexes block?]
:or {throughput {:read 1 :write 1}}
:as opts})
Creates a table with options: hash-keydef - [<name> <#{:s :n :ss :ns :b :bs}>]. :range-keydef - [<name> <#{:s :n :ss :ns :b :bs}>]. :throughput - {:read <units> :write <units>}. :lsindexes - [{:name _ :range-keydef _ :projection #{:all :keys-only [<attr> ...]}}]. :gsindexes - [{:name _ :hash-keydef _ :range-keydef _ :projection #{:all :keys-only [<attr> ...]} :throughput _}]. :block? - Block for table to actually be active?
Additional examples (using dynolite) :
(dl/create-table :employee1 [:site-uid :s]
:range-keydef [:uid :s]
:gsindexes [{:name :fname-index :hash-keydef [:emailAddress :s]
:range-keydef [:familyName :s]
:projection [:firstName :paymentSchedule :phoneNumber :dateEmployment]
:throughput {:read 1 :write 1}}])
(dl/create-table :employee [:site-uid :s]
:range-keydef [:uid :s]
:lsindexes [{:name :family-name-index :range-keydef [:familyName :s]
:projection [:firstName :emailAddress :phoneNumber :dateEmployment]}])
Creates a table with options: hash-keydef - [<name> <#{:s :n :ss :ns :b :bs}>]. :range-keydef - [<name> <#{:s :n :ss :ns :b :bs}>]. :throughput - {:read <units> :write <units>}. :lsindexes - [{:name _ :range-keydef _ :projection #{:all :keys-only [<attr> ...]}}]. :gsindexes - [{:name _ :hash-keydef _ :range-keydef _ :projection #{:all :keys-only [<attr> ...]} :throughput _}]. :block? - Block for table to actually be active? Additional examples (using dynolite) : (dl/create-table :employee1 [:site-uid :s] :range-keydef [:uid :s] :gsindexes [{:name :fname-index :hash-keydef [:emailAddress :s] :range-keydef [:familyName :s] :projection [:firstName :paymentSchedule :phoneNumber :dateEmployment] :throughput {:read 1 :write 1}}]) (dl/create-table :employee [:site-uid :s] :range-keydef [:uid :s] :lsindexes [{:name :family-name-index :range-keydef [:familyName :s] :projection [:firstName :emailAddress :phoneNumber :dateEmployment]}])
(delete-item client-opts
table
prim-kvs
&
{:keys [return expected return-cc?] :or {return :none}})
Deletes an item from a table by its primary key.
See put-item
for option docs.
Deletes an item from a table by its primary key. See `put-item` for option docs.
(delete-table client-opts table)
(describe-table client-opts table)
Returns a map describing a table, or nil if the table doesn't exist.
Returns a map describing a table, or nil if the table doesn't exist.
(error s & more)
(filter-exp->filter-exp-str exp & {:keys [name-aliases value-aliases]})
(get-item client-opts
table
prim-kvs
&
{:keys [attrs consistent? return-cc? alias-attr-name-map
projection-attrs]})
Retrieves an item from a table by its primary key with options: prim-kvs - {<hash-key> <val>} or {<hash-key> <val> <range-key> <val>}. :attrs - Attrs to return, [<attr> ...]. :consistent? - Use strongly (rather than eventually) consistent reads? :alias-attr-name-map - {<alias> <attr>}, that can be used in :projection-attrs :projection-attrs - [<attr> ...]
Additional examples (using dynolite) :
(dl/get-item :employee {:site-id "4w", :id "yVSEkgAb9dDWtA"} :alias-attr-name-map {:fn :firstName :sn :familyName :e :emailAddress :p :phoneNumber :d :dateEmployment :t :terminatedP :i :id} :projection-attrs [:fn :sn :e :p :d :t :i])
Retrieves an item from a table by its primary key with options: prim-kvs - {<hash-key> <val>} or {<hash-key> <val> <range-key> <val>}. :attrs - Attrs to return, [<attr> ...]. :consistent? - Use strongly (rather than eventually) consistent reads? :alias-attr-name-map - {<alias> <attr>}, that can be used in :projection-attrs :projection-attrs - [<attr> ...] Additional examples (using dynolite) : (dl/get-item :employee {:site-id "4w", :id "yVSEkgAb9dDWtA"} :alias-attr-name-map {:fn :firstName :sn :familyName :e :emailAddress :p :phoneNumber :d :dateEmployment :t :terminatedP :i :id} :projection-attrs [:fn :sn :e :p :d :t :i])
(inline-secondary-index-description-result d & {:keys [throughput?]})
(java->clojure x)
(list-tables client-opts)
Returns a vector of table names.
Returns a vector of table names.
(projection-attrs->exp attrs alias-map)
(put-item client-opts
table
item
&
{:keys [return expected return-cc?] :or {return :none}})
Adds an item (Clojure map) to a table with options: :return - e/o #{:none :all-old}. :expected - A map of item attribute/condition pairs, all of which must be met for the operation to succeed. e.g.: {<attr> <expected-value> ...} {<attr> false ...} ; Attribute must not exist
Adds an item (Clojure map) to a table with options: :return - e/o #{:none :all-old}. :expected - A map of item attribute/condition pairs, all of which must be met for the operation to succeed. e.g.: {<attr> <expected-value> ...} {<attr> false ...} ; Attribute must not exist
(query client-opts
table
prim-key-conds
&
{:keys [last-prim-kvs query-filter logical-op span-reqs return index
order limit consistent? return-cc? alias-attr-name-map
alias-attr-value-map projection-attrs filter-exp]
:as opts
:or {span-reqs {:max 5} order :asc}})
Retrieves items from a table (indexed) with options: prim-key-conds - {<key-attr> [<comparison-operator> <val-or-vals>] ...}. :last-prim-kvs - Primary key-val from which to eval, useful for paging. :query-filter - {<key-attr> [<comparison-operator> <val-or-vals>] ...}. :logical-op - A logical operator to apply to :query-filter, #{:and :or} :span-reqs - {:max _ :throttle-ms _} controls automatic multi-request stitching. :return - e/o #{:all-attributes :all-projected-attributes :count [<attr> ...]}. :index - Name of a local or global secondary index to query. :order - Index scaning order e/o #{:asc :desc}. :limit - Max num >=1 of items to eval (≠ num of matching items). Useful to prevent harmful sudden bursts of read activity. :consistent? - Use strongly (rather than eventually) consistent reads? :alias-attr-name-map - {<alias> <attr>}, that can be used in filter-exp and projection-attrs. :alias-attr-value-map - {<alias> <val>}, that can be used in filter-exp. :projection-attrs - [<attr> ...] :filter-exp - Prefixed expression with: #{:= :<> :< :<= :> :>= :and :or :not :exists :not-exists :begins-with :contains :between :in} For available comparators and functions, see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html#ConditionExpressionReference
Note: the newly added :alias-attr-name-map, :alias-attr-value-map, :filter-exp, and :projection-attrs are Amazon's preferred way of doing filtering. Only one of query-filter or filter-exp has to exist in a query/scan.
(create-table client-opts :my-table [:name :s] {:range-keydef [:age :n] :block? true})
(do (put-item client-opts :my-table {:name "Steve" :age 24}) (put-item client-opts :my-table {:name "Susan" :age 27})) (query client-opts :my-table {:name [:eq "Steve"] :age [:between [10 30]]}) => [{:age 24, :name "Steve"}]
The old style comparison-operators e/o #{:eq :le :lt :ge :gt :begins-with :between}.
For unindexed item retrievel see scan
.
Ref. http://goo.gl/XfGKW for query+scan best practices.
Additional examples (using dynolite) :
(dl/query :employee {:site-uid [:eq "4w"]} :query-filter {:phoneNumber :not-null})
(dl/query :employee {:site-uid [:eq "4w"]} :query-filter {:emailAddress [:contains "Super"]} :limit 10)
(dl/query :employee {:site-id [:eq "4w"]}
:exp-attr-name-map {"#f" "firstName" "#s" "site-id"}
:exp-attr-val-map {":fn" "Louis" ":id" "4w"}
:filter-exp "#f = :fn AND #s = :id")
(dl/query :employee {:site-id [:eq "4w"]}
:index :family-name-index
:alias-attr-name-map {:fn :firstName :sn :familyName :e :emailAddress
:p :phoneNumber :d :dateEmployment :t :terminatedP :a :active?}
:alias-attr-value-map {:active true}
:projection-attrs [:fn :sn :e :p :d :t :id]
:filter-exp [:= :a :active])
Retrieves items from a table (indexed) with options: prim-key-conds - {<key-attr> [<comparison-operator> <val-or-vals>] ...}. :last-prim-kvs - Primary key-val from which to eval, useful for paging. :query-filter - {<key-attr> [<comparison-operator> <val-or-vals>] ...}. :logical-op - A logical operator to apply to :query-filter, #{:and :or} :span-reqs - {:max _ :throttle-ms _} controls automatic multi-request stitching. :return - e/o #{:all-attributes :all-projected-attributes :count [<attr> ...]}. :index - Name of a local or global secondary index to query. :order - Index scaning order e/o #{:asc :desc}. :limit - Max num >=1 of items to eval (≠ num of matching items). Useful to prevent harmful sudden bursts of read activity. :consistent? - Use strongly (rather than eventually) consistent reads? :alias-attr-name-map - {<alias> <attr>}, that can be used in filter-exp and projection-attrs. :alias-attr-value-map - {<alias> <val>}, that can be used in filter-exp. :projection-attrs - [<attr> ...] :filter-exp - Prefixed expression with: #{:= :<> :< :<= :> :>= :and :or :not :exists :not-exists :begins-with :contains :between :in} For available comparators and functions, see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html#ConditionExpressionReference Note: the newly added :alias-attr-name-map, :alias-attr-value-map, :filter-exp, and :projection-attrs are Amazon's preferred way of doing filtering. Only one of query-filter or filter-exp has to exist in a query/scan. (create-table client-opts :my-table [:name :s] {:range-keydef [:age :n] :block? true}) (do (put-item client-opts :my-table {:name "Steve" :age 24}) (put-item client-opts :my-table {:name "Susan" :age 27})) (query client-opts :my-table {:name [:eq "Steve"] :age [:between [10 30]]}) => [{:age 24, :name "Steve"}] The old style comparison-operators e/o #{:eq :le :lt :ge :gt :begins-with :between}. For unindexed item retrievel see `scan`. Ref. http://goo.gl/XfGKW for query+scan best practices. Additional examples (using dynolite) : (dl/query :employee {:site-uid [:eq "4w"]} :query-filter {:phoneNumber :not-null}) (dl/query :employee {:site-uid [:eq "4w"]} :query-filter {:emailAddress [:contains "Super"]} :limit 10) (dl/query :employee {:site-id [:eq "4w"]} :exp-attr-name-map {"#f" "firstName" "#s" "site-id"} :exp-attr-val-map {":fn" "Louis" ":id" "4w"} :filter-exp "#f = :fn AND #s = :id") (dl/query :employee {:site-id [:eq "4w"]} :index :family-name-index :alias-attr-name-map {:fn :firstName :sn :familyName :e :emailAddress :p :phoneNumber :d :dateEmployment :t :terminatedP :a :active?} :alias-attr-value-map {:active true} :projection-attrs [:fn :sn :e :p :d :t :id] :filter-exp [:= :a :active])
(query-or-scan-result r)
(scan client-opts
table
&
{:keys [attr-conds logical-op last-prim-kvs span-reqs return limit
total-segments segment return-cc? alias-attr-name-map
alias-attr-value-map projection-attrs filter-exp]
:as opts
:or {span-reqs {:max 5}}})
Retrieves items from a table (unindexed) with options: :attr-conds - {<attr> [<comparison-operator> <val-or-vals>] ...}. :logical-op - A logical operator to apply to :attr-conds, #{:and :or} :limit - Max num >=1 of items to eval (≠ num of matching items). Useful to prevent harmful sudden bursts of read activity. :last-prim-kvs - Primary key-val from which to eval, useful for paging. :span-reqs - {:max _ :throttle-ms _} controls automatic multi-request stitching. :return - e/o #{:all-attributes :all-projected-attributes :count [<attr> ...]}. :total-segments - Total number of parallel scan segments. :segment - Calling worker's segment number (>=0, <=total-segments). :alias-attr-name-map - {<alias> <attr>}, that can be used in filter-exp and projection-attrs. :alias-attr-value-map - {<alias> <val>}, that can be used in filter-exp. :projection-attrs - [<attr> ...] :filter-exp - Prefixed expression with: #{:= :<> :< :<= :> :>= :and :or :not :exists :not-exists :begins-with :contains :between :in} For available comparators and functions, see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html#ConditionExpressionReference
Note: the newly added :alias-attr-name-map, :alias-attr-value-map, :filter-exp, and :projection-attrs are Amazon's preferred way of doing filtering. Only one of query-filter or filter-exp has to exist in a query/scan.
The old style comparison-operators e/o #{:eq :le :lt :ge :gt :begins-with :between :ne :not-null :null :contains :not-contains :in}.
(create-table client-opts :my-table [:name :s] {:range-keydef [:age :n] :block? true})
(do (put-item client-opts :my-table {:name "Steve" :age 24}) (put-item client-opts :my-table {:name "Susan" :age 27})) (scan client-opts :my-table :attr-conds {:age [:in [24 27]]}) => [{:age 24, :name "Steve"} {:age 27, :name "Susan"}]
For automatic parallelization & segment control see scan-parallel
.
For indexed item retrievel see query
.
Ref. http://goo.gl/XfGKW for query+scan best practices.
Additional examples (using dynolite) :
(dl/scan :employee :attr-conds {:emailAddress [:contains "Super"]} :limit 100)
(dl/scan :employee :attr-conds {:emailAddress :null})
(dl/scan :employee
:exp-attr-name-map {"#f" "firstName" "#s" "site-id"}
:exp-attr-val-map {":fn" "Louis" ":id" "4w"}
:filter-exp "#f = :fn AND #s = :id")
(dl/scan :employee
:index :family-name-index
:alias-attr-name-map {:fn :firstName :sn :familyName :e :emailAddress
:p :phoneNumber :d :dateEmployment :t :terminatedP :a :active?}
:alias-attr-value-map {:active true}
:projection-attrs [:fn :sn :e :p :d :t :id]
:filter-exp [:= :a :active])
Retrieves items from a table (unindexed) with options: :attr-conds - {<attr> [<comparison-operator> <val-or-vals>] ...}. :logical-op - A logical operator to apply to :attr-conds, #{:and :or} :limit - Max num >=1 of items to eval (≠ num of matching items). Useful to prevent harmful sudden bursts of read activity. :last-prim-kvs - Primary key-val from which to eval, useful for paging. :span-reqs - {:max _ :throttle-ms _} controls automatic multi-request stitching. :return - e/o #{:all-attributes :all-projected-attributes :count [<attr> ...]}. :total-segments - Total number of parallel scan segments. :segment - Calling worker's segment number (>=0, <=total-segments). :alias-attr-name-map - {<alias> <attr>}, that can be used in filter-exp and projection-attrs. :alias-attr-value-map - {<alias> <val>}, that can be used in filter-exp. :projection-attrs - [<attr> ...] :filter-exp - Prefixed expression with: #{:= :<> :< :<= :> :>= :and :or :not :exists :not-exists :begins-with :contains :between :in} For available comparators and functions, see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html#ConditionExpressionReference Note: the newly added :alias-attr-name-map, :alias-attr-value-map, :filter-exp, and :projection-attrs are Amazon's preferred way of doing filtering. Only one of query-filter or filter-exp has to exist in a query/scan. The old style comparison-operators e/o #{:eq :le :lt :ge :gt :begins-with :between :ne :not-null :null :contains :not-contains :in}. (create-table client-opts :my-table [:name :s] {:range-keydef [:age :n] :block? true}) (do (put-item client-opts :my-table {:name "Steve" :age 24}) (put-item client-opts :my-table {:name "Susan" :age 27})) (scan client-opts :my-table :attr-conds {:age [:in [24 27]]}) => [{:age 24, :name "Steve"} {:age 27, :name "Susan"}] For automatic parallelization & segment control see `scan-parallel`. For indexed item retrievel see `query`. Ref. http://goo.gl/XfGKW for query+scan best practices. Additional examples (using dynolite) : (dl/scan :employee :attr-conds {:emailAddress [:contains "Super"]} :limit 100) (dl/scan :employee :attr-conds {:emailAddress :null}) (dl/scan :employee :exp-attr-name-map {"#f" "firstName" "#s" "site-id"} :exp-attr-val-map {":fn" "Louis" ":id" "4w"} :filter-exp "#f = :fn AND #s = :id") (dl/scan :employee :index :family-name-index :alias-attr-name-map {:fn :firstName :sn :familyName :e :emailAddress :p :phoneNumber :d :dateEmployment :t :terminatedP :a :active?} :alias-attr-value-map {:active true} :projection-attrs [:fn :sn :e :p :d :t :id] :filter-exp [:= :a :active])
(update-item client-opts
table
prim-kvs
update-map
&
{:keys [return expected return-cc?] :or {return :none}})
Updates an item in a table by its primary key with options: prim-kvs - {<hash-key> <val>} or {<hash-key> <val> <range-key> <val>}. update-map - {<attr> [<#{:put :add :delete}> <optional value>]}. :return - e/o #{:none :all-old :updated-old :all-new :updated-new}. :expected - {<attr> <#{<expected-value> false}> ...}.
Updates an item in a table by its primary key with options: prim-kvs - {<hash-key> <val>} or {<hash-key> <val> <range-key> <val>}. update-map - {<attr> [<#{:put :add :delete}> <optional value>]}. :return - e/o #{:none :all-old :updated-old :all-new :updated-new}. :expected - {<attr> <#{<expected-value> false}> ...}.
(update-table client-opts
table
throughput
&
{:keys [span-reqs block?] :or {span-reqs {:max 5 :block? false}}})
(with-binary-reader-writer
[&
{:keys [writer reader]
:or {reader (quote ozjongwon.dynohub/*binary-reader*)
writer (quote ozjongwon.dynohub/*binary-writer*)}}]
&
body)
(without-binary-reader-writer [] & body)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close