SequelSphereDB / Ext JS 4 Connector

How to use the SequelSphereDB / Ext JS 4 Connector

To use the connector as part of your SequelSphereDB / Ext JS 4 application:

  1. Download the Connector
  2. Reference the connector from your code
  3. Create SQL to query existing Ext JS Stores
  4. Create a SqlStore based on a SQL Query

How to reference (link to) the SequelSphereDB / Ext JS 4 Connector

After making the decision to either download or use the connector straight from the SequelSphereDB site, you must reference the connector in the HEAD section of your Ext JS / SequelSphereDB application as follows:

<head>
    <meta charset="UTF-8">
    <title>Your Application Title</title>
    <link rel="stylesheet" href="resources/css/default/app.css">
    <!--  Include a reference to SequelSphereDB -->
    <script type="text/javascript"
             src="http://www.sequelsphere.com/db/edge/your_token/SequelSphereDB.js"
    ></script>

    <!--  Include references to Ext JS 4 application -->
    <script type="text/javascript"
             src="all-classes.js"
    ></script>

    <!--  Include reference to SequelSphereDB / Ext JS 4 plugin -->
    <script type="text/javascript"
             src=" http: //www.sequelsphere.com/connectors/ExtJS/1.0/SqlStore.js"
    ></script>
</head>
	

Alternatively, you can have the Ext JS 4 framework load the connector by including the 'SqlStore.js' file in your Ext JS application�s directory structure at:

  • ~/Ext/ux/data/SqlStore.js

How to Query Ext JS 4 Stores:

Once the connector has been loaded into your application, any query performed by SequelSphereDB will automatically include the Ext JS Stores managed by Ext.data.StoreManager. This includes all types of stores inheriting from Ext.data.Store including:

  • JsonStore
  • JsonPStore
  • ArrayStore
  • DirectStore
  • SqlStore (provided by this connector)

To perform a query against these stores, you can use all of the existing SequelSphereDB query methods:

var results = db.query('select * from MyJsonStore a, MyArrayStore b WHERE a.id = b.id');
	

Alternatively, you can create an instance of Ext.ux.data.SqlStore to perform the query for you. See the next section for details.

How to Create a SqlStore

Creating a SqlStore occurs much like creating any type of Ext JS Store:

var store = Ext.create('Ext.ux.data.SqlStore', {
    storeId: "EmplDeptQuery",
    sql: "SELECT empl_id, e.name, age, d.name as dept_name " +
         "  FROM empl e " +
         "  JOIN dept d " +
         "    ON e.dept_id = d.dept_id " +
         " WHERE age > 30"
});
	

The above code creates a SqlStore object based on the results of executing the SQL query provided in the configuration parameters. Here are a couple of notes to consider:

  • No Model needs to be provided, as the SqlStore creates an Ext.data.Model object based on the results of executing the SQL Query.
  • The SQL gets executed once at the creation time of the SqlStore, and is not executed subsequently.
  • If you want the query executed again, call the 'reload(options)' method. You can pass a new SQL statement to the reload method using the options.
  • Invalid SQL will throw the standard SequelSphereDB Exceptions during create() or reload().
  • SqlStore is a Read Only Store (No Insert/Update/Delete capabilities)
  • Once created, a SqlStore can be used in other queries just like any other Ext JS Store.