@@ -113,6 +113,34 @@ function compileSelectStar(query, aliases, joinstar) {
113113 return { s : ss . join ( ',' ) , sp : sp } ;
114114}
115115
116+ // Helper function to check if an expression is an arrow operation and extract its path
117+ // Returns null if not an arrow op, or an array of path parts if it is
118+ function getArrowPath ( expr ) {
119+ if ( ! expr || expr . op !== '->' ) {
120+ return null ;
121+ }
122+ var path = [ ] ;
123+ var current = expr ;
124+ while ( current && current . op === '->' ) {
125+ // The right side is the property name
126+ if ( typeof current . right === 'string' ) {
127+ path . unshift ( current . right ) ;
128+ } else if ( typeof current . right === 'number' ) {
129+ path . unshift ( current . right ) ;
130+ } else {
131+ // Complex expression on right side, can't extract path
132+ return null ;
133+ }
134+ current = current . left ;
135+ }
136+ // The leftmost should be a column
137+ if ( current && current . columnid ) {
138+ path . unshift ( current . columnid ) ;
139+ return path ;
140+ }
141+ return null ;
142+ }
143+
116144yy . Select . prototype . compileSelect1 = function ( query , params ) {
117145 var self = this ;
118146 query . columns = [ ] ;
@@ -326,26 +354,63 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
326354 // }
327355 } else {
328356 // console.log(203,col.as,col.columnid,col.toString());
329- ss . push (
330- "'" +
331- escapeq ( col . as || col . columnid || col . toString ( ) ) +
332- "':" +
333- n2u ( col . toJS ( 'p' , query . defaultTableid , query . defcols ) )
334- ) ;
335- // ss.push('\''+escapeq(col.toString())+'\':'+col.toJS("p",query.defaultTableid));
336- //if(col instanceof yy.Expression) {
337- query . selectColumns [ escapeq ( col . as || col . columnid || col . toString ( ) ) ] = true ;
357+ // Check if this is an arrow expression and we're outputting to OBJECT
358+ var arrowPath = query . intoObject && ! col . as ? getArrowPath ( col ) : null ;
359+ if ( arrowPath && arrowPath . length > 1 ) {
360+ // For arrow expressions in INTO OBJECT(), generate nested object assignment
361+ // This will be added to sp (post-processing) instead of ss (inline object)
362+ var valueJs = n2u ( col . toJS ( 'p' , query . defaultTableid , query . defcols ) ) ;
363+ // Generate code to create nested structure
364+ // e.g., for path ['details', 'stock']: r['details'] = r['details'] || {}; r['details']['stock'] = value;
365+ for ( var i = 0 ; i < arrowPath . length - 1 ; i ++ ) {
366+ var pathSoFar = arrowPath . slice ( 0 , i + 1 ) ;
367+ var accessor = pathSoFar
368+ . map ( function ( p ) {
369+ return "['" + escapeq ( p ) + "']" ;
370+ } )
371+ . join ( '' ) ;
372+ sp += 'r' + accessor + ' = r' + accessor + ' || {};' ;
373+ }
374+ var fullAccessor = arrowPath
375+ . map ( function ( p ) {
376+ return "['" + escapeq ( p ) + "']" ;
377+ } )
378+ . join ( '' ) ;
379+ sp += 'r' + fullAccessor + ' = ' + valueJs + ';' ;
380+
381+ // Use the first part of the path as the column name for metadata
382+ var colName = arrowPath [ 0 ] ;
383+ query . selectColumns [ escapeq ( colName ) ] = true ;
384+ var coldef = {
385+ columnid : colName ,
386+ } ;
387+ // Only add if not already added
388+ if ( ! query . xcolumns [ coldef . columnid ] ) {
389+ query . columns . push ( coldef ) ;
390+ query . xcolumns [ coldef . columnid ] = coldef ;
391+ }
392+ } else {
393+ ss . push (
394+ "'" +
395+ escapeq ( col . as || col . columnid || col . toString ( ) ) +
396+ "':" +
397+ n2u ( col . toJS ( 'p' , query . defaultTableid , query . defcols ) )
398+ ) ;
399+ // ss.push('\''+escapeq(col.toString())+'\':'+col.toJS("p",query.defaultTableid));
400+ //if(col instanceof yy.Expression) {
401+ query . selectColumns [ escapeq ( col . as || col . columnid || col . toString ( ) ) ] = true ;
338402
339- var coldef = {
340- columnid : col . as || col . columnid || col . toString ( ) ,
341- // dbtypeid:tcol.dbtypeid,
342- // dbsize:tcol.dbsize,
343- // dbpecision:tcol.dbprecision,
344- // dbenum: tcol.dbenum,
345- } ;
346- // console.log(2);
347- query . columns . push ( coldef ) ;
348- query . xcolumns [ coldef . columnid ] = coldef ;
403+ var coldef = {
404+ columnid : col . as || col . columnid || col . toString ( ) ,
405+ // dbtypeid:tcol.dbtypeid,
406+ // dbsize:tcol.dbsize,
407+ // dbpecision:tcol.dbprecision,
408+ // dbenum: tcol.dbenum,
409+ } ;
410+ // console.log(2);
411+ query . columns . push ( coldef ) ;
412+ query . xcolumns [ coldef . columnid ] = coldef ;
413+ }
349414 }
350415 } ) ;
351416 s += ss . join ( ',' ) + '};' + sp ;
0 commit comments