-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved MySQL-specific code to separate file
- Loading branch information
Showing
3 changed files
with
44 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Neighbor | ||
module MySQL | ||
def self.initialize! | ||
require_relative "type/mysql_vector" | ||
|
||
require "active_record/connection_adapters/abstract_mysql_adapter" | ||
|
||
# ensure schema can be dumped | ||
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES[:vector] = {name: "vector"} | ||
|
||
# ensure schema can be loaded | ||
unless ActiveRecord::ConnectionAdapters::TableDefinition.method_defined?(:vector) | ||
ActiveRecord::ConnectionAdapters::TableDefinition.send(:define_column_methods, :vector) | ||
end | ||
|
||
# prevent unknown OID warning | ||
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.singleton_class.prepend(RegisterTypes) | ||
if ActiveRecord::VERSION::STRING.to_f < 7.1 | ||
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.register_vector_type(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::TYPE_MAP) | ||
end | ||
end | ||
|
||
module RegisterTypes | ||
def initialize_type_map(m) | ||
super | ||
register_vector_type(m) | ||
end | ||
|
||
def register_vector_type(m) | ||
m.register_type %r(^vector)i do |sql_type| | ||
limit = extract_limit(sql_type) | ||
Type::MysqlVector.new(limit: limit) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters