@@ -14,8 +14,8 @@ Status](https://travis-ci.org/mcollina/levelgraph-jsonld.png)](https://travis-ci
1414
1515## Install on Node.js
1616
17- ```
18- npm install levelgraph levelgraph-jsonld --save
17+ ``` shell
18+ $ npm install levelgraph levelgraph-jsonld --save
1919```
2020
2121At the moment it requires node v0.10.x, but the port to node v0.8.x
@@ -24,21 +24,22 @@ If you need it, just open a pull request.
2424
2525## Install in the Browser
2626
27- TO BE DONE!
27+ WORK IN PROGRESS! [ # 3 ] ( http://github.com/mcollina/levelgraph-jsonld/issues/3 )
2828
2929## Usage
3030
3131Adding support for JSON-LD to LevelGraph is easy:
32- ```
32+ ``` javascript
3333var levelgraph = require (" levelgraph" )
3434 , jsonld = require (" levelgraph-jsonld" )
3535 , db = jsonld (levelgraph (" yourdb" ));
3636```
3737
3838### Put
3939
40- Storing a JSON-LD file in the database is extremey easy:
41- ```
40+ Please keep in mind that LevelGraph-JSONLD __ doesn't store the original
41+ JSON-LD document but decomposes it into triples__ ! Storing triples from JSON-LD document is extremely easy:
42+ ``` javascript
4243var manu = {
4344 " @context" : {
4445 " name" : " http://xmlns.com/foaf/0.1/name"
@@ -57,39 +58,39 @@ db.jsonld.put(manu, function(err, obj) {
5758});
5859```
5960
60- if the object as no ` '@id' ` key, one will be generated for you,
61- using a UUID and the ` 'base' ` argument, like so:
62- ```
61+ if the top level objects have no ` '@id' ` key, one will be generated for
62+ each, using a UUID and the ` 'base' ` argument, like so:
63+ ``` javascript
6364delete manu[" @id" ];
6465db .jsonld .put (manu, { base: " http://this/is/an/iri" }, function (err , obj ) {
6566 // obj["@id"] will be something like
66- http://this/is/an/iri/b1e783b0-eda6-11e2-9540-d7575689f4bc
67+ // http://this/is/an/iri/b1e783b0-eda6-11e2-9540-d7575689f4bc
6768});
6869```
6970
7071` 'base' ` can also be specified when you create the db:
71- ```
72+ ``` javascript
7273var levelgraph = require (" levelgraph" )
7374 , jsonld = require (" levelgraph-jsonld" )
7475 , opts = { base: " http://matteocollina.com/base" }
7576 , db = jsonld (levelgraph (" yourdb" ), opts);
7677```
7778
7879__ LevelGraph-JSONLD__ also support nested objects, like so:
79- ```
80+ ``` javascript
8081var nested = {
81- "@context": {
82- "name": "http://xmlns.com/foaf/0.1/name"
83- , "knows": "http://xmlns.com/foaf/0.1/knows"
84- }
85- , "@id": "http://matteocollina.com"
86- , "name": "matteo"
87- , "knows": [{
88- "name": "daniele"
89- }, {
90- "name": "lucio"
91- }]
92- };
82+ " @context" : {
83+ " name" : " http://xmlns.com/foaf/0.1/name"
84+ , " knows" : " http://xmlns.com/foaf/0.1/knows"
85+ }
86+ , " @id" : " http://matteocollina.com"
87+ , " name" : " matteo"
88+ , " knows" : [{
89+ " name" : " daniele"
90+ }, {
91+ " name" : " lucio"
92+ }]
93+ };
9394
9495db .jsonld .put (nested, function (err , obj ) {
9596 // do something...
@@ -98,8 +99,8 @@ db.jsonld.put(nested, function(err, obj) {
9899
99100### Get
100101
101- Retrieving a JSON-LD document from the store requires its ` '@id' ` :
102- ```
102+ Retrieving a JSON-LD object from the store requires its ` '@id' ` :
103+ ``` javascript
103104db .jsonld .get (manu[" @id" ], { " @context" : manu[" @context" ] }, function (err , obj ) {
104105 // obj will be the very same of the manu object
105106});
@@ -108,22 +109,22 @@ db.jsonld.get(manu["@id"], { "@context": manu["@context"] }, function(err, obj)
108109The format of the loaded object is entirely specified by the
109110` '@context' ` , so have fun :).
110111
111- As with ` 'put' ` it correctly support nested objects, but it
112- inserts ` '@id' ` properties for them, like so :
113- ```
112+ As with ` 'put' ` it correctly support nested objects. If nested objects didn't originally include ` '@id' ` properties, now they will have them since ` 'put' ` generates them by using UUID and formats
113+ them as * blank node identifiers * :
114+ ``` javascript
114115var nested = {
115- "@context": {
116- "name": "http://xmlns.com/foaf/0.1/name"
117- , "knows": "http://xmlns.com/foaf/0.1/knows"
118- }
119- , "@id": "http://matteocollina.com"
120- , "name": "matteo"
121- , "knows": [{
122- "name": "daniele"
123- }, {
124- "name": "lucio"
125- }]
126- };
116+ " @context" : {
117+ " name" : " http://xmlns.com/foaf/0.1/name"
118+ , " knows" : " http://xmlns.com/foaf/0.1/knows"
119+ }
120+ , " @id" : " http://matteocollina.com"
121+ , " name" : " matteo"
122+ , " knows" : [{
123+ " name" : " daniele"
124+ }, {
125+ " name" : " lucio"
126+ }]
127+ };
127128
128129db .jsonld .put (nested, function (err , obj ) {
129130 // obj will be
@@ -135,19 +136,21 @@ db.jsonld.put(nested, function(err, obj) {
135136 // , "@id": "http://matteocollina.com"
136137 // , "name": "matteo"
137138 // , "knows": [{
138- // "name": "daniele"
139+ // "@id": "_:7053c150-5fea-11e3-a62e-adadc4e3df79"
140+ // , "name": "daniele"
139141 // }, {
142+ // "@id": "_:9d2bb59d-3baf-42ff-ba5d-9f8eab34ada5"
140143 // "name": "lucio"
141144 // }]
142145 // }
143146});
144147```
145148
146- ### Deleting
149+ ### Delete
147150
148151In order to delete an object, you can just pass it's ` '@id' ` to the
149152` '@del' ` method:
150- ```
153+ ``` javascript
151154db .jsonld .del (manu[" @id" ], function (err ) {
152155 // do something after it is deleted!
153156});
@@ -157,20 +160,20 @@ db.jsonld.del(manu["@id"], function(err) {
157160
158161__ LevelGraph-JSONLD__ does not support searching for objects, because
159162that problem is already solved by __ LevelGraph__ itself, like these:
160- ```
163+ ``` javascript
161164var nested = {
162- "@context": {
163- "name": "http://xmlns.com/foaf/0.1/name"
164- , "knows": "http://xmlns.com/foaf/0.1/knows"
165- }
166- , "@id": "http://matteocollina.com"
167- , "name": "matteo"
168- , "knows": [{
169- "name": "daniele"
170- }, {
171- "name": "lucio"
172- }]
173- };
165+ " @context" : {
166+ " name" : " http://xmlns.com/foaf/0.1/name"
167+ , " knows" : " http://xmlns.com/foaf/0.1/knows"
168+ }
169+ , " @id" : " http://matteocollina.com"
170+ , " name" : " matteo"
171+ , " knows" : [{
172+ " name" : " daniele"
173+ }, {
174+ " name" : " lucio"
175+ }]
176+ };
174177
175178db .jsonld .put (nested, function (err ) {
176179 db .join ([{
0 commit comments