Class: Myq::Commands

Inherits:
Thor
  • Object
show all
Defined in:
lib/myq/commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Commands

Returns a new instance of Commands.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/myq/commands.rb', line 21

def initialize(args = [], options = {}, config = {})
  super(args, options, config)
  global_options = config[:shell].base.options
  if File.exist?("#{ENV['HOME']}/.database.yml")
    data = YAML.load_file("#{ENV['HOME']}/.database.yml")[global_options['profile']]
    host = data['host']
    username = data['username']
    password = data['password']
    database = data['database']
    port = data['port']
  else
    host = global_options['host']
    username = global_options['username']
    password = global_options['password']
    database = global_options['database']
    port = global_options['port']
  end
  @client = Mysql2::Client.new(host: host, username: username, password: password, database: database, port: port)
end

Instance Method Details

#query_file(file) ⇒ Object



47
48
49
# File 'lib/myq/commands.rb', line 47

def query_file(file)
  query(File.read(file))
end

#query_inline(query) ⇒ Object



42
43
44
# File 'lib/myq/commands.rb', line 42

def query_inline(query)
  query(query)
end

#sample(table) ⇒ Object



53
54
55
# File 'lib/myq/commands.rb', line 53

def sample(table)
  query("select * from #{table} limit #{options['limit']}")
end

#versionObject



58
59
60
# File 'lib/myq/commands.rb', line 58

def version
  puts VERSION
end