JSON object import

This commit is contained in:
Jan Prochazka
2024-09-17 12:52:53 +02:00
parent 503e09ddd1
commit fd8a28831e
2 changed files with 54 additions and 14 deletions

View File

@@ -89,8 +89,34 @@ test('JSON array import test', async () => {
const rows = await getReaderRows(reader);
expect(rows.length).toEqual(2);
expect(rows[0]).toEqual({
id: 1,
val: 'v1',
});
expect(rows).toEqual([
{ id: 1, val: 'v1' },
{ id: 2, val: 'v2' },
]);
});
test('JSON object import test', async () => {
const jsonFileName = tmp.tmpNameSync();
fs.writeFileSync(
jsonFileName,
JSON.stringify({
k1: { id: 1, val: 'v1' },
k2: { id: 2, val: 'v2' },
})
);
const reader = await dbgateApi.jsonReader({
fileName: jsonFileName,
jsonStyle: 'object',
keyField: 'mykey',
});
const rows = await getReaderRows(reader);
expect(rows.length).toEqual(2);
expect(rows).toEqual([
{ mykey: 'k1', id: 1, val: 'v1' },
{ mykey: 'k2', id: 2, val: 'v2' },
]);
});