@@ -399,39 +399,36 @@ function jSQLTable(name, columns, data, types, keys, auto_increment){
399399 unique : [ ]
400400 } ;
401401
402- // Create the table and load the data, if there is any
403- self . init = function ( name , columns , data , types , keys , auto_increment ) {
404- self . name = name ;
405-
406- // If the types array does not exist, create it
407- if ( undefined === types ) types = [ ] ;
408-
409- // If first param is array, no third param
410- if ( Array . isArray ( columns ) && undefined === data )
411- // Create the data parameter from column param
412- { data = columns ; columns = [ ] ; }
413-
414- // If second param is array of objects
415- // - Create table from first object
416- // - Generate data (3rd) param
417- if ( Array . isArray ( columns ) && ! Array . isArray ( columns [ 0 ] ) && typeof columns [ 0 ] === "object" ) {
418- var cols = [ ] , n ;
419- for ( n in columns [ 0 ] )
420- if ( columns [ 0 ] . hasOwnProperty ( n ) )
421- cols . push ( n ) ;
422- data = columns ;
423- columns = cols ;
424- }
402+ self . name = name ;
403+
404+ // If the types array does not exist, create it
405+ if ( undefined === types ) types = [ ] ;
406+
407+ // If first param is array, no third param
408+ if ( Array . isArray ( columns ) && undefined === data )
409+ // Create the data parameter from column param
410+ { data = columns ; columns = [ ] ; }
411+
412+ // If second param is array of objects
413+ // - Create table from first object
414+ // - Generate data (3rd) param
415+ if ( Array . isArray ( columns ) && ! Array . isArray ( columns [ 0 ] ) && typeof columns [ 0 ] === "object" ) {
416+ var cols = [ ] , n ;
417+ for ( n in columns [ 0 ] )
418+ if ( columns [ 0 ] . hasOwnProperty ( n ) )
419+ cols . push ( n ) ;
420+ data = columns ;
421+ columns = cols ;
422+ }
425423
426- self . initColumns ( columns , types ) ;
424+ self . initColumns ( columns , types ) ;
427425
428- self . initKeys ( keys , auto_increment ) ;
426+ self . initKeys ( keys , auto_increment ) ;
429427
430- // Load the data, if there is any
431- if ( data !== undefined ) self . loadData ( data ) ;
432- } ;
428+ self . initAI ( auto_increment ) ;
433429
434- self . init ( name , columns , data , types , keys , auto_increment ) ;
430+ // Load the data, if there is any
431+ if ( data !== undefined ) self . loadData ( data ) ;
435432}
436433
437434jSQLTable . prototype . initColumns = function ( columns , types ) {
@@ -457,7 +454,7 @@ jSQLTable.prototype.initColumns = function(columns, types){
457454 for ( i = 0 ; i < columns . length ; i ++ ) this . colmap [ columns [ i ] ] = i ;
458455} ;
459456
460- jSQLTable . prototype . initKeys = function ( keys , auto_increment ) {
457+ jSQLTable . prototype . initKeys = function ( keys ) {
461458 // Set up keys if key data is provided
462459 var key ;
463460 var keyTypes = [ "primary" , "unique" ] ;
@@ -474,7 +471,9 @@ jSQLTable.prototype.initKeys = function(keys, auto_increment){
474471 if ( type === "primary" ) this . keys . primary . column = key . column ;
475472 if ( type === "unique" ) this . keys . unique . push ( { column :key . column , map :{ } } ) ;
476473 }
474+ } ;
477475
476+ jSQLTable . prototype . initAI = function ( auto_increment ) {
478477 // if there's an AI column
479478 if ( auto_increment ) {
480479 var isInPKArray = Array . isArray ( this . keys . primary . column ) && this . keys . primary . column . indexOf ( auto_increment ) > - 1 ;
@@ -647,7 +646,7 @@ jSQLTable.prototype.updateKeysOnInsert = function(row, ignore){
647646
648647 // Check the unique keys, There may be multiple and they may be compound
649648 for ( var k = 0 , ukey ; k < this . keys . unique . length ; k ++ ) {
650- ukey = this . keys . unique [ k ]
649+ ukey = this . keys . unique [ k ] ;
651650 var key_columns = Array . isArray ( ukey . column ) ? ukey . column : [ ukey . column ] ;
652651 var col , vals = [ ] ;
653652 for ( var uk = 0 ; uk < key_columns . length ; uk ++ ) {
0 commit comments