Repository navigation
Description
What happens today
- For
INTO OBJECT(),compileInScope(src/select/select.js) setsquery.intoObject(line 303), andcompileSelect1(src/select/columns.js, line 503) then compiles an arrow column without alias (a->b->c) into nested assignments. - It also sets
query.preserveArrayResult(line 483). Without that flagqueryfn(src/select/queryfn.js, line 72) turns a source's array into its length whenever the query has an INTO. - Every INTO target becomes generated code in
compileInScope(lines 418-512).query.intofnsandquery.intoallfnsare strings turned into functions withnew Function, called at the end ofqueryfn3(lines 526-540). - Modifiers are a
switchinmodify()(src/select/select.js, line 940).
What to change
-
In
src/select/select.jsreplace theswitchinmodify()with a table of functions that read{columns, rows, distinct}.columnscomes fromresultColumns(Decide the result columns of a SELECT in one function and let modify() read them from it #2651).const modifiers = { VALUE: r => (r.rows.length ? r.rows[0][firstKey(r)] : undefined), COLUMN: r => { const k = firstKey(r); const a = r.rows.map(t => t[k]); return r.distinct ? distinctArray(a) : a; }, RECORDSET: r => new alasql.Recordset({columns: r.columns, data: r.rows}), // ROW, MATRIX, INDEX, TEXTSTRING, ALASQL_DETAILS the same way };
-
Remove
query.intoObjectand the arrow branch ofcompileSelect1. The compiler records the path of an arrow column without alias on its column (coldef.path = ['a', 'b', 'c']).alasql.into.OBJECTinsrc/formats/into.jsbuilds the nested objects fromcolumns, plain columns first and nested ones after. -
Remove
query.preserveArrayResultand the array-to-length conversion inqueryfn. Eachalasql.intofunction and the table,?and@variabletargets return whatalasql()returns today. Turnintofnsandintoallfnsinto plain functions of(result, params, cb). -
INTO formats keep taking their columns from the first row.
What stays the same
- The output of every modifier and the return value and file content of every INTO format.
- The key order of
INTO OBJECT(), and an arrow column with an alias stays flat. - SELECT INTO a table keeps its type conversion.
- No result changes.
Done when
- A new test file named after this issue pins the return value of
SELECT ... INTOfor OBJECT, JSON, CSV, TXT, a table,?,$nameand@variable, synchronously and with a callback, and the output of every modifier over a table,?and an empty result. src/select/columns.jsandsrc/select/queryfn.jshave no code that depends on the kind of INTO or on the modifier.- The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.
Activity
[-]Review #2276 for code improvements: INTO OBJECT() changes how the SELECT list is compiled[/-][+]Let modifiers and INTO formats only read the finished result[/+]