SequelSphereDB / YUI Overview

The simplicity and straighforward nature of the SequelSphere API and the product's lack of dependence on any Javascript framework allows it to be used easily in a YUI framework application without special connectors. Several examples are provided on the Examples page . The YUI framework does provide, however, a number of capbilities for integration with an external data store. These are examined here for suitability of use with SequelSphere.

YUI DataSource

YUI includes several DataSource classes which act as sources of data for widgets like DataTable and Charts . The existing classes, in particular the DataSource.Function class, is sufficiently flexible and useful for an application programmer to wrap access to SequelSphere within an out-of-the-box data source. So, no SequelSphere connector is, stricly speaking, necessary. The examples page includes a DataSource.Function example to demonstrate how this is done. The example also includes how to attach the data souce to the YUI DataTable widget. In brief, the data source is created as shown below. Note the use of db.queryObjects , which returns the data in a format matching what YUI data sources expect.
YUI().use("datasource-function", function(Y) {
	// Create the data source
	var example3_ds2 = new Y.DataSource.Function({
		source: function(request) {
			try {
				var sql = "SELECT * FROM EMPL WHERE DEPT_ID=" + request.DEPT_ID;
				var results = db.queryObjects(sql);	
				return results.data;
			}
			catch(err) {
				return { error:err };
			}
		}
	});
	// Plugging in a JSON schema is useful
	example3_ds2.plug(Y.Plugin.DataSourceJSONSchema, {
		schema: {
			resultFields: ["EMPL_ID","NAME","AGE","DEPT_ID","DEPT_NAME"]
		}
	});
	// To execute query, call the load function
	example3_ds2.load({DEPT_ID:1});
	// Or, if you attached the data source to a data table
	exampl3_datatable.datasource.load({DEPT_ID:1});
});
	

SequelSphere Y.DataSource.SQL

Although the use of DataSource.Function is straightforward, SequelSphere provides a connector in the form of a DataSource called DataSource.SQL . This connector hides the SequelSphere API from the application programmer completely. For example:

YUI().use("ssdb-datasource", function(Y) {
	example3_ds3 = new Y.DataSource.SQL({});
	example3_ds3.plug(Y.Plugin.DataSourceJSONSchema, {
		schema: {
			resultFields: ["EMPL_ID","NAME","AGE","DEPT_ID","DEPT_NAME"]
		}
	});
	...
	example3_ds2.load({ request:"SELECT * FROM EMPL"}); // the sql is the "request" above
});
	

SequelSphere SQLModel and SQLModelList

SequelSphere provides the SQLModel and SQLModelList classes, overriding the YUI Model and ModelList classes with a SequelSphere sync layer. As with all Model classes, instances hold the data attributes and support loading, updating, creating and inserting from and to the underlying data store. In this case, the load is a query and the modifications are using SequelSphere data manipulation operations.

The typical use to is extend SQLModel by adding attributes and a few fields controlling the access to the database, such as the query to execute. No other code is required to be overridden. A similar extension is typical for the SQLModelList . These provide the connection point between YUI widgets and data. Examples are provided at Example #7 and Example #8 . In brief, the code below is all that is needed to create custom models. Then instantiate and use them as you would any other YUI Model and ModelList objects.

YUI().use("ssdb-sqlmodel", function(Y) {
	Y.EmplModel = Y.Base.create('emplModel', Y.SQLModel, [], 
		{
			dbReadSQL: "SELECT * FROM EMPL WHERE EMPL_ID={EMPL_ID}", // load query
			dbTableName: "EMPL",  // name required for updates
			dbKeyFields: ["EMPL_ID"] // key fields needed for Model id
		}, 
		{
			// include each table column here as an attribute
			ATTRS: { EMPL_ID:-1, NAME:"", AGE:0, DEPT_ID:-1 }
		}
	);	
	
	Y.EmplList = Y.Base.create('emplList', Y.SQLModelList, [], 
		{	
			model: Y.EmplModel,
			dbTableName: "EMPL",
			dbReadSQL: "SELECT * FROM EMPL", // list query
			dbItemReadSQL: "SELECT * FROM EMPL WHERE EMPL_ID={EMPL_ID}", // item query
			dbKeyFields: ["EMPL_ID"]
		}
	);
});
	

YUI Storage as a backing store

YUI provides multiple storage options which hide from the application programmer the underlying storage mechanism. This allows YUI to decide based on browser capabilities which storage mechanism to use. These include Storage and StorageLite . It would seem logical, given the SequelSphere ability to define Storage Providers to wrap external storage mechanisms, to provide a connector here for YUI. However, SequelSphere uses its knowledge of the nature of the abiity of each Storage Provider to support transactional semantics. Given that the YUI Storage solutions hide that knowledge, it is better to let SequelSphere decide on the storage mechanism. No connector is necessary to wrap YUI storage solutions.

YQL

YUI YQL is a query language for using an SQL-like syntax to query information provided by web services. While this would seem a natural integration point, YQL and SequelSphere are, in fact, providing two very different services. The purpose of YQL is to provide uniform access to data exposed on the Internet, not to access local data or integrate with locally running APIs. As such, an integration point with YQL is not appropriate.