@@ -7,16 +7,16 @@ exports.CreateQuery = CreateQuery;
77 * @returns {string }
88 */
99var tmpl = function ( template , args ) {
10- var has = { } . hasOwnProperty ;
11- for ( var key in args ) {
12- if ( ! has . call ( args , key ) ) {
13- continue ;
14- }
15- var token = '{{' + key + '}}' ;
16- template = template . split ( token ) . join ( args [ key ] ) ;
17- }
10+ var has = { } . hasOwnProperty ;
11+ for ( var key in args ) {
12+ if ( ! has . call ( args , key ) ) {
13+ continue ;
14+ }
15+ var token = '{{' + key + '}}' ;
16+ template = template . split ( token ) . join ( args [ key ] ) ;
17+ }
1818
19- return template ;
19+ return template ;
2020} ;
2121/**
2222 * Builds a list of fields according to the used dialect
@@ -25,20 +25,20 @@ var tmpl = function (template, args) {
2525 * @returns {string }
2626 */
2727var buildFieldsList = function ( dialect , structure ) {
28- if ( ! structure ) {
29- return "" ;
30- }
31- var tpl = "'{{NAME}}' {{TYPE}}" , fields = [ ] , has = { } . hasOwnProperty ;
32- for ( var field in structure ) {
33- if ( has . call ( structure , field ) ) {
34- fields . push ( tmpl ( tpl , {
35- NAME : field ,
36- TYPE : dialect . DataTypes [ structure [ field ] ]
37- } ) ) ;
38- }
39- }
28+ if ( ! structure ) {
29+ return "" ;
30+ }
31+ var tpl = "'{{NAME}}' {{TYPE}}" , fields = [ ] , has = { } . hasOwnProperty ;
32+ for ( var field in structure ) {
33+ if ( has . call ( structure , field ) ) {
34+ fields . push ( tmpl ( tpl , {
35+ NAME : field ,
36+ TYPE : dialect . DataTypes [ structure [ field ] ]
37+ } ) ) ;
38+ }
39+ }
4040
41- return fields . join ( ',' ) ;
41+ return fields . join ( ',' ) ;
4242} ;
4343
4444/**
@@ -49,64 +49,64 @@ var buildFieldsList = function (dialect, structure) {
4949 * @constructor
5050 */
5151function CreateQuery ( Dialect , opts ) {
52- var sql = { } ;
53- var tableName = null ;
54- var structure = { } ;
52+ var sql = { } ;
53+ var tableName = null ;
54+ var structure = { } ;
5555
56- return {
57- /**
58- * Set the table name
59- * @param table_name
60- * @returns {* }
61- */
62- table : function ( table_name ) {
63- tableName = table_name ;
56+ return {
57+ /**
58+ * Set the table name
59+ * @param table_name
60+ * @returns {* }
61+ */
62+ table : function ( table_name ) {
63+ tableName = table_name ;
6464
65- return this ;
66- } ,
67- /**
68- * Add a field
69- * @param name
70- * @param type
71- * @returns {Object }
72- */
73- field : function ( name , type ) {
74- structure [ name ] = type ;
65+ return this ;
66+ } ,
67+ /**
68+ * Add a field
69+ * @param name
70+ * @param type
71+ * @returns {Object }
72+ */
73+ field : function ( name , type ) {
74+ structure [ name ] = type ;
7575
76- return this ;
77- } ,
78- /**
79- * Set all the fields
80- * @param fields
81- * @returns {Object }
82- */
83- fields : function ( fields ) {
84- if ( ! fields ) {
85- return structure ;
86- }
87- structure = fields ;
76+ return this ;
77+ } ,
78+ /**
79+ * Set all the fields
80+ * @param fields
81+ * @returns {Object }
82+ */
83+ fields : function ( fields ) {
84+ if ( ! fields ) {
85+ return structure ;
86+ }
87+ structure = fields ;
8888
89- return this ;
90- } ,
89+ return this ;
90+ } ,
9191
92- /**
93- * Build a query from the passed params
94- * @returns {string }
95- */
96- build : function ( ) {
97- var query , fieldsList , template = "CREATE TABLE '{{TABLE_NAME}}'({{FIELDS_LIST}})" ;
92+ /**
93+ * Build a query from the passed params
94+ * @returns {string }
95+ */
96+ build : function ( ) {
97+ var query , fieldsList , template = "CREATE TABLE '{{TABLE_NAME}}'({{FIELDS_LIST}})" ;
9898
99- if ( ! tableName ) {
100- return '' ;
101- }
99+ if ( ! tableName ) {
100+ return '' ;
101+ }
102102
103- fieldsList = buildFieldsList ( Dialect , structure ) ;
103+ fieldsList = buildFieldsList ( Dialect , structure ) ;
104104
105- return tmpl ( template , {
106- TABLE_NAME : tableName ,
107- FIELDS_LIST : fieldsList
108- } ) ;
105+ return tmpl ( template , {
106+ TABLE_NAME : tableName ,
107+ FIELDS_LIST : fieldsList
108+ } ) ;
109109
110- }
111- } ;
110+ }
111+ } ;
112112}
0 commit comments