Class: TinyMysql

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_mysql.rb,
lib/tiny_mysql/version.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TinyMysql

Returns a new instance of TinyMysql.



11
12
13
14
15
16
17
18
19
# File 'lib/tiny_mysql.rb', line 11

def initialize(options = {})
  @mysql_command = options[:mysql_command] || 'mysql'
  @defaults_extra_file = options[:defaults_extra_file]
  @host = options[:host] || 'localhost' unless @defaults_extra_file
  @port = options[:port]
  @username = options[:username] || 'root' unless @defaults_extra_file
  @password = options[:password]
  @database = options[:database]
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



9
10
11
# File 'lib/tiny_mysql.rb', line 9

def database
  @database
end

#defaults_extra_fileObject (readonly)

Returns the value of attribute defaults_extra_file.



5
6
7
# File 'lib/tiny_mysql.rb', line 5

def defaults_extra_file
  @defaults_extra_file
end

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/tiny_mysql.rb', line 6

def host
  @host
end

#mysql_commandObject (readonly)

Returns the value of attribute mysql_command.



4
5
6
# File 'lib/tiny_mysql.rb', line 4

def mysql_command
  @mysql_command
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/tiny_mysql.rb', line 7

def port
  @port
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/tiny_mysql.rb', line 8

def username
  @username
end

Instance Method Details

#query(sql) ⇒ Object



21
22
23
24
25
# File 'lib/tiny_mysql.rb', line 21

def query(sql)
  out, err, status = Open3.capture3(*cmd_with_args, :stdin_data => sql)
  status.success? or raise err
  parse(out)
end