~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/workspace/extjs/docs/source/Table.html

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
  <title>The source code</title>
 
4
    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
 
5
    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
 
6
</head>
 
7
<body  onload="prettyPrint();">
 
8
    <pre class="prettyprint lang-js">Ext.sql.Table = function(conn, name, keyName){
 
9
        this.conn = conn;
 
10
        this.name = name;
 
11
        this.keyName = keyName;
 
12
};
 
13
 
 
14
Ext.sql.Table.prototype = {
 
15
        update : function(o){
 
16
                var clause = this.keyName + " = ?";
 
17
                return this.updateBy(o, clause, [o[this.keyName]]);
 
18
        },
 
19
 
 
20
        updateBy : function(o, clause, args){
 
21
                var sql = "UPDATE " + this.name + " set ";
 
22
                var fs = [], a = [];
 
23
                for(var key in o){
 
24
                        if(o.hasOwnProperty(key)){
 
25
                                fs[fs.length] = key + ' = ?';
 
26
                                a[a.length] = o[key];
 
27
                        }
 
28
                }
 
29
                for(var key in args){
 
30
                        if(args.hasOwnProperty(key)){
 
31
                                a[a.length] = args[key];
 
32
                        }
 
33
                }
 
34
                sql = [sql, fs.join(','), ' WHERE ', clause].join('');
 
35
                return this.conn.execBy(sql, a);
 
36
        },
 
37
 
 
38
        insert : function(o){
 
39
                var sql = "INSERT into " + this.name + " ";
 
40
                var fs = [], vs = [], a = [];
 
41
                for(var key in o){
 
42
                        if(o.hasOwnProperty(key)){
 
43
                                fs[fs.length] = key;
 
44
                                vs[vs.length] = '?';
 
45
                                a[a.length] = o[key];
 
46
                        }
 
47
                }
 
48
                sql = [sql, '(', fs.join(','), ') VALUES (', vs.join(','), ')'].join('');
 
49
        return this.conn.execBy(sql, a);
 
50
    },
 
51
 
 
52
        lookup : function(id){
 
53
                return this.selectBy('where ' + this.keyName + " = ?", [id])[0] || null;
 
54
        },
 
55
 
 
56
        exists : function(id){
 
57
                return !!this.lookup(id);
 
58
        },
 
59
 
 
60
        save : function(o){
 
61
                if(this.exists(o[this.keyName])){
 
62
            this.update(o);
 
63
        }else{
 
64
            this.insert(o);
 
65
        }
 
66
        },
 
67
 
 
68
        select : function(clause){
 
69
                return this.selectBy(clause, null);
 
70
        },
 
71
 
 
72
        selectBy : function(clause, args){
 
73
                var sql = "select * from " + this.name;
 
74
                if(clause){
 
75
                        sql += ' ' + clause;
 
76
                }
 
77
                args = args || {};
 
78
                return this.conn.queryBy(sql, args);
 
79
        },
 
80
 
 
81
        remove : function(clause){
 
82
                this.deleteBy(clause, null);
 
83
        },
 
84
 
 
85
        removeBy : function(clause, args){
 
86
                var sql = "delete from " + this.name;
 
87
                if(clause){
 
88
                        sql += ' where ' + clause;
 
89
                }
 
90
                args = args || {};
 
91
                this.conn.execBy(sql, args);
 
92
        }
 
93
};</pre>    
 
94
</body>
 
95
</html>
 
 
b'\\ No newline at end of file'