Coder Social home page Coder Social logo

appoxy / simple_record Goto Github PK

View Code? Open in Web Editor NEW
129.0 129.0 29.0 875 KB

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

Ruby 99.77% Shell 0.23%

simple_record's People

Contributors

blakeeb avatar celeduc avatar douglasr avatar foreverman avatar jredville avatar rkononov avatar superjustin avatar treeder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple_record's Issues

Set att_accessors from parameters hash

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

Finder Methods aren't Working - JRuby 1.6.2

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_'

Not accessable from local machine but it works from my amazon server

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:inloop'
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:inrequest_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:inadd!'
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:inrequest_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:inselect'
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:infind_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:inall'
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

Lots of wrong tests

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.

CLOB setting endzone/amazon zone Europe

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 !

Jruby Gem Build fail

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.

.pre_save ?

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?

Given logger not respected by S3 connection

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 ;)

created_at search

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

Generate paths for Rails form_for

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: 

Activerecordtosdb_subrecord_array self.sanitize_sql function not working with rails 3

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:inmethod_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:infind'
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:instart'
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:inrequire'
from script/rails:6:in `

'

memcached

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.

simple_record-1.5.7 causing: Aws::AwsError: InvalidNextToken: The specified next token is not valid.

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?

Validations not working

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.

Clarification of Created and Updated At Columns section of the readme

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?

simple_record with paperclip plugin

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

Rails 3 Validation fails for attr_accessors when using SimpleRecord

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

For this example new_passwords must be formated like emails

validates_format_of :new_password, :with => /^[-a-z0-9_+.]+@([-a-
z0-9]+.)+[a-z0-9]{2,4}$/i

Stuff for encrypting and setting password...

end

bar = Foo.new
bar.new_password = [email protected]
bar.valid? #=> false
bar.errors #=> {:new_password=>["is invalid"]}

Thanks,
Josh

as_json chokes on invalid data

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?

Do not get lob object when setting dirty

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.

Message "Using ActiveModel validations."

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

cleaning up the 'puts'

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.

Add some info to Getting Started

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.