Class Sequel::Mock::Database
In: lib/sequel/adapters/mock.rb
Parent: Sequel::Database

Database class for Sequel‘s mock adapter.

Methods

Constants

SHARED_ADAPTERS = { 'access'=>'Access', 'db2'=>'DB2', 'firebird'=>'Firebird', 'informix'=>'Informix', 'mssql'=>'MSSQL', 'mysql'=>'MySQL', 'oracle'=>'Oracle', 'postgres'=>'Postgres', 'sqlite'=>'SQLite'   Map of database type names to module names, used for handling mock adapters for specific database types.

Attributes

autoid  [W]  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
Array :First insert gets the first value in the array, second gets the second value, etc.
Proc :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.
columns  [W]  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.
Proc :Called with the select SQL query, uses the value returned, which should be an array of symbols
fetch  [W]  Set the hashes to yield by execute when retrieving rows. Argument types supported:
nil :Yield no rows
Hash :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.
Proc :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.
numrows  [W]  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
Array :First update/delete gets the first value in the array, second gets the second value, etc.
Proc :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.

Public Class methods

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.

[Source]

     # File lib/sequel/adapters/mock.rb, line 109
109:       def initialize(opts={})
110:         super
111:         opts = @opts
112:         if mod_name = SHARED_ADAPTERS[opts[:host]]
113:           require "sequel/adapters/shared/#{opts[:host]}"
114:           extend Sequel.const_get(mod_name)::DatabaseMethods
115:           extend_datasets Sequel.const_get(mod_name)::DatasetMethods
116:         end
117:         self.autoid = opts[:autoid]
118:         self.columns = opts[:columns]
119:         self.fetch = opts[:fetch]
120:         self.numrows = opts[:numrows]
121:         extend(opts[:extend]) if opts[:extend]
122:         @sqls = opts[:sqls] || []
123:       end

Public Instance methods

Return a related Connection option connecting to the given shard.

[Source]

     # File lib/sequel/adapters/mock.rb, line 126
126:       def connect(server)
127:         Connection.new(self, server, server_opts(server))
128:       end

Store the sql used for later retrieval with sqls, and return the appropriate value using either the autoid, fetch, or numrows methods.

[Source]

     # File lib/sequel/adapters/mock.rb, line 133
133:       def execute(sql, opts={}, &block)
134:         synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)} 
135:       end
execute_ddl(sql, opts={}, &block)

Alias for execute

Store the sql used, and return the value of the numrows method.

[Source]

     # File lib/sequel/adapters/mock.rb, line 139
139:       def execute_dui(sql, opts={})
140:         execute(sql, opts.merge(:meth=>:numrows))
141:       end

Store the sql used, and return the value of the autoid method.

[Source]

     # File lib/sequel/adapters/mock.rb, line 144
144:       def execute_insert(sql, opts={})
145:         execute(sql, opts.merge(:meth=>:autoid))
146:       end

Return all stored SQL queries, and clear the cache of SQL queries.

[Source]

     # File lib/sequel/adapters/mock.rb, line 150
150:       def sqls
151:         s = @sqls.dup
152:         @sqls.clear
153:         s
154:       end

Enable use of savepoints.

[Source]

     # File lib/sequel/adapters/mock.rb, line 157
157:       def supports_savepoints?
158:         true
159:       end

[Validate]