Module: Weka::Db

Defined in:
lib/ruby-band/weka/db/db.rb

Class Method Summary collapse

Class Method Details

.query_mysql(db_url, user, psw, query) ⇒ Object

  • db_url -> The database URL

    • user -> User name

    • psw -> Password

    • quey -> A query to submit



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby-band/weka/db/db.rb', line 15

def Db.query_mysql(db_url,user,psw,query)
  open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
    open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_mysql'),'r') do |f|
      f.each_line do |line|
        out.write line
      end
    end
  end
    loader = DatabaseLoader.new
  loader.setSource(db_url,user,psw)
  loader.setQuery(query)
  data = loader.getDataSet
  return data
end

.query_postgresql(db_url, user, psw, query) ⇒ Object

  • db_url -> The database URL

    • user -> User name

    • psw -> Password

    • quey -> A query to submit



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby-band/weka/db/db.rb', line 36

def Db.query_postgresql(db_url,user,psw,query)
  open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
    open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_postgresql'),'r') do |f|
      f.each_line do |line|
        out.write line
      end
    end
  end
    loader = DatabaseLoader.new
  loader.setSource(db_url,user,psw)
  loader.setQuery(query)
  data = loader.getDataSet
  return data
end

.save_to_mysql(db_url, user, psw, data, table) ⇒ Object

  • db_url -> The database URL

    • user -> User name

    • psw -> Password

    • data -> An Instances class object

    • table -> The destination table in the database



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ruby-band/weka/db/db.rb', line 58

def Db.save_to_mysql(db_url,user,psw,data,table)
  open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
    open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_mysql'),'r') do |f|
      f.each_line do |line|
        out.write line
      end
    end
  end
  saver = DatabaseSaver.new
  saver.setDestination(db_url,user,psw)
  saver.setTableName(table)
  saver.setRelationForTableName(false)
  saver.setInstances(data)
  saver.writeBatch
end