Skip to main content

CSV

You can export the data generated by schemas or any type of data to CSV format

What can you export?

Data can only be exported in two ways:

  • An array with similar objects (objects must have the same fields)

    // ✅ correct
    await chaca.export([
    { id: 1, name: 'Amaya' },
    { id: 2, name: 'Jose' },
    { id: 3, name: 'Hector' },
    ])

    // ❌ wrong
    await chaca.export([
    { id: 1, name: 'Amaya' },
    { id: 2, name: 'Jose' },
    {
    id: 3,
    name: 'Hector',
    // this field does not exists in other objects
    image: 'https://pixabay.com/get/gced34cca12f5b9cb12e765ebc87a3be51118a7437a87d4636caa28a26ae72d433b2554e104ca79735997400b3fa19634c943d6d63cf5b9e7be93b525d459d86e_1280.jpg',
    },
    ])
  • An object with data

Example case

const userSchema = chaca.schema({
id: schemas.id.uuid(),
username: schemas.internet.userName(),
image: { type: schemas.image.people(), posibleNull: 50 },
})

await userSchema.generateAndExport({
filaName: 'data',
format: 'csv',
location: 'folder',
})

For example, if we have this schema, we generate 5 documents and export them in CSV format, we will obtain the following result

id,username,image
"b178e855-44bc-427e-8cc0-99a56d80439a","Nova.",NULL
"7d800115-b986-4310-a49c-0038c8eddd20","Leilani.","https://images.pexels.com/photos/886285/pexels-photo-886285.jpeg"
"c460e947-bb9c-42ce-b6db-3831560e38b0","Charlotte_",NULL
"76aae93c-a8d5-45e6-9dba-78385b300cb4","Luna191",NULL
"0e630ecb-da45-4bda-9d79-01d31b115b7d","Lucy544","https://pixabay.com/get/gced34cca12f5b9cb12e765ebc87a3be51118a7437a87d4636caa28a26ae72d433b2554e104ca79735997400b3fa19634c943d6d63cf5b9e7be93b525d459d86e_1280.jpg"
You can't export complex data

Until this version in CSV format, it is not possible to export complex data such as arrays or objects as field values.

info

If the data of several schemas are exported, a zip file will be created with several csv files with the content of each of the schemas