Class: DB::Postgres::Connection
- Inherits:
-
Async::Pool::Resource
- Object
- Async::Pool::Resource
- DB::Postgres::Connection
- Defined in:
- lib/db/postgres/connection.rb
Overview
This implements the interface between the underlying
Instance Method Summary collapse
- #append_identifier(value, buffer = String.new) ⇒ Object
- #append_literal(value, buffer = String.new) ⇒ Object
- #append_string(value, buffer = String.new) ⇒ Object
- #close ⇒ Object
-
#initialize(**options) ⇒ Connection
constructor
A new instance of Connection.
- #key_column(name = 'id', primary: true, null: false) ⇒ Object
- #next_result ⇒ Object
- #send_query(statement) ⇒ Object
- #status ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(**options) ⇒ Connection
Returns a new instance of Connection.
32 33 34 35 36 |
# File 'lib/db/postgres/connection.rb', line 32 def initialize(**) @native = Native::Connection.connect(**) super() end |
Instance Method Details
#append_identifier(value, buffer = String.new) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/db/postgres/connection.rb', line 76 def append_identifier(value, buffer = String.new) case value when Array first = true value.each do |part| buffer << '.' unless first first = false buffer << @native.escape_identifier(part) end else buffer << @native.escape_identifier(value) end return buffer end |
#append_literal(value, buffer = String.new) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/db/postgres/connection.rb', line 57 def append_literal(value, buffer = String.new) case value when Time, DateTime, Date append_string(value.iso8601, buffer) 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
51 52 53 54 55 |
# File 'lib/db/postgres/connection.rb', line 51 def append_string(value, buffer = String.new) buffer << @native.escape_literal(value) return buffer end |
#close ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/db/postgres/connection.rb', line 38 def close if @native @native&.close @native = nil end super end |
#key_column(name = 'id', primary: true, null: false) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/db/postgres/connection.rb', line 93 def key_column(name = 'id', primary: true, null: false) buffer = String.new append_identifier(name, buffer) if primary buffer << " BIGSERIAL" else buffer << " BIGINT" end if primary buffer << " PRIMARY KEY" elsif !null buffer << " NOT NULL" end return buffer end |
#next_result ⇒ Object
123 124 125 |
# File 'lib/db/postgres/connection.rb', line 123 def next_result @native.next_result end |
#send_query(statement) ⇒ Object
117 118 119 120 121 |
# File 'lib/db/postgres/connection.rb', line 117 def send_query(statement) @native.discard_results @native.send_query(statement) end |
#status ⇒ Object
113 114 115 |
# File 'lib/db/postgres/connection.rb', line 113 def status @native.status end |
#types ⇒ Object
47 48 49 |
# File 'lib/db/postgres/connection.rb', line 47 def types @native.types end |