Skip to content

OneAndOnlyFinbar/sequel-csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 

Repository files navigation

Sequel-CSV

Package for executing simple sql queries against a csv file.

Buy Me a Coffee at ko-fi.com

Installation

NPM

npm i sequel-csv

Yarn

yarn add sequel-csv

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 }]