nl_tokens: Create a where and set string and a new object with unique propertynames Example : whereSetProperties ( user { userid : 123 firstname : foo } { firstname : bar } ) returns { where : user . userid = { xQ_1 } AND user . firstname = { xQ_2 } set : user . firstname = { xQ_3 } props { xQ_1 : 123 xQ_2 : foo xQ_2 : bar } }
pl_tokens: function whereSetProperties ( fieldName , oldProps , newProps ) { var prefix = 'xQ_' , whereClause = '' , setClause = '' , notFirst = false , props = { } , i = 0 , obj ; fieldName += '.' ; // Build WHERE for ( var k in oldProps ) { obj = oldProps [ k ] ; if ( notFirst ) whereClause += ' AND ' ; else notFirst = true ; whereClause += fieldName + k + '={' + prefix + ( ++ i ) + '}' ; props [ <mask> + i ] = obj ; } notFirst = false ; // Build SET for ( var key in newProps ) { obj = newProps [ key ] ; if ( notFirst ) setClause += ',' ; else notFirst = true ; // Create unique placeholder {xx1} {xx2} ... setClause += fieldName + key + '={' + prefix + ( ++ i ) + '}' ; // Build new properties object props [ prefix + i ] = obj ; } // Return stringified `where` and `set` clause and a new object with unique property names // So there are no name collisions return { where : whereClause , set : setClause , properties : props } ; }