Permalink
Browse files

Beef up readme.

  • Loading branch information...
1 parent 716de43 commit ff647885ce4c3e1893133158a7fc2522ecd4f88a @jnunemaker jnunemaker committed Apr 20, 2012
Showing with 83 additions and 3 deletions.
  1. +83 −3 README.md
View
@@ -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.

0 comments on commit ff64788

Please sign in to comment.