1
votes

I successfully tried sencha touch app example showed here

They are using store proxy type as localstorage, its working good and then i changed the proxy type to sql as shown below

Ext.define('notesApp.store.Notes', {
    extend : 'Ext.data.Store',
    requires : 'Ext.data.proxy.Sql',
    config : {
        model : 'notesApp.model.Note',
        proxy : {
            type : 'sql',
            database: "SqlProxyTest",
            table: "Notes",
            id : 'notes-app-store'
        },
        sorters : [{property : 'dateCreated', direction : 'DESC'}],
        grouper : {
            sortProperty : 'dateCreated',
            direction : 'DESC',
            groupFn : function(record) {
                if(record && record.data.dateCreated) {
                    return record.data.dateCreated.toString();
                }
                return '';
            }
        }
    }
});

There is no error. I can insert data and i can see the record in list view, but chrome resource showing "The Node table is empty". If i refresh the browser the record is gone from the list.

enter image description here

Am i missing anything or is it right way to use sql proxy in sencha touch ?

2

2 Answers

4
votes

If you have change your model (add a field) you have to drop the table and recreate it. And when you add a new row on your datastore be sure to put all fields.

Example if i have a model with firstName, lastName, email :

// This one is not added cause email is absent
       Ext.getStore('Users').add([{
          firstName: 'Toto',
          lastName: 'test',
       }]);


// This one is added
       Ext.getStore('Users').add([{
          firstName: 'toto',
          lastName: 'test',
          email : '[email protected]'
       }]);
2
votes

The mistake i did was, i created id for the record i am trying to insert as they showed in that demo example, when i changed below model from

    Ext.define("NotesApp.model.Note", {
    extend: "Ext.data.Model",
    config: {
        idProperty: 'id',
        fields: [
            { name: 'id', type: 'int' },
            { name: 'dateCreated', type: 'date', dateFormat: 'c' },
            { name: 'title', type: 'string' },
            { name: 'narrative', type: 'string' }
        ]
    }
});

to

    Ext.define('notesApp.model.Note', {
    extend : 'Ext.data.Model',
    config : {
        fields : [
            { name : 'dateCreated', type : 'string', dateFormat : 'D'},
            { name : 'title', type : 'string'},
            { name : 'narrative', type : 'string'}
        ],

        validations : [
            {type : 'presence', field : 'dateCreated'},
            {type : 'presence', field : 'title', message : 'Please enter a title for the note!'}
        ]
    }
});

Everything works fine.