ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

Exporting JSStore Data to a CSV/XLSX #115

Closed rkolagatla closed 5 years ago

rkolagatla commented 5 years ago

Hi, After inserting the data into JSStore is it possible to export the data to a CSV or an Excel File. Thanks, Rajesh

ujjwalguptaofficial commented 5 years ago

Hi You can export data into any format. You need to fetch data that you want to export using select query and then you can export to any format.

Here is an example to export as json -

function exportAsJson(data) {
    let dataStr = JSON.stringify(jsonData);
    let dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr);

    let exportFileDefaultName = 'data.json';

    let linkElement = document.createElement('a');
    linkElement.setAttribute('href', dataUri);
    linkElement.setAttribute('download', exportFileDefaultName);
    linkElement.click();
}

var datas = await jsStoreCon.select({
    from: 'customers'
});

exportAsJson(data);

Similarly you can export to other formats. Here is a link which explains exporting into csv - https://www.codevoila.com/post/30/export-json-data-to-downloadable-file-using-javascript