Class: ActiveRecord::ConnectionAdapters::RunivedoAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::RunivedoAdapter
- Defined in:
- lib/active_record/connection_adapters/runivedo_adapter.rb
Defined Under Namespace
Classes: BindSubstitution
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#perspective ⇒ Object
readonly
Returns the value of attribute perspective.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#adapter_name ⇒ Object
:nodoc:.
- #columns(table_name) ⇒ Object
- #connect ⇒ Object
-
#delete_sql(sql, name = nil) ⇒ Object
:nodoc:.
-
#disconnect! ⇒ Object
Disconnects from the database if already connected.
- #exec_delete(sql, name = 'SQL', binds = []) ⇒ Object (also: #exec_update)
-
#exec_query(sql, name = nil, binds = []) ⇒ Object
DATABASE STATEMENTS ======================================.
-
#execute(sql, name = nil) ⇒ Object
:nodoc:.
-
#initialize(url, bucket, app, uts, username, logger, config) ⇒ RunivedoAdapter
constructor
A new instance of RunivedoAdapter.
-
#insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
(also: #create)
:nodoc:.
- #last_inserted_id(result) ⇒ Object
-
#native_database_types ⇒ Object
:nodoc:.
- #primary_key(table_name) ⇒ Object
-
#quote_column_name(name) ⇒ Object
:nodoc:.
-
#quote_table_name_for_assignment(table, attr) ⇒ Object
QUOTING ==================================================.
- #reconnect! ⇒ Object
- #select_rows(sql, name = nil, binds = []) ⇒ Object
-
#tables(name = nil, table_name = nil) ⇒ Object
SCHEMA STATEMENTS ========================================.
-
#update_sql(sql, name = nil) ⇒ Object
:nodoc:.
Constructor Details
#initialize(url, bucket, app, uts, username, logger, config) ⇒ RunivedoAdapter
Returns a new instance of RunivedoAdapter.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 38 def initialize(url, bucket, app, uts, username, logger, config) super(nil, logger) @url = url @bucket = bucket @app = app @uts = uts @username = username @result = nil type_map.register_type 'uuid', Type::UUID.new @visitor = Arel::Visitors::SQLite.new self @prepared_statements = true connect end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
32 33 34 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 32 def bucket @bucket end |
#perspective ⇒ Object (readonly)
Returns the value of attribute perspective.
32 33 34 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 32 def perspective @perspective end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
32 33 34 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 32 def session @session end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
32 33 34 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 32 def url @url end |
Instance Method Details
#active? ⇒ Boolean
61 62 63 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 61 def active? !@session.closed? end |
#adapter_name ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 57 def adapter_name #:nodoc: 'Runivedo' end |
#columns(table_name) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 183 def columns(table_name) @perspective.get_fields_for_table(table_name).map do |name, sql_type| sql_type = "integer" if sql_type == "pk" cast_type = lookup_cast_type(sql_type) Column.new(name, nil, cast_type, sql_type) end end |
#connect ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 65 def connect @connection = Runivedo::Connection.new(@url) @session = @connection.get_session(@bucket, {username: @username}) @session.apply_uts(@uts) if @uts @perspective = session.get_perspective(@app) @connection = @perspective.query end |
#delete_sql(sql, name = nil) ⇒ Object
:nodoc:
158 159 160 161 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 158 def delete_sql(sql, name = nil) #:nodoc: sql += " WHERE 1=1" unless sql =~ /WHERE/i super sql, name end |
#disconnect! ⇒ Object
Disconnects from the database if already connected. Otherwise, this method does nothing.
75 76 77 78 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 75 def disconnect! super @session.close rescue nil end |
#exec_delete(sql, name = 'SQL', binds = []) ⇒ Object Also known as: exec_update
136 137 138 139 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 136 def exec_delete(sql, name = 'SQL', binds = []) exec_query(sql, name, binds) @result.num_affected_rows end |
#exec_query(sql, name = nil, binds = []) ⇒ Object
DATABASE STATEMENTS ======================================
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 117 def exec_query(sql, name = nil, binds = []) log(sql, name, binds) do if without_prepared_statement?(binds) binds = [] end stmt = @connection.prepare(sql) cols = stmt.column_names i = -1 binds_hash = Hash[binds.map { |col, val| [i += 1, val] }] @result.close if @result @result = stmt.execute(binds_hash) records = @result.to_a stmt.close ActiveRecord::Result.new(cols, records) end end |
#execute(sql, name = nil) ⇒ Object
:nodoc:
147 148 149 150 151 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 147 def execute(sql, name = nil) #:nodoc: log(sql, name) do @connection.prepare(sql).execute.to_a end end |
#insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object Also known as: create
:nodoc:
163 164 165 166 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 163 def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc: super id_value || @connection.last_insert_row_id end |
#last_inserted_id(result) ⇒ Object
142 143 144 145 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 142 def last_inserted_id(result) raise "didn't insert anything" unless @result @result.last_inserted_id end |
#native_database_types ⇒ Object
:nodoc:
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 86 def native_database_types #:nodoc: { :primary_key => default_primary_key_type, :string => { :name => "varchar" }, :text => { :name => "text" }, :integer => { :name => "integer" }, :float => { :name => "float" }, :decimal => { :name => "decimal" }, :datetime => { :name => "datetime" }, :timestamp => { :name => "datetime" }, :time => { :name => "time" }, :date => { :name => "date" }, :binary => { :name => "blob" }, :boolean => { :name => "boolean" }, :uuid => { :name => "uuid" }, } end |
#primary_key(table_name) ⇒ Object
179 180 181 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 179 def primary_key(table_name) "id" end |
#quote_column_name(name) ⇒ Object
:nodoc:
110 111 112 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 110 def quote_column_name(name) #:nodoc: %Q("#{name.to_s.gsub('"', '""')}") end |
#quote_table_name_for_assignment(table, attr) ⇒ Object
QUOTING ==================================================
106 107 108 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 106 def quote_table_name_for_assignment(table, attr) quote_column_name(attr) end |
#reconnect! ⇒ Object
80 81 82 83 84 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 80 def reconnect! super disconnect! rescue nil connect end |
#select_rows(sql, name = nil, binds = []) ⇒ Object
169 170 171 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 169 def select_rows(sql, name = nil, binds = []) exec_query(sql, name, binds).rows end |
#tables(name = nil, table_name = nil) ⇒ Object
SCHEMA STATEMENTS ========================================
175 176 177 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 175 def tables(name = nil, table_name = nil) #:nodoc: @perspective.get_tables end |
#update_sql(sql, name = nil) ⇒ Object
:nodoc:
153 154 155 156 |
# File 'lib/active_record/connection_adapters/runivedo_adapter.rb', line 153 def update_sql(sql, name = nil) #:nodoc: super @result.num_affected_rows end |