2323require 'active_record/base'
2424require 'active_record/base'
2525require 'arel/arel_crate'
26- require 'arel/visitors/bind_visitor '
26+ require 'arel/visitors/visitor '
2727require 'active_support/dependencies/autoload'
2828require 'active_support/callbacks'
2929require 'active_support/core_ext/string'
@@ -45,7 +45,7 @@ module ActiveRecord
4545 class Base
4646 def self . crate_connection ( config ) #:nodoc:
4747 config = config . symbolize_keys
48- ConnectionAdapters ::CrateAdapter . new ( nil , logger , nil , config )
48+ ConnectionAdapters ::CrateAdapter . new ( nil , logger , config )
4949 end
5050 end
5151
@@ -60,9 +60,10 @@ class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
6060
6161 ADAPTER_NAME = 'Crate' . freeze
6262
63- def schema_creation # :nodoc:
64- Crate ::SchemaCreation . new self
65- end
63+ # TODO: Croaks with `NotImplementedError`.
64+ # def schema_creation # :nodoc:
65+ # Crate::SchemaCreation.new self
66+ # end
6667
6768 NATIVE_DATABASE_TYPES = {
6869 boolean : { name : "boolean" } ,
@@ -77,13 +78,13 @@ def schema_creation # :nodoc:
7778 }
7879
7980 class BindSubstitution < Arel ::Visitors ::Crate # :nodoc:
80- include Arel ::Visitors :: BindVisitor
81+ include Arel ::Visitors
8182 end
8283
83- def initialize ( connection , logger , pool , config )
84+ def initialize ( connection , logger , config )
8485 @port = config [ :port ]
8586 @host = config [ :host ]
86- super ( connection , logger , pool )
87+ super ( connection , logger , config )
8788 @schema_cache = SchemaCache . new self
8889 @visitor = Arel ::Visitors ::Crate . new self
8990 @quoted_column_names = { }
@@ -127,11 +128,20 @@ def supports_migrations?
127128
128129 def connect
129130 @connection = CrateRuby ::Client . new ( [ "#{ @host } :#{ @port } " ] )
131+
132+ # Monkeypatch to make the client instance provide `supports_datetime_with_precision`.
133+ # FIXME: Implement within `CrateRuby::Client`.
134+ def @connection . supports_datetime_with_precision?
135+ # TODO: Should it be `true` instead?
136+ return false
137+ end
138+
130139 end
131140
132141 def columns ( table_name ) #:nodoc:
133142 cols = @connection . table_structure ( table_name ) . map do |field |
134- name = dotted_name ( field [ 2 ] )
143+ # TODO: Review. What if the table structure changes again?
144+ name = dotted_name ( field [ 12 ] )
135145 CrateColumn . new ( name , nil , field [ 4 ] , nil )
136146 end
137147 cols
@@ -172,10 +182,10 @@ class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
172182 # +SecureRandom.uuid+ method and a +before_save+ callback, for instance.
173183 def primary_key ( name , type = :primary_key , options = { } )
174184 options [ :primary_key ] = true
175- column name , "STRING PRIMARY KEY" , options
185+ column name , "STRING PRIMARY KEY"
176186 end
177187
178- def column ( name , type = nil , options = { } )
188+ def column ( name , type = nil , ** options )
179189 super
180190 column = self [ name ]
181191 column . array = options [ :array ]
@@ -189,19 +199,19 @@ def object(name, options = {})
189199 schema = options . delete ( :object_schema )
190200 type = "#{ type } as (#{ object_schema_to_string ( schema ) } )" if schema
191201
192- column name , type , options . merge ( object : true )
202+ column name , type , ** options . merge ( object : true )
193203 end
194204
195205 def array ( name , options = { } )
196206 array_type = options . delete ( :array_type )
197207 raise "Array columns must specify an :array_type (e.g. array_type: :string)" unless array_type . present?
198- column name , "array(#{ array_type } )" , options . merge ( array : true )
208+ column name , "array(#{ array_type } )" , ** options . merge ( array : true )
199209 end
200210
201211 private
202212
203- def create_column_definition ( name , type )
204- ColumnDefinition . new name , type
213+ def create_column_definition ( name , type , options )
214+ ColumnDefinition . new ( name , type , options )
205215 end
206216
207217 def object_schema_to_string ( s )
@@ -220,8 +230,8 @@ def object_schema_to_string(s)
220230
221231 end
222232
223- def create_table_definition ( name , temporary , options , as = nil )
224- TableDefinition . new native_database_types , name , temporary , options , as
233+ def create_table_definition ( name )
234+ TableDefinition . new @connection , name
225235 end
226236
227237 def native_database_types
0 commit comments