Skip to content

WASM/JS implementation of csvs, a general-purpose plain-text relational database. Serverless CRUD.

License

Notifications You must be signed in to change notification settings

fetsorn/csvs-js

Repository files navigation

csvs-js

Create, read, update and delete records in a csvs database, run powerful search queries.

Setup

# install
npm i @fetsorn/csvs-js

# test js functions
yarn test
# test wasm functions in the browser with index.html
npx http-server

# publish
yarn build
npm publish

Getting started

// functions exported by csvs-js require a callback
// that describes how to fetch and write files from a csvs database

function fetchDataMetadir(path) {
  // fetch file from path
}

function writeDataMetadir(path, content) {
  // write content to file at path
}

const callback = {
  fetch: fetchDataMetadir,
  write: writeDataMetadir
}

// get array of results from query
var searchParams = new URLSearchParams()
searchParams.set('val1', 'foo')
const query1 = await queryMetadir(searchParams, callback, true)
console.log(query1)
//  [{"val1": "foo",
//    "val2": "bar",
//    "UUID": "b29b9ee3ad01efde7d8694cea4a37844c677ad807b61fa90c44409a21710035c"}]

// if object has no uuid
// editEntry creates a new record in the database
// and returns it
let entryBaz = {"val1": "foo", "val2": "baz"}
let entryNew1 = await editEntry(entryBaz, callback)
console.log(entryNew1)
// {"val1": "foo",
//  "val2": "baz",
//  "UUID": "33d6e141e92852d5be1930458c1713c2bed09f42d545bf95c0f6d6e271b4077a"}

const query2 = await queryMetadir(searchParams, callback, true)
console.log(query2)
//  [{"val1": "foo",
//    "val2": "bar",
//    "UUID": "b29b9ee3ad01efde7d8694cea4a37844c677ad807b61fa90c44409a21710035c"},
//   {"val1": "foo",
//    "val2": "baz",
//    "UUID": "33d6e141e92852d5be1930458c1713c2bed09f42d545bf95c0f6d6e271b4077a"}]

// if object has a uuid
// editEntry updates the record with matching uuid
// and returns it
let entryBarbaz = {"val1": "foo",
                   "val2": "barbaz",
                   "UUID": "33d6e141e92852d5be1930458c1713c2bed09f42d545bf95c0f6d6e271b4077a"}
let entryNew2 = await editEntry(entryBarbaz, callback)
console.log(entryNew)
// {"val1": "foo",
//  "val2": "barbaz",
//  "UUID": "33d6e141e92852d5be1930458c1713c2bed09f42d545bf95c0f6d6e271b4077a"}

const query3 = await queryMetadir(searchParams, callback, true)
console.log(query3)
//  [{"val1": "foo",
//    "val2": "bar",
//    "UUID": "b29b9ee3ad01efde7d8694cea4a37844c677ad807b61fa90c44409a21710035c"},
//   {"val1": "foo",
//    "val2": "barbaz",
//    "UUID": "33d6e141e92852d5be1930458c1713c2bed09f42d545bf95c0f6d6e271b4077a"}]

// deleteEntry deletes a record with matching uuid
let uuid = "b29b9ee3ad01efde7d8694cea4a37844c677ad807b61fa90c44409a21710035c"
await deleteEntry(uuid, callback)

const query4 = await queryMetadir(searchParams, callback, true)
console.log(query4)
//  [{"val1": "foo",
//    "val2": "barbaz",
//    "UUID": "33d6e141e92852d5be1930458c1713c2bed09f42d545bf95c0f6d6e271b4077a"}]

More csvs projects

csvs-spec - format description

qualia - Web UI and desktop app

csvs-sh - command-line interface

wasm-grep - ripgrep compiled to WASM

About

WASM/JS implementation of csvs, a general-purpose plain-text relational database. Serverless CRUD.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages