Skip to content
/ csvdb Public

A database module that uses a single csv file as data store.

Notifications You must be signed in to change notification settings

farmisen/csvdb

Repository files navigation

csvdb

Intro

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.

API

Table of Contents

connect

Creates a db connection to a csv file. In case the file does not exist, it will be created when first needed.

Parameters

  • path string The path to the csv file.

Examples

const db = await connect('./db.csv');

rows

Returns a copy of all the rows

Examples

:
db.rows();

Returns Array<Object> A copy of all the rows

find

Finds the rows that fulfill a predicate

Parameters

  • predicate function The predicate used to find the row

Examples

:
db.find(({bar}=>bar==='zed');

Returns Array<Object> A copy of all the found rows

create

Creates a new row

Parameters

Examples

db.create({foo: '1', bar: 'zed'})
  • Throws DuplicateRowError if trying to create a duplicate row

update

Updates an existing row

Parameters

  • row object The current row data
  • newRow object The updated row data

Examples

db.update({foo: '1', bar: 'zed'}, {foo: '1', bar: 'baz'})
  • Throws RowNotFoundError if trying to update a row that does not exist

update

Updates the first row that fulfills a predicate or create a new one

Parameters

  • predicate function The predicate used to find the row
  • newRow object The new/updated row data

Examples

db.createOrUpdate(({bar}=>bar==='zed', {foo: '1', bar: 'baz'});

exists

Checks if a row exists

Parameters

Examples

db.exists({foo: '1', bar: 'baz'});

Returns boolean true if the row exists, false otherwise

About

A database module that uses a single csv file as data store.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages