Class: Baza::Driver::Mysql::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/baza/driver/mysql/commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Commands

Returns a new instance of Commands.



2
3
4
# File 'lib/baza/driver/mysql/commands.rb', line 2

def initialize(args)
  @db = args.fetch(:db)
end

Instance Method Details

#last_idObject



36
37
38
# File 'lib/baza/driver/mysql/commands.rb', line 36

def last_id
  @db.query("SELECT LAST_INSERT_ID() AS `id`").fetch.fetch(:id).to_i
end

#upsert(table_name, updates, terms, args = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/baza/driver/mysql/commands.rb', line 17

def upsert(table_name, updates, terms, args = {})
  if args[:buffer]
    Baza::SqlQueries::NonAtomicUpsert.new(
      db: @db,
      table_name: table_name,
      buffer: args[:buffer],
      terms: terms,
      updates: updates
    ).execute
  else
    Baza::SqlQueries::MysqlUpsert.new(
      db: @db,
      table_name: table_name,
      updates: updates,
      terms: terms
    ).execute
  end
end

#upsert_duplicate_key(table_name, updates, terms, args = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/baza/driver/mysql/commands.rb', line 6

def upsert_duplicate_key(table_name, updates, terms, args = {})
  Baza::SqlQueries::MysqlUpsertDuplicateKey.new(
    db: @db,
    table_name: table_name,
    updates: updates,
    terms: terms,
    buffer: args[:buffer],
    return_id: args[:return_id]
  ).execute
end