This tutorial will walk you through a series of interactive examples of JQL simple enough that you can follow along in your Python interpreter if you so desire. For those of you familar with SQL, we’ll also show equivalent SQL examples side-by-side.
First we’ll create a simple JSON store with some sample JSON. For readability, we’ll use native Python dictionaries and lists instead of strings of JSON.
>>> from vesper import app
>>> model1 = app.createStore(
... '''[
... {
... "type": "post",
... "id": "post1",
... "contents": "a post",
... "author": "@user:1"
... },
... {
... "contents": "a comment",
... "type": "comment",
... "id": "comment1",
... "parent": "@post1",
... "author": "@user:2"
... },
... {
... "author": "@user:1",
... "type": "comment",
... "id": "comment2",
... "parent": "@comment1",
... "contents": "a reply"
... },
... {
... "author": "@user:1",
... "type": "comment",
... "id": "comment3",
... "parent": "@comment4",
... "contents": "different parent"
... },
... {
... "displayname": "abbey aardvaark",
... "type": "user",
... "id": "user:1",
... "email": [
... "abbey@aardvaark.com",
... "abbey_aardvaak@gmail.com"
... ]
... },
... {
... "displayname": "billy billygoat",
... "type": "user",
... "id": "user:2"
... }
... ]''')
Four top-level objects, two users and two projects. Many-to-many to One user we have two postal addresses and another we have any at all.
The pJSON (persistent json) module does the serialization from JSON to an internal representation that can be saved in a variety of backends ranging from a JSON text file to SQL database, RDF datastores and simple Memcache or BerkeleyDb. By default raccoon.createStore() will use a simple in-memory store.
To illustrate let’s create SQL schema that will data mapping. One to many
|
| ||||||||||||||||||||||||||||||||||||||
|
|