commit extjs-2.2.1
[extjs.git] / air / src / sql / SQLiteStore.js
1 /*\r
2  * Ext JS Library 0.30\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 /**
10  * @class Ext.sql.SQLiteStore
11  * @extends Ext.data.Store
12  * Convenience class which assists in setting up SQLiteStore's.
13  * This class will create the necessary table if it does not exist.
14  * This class requires that all fields stored in the database will also be kept
15  * in the Ext.data.Store.
16  */
17 Ext.sql.SQLiteStore = Ext.extend(Ext.data.Store, {
18     /**
19      * @cfg {String} key This is the primary key for the table and the id for the Ext.data.Record.
20      */
21     /**
22      * @cfg {Array} fields Array of fields to be used. Both name and type must be specified for every field.
23      */
24     /**
25      * @cfg {String} dbFile Filename to create/open
26      */
27     /**
28      * @cfg {String} tableName  Name of the database table
29      */
30     constructor: function(config) {
31         config = config || {};
32         config.reader = new Ext.data.JsonReader({
33             id: config.key,
34             fields: config.fields
35         });
36         var conn = Ext.sql.Connection.getInstance();
37         
38         conn.open(config.dbFile);
39         // Create the database table if it does
40         // not exist
41         conn.createTable({
42             name: config.tableName,
43             key: config.key,
44             fields: config.reader.recordType.prototype.fields
45         });                
46         Ext.sql.SQLiteStore.superclass.constructor.call(this, config);
47         this.proxy = new Ext.sql.Proxy(conn, config.tableName, config.key, this, false);        
48     }
49 });