Package for executing simple sql queries against a csv file.
NPM
npm i sequel-csv
Yarn
yarn add sequel-csv
userId,level
1,5
2,10
3,40
const { Database } = require('./package/index.js');
const database = new Database();
/*
By default when registering a new table the table name is taken from the file name, excluding path and
extension.
To set a custom schema name provide the name as a string in the second parameter.
*/
database.registerSchema('./table.csv')
//Get all rows
const results = await table.query('SELECT * FROM test');
console.log(results) // [{ userId: 1, level: 5 }, { userId: 2, level: 10 }, { userId: 3, level: 40 }]
//Examples of filtering results
const results = await table.query('SELECT * FROM test WHERE level > 10');
console.log(results); // [{ userId: 3, level: 40 }]
const results = await table.query('SELECT * FROM test WHERE userId = 1');
console.log(results); // [{ userId: 1, level: 5 }]