Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vano

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vano

small and flexible collection storage for nodejs

  • 0.1.4
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-87.14%
Maintainers
1
Weekly downloads
 
Created
Source

vano

npm version types size coverage vulnerabilities dependencies devDependencies License

small and flexible collection storage library suitable for small projects.

Installation

$ npm i vano

Usage

import vano, {file} from 'vano';

(async () => {
    const db = vano({adapter: file('./storage')});

    const characters = db.collection('characters', {
        name: '',
        age: 0,
    });
    
    characters.add({name: "john doe", age: 30});

    await characters.write();
})()

API

Library

vano(config: Config)

Config
requireddefaultdescription
adapterinterface for the communication between vano and io system. it can be file, memory or a custom function. adapter

Creates a new vano instance.

import vano, {memory} from 'vano';

const db = vano({adapter: memory()});

Adapter

file(base)

Reads/writes the collections as JSON file to the provided base directory.

import vano, {file} from 'vano';

const db = vano({adapter: file('./collections')});

memory()

Keeps all collections in the memory.

import vano, {memory} from 'vano';

const db = vano({adapter: memory()});

Custom

Custom adapters can be used to read and write collections from and in different formats. These have to adhere the Adapter interface and return a function with four of the following sub-functions:

functionparameterreturndescription
readkey: stringPromise<any> resource reading logic. should return anything deserialize is comfortable with.
writekey: string, data: anyvoidresource saving logic. data is previously by serialize processed.
serializedata: anyPromise<any>transform data into a processable form for write.
deserializedata: anyPromise<any>transform data into a processable form for read.
Example:
const adapterFactory = (someLibrary, someSerializer) => {
  const read = (key) => {
    return someLibrary.loadByKey(key);
  }

  const write = (key, value) => {
    someLibrary.saveByKey(key, value);
  }

  const serialize = (data) => {
    return someSerializer.serialize(data);
  }

  const deserialize = (data) => {
    return someSerializer.deserialize(data);
  }
}

Collection

db.collection(name[, schema])

Creates a collection with:

  • name (only alphanumeric)
  • optional schema (rough shape of every collection item)

vano uses schema for autocompletion and can be omitted if not necessary.

const col = db.collection('users', {name: "", age: 0});

col.read()

Asynchronously loads a collection into the memory via adapter, given a previously written collection exists.

col.read();

col.write()

Asynchronously saves a collection from the memory via adapter.

col.write();

col.add(item)

Adds an item to the collection and returns the unique id of the item inside the collection.

const id = col.add({name: "john doe", "age": 30});

col.all()

Returns all items from the collection.

const items = col.all();

col.count()

Returns the count of all items in the collection.

const count = col.count();

col.get(id)

Returns the item from the collection via id.

const item = col.get('ID');

col.remove(id)

Removes the item from the collection via id.

col.remove('ID');

col.update(id, update)

Updates the values of an item by an id and update object.

col.update('ID', {name: "max mustermann"});

col.reset()

Removes all items from the collection.

col.reset();

col.on(event, listener[, {once: bool])

Binds an event listener to one of the following actions add | update | remove.

const onAdd = (data) => console.log(data);
col.on('add', onAdd);

col.off(event, listener)

Unbinds the previously bound event listener.

const onAdd = (data) => console.log(data);
col.off('add', onAdd);

col.query()

Returns a query function for basic querying. See query.

const query = col.query();

Query

query.eq(key, value)

Selects items where item[key] is equal value and returns a new query function. Value can also be a regular expression.

const query = query.eq('name', 'doe');

query.neq(key, value)

Selects items where item[key] is not equal value and returns a new query function. Value can also be a regular expression.

const query = query.neq('name', 'doe');

query.gt(key, value)

Selects items where item[key] is greater than value and returns a new query function.

const query = query.gt('age', 20);

query.gte(key, value)

Selects items where item[key] is greater than or equal value and returns a new query function.

const query = query.gte('age', 30);

query.lt(key, value)

Selects items where item[key] is lesser than value and returns a new query function.

const query = query.lt('age', 20);

query.lte(key, value)

Selects items where item[key] is lesser than or equal value and returns a new query function.

const query = query.lte('age', 30);

query.skip(n)

Sets an offset of n and returns a new query function.

const query = query.skip(2);

query.limit(n)

Sets a limit of n items and returns a new query function.

const query = query.limit(10);

query.get()

Returns the queried items as an array.

const items = query.get();

ToDo

  • autocompletion via schema in collection.query() and collection.update()

Licence

MIT License, see LICENSE

Keywords

FAQs

Package last updated on 25 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc