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

Methods

Attributes

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.
server_version  [RW]  Mock the server version, useful when using the shared adapters

Public Instance methods

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.

[Source]

    # File lib/sequel/adapters/mock.rb, line 49
49:       def autoid=(v)
50:         @autoid = case v
51:         when Integer
52:           i = v - 1
53:           proc{@mutex.synchronize{i+=1}}
54:         else
55:           v
56:         end
57:       end

Return a related Connection option connecting to the given shard.

[Source]

     # File lib/sequel/adapters/mock.rb, line 101
101:       def connect(server)
102:         Connection.new(self, server, server_opts(server))
103:       end

[Source]

     # File lib/sequel/adapters/mock.rb, line 105
105:       def disconnect_connection(c)
106:       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 111
111:       def execute(sql, opts=OPTS, &block)
112:         synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)} 
113:       end
execute_ddl(sql, opts=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 117
117:       def execute_dui(sql, opts=OPTS)
118:         execute(sql, opts.merge(:meth=>:numrows))
119:       end

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

[Source]

     # File lib/sequel/adapters/mock.rb, line 122
122:       def execute_insert(sql, opts=OPTS)
123:         execute(sql, opts.merge(:meth=>:autoid))
124:       end

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

[Source]

     # File lib/sequel/adapters/mock.rb, line 128
128:       def sqls
129:         @mutex.synchronize do
130:           s = @sqls.dup
131:           @sqls.clear
132:           s
133:         end
134:       end

Enable use of savepoints.

[Source]

     # File lib/sequel/adapters/mock.rb, line 137
137:       def supports_savepoints?
138:         shared_adapter? ? super : true
139:       end

[Validate]