Permalink
Browse files

Merge branch 'master' into caching

Conflicts:
	README.markdown
  • Loading branch information...
2 parents 3114bf0 + c2eeb99 commit 7fc089b01a4f5f41b17ff5cf19243b83af724cda @treeder treeder committed Dec 23, 2010
View
@@ -1 +1,2 @@
.idea/*
+pkg
View
@@ -19,7 +19,7 @@ Brought to you by: [![Appoxy](http://www.simpledeployr.com/images/global/appoxy-
require 'simple_record'
class MyModel < SimpleRecord::Base
- has_attributes :name
+ has_strings :name
has_ints :age
end
@@ -45,25 +45,26 @@ More about ModelAttributes below.
puts 'got=' + mm2.name + ' and he/she is ' + mm.age.to_s + ' years old'
# Or more advanced queries? mms = MyModel?.find(:all, ["age=?", 32], :order=>"name", :limit=>10)
+That's literally all you need to do to get started. No database install, no other setup required.
## Attributes and modifiers for models
NOTE: All objects will automatically have :id, :created, :updated attributes.
-### has_attributes
+### has_strings
Add string attributes.
class MyModel < SimpleRecord::Base
- has_attributes :name
+ has_strings :name
end
### has_ints, has_dates and has_booleans
-Lets simple_record know that certain attributes defined in has_attributes should be treated as integers, dates or booleans. This is required because SimpleDB only has strings so SimpleRecord needs to know how to convert, pad, offset, etc.
+This is required because SimpleDB only has strings so SimpleRecord needs to know how to convert, pad, offset, etc.
class MyModel < SimpleRecord::Base
- has_attributes :name
+ has_strings :name
has_ints :age, :height
has_dates :birthday
has_booleans :is_nerd
@@ -75,7 +76,7 @@ Creates a many-to-one relationship. Can only have one per belongs_to call.
class MyModel < SimpleRecord::Base
belongs_to :school
- has_attributes :name
+ has_strings :name
has_ints :age, :height
has_dates :birthday
has_booleans :is_nerd
@@ -118,6 +119,10 @@ To find all:
Company.find_all_by_name_and_division("Appoxy", "West")
+Consistent read:
+
+ Company.find(:all, :conditions => ["created > ?", 10.days.ago], :order=>"name", :limit=>50, :consistent_read=>true)
+
There are so many different combinations of the above for querying that I can't put them all here,
but this should get you started.
@@ -190,11 +195,21 @@ This is most helpful on windows so Rails doesn't need sqlite or mysql gems/drive
Typical databases support BLOB's and/or CLOB's, but SimpleDB has a 1024 character per attribute maximum so larger
values should be stored in S3. Fortunately SimpleRecord takes care of this for you by defining has_clobs for a large
-string value.
+string value. There is no support for blobs yet.
has_clobs :my_clob
-These clob values will be stored in s3 under a bucket named: "#{aws_access_key}_lobs"
+These clob values will be stored in s3 under a bucket named "#{aws_access_key}_lobs"
+OR "simple_record_#{aws_access_key}/lobs" if you set :new_bucket=>true in establish_connection (RECOMMENDED).
+
+If you have more than one clob on an object and if it makes sense for performance reasons, you can set a configuration option on the class to store all clobs
+as one item on s3 which means it will do a single put to s3 and a single get for all the clobs on the object.
+This would generally be good for somewhat small clob values or when you know you will always be accessing
+all the clobs on the object.
+
+ sr_config :single_clob=>true
+
+Setting this will automatically use :new_bucket=>true as well.
## Tips and Tricks and Things to Know
@@ -232,20 +247,37 @@ or
o.something_id = x
-### Batch Save
+Accessing the id can prevent a database call so if you only need the ID, then you
+should use this.
+
+## Batch Save
To do a batch save using SimpleDB's batch saving feature to improve performance, simply create your objects, add them to an array, then call:
MyClass.batch_save(object_list)
+## Batch Delete
+
+To do a batch delete using SimpleDB's batch delete feature to improve performance, simply create your objects, add them to an array, then call:
+
+ MyClass.batch_delete(object_list or list_of_ids)
+
+## Operations across a Query
+
+ MyClass.delete_all(find_options)
+ MyClass.destroy_all(find_options)
+
+find_options can include anything you'd add after a find(:all, find_options) including :conditions, :limit, etc.
+
## Caching
You can use any cache that supports the ActiveSupport::Cache::Store interface.
SimpleRecord::Base.cache_store = my_cache_store
-If you want a simple in memory cache store, try: [http://gemcutter.org/gems/local_cache](http://gemcutter.org/gems/local_cache). It supports max cache size and
-timeouts. You can also use memcached or [http://www.getcloudcache.com/](http://www.getcloudcache.com/).
+If you want a simple in memory cache store that supports max cache size and expiration,
+try: <https://github.com/appoxy/local_cache>.
+You can also use memcached or [http://www.getcloudcache.com/](http://www.getcloudcache.com/).
## Encryption
@@ -271,6 +303,24 @@ ob2.password == "mypassword"
This will actually be compared by hashing "mypassword" first.
+## Sharding
+
+Sharding allows you to partition your data for a single class across multiple domains allowing increased write throughput,
+faster queries and more space (multiply your 10GB per domain limit). And it's very easy to implement with SimpleRecord.
+
+ shard :shards=>:my_shards_function, :map=>:my_mapping_function
+
+The :shards function should return a list of shard names, for example: ['CA', 'FL', 'HI', ...] or [1,2,3,4,...]
+
+The :map function should return which shard name the object should be stored to.
+
+When executing a find() operation, you can explicitly specify the shard(s) you'd like to find on. This is
+particularly useful if you know in advance which shard the data will be in.
+
+ MyClass.find(:all, :conditions=>....., :shard=>["CA", "FL"])
+
+You can see some [example classes here](https://github.com/appoxy/simple_record/blob/master/test/my_sharded_model.rb).
+
## Kudos
Special thanks to Garrett Cox for creating Activerecord2sdb which SimpleRecord is based on:
View
@@ -1,5 +1,5 @@
---
-:major: 1
-:minor: 5
-:patch: 6
+:major: 2
+:minor: 0
+:patch: 2
:build:
Oops, something went wrong.

0 comments on commit 7fc089b

Please sign in to comment.