AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

joinstar option not working #1004

Open mathiasrw opened 6 years ago

mathiasrw commented 6 years ago

Spawned from https://github.com/agershun/alasql/issues/547#issuecomment-388832335


The alasql.options.joinstar option seems not working now.

If we reproduce the example of @filipkis, but defining alasql.options.joinstar = 'underscore', the result is not the expected:

var data = [{ dep: 'A', qt: 10, price: 5, extra: 1}];
var data2 = [{ dep: 'B', qt: 2, price: 5}];
alasql.options.joinstar = 'underscore';  
var res = alasql('SELECT * FROM ? as a JOIN ? as b',[data,data2]);

results is:

[{"dep":"B","qt":2,"price":5,"extra":1}]

and it should be

[{ data_dep: 'A', data_qt: 10, data_price: 5, data_extra: 1,data2_dep: 'B', data2_qt: 2, data2_price: 5 }]

if I'm not wrong.

txusma23 commented 6 years ago

After some research this is what I found:

The queryobject has a sources property where the tables that appear in the select clause are defined. If we use arrays instead of tables, the sources are created but their columns property are not populated. Then the compileSelectStar function requires that the columns property of every source are populated in order to decide the names of the final columns according to the alasql.options.joinstar option (line 9377).

The same problem happens when you create a table and then add data from an array. The data is added, but the columns property of the table in the database is not updated.

mathiasrw commented 6 years ago

Thank you so much for looking into this :)

joewandy commented 6 years ago

Is there any resolution or workaround to this issue?

mathiasrw commented 6 years ago

Not that I know of. Any inputs or PR's would be greatly appreciated.