Class: Database
- Inherits:
-
Object
- Object
- Database
- Defined in:
- lib/db/database.rb
Direct Known Subclasses
Instance Method Summary collapse
- #connect(addr = "localhost", port = 9999, id = "public", pw = "") ⇒ Object
- #delete(table, condition, option = "") ⇒ Object
- #disconnect ⇒ Object
- #dispose ⇒ Object
- #execute(query) ⇒ Object
-
#initialize(addr = "localhost", port = 9999, id = "public", pw = "") ⇒ Database
constructor
A new instance of Database.
- #insert(table, row, *args) ⇒ Object
- #prepare(query) ⇒ Object
- #select(table, row, condition = "", option = "") ⇒ Object
- #update(table, update, condition = "", option = "") ⇒ Object
Constructor Details
#initialize(addr = "localhost", port = 9999, id = "public", pw = "") ⇒ Database
Returns a new instance of Database.
2 3 4 |
# File 'lib/db/database.rb', line 2 def initialize(addr="localhost", port=9999, id="public", pw="") connect(addr, port , id, pw) end |
Instance Method Details
#connect(addr = "localhost", port = 9999, id = "public", pw = "") ⇒ Object
9 10 |
# File 'lib/db/database.rb', line 9 def connect(addr="localhost", port=9999, id="public", pw="") end |
#delete(table, condition, option = "") ⇒ Object
32 33 34 |
# File 'lib/db/database.rb', line 32 def delete(table, condition, option="") execute("delete from #{table} #{condition=="" ? "" : "where"} #{condition} #{option};") end |
#disconnect ⇒ Object
11 12 |
# File 'lib/db/database.rb', line 11 def disconnect end |
#dispose ⇒ Object
5 6 7 |
# File 'lib/db/database.rb', line 5 def dispose disconnect end |
#execute(query) ⇒ Object
16 17 |
# File 'lib/db/database.rb', line 16 def execute(query) end |
#insert(table, row, *args) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/db/database.rb', line 26 def insert(table, row, *args) data = "" args.each { |v| data += v.to_s + "," } data = data[0..data.length-2] execute("insert into #{table} (#{row}) values (#{data});") end |
#prepare(query) ⇒ Object
14 15 |
# File 'lib/db/database.rb', line 14 def prepare(query) end |
#select(table, row, condition = "", option = "") ⇒ Object
19 20 21 22 |
# File 'lib/db/database.rb', line 19 def select(table, row, condition="", option="") stm = prepare("select #{row} from #{table} #{condition=="" ? "" : "where"} #{condition} #{option};") stm.execute end |
#update(table, update, condition = "", option = "") ⇒ Object
23 24 25 |
# File 'lib/db/database.rb', line 23 def update(table, update, condition="", option="") execute("update #{table} set #{update} #{condition=="" ? "" : "where"} #{condition} #{option};") end |