|
10 | 10 | var isNode = !!(typeof module !== 'undefined' && module.exports); |
11 | 11 | var jSQL = (function(){ |
12 | 12 | "use strict"; |
13 | | - //////////////////////////////////////////////////////////////////////////// |
14 | | - // jSQL Error Handling ///////////////////////////////////////////////////// |
15 | | - //////////////////////////////////////////////////////////////////////////// |
16 | 13 |
|
| 14 | + /** |
| 15 | + * Error object constructor |
| 16 | + * @param {String} error_no |
| 17 | + */ |
17 | 18 | function jSQL_Error(error_no) { |
18 | 19 | this.error = error_no; |
19 | 20 | this.stack = undefined; |
|
96 | 97 | return "jSQL Error #"+this.error+" - "+this.message; |
97 | 98 | }; |
98 | 99 | } |
| 100 | + |
99 | 101 |
|
100 | 102 | var error_handler_function = function(){}; |
101 | 103 | var mute_jsql_errors = false; |
|
107 | 109 | function onError(funct){ |
108 | 110 | if(typeof funct === "function") error_handler_function = funct; |
109 | 111 | } |
| 112 | + |
110 | 113 |
|
111 | | - //////////////////////////////////////////////////////////////////////////// |
112 | | - // jSQLDataTypeList //////////////////////////////////////////////////////// |
113 | | - //////////////////////////////////////////////////////////////////////////// |
114 | | - |
115 | | - function jSQLDataTypeList(){ |
| 114 | +function jSQLDataTypeList(){ |
116 | 115 | this.list = [{ |
117 | 116 | type: "NUMERIC", |
118 | 117 | aliases: ["NUMBER", "DECIMAL", "FLOAT"], |
|
332 | 331 | return _throw(new jSQL_Error("0007")); |
333 | 332 | }; |
334 | 333 | } |
335 | | - |
336 | | - //////////////////////////////////////////////////////////////////////////// |
337 | | - // jSQL Table constructor ////////////////////////////////////////////////// |
338 | | - //////////////////////////////////////////////////////////////////////////// |
| 334 | + |
339 | 335 |
|
340 | 336 | function jSQLTable(name, columns, data, types, keys, auto_increment){ |
341 | 337 | var self = this; |
|
611 | 607 |
|
612 | 608 | self.init(name, columns, data, types, keys, auto_increment); |
613 | 609 | } |
614 | | - |
615 | | - //////////////////////////////////////////////////////////////////////////// |
616 | | - // jSQL Query constructor ////////////////////////////////////////////////// |
617 | | - //////////////////////////////////////////////////////////////////////////// |
| 610 | + |
618 | 611 |
|
619 | 612 | function jSQLQuery(type){ |
620 | 613 | var self = this; |
|
649 | 642 | }; |
650 | 643 | })(i); |
651 | 644 | } |
652 | | - |
653 | | - //////////////////////////////////////////////////////////////////////////// |
654 | | - // jSQL Query Type constructors //////////////////////////////////////////// |
655 | | - //////////////////////////////////////////////////////////////////////////// |
| 645 | + |
656 | 646 |
|
657 | 647 | function jSQLDeleteQuery(){ |
658 | 648 | this.init = function(tablename){ |
|
733 | 723 | return this; |
734 | 724 | }; |
735 | 725 | } |
| 726 | + |
736 | 727 |
|
737 | 728 | function jSQLDropQuery(){ |
738 | 729 | this.init = function(tablename){ |
|
748 | 739 | this.fetch = function(){ return null; }; |
749 | 740 | this.fetchAll = function(){ return []; }; |
750 | 741 | } |
| 742 | + |
751 | 743 |
|
752 | 744 | function jSQLInsertQuery(){ |
753 | 745 | this.init = function(table){ |
|
779 | 771 | this.fetch = function(){ return null; }; |
780 | 772 | this.fetchAll = function(){ return []; }; |
781 | 773 | } |
| 774 | + |
782 | 775 |
|
783 | 776 | function jSQLSelectQuery(){ |
784 | 777 | this.init = function(columns){ |
|
863 | 856 | return this; |
864 | 857 | }; |
865 | 858 | } |
| 859 | + |
866 | 860 |
|
867 | 861 | function jSQLUpdateQuery(){ |
868 | 862 | this.init = function(table){ |
|
1020 | 1014 | this.fetchAll = function(){ return []; }; |
1021 | 1015 | } |
1022 | 1016 |
|
1023 | | - //////////////////////////////////////////////////////////////////////////// |
1024 | | - // Parse String Query ////////////////////////////////////////////////////// |
1025 | | - //////////////////////////////////////////////////////////////////////////// |
1026 | | - |
1027 | 1017 | function jSQLParseQuery(query){ |
1028 | 1018 |
|
1029 | 1019 | // Predcit the correct casing for column and table names |
|
1712 | 1702 | return _throw(new jSQL_Error("0041")); |
1713 | 1703 | } |
1714 | 1704 | } |
1715 | | - |
1716 | | - //////////////////////////////////////////////////////////////////////////// |
1717 | | - // Where caluse //////////////////////////////////////////////////////////// |
1718 | | - //////////////////////////////////////////////////////////////////////////// |
| 1705 | + |
1719 | 1706 |
|
1720 | 1707 | function jSQLWhereClause(context){ |
1721 | 1708 | var self = this; |
|
1980 | 1967 | return resultRowIndexes; |
1981 | 1968 | }; |
1982 | 1969 | } |
1983 | | - |
1984 | | - //////////////////////////////////////////////////////////////////////////// |
1985 | | - // Data Storage APIs /////////////////////////////////////////////////////// |
1986 | | - //////////////////////////////////////////////////////////////////////////// |
| 1970 | + |
1987 | 1971 |
|
1988 | 1972 | var API = { |
1989 | 1973 |
|
|
2386 | 2370 |
|
2387 | 2371 | } |
2388 | 2372 | }; |
2389 | | - |
2390 | | - //////////////////////////////////////////////////////////////////////////// |
2391 | | - // Persistence Manager ///////////////////////////////////////////////////// |
2392 | | - //////////////////////////////////////////////////////////////////////////// |
| 2373 | + |
2393 | 2374 |
|
2394 | 2375 | var persistenceManager = new (function(){ |
2395 | 2376 | var self = this; |
|
2589 | 2570 |
|
2590 | 2571 | })(); |
2591 | 2572 |
|
2592 | | - //////////////////////////////////////////////////////////////////////////// |
2593 | | - // Syntactic sugar ///////////////////////////////////////////////////////// |
2594 | | - //////////////////////////////////////////////////////////////////////////// |
2595 | | - |
2596 | 2573 | function createTable(name, columnsOrData, types, keys, auto_increment){ |
2597 | 2574 |
|
2598 | 2575 | // allow for all params to be passed in a single object |
|
2653 | 2630 | if(!Array.isArray(keys)) keys=[keys]; |
2654 | 2631 | return new jSQLQuery("CREATE").init(name, columnsOrData, types, keys, auto_increment); |
2655 | 2632 | } |
| 2633 | + |
2656 | 2634 |
|
2657 | 2635 | function select(cols){ |
2658 | 2636 | if(!Array.isArray(cols)) cols=[cols]; |
2659 | 2637 | return new jSQLQuery("SELECT").init(cols); |
2660 | 2638 | } |
| 2639 | + |
2661 | 2640 |
|
2662 | 2641 | function update(table){ |
2663 | 2642 | return new jSQLQuery("UPDATE").init(table); |
2664 | 2643 | } |
| 2644 | + |
2665 | 2645 |
|
2666 | 2646 | function insertInto(tablename){ |
2667 | 2647 | return new jSQLQuery("INSERT").init(tablename); |
|
2670 | 2650 | function dropTable(tablename){ |
2671 | 2651 | return new jSQLQuery("DROP").init(tablename); |
2672 | 2652 | } |
| 2653 | + |
2673 | 2654 |
|
2674 | 2655 | function deleteFrom(tablename){ |
2675 | 2656 | return new jSQLQuery("DELETE").init(tablename); |
2676 | 2657 | } |
2677 | | - |
2678 | | - //////////////////////////////////////////////////////////////////////////// |
2679 | | - // Helper/Misc Methods ///////////////////////////////////////////////////// |
2680 | | - //////////////////////////////////////////////////////////////////////////// |
| 2658 | + |
2681 | 2659 |
|
2682 | 2660 | function jSQLReset(){ |
2683 | 2661 | jSQL.tables = {}; |
2684 | 2662 | jSQL.commit(); |
2685 | 2663 | } |
2686 | | - |
| 2664 | + |
| 2665 | + |
2687 | 2666 | function jSQLMinifier(sql){ |
2688 | 2667 | var cleanSQL = ""; |
2689 | 2668 | var lines = sql.split("\n"); |
|
2756 | 2735 | } |
2757 | 2736 |
|
2758 | 2737 | return { |
2759 | | - version: 0, |
| 2738 | + version: "2.9.1", |
2760 | 2739 | tables: {}, |
2761 | 2740 | query: jSQLParseQuery, |
2762 | 2741 | createTable: createTable, |
|
0 commit comments