Project

sodacan

0.0
No commit activity in last 3 years
No release in over 3 years
Wrapper to make ActiveRecord type queries on Soda2 interfaces.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

= 1.7.7
 Project Readme

#sodacan

An ActiveRecord-like interface to databases with a JSON based Soda2 interface, and example of which is the NYC OpenData set.

##Install

Install the gem from rubygems

$ gem install sodacan

Require it as needed

require 'sodacan'

##Usage

A new database should be added to an application by subclassing SodaCan::Base

class MyDB < SodaCan::Base
end

This new class comes with a host of query methods out of the box. Before querying the database, connect it to the Soda2 database

MyDB.connect [uri string here]

##Query Methods

All query methods are class methods on a DB class. Query methods return instances of the DB class, just like ActiveRecord.

###.many

Returns an array of up to the first 1000 instances in the database

###.execute query

Returns the instances retrieved as a result of sending the query to the database

###.find id

Returns the instance in the database with the given ID, nil if the id is not found

###.search term

Returns an array of any instances that have the term string as a value for any field. Search works only for full tokens in the database. "ban" will match "ban on apples" but not "bananas are good"

###.where params

Returns an array of instances where the field represented by the key in the params hash has the value represented by the value in the params hash

##Instance methods

####_fields

Returns a hash of field names and types found in the instance

####accessors

Depending upon the record being accessed a number of accessor methods are created for the instance, allowing access to the fields.

##Example

class MyDB < SodaCan::Base
end

MyDB.connect 'http://someurl.com/'

first = MyDB.find 1
bananas = MyDB.search "banana"
bananas.first.calories # calorie count of the first banana
fruit = MyDB.where(food_group: 'fruit')