Sha256: f6d47bf9f5f3afb5b7b0a5498b22f0375f7cff02e0a84e3dec0b9ccf5113812f

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

# frozen-string-literal: true

require 'swift/db/postgres'
Sequel.require 'adapters/shared/postgres'

module Sequel
  module Swift
    # Adapter, Database, and Dataset support for accessing a PostgreSQL
    # database via Swift.
    module Postgres
      # Methods to add to Database instances that access PostgreSQL via Swift.
      module DatabaseMethods
        include Sequel::Postgres::DatabaseMethods
        
        # Add the primary_keys and primary_key_sequences instance variables,
        # so we can get the correct return values for inserted rows.
        def self.extended(db)
          super
          db.send(:initialize_postgres_adapter)
        end
        
        private
        
        DATABASE_ERROR_CLASSES = [::Swift::Error].freeze
        def database_error_classes
          DATABASE_ERROR_CLASSES
        end

        # Remove all other options except for ones specifically handled, as
        # otherwise swift passes them to dbic++ which passes them to PostgreSQL
        # which can raise an error.
        def server_opts(o)
          o = super
          so = {}
          [:db, :user, :password, :host, :port].each{|s| so[s] = o[s] if o.has_key?(s)}
          so
        end
      
        # Extend the adapter with the Swift PostgreSQL AdapterMethods.
        def setup_connection(conn)
          conn = super(conn)
          conn.native_bind_format = true
          connection_configuration_sqls.each{|sql| log_connection_yield(sql, conn){conn.execute(sql)}}
          conn
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sequel-4.49.0 lib/sequel/adapters/swift/postgres.rb
sequel-4.48.0 lib/sequel/adapters/swift/postgres.rb