Socket
Book a DemoInstallSign in
Socket

activerecord-alt-mongo-adapter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

activerecord-alt-mongo-adapter

0.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

= ActiveTokyoCabinet

Copyright (c) 2010 SUGAWARA Genki sgwr_dts@yahoo.co.jp

== Description

activerecord-alt-mongo-adapter is a MongoDB adapter for ActiveRecord.

activerecord-alt-mongo-adapter on MongoDB Ruby Driver.

see http://www.mongodb.org/display/DOCS/Home , http://api.mongodb.org/ruby/0.18.3/index.html

== Project Page

http://rubyforge.org/projects/araltmongo/

== Install

gem install activerecord-alt-mongo-adapter

== Example === database.yml

development:
  adapter:  mongo,
  host:     localhost
  port:     27017
  database: scott

=== Model

class Emp < ActiveRecord::Base
  include ActiveMongo::Collection
  # There is no need to define a schema.
end

=== ActiveRecord API

# see http://api.rubyonrails.org/classes/ActiveRecord/Base.html

emp = Emp.find(:first, 
        :conditions => ["job = ? and sal >= ?", "MANAGER", 2800],
        :order => 'sal desc', :limit => 3, :offset => 1)

p emp.id #=> "4bb795e8f15d3d0324000006"
emp.age = 30
emp.save

emp_list = Emp.find(:all, :conditions => {:empno => [7654, 7698, 7782]})

emp_list.each do |i|
  i.destroy if i.sal < 2000
end

new_emp = Emp.new
new_emp.empno = 8000
new_emp.ename = 'YAMADA'
new_emp.age   = 27
new_emp.save!

# not available:
# - :include, :group
# - `OR'
# - Include `ID' in search condition
# http://araltmongo.rubyforge.org/svn/trunk/lib/active_mongo/sqlparser.y

=== Expanded operator

# see http://www.mongodb.org/display/DOCS/Advanced+Queries

emp = Emp.find(:all, :conditions => ['job regexp ?', 'LE'])

emp = Emp.find(:all, :conditions => ['empno mod ?', [2, 0]])

emp = Emp.find(:all, :conditions => ['foo exists ?', true])

=== Low layer API

coll = Emp.collection

m =<<-EOS
  function() {
    emit(this.job, 1);
  }
EOS

r =<<-EOS
  function(k, vals) {
    var sum = 0;

    for(var i in vals) {
      sum += vals[i];
    }

    return sum;
  }
EOS

coll.map_reduce(m, r).find.each do |i|
  # do anything
end

FAQs

Package last updated on 03 Apr 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.