Module: ActivePostgrest::Mutations
- Included in:
- Relation
- Defined in:
- lib/active_postgrest/mutations.rb
Instance Method Summary collapse
- #create(attrs) ⇒ Object
- #create!(attrs) ⇒ Object
- #delete_all ⇒ Object
- #insert(attrs) ⇒ Object
- #insert_all(records) ⇒ Object
- #update_all(attrs) ⇒ Object
- #upsert(attrs) ⇒ Object
- #upsert_all(records) ⇒ Object
Instance Method Details
#create(attrs) ⇒ Object
6 7 8 |
# File 'lib/active_postgrest/mutations.rb', line 6 def create(attrs) insert(attrs) end |
#create!(attrs) ⇒ Object
10 11 12 |
# File 'lib/active_postgrest/mutations.rb', line 10 def create!(attrs) insert(attrs) || raise(ActivePostgrest::RecordNotSaved.new(@model_class, attrs)) end |
#delete_all ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/active_postgrest/mutations.rb', line 47 def delete_all return [] if @null result = @client.delete(@table, build_params, prefer: 'return=representation', schema: @schema) instantiate_all(result.body) end |
#insert(attrs) ⇒ Object
14 15 16 17 |
# File 'lib/active_postgrest/mutations.rb', line 14 def insert(attrs) result = @client.post(@table, attrs, prefer: 'return=representation', schema: @schema) instantiate_result(result.body) end |
#insert_all(records) ⇒ Object
19 20 21 22 |
# File 'lib/active_postgrest/mutations.rb', line 19 def insert_all(records) result = @client.post(@table, records, prefer: 'return=representation', schema: @schema) instantiate_all(result.body) end |
#update_all(attrs) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/active_postgrest/mutations.rb', line 38 def update_all(attrs) return [] if @null result = @client.patch(@table, build_params, attrs, prefer: 'return=representation', schema: @schema) instantiate_all(result.body) end |
#upsert(attrs) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/active_postgrest/mutations.rb', line 24 def upsert(attrs) result = @client.post(@table, attrs, prefer: 'return=representation,resolution=merge-duplicates', schema: @schema) instantiate_result(result.body) end |
#upsert_all(records) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/active_postgrest/mutations.rb', line 31 def upsert_all(records) result = @client.post(@table, records, prefer: 'return=representation,resolution=merge-duplicates', schema: @schema) instantiate_all(result.body) end |