abstract class DB::Statement


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.

Included Modules

Defined in:



Instance Method Summary

Macro Summary

Instance methods inherited from module DB::StatementMethods

exec : ExecResult
exec(*args_, args : Array? = nil) : ExecResult
, query(*args_, args : Array? = nil, &)
query : ResultSet
query(*args_, args : Array? = nil) : ResultSet
, scalar(*args_, args : Array? = nil) scalar

Instance methods inherited from module DB::Disposable

close close, closed? closed?

Constructor Detail

def self.new(connection : Connection, command : String) #

[View source]

Instance Method Detail

def command : String #

[View source]
def exec : DB::ExecResult #

[View source]
def exec(*args_, args : Array? = nil) : DB::ExecResult #

[View source]
def query : DB::ResultSet #

[View source]
def query(*args_, args : Array? = nil) : DB::ResultSet #

[View source]
def release_connection #

[View source]

Macro Detail

macro def_around_query_or_exec(&block) #

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

[View source]