appoxy / simple_record Goto Github PK
View Code? Open in Web Editor NEWAn ActiveRecord like interface for SimpleDB. Can be used as a drop in replacement for ActiveRecord in rails.
Home Page: http://www.appoxy.com
License: MIT License
An ActiveRecord like interface for SimpleDB. Can be used as a drop in replacement for ActiveRecord in rails.
Home Page: http://www.appoxy.com
License: MIT License
Using simple_record, if you have a model with attr_accessor(s), the attr_accessors are not set if their value is present in the params hash for new objects.
class Foo < SimpleRecord::Base
has_attributes :stuff
attr_accessor :bar
end
f = Foo.new(:bar => "test, :stuff => "yep")
f.stuff # puts "yep"
f.bar # puts nil instead of "test"
I came up with this: http://gist.github.com/609851
None of the finder methods are working with JRuby. They all return the same error:
ArgumentError: wrong number of arguments (2 for 1) from ...simple_record-2.1.8/lib/simple_record/active_sdb.rb:441:in `select_all_by_'
Initally I was able to work on my local machine and access simple db record easliy but from last few months i m faceing lot of issues .
when i try to access SimpleDb Records i get this
Retailer.all
Aws::AwsError: sdb.ap-southeast-2.amazonaws.com temporarily unavailable: (execution expired)
from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/http_connection-1.4.4/lib/right_http_connection.rb:335:in request' from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/http_connection-1.4.4/lib/right_http_connection.rb:325:in
loop'
from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/http_connection-1.4.4/lib/right_http_connection.rb:325:in request' from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/aws-2.9.1/lib/awsbase/awsbase.rb:560:in
request_info_impl'
from /home/chetan/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/benchmark.rb:293:in measure' from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/aws-2.9.1/lib/awsbase/benchmark_fix.rb:30:in
add!'
from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/aws-2.9.1/lib/awsbase/awsbase.rb:560:in request_info_impl' from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/aws-2.9.1/lib/awsbase/awsbase.rb:319:in
request_info2'
from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/aws-2.9.1/lib/sdb/sdb_interface.rb:106:in request_info' from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/aws-2.9.1/lib/sdb/sdb_interface.rb:704:in
select'
from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/simple_record-2.1.0/lib/simple_record/active_sdb.rb:411:in sql_select' from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/simple_record-2.1.0/lib/simple_record/active_sdb.rb:293:in
find_with_metadata'
from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/simple_record-2.1.0/lib/simple_record.rb:963:in find' from /home/chetan/.rvm/gems/ruby-1.8.7-p371/gems/simple_record-2.1.0/lib/simple_record.rb:1002:in
all'
from (irb):2
The same code is working on amazon Ec2 medium instance (amazon LInux )
ruby 1.8.7
rails 3.2.11
and simple_record 2.1.0
Please can you help me out
In the current test suite lots of tests don't do what they are supposed to because of syntax errors, for instance in test_simple_record.rb:
assert mm2.cool = true
assert mm2.name = "Travis"
You should probably use assert_equal instead to avoid this kind of problems.
When I'm trying to update my record, it shouldn't tell me that the record is 'not unique'.
Hello,
I have tried in vain to have this to work with S3 in Europe which would be with server
s3-eu-west-1.amazonaws.com
as a last resort I tried even to set the server s3-eu-west-1.amazonaws.com
as DEFAULT_HOST on
https://github.com/appoxy/aws/blob/master/lib/s3/s3_interface.rb
but unfortunately it returns the infamous "moved permanently" error from amazon (probably caused by the URL formatting https://forums.aws.amazon.com/thread.jspa?threadID=17989 )
Is there any simple way to make CLOB working exactly like the simple_Db connection e.g.
SimpleRecord.establish_connection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, :server=> 'sdb.eu-west-1.amazonaws.com')
with the possibility to specify and S3 server like s3-eu-west-1.amazonaws.com that just works ?
Thanks again for this great library !
The values are just empty after initialization. No error is thrown.
Perhaps have a reference back to the ResultsArray in any object that comes out of it and the ResultsArray has a cache of objects. This could cut down on the db calls pretty substantially in certain cases.
after that it will always fail on subsequent saves since there self will be found. It should do an id comparison if new_record? is false.
I was trying out jruby and threading goodness by branching an existing project but ran into an issue installing the latest simple_record gem:
/Users/joshmckin/.rvm/rubies/jruby-1.6.0/bin/jruby extconf.rb
WARNING: JRuby does not support native extensions or the `mkmf' library very well.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
mkmf.rb can't find header files for ruby at /Users/joshmckin/.rvm/rubies/jruby-1.6.0/lib/native/include/ruby/ruby.h
Gem files will remain installed in /Users/joshmckin/.rvm/gems/jruby-1.6.0/gems/escape_utils-0.2.3 for inspection.
According to the bug below escape_utils has not plans to build a jruby/java extenion. Would i be possible to make use of anther gem? brianmario/escape_utils#7
I was able to install version simple_record-2.0.5.
Greetings!
I'm back to ROR and happy to use SimpleRecord again.
I've faced with some issue. To avoid database inconsistency, I need to track method transaction and save all created objects only if the whole method did succeed.
To do it, I need to create new SimpleRecord objects, but save all of them only at the method's end.
Problem that the objects has no .id until being saved.
I've found .pre_save method and tried to use them as .pre_save({})
Looks like it does work as expected.
Please clarify - is this correct usage and do I need to pass any options for my case?
If I explicitly specify a Logger when creating a simple_record connection, the logger is not passed into the S3 connection.
For example:
SimpleRecord.establish_connection(aws_id, aws_secret, :connection_mode => :per_thread, :s3_bucket => :new, :logger => logger)
I believe the fix is just adding the simple_record logger to the s3_opts hash: https://github.com/appoxy/simple_record/blob/master/lib/simple_record.rb line 137
Additionally, it might be a good idea to pass other connection configuration settings. I have not dived into simple_record/aws enough to make a recommendation regarding if anything should be passed along but I am sure you would know ;)
Its been my observation that searching by "created_at" does not return results. However, searching by "created" does return results. Should the readme be changed/updated or am I doing something wrong?
puts Log.find(:all, :conditions => ["created > ?", 3.days.ago]).length
=> 25
puts Log.find(:all, :conditions => ["created_at > ?", 3.days.ago]).length
=> 0
Thanks,
Josh
for example:
undefined method `coupons_path' for #<#<Class:0x007f31546903e8>:0x007f3154688b98>
Extracted source (around line #3):
1: <h1>New Coupon</h1>
2:
3: <%= form_for @coupon do |f| %>
4:
Currently, creates new connection to s3 for every clob get.
Perhaps it can keep the s3 connection for the entire each loop in ResultsArray, then close it after the loop ends?
Would be nice if there was an option in simple_record to auto truncate the string before encryption. Something that I could activate or deactivate
batch_save would fail if domain is not exist
After that it always fails
For example,
class Store < SimpleRecord::Base
has_many :visitors
end
class Visitor < SimpleRecord::Base
belongs_to :store
end
The following call,
Store.first.visitors.find(:all, :conditions => "gender = 'male'")
will generate these error:
ruby-1.9.2-p0 :010 > Store.first.visitors.find(:all,:conditions => "gender = 'M'")
NoMethodError: protected method sanitize_sql' called for ActiveRecord::Base:Class from /home/park/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/base.rb:1016:in
method_missing'
from /home/park/.rvm/gems/ruby-1.9.2-p0/gems/simple_record-2.0.5/lib/simple_record.rb:1002:in sanitize_sql' from /home/park/.rvm/gems/ruby-1.9.2-p0/gems/simple_record-2.0.5/lib/simple_record.rb:1112:in
find'
from (irb):10
from /home/park/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in start' from /home/park/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in
start'
from /home/park/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in <top (required)>' from script/rails:6:in
require'
from script/rails:6:in `
I cannot figure out how to get caching working with either memcached or dalli. This code:
store = :memcache_store, 'localhost', { :namespace => 'my_program', :expires_in => 1.day, :compress => true, :compress_threshold => 64*1024 }
SimpleRecord::Base.cache_store = store
results in undefined method `write' for #Array:0x00000101b80540
* file: simple_record.rb
* location: cache_results
* line: 1061
I'm working in Sinatra.
Running simple_record/test/test_lobs.rb will leave a file orphaned in S3, caused by the reassignment of mm.clob1 inside test_clobs.
The test itself does not detect this orphaned file, but it does fail.
Updated to 1.5.7 but receive the following error when I try a get request:
Aws::AwsError: InvalidNextToken: The specified next token is not valid.
REQUEST=sdb.amazonaws.com:443/?AWSAccessKeyId=CHANGEDRF6UVPI3XSHQA&Action=Select&NextToken=%7B%7D&SelectExpression=SELECT%20%2A%20FROM%20%60sit_pay_accounts%60&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2010-12-03T14%3A39%3A51.000Z&Version=2009-04-15&Signature=CHANGED5HXuAgcLmWveypSAsphzxecKK3faors%2B0%3D
(I added the CHANGED to the signaure and keyid)
Works just fine in simple_record-1.4.19.
Did something change that requires a change in my model from 1.4.19 to 1.5.7?
class MyThing < SimpleRecord::Base
validates_presence_of :code
validates_presence_of :x
validates_numericality_of :x, :only_integer => true
has_strings :code
has_ints :x
end
If x is empty string from form input, still saves ok. Also if x is a string, not an integer, saves as zero.
I'm confused by the "Created and Updated At Columns" section of the readme. It states "Although you can use created_at and updated_at methods, you may still want the columns in SimpleDB to be created_at and updated_at.", which to me says that we could go ahead and set the columns to created_at and updated_at. But the example following this statement sets them to "created" and "updated", not "created_at" or "updated_at". The first part of the subsequent "note" seems to recommend setting the columns to "created_at" and "updated_at", but the example given in the note again uses "created" and "updated".
Is it okay to use created_at and updated_at so that we can use these in our queries just as we do in regular active_record queries?
I'm sure it's more efficient to get it directly by Amazon's key.
Same storage format probably?
Hi.
Great plugin btw, thanks for your work in this!
I'm trying to use simple_record and paperclip (http://github.com/thoughtbot/paperclip) and getting an error: undefined method `validates_each'
Any chance you can make simple_record more compatible with paperclip? It would be awesome if I could provide file upload to my rails app.
Or do you another file-upload plugin instead?
Thanks again
The performance of the get_attribute method for simple record is pretty bad. Profiling results show the code spends 1.65 secs in this method for 8050 calls. Surely something is wrong
has_one isn't working
Sorry for the delay in making this ticket, been swamped.
Issue: attr_accessor it gives bogus errors
class Foo < SimpleRecord::Base
has_strings :password
attr_accessor :new_password
validates_format_of :new_password, :with => /^[-a-z0-9_+.]+@([-a-
z0-9]+.)+[a-z0-9]{2,4}$/i
end
bar = Foo.new
bar.new_password = [email protected]
bar.valid? #=> false
bar.errors #=> {:new_password=>["is invalid"]}
Thanks,
Josh
While that doesn't exactly sound like a bad thing โ it is being presented invalid data, after all! โ I found the best way for one bad attribute not to take down everything was to monkeypatch the Json module:
module SimpleRecord::Json
def as_json(options={})
result = {
'id' => self.id
}
result['json_class'] = self.class.name unless options && options[:exclude_json_class]
defined_attributes_local.each_pair do |name, val|
if val.type == :belongs_to
result[name.to_s + "_id"] = get_attribute_sdb(name) rescue nil
else
result[name] = get_attribute(name) rescue nil
end
end
result
end
end
Perhaps this could be an option or just mentioned in the README if nothing else?
It looks like it started to get objects from s3 and set the value in the changed[0] array. Should maybe put a Lob placeholder in there and only retrieve it if it's required/used.
Writing a test app and noticed that the standard Rails validator "validates_presence_of" or "validates :presence => true" does not work. This was a Rails 3 app.
See: appoxy/aws#66
I've played some time with per_token option and found that it set box_usage only for the last (or for the first?) request.
To better logic, it should summarize every SDB call's box usage.
can't create an record with column assigned with association(must use association_id)
This seems not appropriate. This gem just makes puts to stdout with this message, and any console opening is messed with it. I think its ok to put some deprecation warnings. But this is just some minor information
Would you be open to a pull request that removes puts statements, or that creates a class setting whereby putting can be disabled? '3 update' and '3 create' are making my tests run ugly.
The author did great work, but some people (like me) will save a lot of time knowing that simple_record DO support Consistent Read and multiple attribute values (returning them as array).
Just noticed that batch saving does not update 'updated' attribute :(
Is this by design?
Right now it only deletes from SimpleDB so the s3 objects are left orphaned.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.