Skip to content

Instantly share code, notes, and snippets.

@dkubb
Last active December 19, 2015 22:59

Revisions

  1. dkubb revised this gist Jul 27, 2013. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -5,35 +5,35 @@
    orders: Axiom::Relation.new([[:id, Integer], [:customer_id, Integer]])
    )

    # insert customer data
    # Insert customer data
    customers = adapter[:customers]
    customers.insert([[1, 'Dan Kubb']])
    customers.insert([[2, 'John Doe']])

    # insert order data
    # Insert order data
    orders = adapter[:orders]
    orders.insert([[1, 1]])
    orders.insert([[2, 1]])
    orders.insert([[3, 1]])
    orders.insert([[4, 2]])

    # join customers and orders
    # Join customers and orders
    customer_orders = customers.
    rename(id: :customer_id).
    join(orders.rename(id: :order_id))

    # demonstrate writable view-like behaviour
    # Demonstrate writable view-like behaviour

    # insert into the join
    # Insert into the join
    customer_orders.insert([[3, 'Jane Doe', 5]])

    # inserts are propagated to the base relations
    # Inserts are propagated to the base relations
    customers.count # => 3
    orders.count # => 5

    # delete from a join
    # Delete from a join
    customer_orders.delete([[3, 'Jane Doe', 5]])

    # deletes are propagated to the base relations
    # Deletes are propagated to the base relations
    customers.count # => 2
    orders.count # => 4
  2. dkubb revised this gist Jul 27, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,12 @@
    )

    # insert customer data
    customers = adapter['customers']
    customers = adapter[:customers]
    customers.insert([[1, 'Dan Kubb']])
    customers.insert([[2, 'John Doe']])

    # insert order data
    orders = adapter['orders']
    orders = adapter[:orders]
    orders.insert([[1, 1]])
    orders.insert([[2, 1]])
    orders.insert([[3, 1]])
  3. dkubb revised this gist Jul 27, 2013. 1 changed file with 3 additions and 9 deletions.
    12 changes: 3 additions & 9 deletions axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,8 @@
    require 'axiom-memory-adapter'

    adapter = Axiom::Adapter::Memory.new

    # setup base relations
    adapter['customers'] = Axiom::Relation.new(
    [[:id, Integer], [:name, String]]
    )

    adapter['orders'] = Axiom::Relation.new(
    [[:id, Integer], [:customer_id, Integer]]
    adapter = Axiom::Adapter::Memory.new(
    customers: Axiom::Relation.new([[:id, Integer], [:name, String]]),
    orders: Axiom::Relation.new([[:id, Integer], [:customer_id, Integer]])
    )

    # insert customer data
  4. dkubb revised this gist Jul 27, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -34,12 +34,12 @@
    customer_orders.insert([[3, 'Jane Doe', 5]])

    # inserts are propagated to the base relations
    adapter['customers'].count # => 3
    adapter['orders'].count # => 5
    customers.count # => 3
    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
    customers.count # => 2
    orders.count # => 4
  5. dkubb revised this gist Jul 27, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,11 @@
    adapter = Axiom::Adapter::Memory.new

    # setup base relations
    adapter['customers'] = Axiom::Relation::Empty.new(
    adapter['customers'] = Axiom::Relation.new(
    [[:id, Integer], [:name, String]]
    )

    adapter['orders'] = Axiom::Relation::Empty.new(
    adapter['orders'] = Axiom::Relation.new(
    [[:id, Integer], [:customer_id, Integer]]
    )

  6. dkubb revised this gist Jul 27, 2013. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -13,15 +13,15 @@

    # insert customer data
    customers = adapter['customers']
    customers = customers.insert([[1, 'Dan Kubb']])
    customers = customers.insert([[2, 'John Doe']])
    customers.insert([[1, 'Dan Kubb']])
    customers.insert([[2, 'John Doe']])

    # insert order data
    orders = adapter['orders']
    orders = orders.insert([[1, 1]])
    orders = orders.insert([[2, 1]])
    orders = orders.insert([[3, 1]])
    orders = orders.insert([[4, 2]])
    orders.insert([[1, 1]])
    orders.insert([[2, 1]])
    orders.insert([[3, 1]])
    orders.insert([[4, 2]])

    # join customers and orders
    customer_orders = customers.
    @@ -31,7 +31,7 @@
    # demonstrate writable view-like behaviour

    # insert into the join
    customer_orders = customer_orders.insert([[3, 'Jane Doe', 5]])
    customer_orders.insert([[3, 'Jane Doe', 5]])

    # inserts are propagated to the base relations
    adapter['customers'].count # => 3
  7. dkubb revised this gist Jul 19, 2013. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@

    adapter = Axiom::Adapter::Memory.new

    # setup base relations
    adapter['customers'] = Axiom::Relation::Empty.new(
    [[:id, Integer], [:name, String]]
    )
    @@ -10,21 +11,26 @@
    [[:id, Integer], [:customer_id, Integer]]
    )

    # insert customer data
    customers = adapter['customers']
    customers = customers.insert([[1, 'Dan Kubb']])
    customers = customers.insert([[2, 'John Doe']])

    # insert order data
    orders = adapter['orders']
    orders = orders.insert([[1, 1]])
    orders = orders.insert([[2, 1]])
    orders = orders.insert([[3, 1]])
    orders = orders.insert([[4, 2]])

    # join customers and orders
    customer_orders = customers.
    rename(id: :customer_id).
    join(orders.rename(id: :order_id))

    # insert into a join
    # demonstrate writable view-like behaviour

    # insert into the join
    customer_orders = customer_orders.insert([[3, 'Jane Doe', 5]])

    # inserts are propagated to the base relations
  8. dkubb created this gist Jul 18, 2013.
    39 changes: 39 additions & 0 deletions axiom-memory-adapter-examples.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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