Skip to content

Commit

Permalink
updated docs. added changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkelley committed Feb 1, 2017
1 parent d63151d commit 671b8cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#### v2.2.0
- Added ability to use `where { ... }` directly from the relation
- Using `:expression_attribute_values`, `:expression_attribute_names` and `:key_condition_expression` when querying.

#### v2.0.2
- Initial release of adapter
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ container = ROM.container(:dynamodb, credentials) do |rom|
rom.relation(:users) do
# Key Schema: id<Hash>
dataset TABLE

def by_id(val)
where { id == val }
end
end

rom.commands(:users) do
Expand Down Expand Up @@ -79,15 +83,13 @@ user = create.call({ id: 2, name: "James" })

# update an existing user
update = container.commands[:users][:update]
update.where(id: user[:id]) { id == id }.call(name: "Mark")
update.by_id(user[:id]).call(name: "Mark")

relation.where(id: user[:id]) { id == id }.one! # => { id: 2, name: "Mark" }

# delete an existing user
delete = container.commands[:users][:delete]
expressions = { id: user[:id] }
filter = -> { id == id }
delete.where(expressions, &filter).call
delete.by_id(user[:id]).call
```
---

Expand All @@ -100,15 +102,15 @@ container = ROM.container(:dynamodb, credentials) do |rom|
dataset "my-logs-table"

def by_host(ip)
equal(:host, ip)
where { host == ip }
end

def after_timestamp(time)
after(:timestamp, time)
where { timestamp > time }
end

def before_timestamp(time)
before(:timestamp, time)
where { timestamp < time }
end
end

Expand Down Expand Up @@ -136,19 +138,19 @@ relation = container.relation(:logs)

relation.count == num_of_logs # => true

all = relation.by_host(host).after(0).to_a # => [{host: "192.168.0.1", ... }, ...]
all = relation.where(ip: host) { host == ip }.after(0).to_a # => [{host: "192.168.0.1", ... }, ...]

all.size # => 20

before = relation.by_host(host).before(Time.now.to_f + 60 * 60).limit(1).to_a
before = relation.where(ip: host) { [host == ip, timestamp < (Time.now.to_f + 60 * 60)] }.limit(1).to_a

before.size # => 1

before.first == logs.first # => true

offset = { host: host, timestamp: logs[-2][:timestamp] }
offset = { ip: host, timestamp: logs[-2][:timestamp] }

last = relation.by_host(host).descending.after(0).offset(offset).limit(1).one!
last = relation.where(ip: host) { ip == host }.descending.after(0).offset(offset).limit(1).one!

last == logs.last # => true
```
Expand Down

0 comments on commit 671b8cb

Please sign in to comment.