Sha256: e7fc6f816d3e54b622d5d1be2cbae07d7825fa7435bbea9ad8eebb886c6c95e7

Contents?: true

Size: 787 Bytes

Versions: 6

Compression:

Stored size: 787 Bytes

Contents

# frozen_string_literal: true

require 'mysql2'

class DBDataSource
  private_class_method :new
  @instance_mutex = Mutex.new

  def initialize
    #тут изменить путь к своему конфигу
    db_config = YAML.load_file('C:/Users/jakep/GitHub/Ruby_Moment/LabStudents/db_config/config.yaml').transform_keys(&:to_sym)
    @client = Mysql2::Client.new(db_config)
    @client.query_options.merge!(symbolize_keys: true)
  end

  def self.instance
    return @instance if @instance

    @instance_mutex.synchronize do
      @instance ||= new
    end

    @instance
  end

  def prepare_exec(statement, *params)
    @client.prepare(statement).execute(*params)
  end

  def query(statement)
    @client.query(statement)
  end

  def last_id
    @client.last_id
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rybish_code-1.1.4 lib/source/repositories/data_sources/db_data_source.rb
rubbish_code-1.1.4 lib/source/repositories/data_sources/db_data_source.rb
rubbish_code-1.1.3 lib/source/repositories/data_sources/db_data_source.rb
rubbish_code-1.1.2 lib/source/repositories/data_sources/db_data_source.rb
rubbish_code-1.1.1 lib/source/repositories/data_sources/db_data_source.rb
rubbish_code-1.1.0 lib/source/repositories/data_sources/db_data_source.rb