Class: MysqlPlug
- Inherits:
-
Object
- Object
- MysqlPlug
- Defined in:
- lib/obvious/files/external/mysql_plug.rb
Overview
assume that DB is defined as a global constant elsewhere
Instance Method Summary collapse
- #get(input) ⇒ Object
-
#initialize(table) ⇒ MysqlPlug
constructor
A new instance of MysqlPlug.
- #list ⇒ Object
- #remove(input) ⇒ Object
- #save(input) ⇒ Object
Constructor Details
#initialize(table) ⇒ MysqlPlug
Returns a new instance of MysqlPlug.
7 8 9 |
# File 'lib/obvious/files/external/mysql_plug.rb', line 7 def initialize table @table = table end |
Instance Method Details
#get(input) ⇒ Object
27 28 29 30 |
# File 'lib/obvious/files/external/mysql_plug.rb', line 27 def get input table = DB[@table] table.first :id => input[:id] end |
#list ⇒ Object
22 23 24 25 |
# File 'lib/obvious/files/external/mysql_plug.rb', line 22 def list table = DB[@table] table.all end |
#remove(input) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/obvious/files/external/mysql_plug.rb', line 32 def remove input table = DB[@table] result = table.where(:id => input[:id]).delete return true if result == 1 false end |
#save(input) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/obvious/files/external/mysql_plug.rb', line 11 def save input table = DB[@table] input[:id] = nil if input[:id] == -1 # this does an upsert result = table.on_duplicate_key_update.insert input input[:id] = result input end |