| Module | RBatis::Repository::ClassMethods |
| In: |
lib/rbatis.rb
|
Returns a BooleanMapper, useful for resultmaps like this:
resultmap :default,
:username => ['userid', String],
:email_offers => ['offersopt', boolean],
Defines a named ResultMap which is a map from field name to mapping specification. For example:
resultmap :default,
:username => ['userid', String],
:email => ['email', String],
:first_name => ['firstname', String],
:last_name => ['lastname', String],
:address1 => ['addr1', String],
:address2 => ['addr2', String],
:city => ['city', String],
:state => ['state', String],
:zip => ['zip', String],
:country => ['country', String],
:phone => ['phone', String],
:favourite_category_name => ['favcategory', String],
:language_preference => ['langpref', String],
:list_option => ['mylistopt', boolean],
:banner_option => ['banneropt', boolean],
:banner => RBatis::LazyAssociation.new(:to => Banner,
:select => :find_by_favcategory,
:key => :favourite_category_name),
:favourite_category => RBatis::LazyAssociation.new(:to => Category,
:select => :find_by_name,
:key => :favourite_category_name)
Instantiates the statement and puts it into statements also generates a class method with the same name that invokes the statement. For example:
class Product < RBatis::Base
statement :select_one, :find do |productid|
["SELECT * FROM product WHERE productid = ?", productid]
end
end
Can be invoked with:
Product.select_one(id)
Note: This also needs a resultmap named +:default+:
statement_type is one of:
| :select: | Selects and maps multiple object (see Select) |
| :select_one: | Selects and maps one object (see SelectOne) |
| :select_value: | Selects a single value such as an integer or a string (see SelectValue) |
| :insert: | Inserts new records into the database (see Insert) |
| :update: | Updates the database (see Update) |
| :delete: | Deletes records from the database (see Delete) |