Class: MysqlClient

Inherits:
Object
  • Object
show all
Defined in:
lib/sqlite2mysql/services/mysql.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MysqlClient

Returns a new instance of MysqlClient.



4
5
6
# File 'lib/sqlite2mysql/services/mysql.rb', line 4

def initialize(*args)
  @client = Mysql2::Client.new(*args)
end

Instance Method Details

#build_from_schema(schema) ⇒ Object



14
15
16
17
18
19
# File 'lib/sqlite2mysql/services/mysql.rb', line 14

def build_from_schema(schema)
  schema.keys.each do |table|
    puts "Creating table: #{table}"
    create_table(table, schema[table])
  end
end

#create_table(table, fields) ⇒ Object



21
22
23
24
# File 'lib/sqlite2mysql/services/mysql.rb', line 21

def create_table(table, fields)
  puts create_table_query(table, fields)
  @client.query(create_table_query(table, fields))
end

#insert_table(table, data) ⇒ Object



26
27
28
29
30
31
# File 'lib/sqlite2mysql/services/mysql.rb', line 26

def insert_table(table, data)
  data.each_slice(1000) do |slice|
    @client.query(chunk_sql(table, slice))
    print '.'
  end
end

#recreate(name) ⇒ Object



8
9
10
11
12
# File 'lib/sqlite2mysql/services/mysql.rb', line 8

def recreate(name)
  @client.query("DROP DATABASE IF EXISTS #{name}")
  @client.query("CREATE DATABASE #{name}")
  @client.query("USE #{name}")
end