Skip to content

Commit 5675129

Browse files
authored
Merge pull request #332 from Dynamoid/update-readme
Update Readme.md
2 parents 930dc3e + 606209c commit 5675129

File tree

1 file changed

+27
-59
lines changed

1 file changed

+27
-59
lines changed

README.md

Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Dynamoid
22

3-
You are viewing the README for version 3 of Dynamoid. See the [CHANGELOG](https://github.com/Dynamoid/Dynamoid/blob/master/CHANGELOG.md#200) for details on breaking changes since 1.3.x.
4-
5-
For version 1.3.x use the [1-3-stable branch](https://github.com/Dynamoid/Dynamoid/blob/1-3-stable/README.md).
3+
[![Build Status](https://travis-ci.org/Dynamoid/dynamoid.svg?branch=master)](https://travis-ci.org/Dynamoid/dynamoid)
4+
[![Code Climate](https://codeclimate.com/github/Dynamoid/dynamoid.svg)](https://codeclimate.com/github/Dynamoid/dynamoid)
5+
[![Coverage Status](https://coveralls.io/repos/github/Dynamoid/Dynamoid/badge.svg?branch=master)](https://coveralls.io/github/Dynamoid/Dynamoid?branch=master)
6+
[![CodeTriage Helpers](https://www.codetriage.com/dynamoid/dynamoid/badges/users.svg)](https://www.codetriage.com/dynamoid/dynamoid)
7+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/github/Dynamoid/dynamoid/frames)
8+
[![Inline docs](http://inch-ci.org/github/Dynamoid/Dynamoid.svg?branch=master)](http://inch-ci.org/github/Dynamoid/Dynamoid)
9+
![GitHub](https://img.shields.io/github/license/Dynamoid/dynamoid.svg)
610

711
Dynamoid is an ORM for Amazon's DynamoDB for Ruby applications. It
812
provides similar functionality to ActiveRecord and improves on
@@ -14,21 +18,6 @@ DynamoDB is not like other document-based databases you might know, and is very
1418

1519
But if you want a fast, scalable, simple, easy-to-use database (and a Gem that supports it) then look no further!
1620

17-
18-
| Project | Dynamoid |
19-
|------------------------ | ----------------- |
20-
| gem name | dynamoid |
21-
| license | MIT |
22-
| download rank | [![Total Downloads](https://img.shields.io/gem/rt/Dynamoid.svg)](https://rubygems.org/gems/dynamoid) |
23-
| version | [![Gem Version](https://badge.fury.io/rb/dynamoid.svg)](https://badge.fury.io/rb/dynamoid) |
24-
| dependencies | [![Depfu](https://badges.depfu.com/badges/6661c063c8e77a5008344fc7283a50aa/status.svg)](https://depfu.com) |
25-
| code quality | [![Code Climate](https://codeclimate.com/github/Dynamoid/dynamoid.svg)](https://codeclimate.com/github/Dynamoid/dynamoid) |
26-
| continuous integration | [![Build Status](https://travis-ci.org/Dynamoid/dynamoid.svg?branch=master)](https://travis-ci.org/Dynamoid/dynamoid) |
27-
| test coverage | [![Coverage Status](https://coveralls.io/repos/github/Dynamoid/Dynamoid/badge.svg?branch=master)](https://coveralls.io/github/Dynamoid/Dynamoid?branch=master) |
28-
| triage helpers | [![CodeTriage Helpers](https://www.codetriage.com/dynamoid/dynamoid/badges/users.svg)](https://www.codetriage.com/dynamoid/dynamoid) |
29-
| homepage | [https://github.com/Dynamoid/dynamoid](https://github.com/Dynamoid/dynamoid) |
30-
| documentation | [http://rdoc.info/github/Dynamoid/dynamoid/frames](http://rdoc.info/github/Dynamoid/dynamoid/frames) |
31-
3221
## Installation
3322

3423
Installing Dynamoid is pretty simple. First include the Gem in your Gemfile:
@@ -176,7 +165,7 @@ class Document
176165
end
177166
```
178167

179-
WARNING: Fields in numeric format are stored with nanoseconds as a fraction part and precision could be lost.
168+
**WARNING:** Fields in numeric format are stored with nanoseconds as a fraction part and precision could be lost.
180169
That's why `datetime` field in numeric format shouldn't be used as a range key.
181170

182171
You have two options if you need to use a `datetime` field as a range key:
@@ -542,8 +531,7 @@ u.addresses.where(city: 'Chicago').all
542531

543532
But keep in mind Dynamoid -- and document-based storage systems in general -- are not drop-in replacements for existing relational databases. The above query does not efficiently perform a conditional join, but instead finds all the user's addresses and naively filters them in Ruby. For large associations this is a performance hit compared to relational database engines.
544533

545-
#### Pagination
546-
##### Limits / Skip-Take
534+
#### Limits
547535

548536
There are three types of limits that you can query with:
549537

@@ -581,8 +569,9 @@ Address.record_limit(10_000).batch(100).each { … } # Batch specified as part o
581569
The implication of batches is that the underlying requests are done in the batch sizes to make the request and responses
582570
more manageable. Note that this batching is for `Query` and `Scans` and not `BatchGetItem` commands.
583571

584-
##### DynamoDB Native Pages
585-
At times it can be useful to rely on DynamoDB [default pages](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.Pagination)
572+
#### DynamoDB pagination
573+
574+
At times it can be useful to rely on DynamoDB [low-level pagination](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.Pagination)
586575
instead of fixed pages sizes. Each page results in a single Query or Scan call
587576
to DyanmoDB, but returns an unknown number of records.
588577

@@ -591,18 +580,20 @@ method, which yields arrays of records.
591580

592581
```ruby
593582
Address.find_by_pages do |addresses, metadata|
594-
# have an array of pages
595583
end
596584
```
597585

598-
Each yielded pages returns metadata as the second argument, which is a hash
586+
Each yielded pages returns page metadata as the second argument, which is a hash
599587
including a key `:last_evaluated_key`. The value of this key can be used for
600588
the `start` method to fetch the next page of records.
601589

590+
This way it can be used for instance to implement efficiently
591+
pagination in web-application:
592+
602593
```ruby
603594
class UserController < ApplicationController
604595
def index
605-
next_page = params[:next_page_token] ? JSON.parse(Base64.decode64(params[:next_page_token])) : ''
596+
next_page = params[:next_page_token] ? JSON.parse(Base64.decode64(params[:next_page_token])) : nil
606597

607598
records, metadata = User.start(next_page).find_by_pages.first
608599

@@ -727,44 +718,17 @@ There are following options:
727718

728719
The only mandatory option is `name`.
729720

730-
To use index in `Document.where` implicitly you need to project all the fields with option `projected_attributes: :all`.
731-
732-
There are two ways to query Global Secondary Indexes (GSI).
733-
734-
#### Explicit
735-
736-
The first way explicitly uses your GSI and utilizes the `find_all_by_secondary_index` method which will lookup a valid
737-
GSI to use based on the inputs, you MUST provide the correct keys to match the GSI you want:
721+
**WARNING:** In order to use global secondary index in `Document.where` implicitly you need to have all the attributes of the original table in the index and declare it with option `projected_attributes: :all`:
738722

739723
```ruby
740-
find_all_by_secondary_index(
741-
{
742-
dynamo_primary_key_column_name => dynamo_primary_key_value
743-
}, # The signature of find_all_by_secondary_index is ugly, so must be an explicit hash here
744-
:range => {
745-
"#{range_column}.#{range_modifier}" => range_value
746-
},
747-
# false is the same as DESC in SQL (newest timestamp first)
748-
# true is the same as ASC in SQL (oldest timestamp first)
749-
scan_index_forward: false # or true
750-
)
751-
```
752-
753-
Where the range modifier is one of `Dynamoid::Finders::RANGE_MAP.keys`, where the `RANGE_MAP` is:
724+
class User
725+
# ...
754726

755-
```ruby
756-
RANGE_MAP = {
757-
'gt' => :range_greater_than,
758-
'lt' => :range_less_than,
759-
'gte' => :range_gte,
760-
'lte' => :range_lte,
761-
'begins_with' => :range_begins_with,
762-
'between' => :range_between,
763-
'eq' => :range_eq
764-
}
727+
global_secondary_index hash_key: :age, projected_attributes: :all
728+
end
765729
```
766730

767-
Most range searches, like `eq`, need a single value, and searches like `between`, need an array with two values.
731+
There is only one implicit way to query Global and Local Secondary Indexes (GSI/LSI).
768732

769733
#### Implicit
770734

@@ -820,6 +784,10 @@ Listed below are all configuration options.
820784
`'t'` and `'f'`. Default is true
821785
* `backoff` - is a hash: key is a backoff strategy (symbol), value is parameters for the strategy. Is used in batch operations. Default id `nil`
822786
* `backoff_strategies`: is a hash and contains all available strategies. Default is { constant: ..., exponential: ...}
787+
* `http_continue_timeout`: The number of seconds to wait for a 100-continue HTTP response before sending the request body. Default option value is `nil`. If not specified effected value is `1`
788+
* `http_idle_timeout`: The number of seconds an HTTP connection is allowed to sit idble before it is considered stale. Default option value is `nil`. If not specified effected value is `5`
789+
* `http_open_timeout`: The number of seconds to wait when opening a HTTP session. Default option value is `nil`. If not specified effected value is `15`
790+
* `http_read_timeout`:The number of seconds to wait for HTTP response data. Default option value is `nil`. If not specified effected value is `60`
823791

824792

825793
## Concurrency

0 commit comments

Comments
 (0)