sequel-csv
v1.6.1
Published
Perform sql operations against csv databases.
Downloads
9
Maintainers
Readme
Sequel-CSV
Package for executing simple sql queries against a csv file.
Installation
NPM
npm i sequel-csv
Yarn
yarn add sequel-csv
Documentation on GitHub
Usage
./table.csv
userId,level
1,5
2,10
3,40
main.js
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 }]