File: sqlite.rb

package info (click to toggle)
ruby-neighbor 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 204 kB
  • sloc: ruby: 840; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 692 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Neighbor
  module SQLite
    # note: this is a public API (unlike PostgreSQL and MySQL)
    def self.initialize!
      return if defined?(@initialized)

      require_relative "type/sqlite_vector"
      require_relative "type/sqlite_int8_vector"

      require "sqlite_vec"
      require "active_record/connection_adapters/sqlite3_adapter"

      ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend(InstanceMethods)

      @initialized = true
    end

    module InstanceMethods
      def configure_connection
        super
        db = @raw_connection
        db.enable_load_extension(1)
        SqliteVec.load(db)
        db.enable_load_extension(0)
      end
    end
  end
end