class

DB::Statement

Inherits DB::Disposable / DB::StatementMethods / Reference / Object

Represents a query in a Connection. It should be created by QueryMethods.

Note to implementors

  1. Subclass Statements
  2. Statements are created from a custom driver Connection#prepare method.
  3. #perform_query executes a query that is expected to return a ResultSet
  4. #perform_exec executes a query that is expected to return an ExecResult
  5. #do_close is called to release the statement resources.

Constructors

new(connection : Connection, command : String)
Source

Instance methods

command
Source
exec

See QueryMethods#exec

Source
exec(*args_, args : Enumerable | Nil = nil) : DB::ExecResult

See QueryMethods#exec

Source
query

See QueryMethods#query

Source
query(*args_, args : Enumerable | Nil = nil) : DB::ResultSet

See QueryMethods#query

Source
release_connection
Source

Macros

def_around_query_or_exec

This macro allows injecting code to be run before and after the execution of the request. It should return the yielded value. It must be called with 1 block argument that will be used to pass the args : Enumerable.

class DB::Statement
  def_around_query_or_exec do |args|
    # do something before query or exec
    res = yield
    # do something after query or exec
    res
  end
end
Source