[dojo-contributors] dojo.data Schema API

Jon Sykes lists at jpsykes.com
Tue Aug 21 17:08:40 EDT 2007


Brian,
This looks very interesting, and along similar lines to something I  
was playing around with a while ago for http://microjson.org/ the  
idea here was to try to convert and extend some of the microformat  
work into the JSON world, with the same aim.  That you could end up  
with having code (server or client) that could identify common  
'chunks' of data out of a larger 'chunks' of data because it followed  
some loose JSON data form structure.

My idea being that if everyone had for example "people data"  
structured the same way (jCard) in open API type services, it would  
make writing data parsers for mashup style applications all that easier.

I did a bunch of research on creating JSON schema's (damned use the  
phrase Schema around ex-XML folk who are now JSON converts and they  
get VERY angry.)  I wanted to be able to have a way of showing the  
expected format (not necessarily for validation purposes - although  
that could open up other interesting doors of possibility).

I'd love to see where this goes, and if I can do anything to help  
don't hesitate to ask.

Jon


On Aug 21, 2007, at 3:49 PM, Brian Douglas Skinner wrote:

> In some recent dojo.data IRC meetings, Jared and Alex and I started
> talking about what we might want the Schema API to look like.
>
> The main purpose of the Schema API is just to provide metadata  
> about all
> the attributes that different kinds of items can have.  For  
> example, in
> a bookstore database, you might have different kinds of items for
> representing Customers and Books.  The Customer items would have
> attributes like Name, Phone Number, and Billing Address.  The Book  
> items
> would have attributes like Title, Author, and ISBN.
>
> We'd like to get feedback from more people about what the Schema API
> should look like.  We haven't yet talked about many of the details,  
> but
> here's a rough approximation of the sort of approach we've been  
> talking
> about...
>
> The Schema API might have just two methods:
>
>    store.getSchema();
>    store.getKindOfItem(item);  // or maybe just getKind(item)
>
> Calling store.getSchema() would return a JSON-like object structure  
> with
> all the schema info for the entire datastore.
>
> For example, say you have a datastore that's connected to a relational
> database, and the database has two tables that look like these:
>
>    TABLE Country:
>              ABBR  NAME
>              ----  -------
>              UKR   Ukraine
>              USA   United States
>
>    TABLE State:
>              NAME  CODE  COUNTRY  POPULATION
>              ----  ----  -------  ----------
>              Utah  UT    USA       2,233,169
>              Ohio  OH    USA      11,353,140
>
> If you call getSchema() like this:
>
>     var schema = store.getSchema();
>
> Then the schema object you get back would look something like this:
>
>      schema == {
>          kinds: {
>              Country: {
>                  attributes: {
>                      ABBR: {type: 'String'},
>                      NAME: {type: 'String'}
>                  }
>              },
>              State: {
>                  attributes: {
>                      NAME: {type: 'String'},
>                      CODE: {type: 'String'},
>                      COUNTRY: {kind: 'Country'},
>                      POPULATION: {type: 'Number'}
>                  }
>              }
>          }
>      }
>
> Or it could perhaps have additional metadata:
>
>      schema == {
>          kinds: {
>              Country: {
>                  label: ['NAME'],
>                  identifier: ['ABBR'],
>                  attributes: {
>                      ABBR: {
>                          label: 'Abbreviation',
>                          summary: 'An ISO 3166-1 country code',
>                          type: 'String',
>                          sourceType: 'char(3)'
>                      },
>                      NAME: {
>                          label: 'Country Name',
>                          type: 'String',
>                          sourceType: 'varchar(255)'
>                      }
>                  }
>              },
>              State: {
>                  label: ['NAME'],
>                  identifier: ['CODE'],
>                  attributes: {
>                      NAME: {
>                          label: 'State Name',
>                          type: 'String',
>                          sourceType: 'varchar(255)'
>                      },
>                      CODE: {
>                          label: 'Postal Code',
>                          type:'String',
>                          sourceType: 'char(2)'
>                      },
>                      COUNTRY: {
>                          summary: 'Country this State is part of',
>                          kind: 'Country'
>                      },
>                      POPULATION: {
>                          label: 'Population',
>                          type: 'Number',
>                          sourceType: 'int'
>                      }
>                  }
>              }
>          }
>      }
>
>
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors




More information about the dojo-contributors mailing list