Taste of Riak

Modeling with Records

Now let's create some records:

> (defrecord customer
    id
    name
    address
    city
    state
    zip
    phone
    created-date)
()
> (defrecord item
    id
    title
    price)
()
> (defrecord order
    id
    customer-id
    salesperson-id
    items
    total
    created-date)
> (defrecord order-summary-entry
    order-id
    total
    order-date)
()
> (defrecord order-summary
    customer-id
    summaries)
()

With the records in hand, we're ready to create some data. Let's start with our customer:

> (set customer-1
    (make-customer
      id 1
      name "Alice Roberts"
      address "123 Main Street"
      city "Columbus"
      state "Ohio"
      zip "43210"
      phone "+1 614 555 1212"
      created-date #(#(2010 10 1) #(10 10 01))))
#(customer 1
  "Alice Roberts"
  "123 Main Street"
  "Columbus"
  "Ohio"
  "43210"
  "+1 614 555 1212"
  #(#(2010 10 1) #(10 10 1)))

Now for an order:

> (set order-1
    (make-order
      id 1
      customer-id (customer-id customer-1)
      salesperson-id 9000
      items `(,(make-item
                 id "TCV37GIT4NJ"
                 title "USB 3.0 Coffee Warmer"
                 price 15.99)
              ,(make-item
                 id "PEG10BBF2PP"
                 title "eTablet Pro, 24GB, Grey"
                 price 3999.99))
      total 415.98
      created-date #(#(2015 1 14) #(14 42 24))))
#(order 1 1 9000
  (#(item "TCV37GIT4NJ" "USB 3.0 Coffee Warmer" 15.99)
   #(item "PEG10BBF2PP" "eTablet Pro, 24GB, Grey" 3999.99))
  415.98
  #(#(2015 1 14) #(14 42 24)))

Let's do some more:

> (set order-2
    (make-order
      id 2
      customer-id (customer-id customer-1)
      salesperson-id 9001
      items `(,(make-item
                 id "OAX19XWN0QP"
                 title "GoSlo Digital Camera"
                 price 359.99))
      total 359.99
      created-date #(#(2015 1 24) #(12 42 24))))
#(order 2 1 9001
  (#(item "OAX19XWN0QP" "GoSlo Digital Camera" 359.99))
  359.99
  #(#(2015 1 24) #(12 42 24)))
> (set order-3
    (make-order
      id 3
      customer-id (customer-id customer-1)
      salesperson-id 9000
      items `(,(make-item
                 id "WYK12EPU5EZ"
                 title "Call of Battle= Goats - Gamesphere 4"
                 price 69.99)
              ,(make-item
                 id "TJB84HAA8OA"
                 title "Bricko Building Blocks"
                 price 4.99))
      total 74.98
      created-date #(#(2015 2 1) #(22 24 42))))
#(order 3 1 9000
  (#(item "WYK12EPU5EZ" "Call of Battle= Goats - Gamesphere 4" 69.99)
   #(item "TJB84HAA8OA" "Bricko Building Blocks" 4.99))
  74.98
  #(#(2015 2 1) #(22 24 42)))

We'll put those together:

> (set orders `(,order-1 ,order-2 ,order-3))
(#(order 1 1 9000
   (#(item "TCV37GIT4NJ" "USB 3.0 Coffee Warmer" 15.99)
    #(item "PEG10BBF2PP" "eTablet Pro, 24GB, Grey" 3999.99))
   415.98
   #(#(2015 1 24) #(14 42 24)))
 #(order 2 1 9001
   (#(item "OAX19XWN0QP" "GoSlo Digital Camera" 359.99))
   359.99
   #(#(2015 1 24) #(12 42 24)))
 #(order 3 1 9000
   (#(item "WYK12EPU5EZ" "Call of Battle= Goats - Gamesphere 4" 69.99)
    #(item "TJB84HAA8OA" "Bricko Building Blocks" 4.99))
   74.98
   #(#(2015 2 1) #(22 24 42))))

Next, the order summary:

> (set ord-sum
    (make-order-summary
      customer-id (order-customer-id order-1)
      summaries `(
        ,(make-order-summary-entry
           order-id (order-id order-1)
           total (order-total order-1)
           order-date (order-created-date order-1))
        ,(make-order-summary-entry
           order-id (order-id order-2)
           total (order-total order-2)
           order-date (order-created-date order-2))
        ,(make-order-summary-entry
           order-id (order-id order-3)
           total (order-total order-3)
           order-date (order-created-date order-3)))))
#(order-summary 1
  (#(order-summary-entry 1 415.98 #(#(2015 1 14) #(14 42 24)))
   #(order-summary-entry 2 359.99 #(#(2015 1 24) #(12 42 24)))
   #(order-summary-entry 3 74.98 #(#(2015 2 1) #(22 24 42)))))