Opened 12 years ago

Last modified 7 years ago

#3127 closed enhancement

[dojo.data] add Schema API — at Initial Version

Reported by: skinner Owned by: anonymous
Priority: low Milestone: future
Component: Data Version: 0.9
Keywords: needsreview Cc: Kris Zyp
Blocked By: Blocking:

Description

Sometime in the future, when we have more time, we should consider adding a dojo.data Schema API.

Here's some brainstorming about what dojo.data.api.Schema might look like:

dojo.declare("dojo.data.api.Schema",dojo.data.api.Read,{
	//	summary:
	//		This is an abstract API that data provider implementations conform to.
	//		This file defines methods signatures and intentionally leaves all the
	//		methods unimplemented.

	getFeatures: function(){
		//	summary: 
		//		See dojo.data.api.Read.getFeatures()
		return {
			 'dojo.data.api.Read': true,
			 'dojo.data.api.Schema': true
		};
	},

	getItemClass: function(/* item */ item){
		//	summary:
		//		Given an item, this method returns the item-class of the item.  
		//		For example, in a library database there might be item-classes 
		//		like Book, Author, and Movie.  Or in an LDAP datastore, 
		//		different items might belong to item-classes like Person, 
		//		Group, Organization, and Country.
		//		An item-class may be represented by a string, like "Book"; or
		//		by object with information about that item-class,
		//		like {name:"Book", attributes:["title", "author"]}; or by a 
		//		special item that holds all the information about that item-class.
		//	examples:
		//		var itemClass = store.getItemClass(item);
		//		var movie = store.getItemClass(starWars);
		//		var book = store.getItemClass(theHobbit);
		//		var person = store.getItemClass(jrrTolkien);
		dojo.unimplemented('dojo.data.api.Schema.getItemClass');
		return itemClass; // itemClass
	},
	
	getItemClasses: function(){
		//	summary:
		//		Returns an array with all the item-classes that may occur in
		//		this datastore.
  		//	examples:
		//		var array = store.getItemClasses(); // [movie, book, person]
		dojo.unimplemented('dojo.data.api.Schema.getItemClasses');
		return array; // Array of item-classes
	},

	getAttributesOfItemClass: function(/* itemClass */ itemClass){
		//	summary:
		//		Returns an array with the attributes that this class of item has.
		//	examples:
		//		var array = store.getAttributesOfItemClass(book); // [title, author]
		//		var array = store.getAttributesOfItemClass(person); // [name, dateOfBirth]
		dojo.unimplemented('dojo.data.api.Schema.getAttributesOfItemClass');
		return array; // Array of attributes
	},
	
	getTypeOfAttribute: function(/* attribute || attribute-name-string */ attribute){
		//	summary:
		//		Returns the type that an attribute normally holds.  The type
		//		may be a literal type like String or Date, or an item-class like
		//		Book or Person.
		//	issue:
		//		At some point we might also want more nuanced types for literals.
		//		We might want to specify JavaScript number literals like 
		//		"Number:int" or "Number:float", or string literals like 
		//		"String:URL".  Or, more importantly, we may need to be able to
		//		interoperate with existing databases without losing native type
		//		information.  When talking to an RDBMS, it may be important to
		//		for an app's user interface to be able to distinguish between
		//		"String:varchar(255)" and a "String:text".  Or, when talking to
		//		an XML database, it may be important to be able to use any of 
		//		the dozens of XML Schema datatypes like "float", "unsignedInt", 
		//		"year", and "uriReference".
		//	examples:
		//		var type = store.getTypeOfAttribute(title); // String
		//		var type = store.getTypeOfAttribute(publicationDate); // Date
		//		var type = store.getTypeOfAttribute(author); // Person
		dojo.unimplemented('dojo.data.api.Schema.getTypeOfAttribute');
		return type; // Object
	},
});

Change History (0)

Note: See TracTickets for help on using tickets.