Last active
December 19, 2015 22:59
-
-
Save dkubb/6031208 to your computer and use it in GitHub Desktop.
Examples for axiom-memory-adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axiom-memory-adapter' | |
adapter = Axiom::Adapter::Memory.new | |
adapter['customers'] = Axiom::Relation::Empty.new( | |
[[:id, Integer], [:name, String]] | |
) | |
adapter['orders'] = Axiom::Relation::Empty.new( | |
[[:id, Integer], [:customer_id, Integer]] | |
) | |
customers = adapter['customers'] | |
customers = customers.insert([[1, 'Dan Kubb']]) | |
customers = customers.insert([[2, 'John Doe']]) | |
orders = adapter['orders'] | |
orders = orders.insert([[1, 1]]) | |
orders = orders.insert([[2, 1]]) | |
orders = orders.insert([[3, 1]]) | |
orders = orders.insert([[4, 2]]) | |
customer_orders = customers. | |
rename(id: :customer_id). | |
join(orders.rename(id: :order_id)) | |
# insert into a join | |
customer_orders = customer_orders.insert([[3, 'Jane Doe', 5]]) | |
# inserts are propagated to the base relations | |
adapter['customers'].count # => 3 | |
adapter['orders'].count # => 5 | |
# delete from a join | |
customer_orders.delete([[3, 'Jane Doe', 5]]) | |
# deletes are propagated to the base relations | |
adapter['customers'].count # => 2 | |
adapter['orders'].count # => 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment