abstract class DB::Statement

Overview

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:

db/statement.cr

Constructors

Instance Method Summary

Macro Summary

Instance methods inherited from module DB::Disposable

close close, closed? closed?

Instance methods inherited from module DB::StatementMethods

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

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 = nil) : DB::ExecResult #

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

[View source]
def query(*args_, args : Array | Nil = 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
    res
  end
end

[View source]