Database class for Sequel's mock adapter.
Map of database type names to module names, used for handling mock adapters for specific database types.
Set the autogenerated primary key integer to be returned when running an insert query. Argument types supported:
nil |
Return nil for all inserts |
Integer |
Starting integer for next insert, with futher inserts getting an incremented value |
First insert gets the first value in the array, second gets the second value, etc. | |
Called with the insert SQL query, uses the value returned | |
Class |
Should be an Exception subclass, will create a new instance an raise it wrapped in a DatabaseError. |
Set the columns to set in the dataset when the dataset fetches rows. Argument types supported:
nil |
Set no columns |
Array of Symbols: Used for all datasets Array (otherwise): First retrieval gets the first value in the
array, second gets the second value, etc.
Called with the select SQL query, uses the value returned, which should be an array of symbols |
Set the hashes to yield by execute when retrieving rows. Argument types supported:
nil |
Yield no rows |
Always yield a single row with this hash | |
Array of Hashes |
Yield separately for each hash in this array |
Array (otherwise) |
First retrieval gets the first value in the array, second gets the second value, etc. |
Called with the select SQL query, uses the value returned, which should be a hash or array of hashes. | |
Class |
Should be an Exception subclass, will create a new instance an raise it wrapped in a DatabaseError. |
Set the number of rows to return from update or delete. Argument types supported:
nil |
Return 0 for all updates and deletes |
Integer |
Used for all updates and deletes |
First update/delete gets the first value in the array, second gets the second value, etc. | |
Called with the update/delete SQL query, uses the value returned. | |
Class |
Should be an Exception subclass, will create a new instance an raise it wrapped in a DatabaseError. |
Additional options supported:
:autoid |
Call autoid= with the value |
:columns |
Call columns= with the value |
:fetch |
Call fetch= with the value |
:numrows |
Call numrows= with the value |
:extend |
A module the object is extended with. |
:sqls |
The array to store the SQL queries in. |
# File lib/sequel/adapters/mock.rb, line 109 def initialize(opts={}) super opts = @opts if mod_name = SHARED_ADAPTERS[opts[:host]] require "sequel/adapters/shared/#{opts[:host]}" extend Sequel.const_get(mod_name)::DatabaseMethods extend_datasets Sequel.const_get(mod_name)::DatasetMethods end self.autoid = opts[:autoid] self.columns = opts[:columns] self.fetch = opts[:fetch] self.numrows = opts[:numrows] extend(opts[:extend]) if opts[:extend] @sqls = opts[:sqls] || [] end
Return a related Connection option connecting to the given shard.
# File lib/sequel/adapters/mock.rb, line 126 def connect(server) Connection.new(self, server, server_opts(server)) end
Store the sql used for later retrieval with sqls, and return the appropriate value using either the autoid, fetch, or numrows methods.
# File lib/sequel/adapters/mock.rb, line 133 def execute(sql, opts={}, &block) synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)} end
Store the sql used, and return the value of the numrows method.
# File lib/sequel/adapters/mock.rb, line 139 def execute_dui(sql, opts={}) execute(sql, opts.merge(:meth=>:numrows)) end
Store the sql used, and return the value of the autoid method.
# File lib/sequel/adapters/mock.rb, line 144 def execute_insert(sql, opts={}) execute(sql, opts.merge(:meth=>:autoid)) end
Generated with the Darkfish Rdoc Generator 2.