Skip to content
aravindet edited this page Oct 13, 2012 · 3 revisions

JSON bits are in SloppyJSON (TM)

1. Nested Objects

Nested objects in select is done!

A. SELECT

customers.all(
  { age: [>, 25] },
  { embed: { bills: { items: true } } }
);
GET /customers?age:gt:25&fields=bills,bills.items
SELECT a.*, b.*, c.* 
    FROM (customers AS a LEFT OUTER JOIN bills AS b ON b.customerId = a.id
        INNER JOIN billItems as c ON c.billId = b.id)
    WHERE a.age > 25
    LIMIT 0,10
[
  {
    id: 123,
    name: Alice,
    age: 30,
    bills: [
      { 
        id: 93284,
        date: 2012-10-11,
        amount: 1150,
        items: [
          { id: 5384792, productId: 9233, rate: 1150, qty: 1 }
        ]
      }
    ]
  },
  ...
]

B. INSERT/UPDATE

javascript bills.add({ customerId: 123, date: 2012-10-13, items: [ { productId: 9233, rate: 830, qty: 1 } ], amount: 830 })

```http
POST /bills
(same data as above)
INSERT INTO bills (customerId, date, amount) VALUES (123, 2012-10-13, 830)
INSERT INTO billItems (billId, productId, rate, qty) VALUES (*insert_id, 9233, 830, 1)

Need to sequence operations correctly;

2. Column options

  • Indexes (Unique?) - allow only indexed columns in WHERE.
  • Hide In Results (password)

3. JSON columns

Backed into TEXT on MySQL, it will be serialized/deserialized automatically. Like TEXT, cannot be indexed.

Clone this wiki locally