Class: AsyncRecord::Connection::MySQL

Inherits:
Base
  • Object
show all
Includes:
Fastr::Log
Defined in:
lib/async_record/connections/mysql.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MySQL

Initializes a MySQL connection



18
19
20
21
22
23
24
25
26
# File 'lib/async_record/connections/mysql.rb', line 18

def initialize(*args)
  args.each do |arg|
    if arg.kind_of? Hash
      arg.each do |k,v|
        self.send("#{k}=", v)
      end
    end
  end
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



13
14
15
# File 'lib/async_record/connections/mysql.rb', line 13

def connections
  @connections
end

#databaseObject

Returns the value of attribute database.



12
13
14
# File 'lib/async_record/connections/mysql.rb', line 12

def database
  @database
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/async_record/connections/mysql.rb', line 8

def host
  @host
end

#mysqlObject

Returns the value of attribute mysql.



15
16
17
# File 'lib/async_record/connections/mysql.rb', line 15

def mysql
  @mysql
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/async_record/connections/mysql.rb', line 11

def password
  @password
end

#portObject

Returns the value of attribute port.



9
10
11
# File 'lib/async_record/connections/mysql.rb', line 9

def port
  @port
end

#userObject

Returns the value of attribute user.



10
11
12
# File 'lib/async_record/connections/mysql.rb', line 10

def user
  @user
end

Instance Method Details

#connectObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/async_record/connections/mysql.rb', line 28

def connect
  settings = {:logging => false, :connections => 4}
  
  settings[:host] = self.host if not self.host.nil?
  settings[:port] = self.port if not self.port.nil?
  settings[:user] = self.user if not self.user.nil?
  settings[:password] = self.password if not self.password.nil?
  settings[:database] = self.database if not self.database.nil?
  settings[:connections] = self.connections if not self.connections.nil?

  EventedMysql.settings.update(settings)
end

#query(queryStr, &blk) ⇒ Object



41
42
43
# File 'lib/async_record/connections/mysql.rb', line 41

def query(queryStr, &blk)
  EventedMysql.select(queryStr, &blk)
end