mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
basic implementation of in memory insertions
Conflicts: lib/arel/engines/memory/relations.rb
This commit is contained in:
parent
20b28b441b
commit
07833d39c2
7 changed files with 49 additions and 4 deletions
8
doc/TODO
8
doc/TODO
|
@ -1,11 +1,12 @@
|
|||
todo:
|
||||
- fix AR
|
||||
- insertions for in memory
|
||||
- cross-engine joins
|
||||
- blocks for joins
|
||||
- deal with table tests in algebra
|
||||
- test sql insertions
|
||||
- implement mnesia adapter
|
||||
- rename externalize to derived.
|
||||
|
||||
- rename externalize to derived.
|
||||
- deal with table tests in algebra
|
||||
- fix grouping
|
||||
- audit unit coverage of algebra
|
||||
- data objects
|
||||
|
@ -92,6 +93,7 @@ done:
|
|||
- result sets to attr correlation too
|
||||
- implement joins in memory
|
||||
- result sets should be array relations
|
||||
- fix AR
|
||||
|
||||
icebox:
|
||||
- #bind in Attribute and Expression should be doing a descend?
|
||||
|
|
|
@ -57,7 +57,7 @@ module Arel
|
|||
|
||||
module Writable
|
||||
def insert(record)
|
||||
session.create Insert.new(self, record); self
|
||||
session.create Insert.new(self, record)
|
||||
end
|
||||
|
||||
def update(assignments)
|
||||
|
|
|
@ -5,6 +5,10 @@ module Arel
|
|||
def read(relation)
|
||||
relation.eval
|
||||
end
|
||||
|
||||
def create(relation)
|
||||
relation.eval
|
||||
end
|
||||
end
|
||||
include CRUD
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require 'arel/engines/memory/relations/array'
|
||||
require 'arel/engines/memory/relations/operations'
|
||||
require 'arel/engines/memory/relations/writes'
|
||||
require 'arel/engines/memory/relations/compound'
|
||||
|
||||
|
|
7
lib/arel/engines/memory/relations/writes.rb
Normal file
7
lib/arel/engines/memory/relations/writes.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
module Arel
|
||||
class Insert < Compound
|
||||
def eval
|
||||
unoperated_rows + [Row.new(self, record.values.collect(&:value))]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,6 +24,7 @@ module Arel
|
|||
module CRUD
|
||||
def create(insert)
|
||||
insert.call
|
||||
insert
|
||||
end
|
||||
|
||||
def read(select)
|
||||
|
@ -34,10 +35,12 @@ module Arel
|
|||
|
||||
def update(update)
|
||||
update.call
|
||||
update
|
||||
end
|
||||
|
||||
def delete(delete)
|
||||
delete.call
|
||||
delete
|
||||
end
|
||||
end
|
||||
include CRUD
|
||||
|
|
28
spec/arel/engines/memory/unit/relations/insert_spec.rb
Normal file
28
spec/arel/engines/memory/unit/relations/insert_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')
|
||||
|
||||
module Arel
|
||||
describe Insert do
|
||||
before do
|
||||
@relation = Array.new([
|
||||
[1, 'duck' ],
|
||||
[2, 'duck' ],
|
||||
[3, 'goose']
|
||||
], [:id, :name])
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
it "manufactures an array of hashes of attributes to values" do
|
||||
@relation \
|
||||
.insert(@relation[:id] => 4, @relation[:name] => 'guinea fowl') \
|
||||
.let do |relation|
|
||||
relation.call.should == [
|
||||
Row.new(relation, [1, 'duck']),
|
||||
Row.new(relation, [2, 'duck']),
|
||||
Row.new(relation, [3, 'goose']),
|
||||
Row.new(relation, [4, 'guinea fowl'])
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue