Class: Cliptic::Database::SQL
- Inherits:
-
Object
- Object
- Cliptic::Database::SQL
- Defined in:
- lib/cliptic/database.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #delete(where: nil) ⇒ Object
- #drop ⇒ Object
-
#initialize(table:) ⇒ SQL
constructor
A new instance of SQL.
- #insert(values:) ⇒ Object
- #make_table ⇒ Object
- #select(cols: "*", where: nil, order: false, limit: false) ⇒ Object
- #update(values:, where:) ⇒ Object
Constructor Details
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
6 7 8 |
# File 'lib/cliptic/database.rb', line 6 def db @db end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/cliptic/database.rb', line 6 def table @table end |
Instance Method Details
#delete(where: nil) ⇒ Object
31 32 33 |
# File 'lib/cliptic/database.rb', line 31 def delete(where:nil) db.execute(sql_delete(where:where), where&.values) end |
#drop ⇒ Object
34 35 36 |
# File 'lib/cliptic/database.rb', line 34 def drop db.execute("DROP TABLE #{table}") end |
#insert(values:) ⇒ Object
24 25 26 27 |
# File 'lib/cliptic/database.rb', line 24 def insert(values:) db.execute(sql_insert(values:values), values.values) end |
#make_table ⇒ Object
14 15 16 |
# File 'lib/cliptic/database.rb', line 14 def make_table db.execute(sql_make) end |
#select(cols: "*", where: nil, order: false, limit: false) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cliptic/database.rb', line 17 def select(cols:"*", where:nil, order:false, limit:false) db.execute( sql_select(cols:cols, where:where, order:order, limit:limit), where&.values&.map(&:to_s) ) end |
#update(values:, where:) ⇒ Object
28 29 30 |
# File 'lib/cliptic/database.rb', line 28 def update(values:, where:) db.execute(sql_update(values:values, where:where), [values.values], [where.values]) end |