Sha256: 17bd8ae49452d1d3e85948330c24059448fdc456a884732e46816fb19faa8b9e

Contents?: true

Size: 1.56 KB

Versions: 31

Compression:

Stored size: 1.56 KB

Contents

module Arql
  class Mysqldump

    def initialize(options = nil)
      options ||= App.connect_options
      @options = options
      if options[:socket]
        port_or_sock = "-S #{options[:socket]}"
      else
        port_or_sock = "-P #{options[:port] || 3306}"
      end
      @base_dump_cmd = "mysqldump -u %{user} -h %{host} %{port_or_sock} %{password} --skip-lock-tables " % {
        user: options[:username],
        host: options[:host],
        password: options[:password].presence.try { |e| "-p#{e}" } || '',
        port_or_sock: port_or_sock
      }
    end

    def dump_table(filename, table_name, no_create_table = false)
      system dump_table_cmd(table_name, no_create_table) + " > #{filename}"
    end

    def dump_database(filename, no_create_db = false)
      system dump_database_cmd(no_create_db) + " > #{filename}"
    end

    def dump_table_cmd(table_name, no_create_table = false)
      @base_dump_cmd + " " + if no_create_table
                               "--no-create-info #{@options[:database]} #{table_name}"
                             else
                               "--add-drop-table #{@options[:database]} #{table_name}"
                             end
    end

    def dump_database_cmd(no_create_db = false)
      @base_dump_cmd + " " + if no_create_db
                               "--no-create-db --add-drop-database --databases #{@options[:database]}"
                             else
                               "--add-drop-database --add-drop-table --databases #{@options[:database]}"
                             end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
arql-0.3.31 lib/arql/mysqldump.rb
arql-0.3.30 lib/arql/mysqldump.rb
arql-0.3.29 lib/arql/mysqldump.rb
arql-0.3.28 lib/arql/mysqldump.rb
arql-0.3.27 lib/arql/mysqldump.rb
arql-0.3.26 lib/arql/mysqldump.rb
arql-0.3.25 lib/arql/mysqldump.rb
arql-0.3.24 lib/arql/mysqldump.rb
arql-0.3.23 lib/arql/mysqldump.rb
arql-0.3.22 lib/arql/mysqldump.rb
arql-0.3.21 lib/arql/mysqldump.rb
arql-0.3.20 lib/arql/mysqldump.rb
arql-0.3.19 lib/arql/mysqldump.rb
arql-0.3.18 lib/arql/mysqldump.rb
arql-0.3.17 lib/arql/mysqldump.rb
arql-0.3.16 lib/arql/mysqldump.rb
arql-0.3.15 lib/arql/mysqldump.rb
arql-0.3.14 lib/arql/mysqldump.rb
arql-0.3.13 lib/arql/mysqldump.rb
arql-0.3.12 lib/arql/mysqldump.rb