Module: Snowflake::Client
- Defined in:
- lib/snowflake_rb.rb
Class Method Summary collapse
- .close(db_pointer) ⇒ Object
- .column_count(query_object) ⇒ Object
-
.column_names(query_object, field_count = nil) ⇒ List<String>
The column values in order.
-
.config ⇒ Dry::Configurable::Config
Configuration for the gem.
- .connect(account = nil, warehouse = nil, database = nil, schema = nil, user = nil, password = nil, role = nil, port = nil) ⇒ Object
- .exec(db_pointer, statement) ⇒ Object
- .fetch(db_pointer, query) ⇒ Object
-
.get_next_row(query_object, field_count) ⇒ List<String>
The column values in order.
-
.select(db_pointer, sql, field_count: nil) ⇒ Object
Send a query and then yield each row as an array of strings to the given block.
Class Method Details
.close(db_pointer) ⇒ Object
58 59 60 |
# File 'lib/snowflake_rb.rb', line 58 def close(db_pointer) ::Snowflake::Binding.close(db_pointer) end |
.column_count(query_object) ⇒ Object
142 143 144 |
# File 'lib/snowflake_rb.rb', line 142 def column_count(query_object) ::Snowflake::Binding.query_column_count(query_object) end |
.column_names(query_object, field_count = nil) ⇒ List<String>
Returns the column values in order.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/snowflake_rb.rb', line 124 def column_names(query_object, field_count = nil) raw_row = ::Snowflake::Binding.query_columns(query_object) return nil if raw_row.nil? || raw_row == FFI::Pointer::NULL raw_row.get_array_of_pointer(0, field_count).map do |cstr| if cstr == FFI::Pointer::NULL || cstr.nil? nil else str = cstr.read_string LibC.free(cstr) str end end ensure LibC.free(raw_row) if raw_row end |
.config ⇒ Dry::Configurable::Config
Returns configuration for the gem.
147 148 149 |
# File 'lib/snowflake_rb.rb', line 147 def config SnowflakeRB::Configuration.config end |
.connect(account = nil, warehouse = nil, database = nil, schema = nil, user = nil, password = nil, role = nil, port = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/snowflake_rb.rb', line 35 def connect( account = nil, warehouse = nil, database = nil, schema = nil, user = nil, password = nil, role = nil, port = nil ) ::Snowflake::Binding.connect( account || Snowflake::configuration.account, warehouse || Snowflake::configuration.warehouse, database || Snowflake::configuration.database, schema || Snowflake::configuration.schema, user || Snowflake::configuration.user, password || Snowflake::configuration.password, role || Snowflake::configuration.role, port || Snowflake::configuration.port ) end |
.exec(db_pointer, statement) ⇒ Object
65 66 67 68 |
# File 'lib/snowflake_rb.rb', line 65 def exec(db_pointer, statement) count = ::Snowflake::Binding.exec(db_pointer, statement) # returns -1 for error count >= 0 ? count : nil end |
.fetch(db_pointer, query) ⇒ Object
95 96 97 |
# File 'lib/snowflake_rb.rb', line 95 def fetch(db_pointer, query) ::Snowflake::Binding.fetch(db_pointer, query) end |
.get_next_row(query_object, field_count) ⇒ List<String>
Returns the column values in order.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/snowflake_rb.rb', line 105 def get_next_row(query_object, field_count) raw_row = ::Snowflake::Binding.next_row(query_object) return nil if raw_row.nil? || raw_row == FFI::Pointer::NULL raw_row.get_array_of_pointer(0, field_count).map do |cstr| if cstr == FFI::Pointer::NULL || cstr.nil? nil else str = cstr.read_string LibC.free(cstr) str end end ensure LibC.free(raw_row) if raw_row end |
.select(db_pointer, sql, field_count: nil) ⇒ Object
Send a query and then yield each row as an array of strings to the given block
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/snowflake_rb.rb', line 75 def select(db_pointer, sql, field_count: nil) return 'db_pointer not initialized' unless db_pointer return to_enum(__method__, db_pointer, sql) unless block_given? query_pointer = fetch(db_pointer, sql) return 'query_pointer is missing' if query_pointer.nil? || query_pointer == FFI::Pointer::NULL field_count ||= column_count(query_pointer) loop do row = get_next_row(query_pointer, field_count) return 'row not present' unless row yield row end nil end |