The Wayback Machine - https://web.archive.org/web/20210107201213/https://github.com/dfahlander/Dexie.js/issues/1070
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtered Export produces invalid JSON file with an extra comma in data row array #1070

Open
alperyazgan opened this issue Jul 5, 2020 · 3 comments

Comments

@alperyazgan
Copy link

@alperyazgan alperyazgan commented Jul 5, 2020

Hi,

Today I faced a problem with filtered export json file;
Normally I do filtering for many tables without any problems, but this table strangely produces an extra comma in the exported data row array;

Here is the main export function I use for the table;

async function exportMember(memberNo, exportName) {
    if (db === null || memberNo === "") return false;

    memberNo = parseInt(memberNo);

    let rowCount = 0;
    let dbAsBlob = await db.export({
      prettyJson       : true,
      progressCallback : exportProgress,
      noTransaction    : true,
      filter           : (table, value) => {
        let returnValue = table === "member" && value.memberNo === memberNo;
        if (returnValue) rowCount++;
        return returnValue;
      }
    });
    //let jsonDB = JSON.parse(await dbAsBlob.text()); // It has a extra "," in the row list

    //jsonDB.data.tables.forEach(function (table) {
    //  table.rowCount = table.name === "member" ? rowCount : 0;
    //});
    //dbAsBlob = new Blob([JSON.stringify(jsonDB, undefined, 2)], { type : dbAsBlob.type });
    download(dbAsBlob, `${exportName || "ExportedMemberWithNo("}${memberNo}).json`, "application/json");

    return true;
  }

and this func generates a file like this

{
  "formatName": "dexie",
  "formatVersion": 1,
  "data": {
    "databaseName": "MemberDB",
    "databaseVersion": 1,
    "tables": [{ "name": "member", "schema": "++id,&memberNo", "rowCount": 1 }],
    "data": [
      {
        "tableName": "member",
        "inbound": true,
        "rows": [
          {
            "memberNo": 2592,
            "fullName": "Some Name",
            "photo": "data:image/jpeg;base64, very long jpeg data",
            "eMail": "[email protected]",
            "mobilePhoneNo": "5555555",
            "bloodType": "A Rh(+)",
            "id": 860,
            "birthday": "01.03.1978",
            "someFieldsAgain": "with some data",
            "workPhoneNo": null
          }
          ,
        ]
      }
    ]
  }
}

I use this approach for the other tables with no problem, only difference is the total row count which is 5500, the other tables have less than 100 rows.

@alperyazgan alperyazgan changed the title Filtered Export produces invalid JSON file with extra comma in data row array Filtered Export produces invalid JSON file with an extra comma in data row array Jul 5, 2020
@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Jul 6, 2020

Thanks!

I think this issue is a "good first issue" for any contributor to fix.

  1. Fork or update your existing fork of Dexie.js
  2. In root of Dexie.js repo: npm install && npm run build
  3. cd addons/dexie-export-import && npm install && npm run build && npm test
  4. In code editor, open addons/dexie-export-import/test/edge-cases.ts and add a unit test that verifies this issue. Look into the other tests - in how they alter the option numRowsPerChunk to lower it in order to reproduce the issue easier.
  5. Try finding the root of the problem and fix it.
  6. npm run build && npm test

If no one has fixed it within two weeks, give me a reminder here.

@ghost
Copy link

@ghost ghost commented Sep 22, 2020

Hello, I would like to be assigned to solve this issue.

@dfahlander dfahlander assigned ghost Sep 22, 2020
@dfahlander
Copy link
Owner

@dfahlander dfahlander commented Sep 22, 2020

Thanks! I assigned it to you. It would be great if you also could add a test that reproduces the error if you have a chance. Please report back if you for some reason didn't complete it or got stuck so we can assign it to someone else.

@ghost ghost mentioned this issue Sep 23, 2020
@dfahlander dfahlander unassigned ghost Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.