3

I am using SQL proxy in my Sencha Touch 2 app and I am able to store and retrieve data offline.

What I cannot do and what the Sencha documentation does not seem to provide is how do I customize the Sencha SQL store.

For eg, to create a SQL based store, I did the following -

Ext.define("MyApp.model.Customer", {
 extend: "Ext.data.Model",
 config: {
  fields: [ 
   {name: 'id', type: 'int'},
   {name: 'name', type: 'string'},
   {name: 'age', type: 'string'}
  ],
  proxy: {
   type: "sql",
   database: "MyDb",
  }
 }
});

1. Now, how do i specify the size of the database ?

2. How do I specify constraints on the fields like unique, primary key etc ?

Say, I have 4 columns in my database : pid, name, age, phone

I want to have a primary key for multiple fields : (pid, name)

If I was creating a table via SQL query, I would do something like -

CREATE TABLE Persons
(
pid int,
name varchar(255),
age int,
phone int,
primary key (pid,name)
);

Now how do I achieve the same via model ?

3. If I want to interact with the database via SQL query, I do the following -

var query = "SELECT * from CUSTOMER";
var db = openDatabase('MyDb', '1.0', 'MyDb', 2 * 1024 * 1024);
db.transaction(function (tx) {
    tx.executeSql(query, [], function (tx, results) {
        // do something here
    }, null);
});

Is this the best way to do it?

senchaDev
  • 587
  • 2
  • 6
  • 19

0 Answers0