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
Param | Type | Description |
---|---|---|
countDocuemnts | number | Number of documents to generate |
exportConfig | export file config | Configuration 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
Param | Type | Description |
---|---|---|
data | any | Data you want to export |
exportConfig | export file config | Configuration 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
Param | Required | Type | Description |
---|---|---|---|
fileName | yes | string | Name of the file to generate |
location | yes | string | Path of the folder where the file will be saved |
format | yes | ('java' , 'csv' , 'typescript' , 'json' , 'javascript' , 'yaml' , 'postgresql' ) | File extension |