@teddy1565/csv-pattern
v1.1.1
Published
```js
Downloads
7
Readme
csv-pattern
How to Use
Create Model
const path = require('path');
const BASIC_MODEL = {
fileName: '$pid/$name/output.csv',
fields: [
{ colName: 'date', type: 'number' },
{ colName: 'sys', type: 'string' }
]
};
const options = {
standdir: path.join(__dirname, 'output');
}
const model = new csv(BASIC_MODEL, options);
async function progress () {
await csv.create({
pid: 'test',
name: 'james'
});
// new csv file in __dirname/output/test/james/output.csv
await csv.insert({
pid: 'test',
name: 'james'
}, [
{
date: Date.now(),
sys: 'hello world'
},
{
date: 123456,
sys: 'good bye'
}
]);
/*
__dirname/output/test/james/output.csv
pid;name
1654430957237;"hello world"
123456;"good bye"
*/
let payload = await csv.read({
pid: 'test', //must
name: 'james' //optional
}, [
{
callback:(x) => {
console.log(x);
/*
first round:
{
pid: "1654430957237",
name: "hello world"
}
second round:
{
pid: "123456"
name: "good bye"
}
*/
if (x.pid === "123456") {
return x;
}
}
}
]);
console.log(payload);
/*
[
{
pid: "123456",
name: "good bye"
}
]
*/
}