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

Returns a new instance of Connection.



38
39
40
41
42
# File 'lib/db/mariadb/connection.rb', line 38

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

Instance Method Details

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



73
74
75
76
77
# File 'lib/db/mariadb/connection.rb', line 73

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

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



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

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



50
51
52
53
54
# File 'lib/db/mariadb/connection.rb', line 50

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

#closeObject



44
45
46
47
48
# File 'lib/db/mariadb/connection.rb', line 44

def close
  @native.close
  
  super
end

#id_column(name = 'id', primary_key: true) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/db/mariadb/connection.rb', line 79

def id_column(name = 'id', primary_key: true)
  buffer = String.new
  
  append_identifier(name, buffer)
  
  buffer << " BIGINT AUTO_INCREMENT"
  
  if primary_key
    buffer << " PRIMARY KEY"
  end
  
  return buffer
end

#next_resultObject



103
104
105
# File 'lib/db/mariadb/connection.rb', line 103

def next_result
  @native.next_result
end

#send_query(statement) ⇒ Object



97
98
99
100
101
# File 'lib/db/mariadb/connection.rb', line 97

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

#statusObject



93
94
95
# File 'lib/db/mariadb/connection.rb', line 93

def status
  @native.status
end