module Base
Definitions
def create(context, **attributes)
Directly create one record.
Implementation
def create(context, **attributes)
Statement::Insert.new(self,
Statement::Fields.new(attributes.keys),
Statement::Tuple.new(attributes.values)
).to_a(context).first
end
def insert(context, keys, rows, **attributes)
Directly insert one or more records.
Implementation
def insert(context, keys, rows, **attributes)
if attributes.any?
fields = Statement::Fields.new(attributes.keys + keys)
values = attributes.values
tuples = rows.map{|row| Statement::Tuple.new(values + row)}
else
fields = Statement::Fields.new(keys)
tuples = rows.map{|row| Statement::Tuple.new(row)}
end
return Statement::Insert.new(self, fields, Statement::Multiple.new(tuples)).to_a(context)
end
def find(context, *key)
Find records which match the given primary key.
Implementation
def find(context, *key)
Statement::Select.new(self,
where: find_predicate(*key),
limit: Statement::Limit::ONE
).to_a(context).first
end