class AocCli::Database::Query
Attributes
db[R]
Public Class Methods
new(path:)
click to toggle source
# File lib/aoc_cli/database.rb, line 11 def initialize(path:) @db = SQLite3::Database.open(path) end
Public Instance Methods
insert(t:, val:)
click to toggle source
# File lib/aoc_cli/database.rb, line 25 def insert(t:, val:) db.execute( "INSERT INTO #{t} "\ "VALUES(#{val.join(", ")})") self end
select(t:, cols:"*", where:)
click to toggle source
# File lib/aoc_cli/database.rb, line 14 def select(t:, cols:"*", where:) db.execute( "SELECT #{cols} FROM #{t} "\ "WHERE #{where.map{|k, v| "#{k} = #{v}"}.join(" AND ")}") end
table(t:, cols:)
click to toggle source
# File lib/aoc_cli/database.rb, line 19 def table(t:, cols:) db.execute( "CREATE TABLE IF NOT EXISTS "\ "#{t}(#{cols.map{|c, t| "#{c} #{t}"}.join(", ")})") self end
update(t:, val:, where:)
click to toggle source
# File lib/aoc_cli/database.rb, line 31 def update(t:, val:, where:) db.execute( "UPDATE #{t} "\ "SET #{val.map{|c, v| "#{c} = #{v}"}.join(", ")} "\ "WHERE #{where.map{|c, v| "#{c} = #{v}"}.join(" AND ")}") self end