1. #1
    Sencha User
    Join Date
    Oct 2012
    Location
    Dallas, TX
    Posts
    6
    Vote Rating
    0
    j.fowler is on a distinguished road

      0  

    Default Ext.ux.data.SqlStore: Using SQL to query any Store

    Ext.ux.data.SqlStore: Using SQL to query any Store


    To whomever likes SQL:

    Using the SequelSphereDB engine, I was able to create an 'Ext.ux.data.SqlStore' Class that allows you to execute SQL against any data Store(s) managed by Ext.data.StoreManager. Here is some sample usage code:

    Code:
    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 > 20"
    });
    In the above example, 'Empl' is an Ext.data.ArrayStore, and 'Dept' is an Ext.data.JsonStore.

    When SQL is executed, it all occurs in the browser, using the SequelSphereDB engine to parse and execute the SQL.

    The Code for Ext.ux.data.SqlStore can be found here:
    And an example app showing integration with a Grid and Chart along with more sample code can be found here:
    As one last example, consider this: let's get the departments whose managers are younger than the average age of the employees in the department.

    Code:
    var store = Ext.create('Ext.ux.data.SqlStore', {
        storeId: "EmplDeptQuery",
        sql: "SELECT d.name, count(*) as nbr_empls, avg(e.age) as age " +
             "     , m.name as mgr_name, m.age as mgr_age " +
             "  FROM dept d " +
             "  JOIN empl e ON e.dept_id = d.dept_id " +
             "  JOIN empl m ON m.empl_id = d.mgr_id " +
             " GROUP BY d.name, m.name, m.age " +
             "HAVING m.age <= avg(e.age) " +
             " ORDER BY avg(e.age) - m.age desc"
    });
    All feedback is welcome. Please let me know if there are other ways you think SQL could be incorporated with ExtJS.

    Cheers!

    john...
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    - John Fowler
    SequelSphere: An HTML5 / JavaScript Relational Database

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Nice contribution!
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread