Class: Fabrique::Test::Fixtures::Repository::MysqlStore

Inherits:
Object
  • Object
show all
Defined in:
lib/fabrique/test/fixtures/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: 'localhost', port: 3306, username: nil, password: nil) ⇒ MysqlStore

Returns a new instance of MysqlStore.



77
78
79
# File 'lib/fabrique/test/fixtures/repository.rb', line 77

def initialize(host: 'localhost', port: 3306, username: nil, password: nil)
  @connection = MysqlConnection.new(host, port, username, password)
end

Instance Method Details

#find(table, id) ⇒ Object



81
82
83
# File 'lib/fabrique/test/fixtures/repository.rb', line 81

def find(table, id)
  @connection.find(table, "WHERE customer_id = ?", [id])
end

#save(table, record) ⇒ Object



94
95
96
# File 'lib/fabrique/test/fixtures/repository.rb', line 94

def save(table, record)
  @connection.update_or_insert(table, record)
end

#search(table, filter) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/fabrique/test/fixtures/repository.rb', line 85

def search(table, filter)
  clauses, bindings = [], []
  filter.each do |k, v|
    clauses << k
    bindings << v
  end
  @connection.select(table, clauses.join(" AND "), bindings)
end