Class: ROM::RethinkDB::Commands::Create
- Inherits:
-
Commands::Create
- Object
- Commands::Create
- ROM::RethinkDB::Commands::Create
- Defined in:
- lib/rom/rethinkdb/commands/create.rb
Instance Method Summary collapse
Instance Method Details
#dataset ⇒ Object
28 29 30 |
# File 'lib/rom/rethinkdb/commands/create.rb', line 28 def dataset relation.dataset end |
#execute(tuples) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/rom/rethinkdb/commands/create.rb', line 10 def execute(tuples) insert_tuples = [tuples].flatten.map do |tuple| attributes = input[tuple] validator.call(attributes) attributes.to_h end insert(insert_tuples) end |
#insert(tuples) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/rom/rethinkdb/commands/create.rb', line 20 def insert(tuples) pks = dataset.scope.insert(tuples) .run(dataset.connection)["generated_keys"] dataset.filter { |user| relation.rql.expr(pks).contains(user["id"]) } .to_a end |