Skip to content

Commit

Permalink
Beef up readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 20, 2012
1 parent 716de43 commit ff64788
Showing 1 changed file with 83 additions and 3 deletions.
86 changes: 83 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,92 @@
= Plucky
# Plucky

Thin layer over the ruby driver that allows you to quickly grab hold of your data (pluck it!).

== Install
## Install

$ gem install plucky

== Note on Patches/Pull Requests
## Examples

```ruby
connection = Mongo::Connection.new
db = connection.db('test')
collection = db['users']
collection.remove # clear out the collection

collection.insert({'_id' => 'chris', 'age' => 26, 'name' => 'Chris'})
collection.insert({'_id' => 'steve', 'age' => 29, 'name' => 'Steve'})
collection.insert({'_id' => 'john', 'age' => 28, 'name' => 'John'})

# initialize query with collection
query = Plucky::Query.new(collection)

puts 'Querying'
pp query.where(:name => 'John').first
pp query.first(:name => 'John')
pp query.where(:name => 'John').all
pp query.all(:name => 'John')

puts 'Find by _id'
pp query.find('chris')
pp query.find('chris', 'steve')
pp query.find(['chris', 'steve'])

puts 'Sort'
pp query.sort(:age).all
pp query.sort(:age.asc).all # same as above
pp query.sort(:age.desc).all
pp query.sort(:age).last # steve

puts 'Counting'
pp query.count # 3
pp query.size # 3
pp query.count(:name => 'John') # 1
pp query.where(:name => 'John').count # 1
pp query.where(:name => 'John').size # 1

puts 'Distinct'
pp query.distinct(:age) # [26, 29, 28]

puts 'Select only certain fields'
pp query.fields(:age).find('chris') # {"_id"=>"chris", "age"=>26}
pp query.only(:age).find('chris') # {"_id"=>"chris", "age"=>26}
pp query.ignore(:name).find('chris') # {"_id"=>"chris", "age"=>26}

puts 'Pagination, yeah we got that'
pp query.sort(:age).paginate(:per_page => 1, :page => 2)
pp query.sort(:age).per_page(1).paginate(:page => 2)

pp query.sort(:age).limit(2).to_a # [chris, john]
pp query.sort(:age).skip(1).limit(2).to_a # [john, steve]
pp query.sort(:age).offset(1).limit(2).to_a # [john, steve]

puts 'Using a cursor'
cursor = query.find_each(:sort => :age) do |doc|
pp doc
end
pp cursor

puts 'Symbol Operators'
pp query.where(:age.gt => 28).count # 1 (steve)
pp query.where(:age.lt => 28).count # 1 (chris)
pp query.where(:age.in => [26, 28]).to_a # [chris, john]
pp query.where(:age.nin => [26, 28]).to_a # [steve]

puts 'Removing'
query.remove(:name => 'John')
pp query.count # 2
query.where(:name => 'Chris').remove
pp query.count # 1
query.remove
pp query.count # 0
```

## Help

https://groups.google.com/forum/#!forum/mongomapper

## Contributing

* Fork the project.
* Make your feature addition or bug fix.
Expand Down

0 comments on commit ff64788

Please sign in to comment.