A database module that uses a single csv file as data store. This has been hacked in a few hours out of boredom and you should definitively not use it.
Creates a db connection to a csv file. In case the file does not exist, it will be created when first needed.
path
string The path to the csv file.
const db = await connect('./db.csv');
Returns a copy of all the rows
:
db.rows();
Returns Array<Object> A copy of all the rows
Finds the rows that fulfill a predicate
predicate
function The predicate used to find the row
:
db.find(({bar}=>bar==='zed');
Returns Array<Object> A copy of all the found rows
Creates a new row
row
object The row data
db.create({foo: '1', bar: 'zed'})
- Throws DuplicateRowError if trying to create a duplicate row
Updates an existing row
db.update({foo: '1', bar: 'zed'}, {foo: '1', bar: 'baz'})
- Throws RowNotFoundError if trying to update a row that does not exist
Updates the first row that fulfills a predicate or create a new one
db.createOrUpdate(({bar}=>bar==='zed', {foo: '1', bar: 'baz'});
Checks if a row exists
row
object The row data
db.exists({foo: '1', bar: 'baz'});
Returns boolean true if the row exists, false otherwise