Skip to main content

Overview

If you want to export certain data generated by the schemas or any type of data to an external file, you can use the following methods

Export schema data

schema.generateAndExport(countDocuments, exportConfig)

With this method you can generate a specific amount of documents from a created schema and it will be exported to a file. This is an asynchronous function that returns a string with the path of the created file.

Params

ParamTypeDescription
countDocuemntsnumberNumber of documents to generate
exportConfigexport file configConfiguration of the file to create

Example

const schema = chaca.schema({ ...fields })

const fileLocation = await schema.generateAndExport(50, {
fileName: 'schemaData',
location: 'location/folder',
format: 'csv',
})

Export any type of data

chaca.export(data, exportConfig)

With this function you can export any type of data to one of the formats defined by the package This is an asynchronous function that returns a string with the path of the created file.

Params

ParamTypeDescription
dataanyData you want to export
exportConfigexport file configConfiguration of the file to create

Example

const data = [1, 'I love Chaca', {}]

const fileLocation = await chaca.export(data, {
fileName: 'data',
location: 'location/folder',
format: 'javascript',
})

Export multiple schemas data

chaca.exportFromSchemas(schemas, exportConfig, logConfig)

Export file config

To configure the parameters of the file to be exported, an object must be passed with the following fields

ParamRequiredTypeDescription
fileNameyesstringName of the file to generate
locationyesstringPath of the folder where the file will be saved
formatyes('java', 'csv', 'typescript', 'json', 'javascript', 'yaml', 'postgresql')File extension