Class: DB::MariaDB::Connection

Inherits:
Async::Pool::Resource
  • Object
show all
Defined in:
lib/db/mariadb/connection.rb

Overview

This implements the interface between the underyling native interface interface and “standardised” connection interface.

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Connection



36
37
38
39
40
# File 'lib/db/mariadb/connection.rb', line 36

def initialize(**options)
  @native = Native::Connection.connect(**options)
  
  super()
end

Instance Method Details

#append_identifier(value, buffer = String.new) ⇒ Object



71
72
73
74
75
# File 'lib/db/mariadb/connection.rb', line 71

def append_identifier(value, buffer = String.new)
  buffer << "`" << @native.escape(value) << "`"
  
  return buffer
end

#append_literal(value, buffer = String.new) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/db/mariadb/connection.rb', line 54

def append_literal(value, buffer = String.new)
  case value
  when Numeric
    buffer << value.to_s
  when TrueClass
    buffer << 'TRUE'
  when FalseClass
    buffer << 'FALSE'
  when nil
    buffer << 'NULL'
  else
    append_string(value, buffer)
  end
  
  return buffer
end

#append_string(value, buffer = String.new) ⇒ Object



48
49
50
51
52
# File 'lib/db/mariadb/connection.rb', line 48

def append_string(value, buffer = String.new)
  buffer << "'" << @native.escape(value) << "'"
  
  return buffer
end

#call(statement, streaming: false) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/db/mariadb/connection.rb', line 89

def call(statement, streaming: false)
  @native.send_query(statement)
  
  last_result = nil
  
  while result = @native.next_result
    last_result = result
  end
  
  return last_result
end

#closeObject



42
43
44
45
46
# File 'lib/db/mariadb/connection.rb', line 42

def close
  @native.close
  
  super
end

#next_resultObject



85
86
87
# File 'lib/db/mariadb/connection.rb', line 85

def next_result
  @native.next_result
end

#send_query(statement) ⇒ Object



81
82
83
# File 'lib/db/mariadb/connection.rb', line 81

def send_query(statement)
  @native.send_query(statement)
end

#statusObject



77
78
79
# File 'lib/db/mariadb/connection.rb', line 77

def status
  @native.status
end