Options
All
  • Public
  • Public/Protected
  • All
Menu

cetriolino

Build Status Maintainability Greenkeeper badge

Simple key-value storage, with no runtime dependencies, written in TypeScript.

Heavily insipired by pickleDB.

Usage

import Cetriolino from 'cetriolino'

const db = new Cetriolino('db.json')

db.set('one', 1)
db.get('one') // 1

db.lcreate('hey') // or: db.set('hey', [])
db.lpush('hey', ['oh', "let's", 'go']) // 3
db.get('hey') // [ 'oh', 'let\'s', 'go' ]

db.dump()

Install

$ npm install cetriolino

or

$ yarn add cetriolino

To-Do

  • Add support for nested dictionaries

Index

Classes

Type aliases

Classes

Cetriolino

Cetriolino:

constructor

  • new Cetriolino(filePath: string, autoDump?: boolean): Cetriolino
  • Creates a new Cetriolino instance.

    See load for more info regarding the file loading.

    Parameters

    • filePath: string

      Path to the JSON file that will be used to persist the data.

    • Default value autoDump: boolean = false

      If enabled, Cetriolino will automatically save data to the specified file after every change.

    Returns Cetriolino

Private autoDump

autoDump: boolean

Private db

db: DB

Private filePath

filePath: string

append

  • Appends additional data to an existing value.

    If the key does not exists, it is created with the provided value.

    Parameters

    Returns void

clear

  • clear(): void
  • Deletes everything from the db.

    Returns void

dump

  • dump(): void
  • Manually dumps the db to the file given in the constructor/load method.

    The file is serialized to JSON and the db content needs to be able to be JSON.stringify-ed to be dumped without issues.

    More info on JSON.stringify` here

    Returns void

exists

  • exists(key: Key): boolean
  • Parameters

    Returns boolean

    Whether or not a given key value equals undefined

get

  • Parameters

    Returns Value | undefined

    Value of the Key, if found, undefined otherwise.

keys

  • keys(): string[]
  • Returns string[]

    Array containing all the keys in the db.

lappend

  • lappend(name: string, position: number, value: Value): void
  • Appends additional data to an existing list value.

    If the element at the chosen position does not exist, it is set with the given value.

    Parameters

    • name: string
    • position: number

      Position within the list of the element to be appended.

    • value: Value

    Returns void

lcreate

  • lcreate(name: string): void
  • Creates an empty list with the given name.

    Parameters

    • name: string

    Returns void

lget

  • lget(name: string, position: number): Value | undefined
  • Parameters

    • name: string
    • position: number

    Returns Value | undefined

    Value of the element at the given position of the given list, if it exists. undefined otherwise.

lgetAll

  • lgetAll(name: string): Value[]
  • Parameters

    • name: string

    Returns Value[]

    Whole list, if it exists.

llength

  • llength(name: string): number
  • Parameters

    • name: string

    Returns number

    Length of the given list, if it exists.

load

  • load(filePath: string): void
  • Manually loads and parses a JSON file to use as db.

    Any JSON file can be used as a starting point. If the given file does not exist, the db will be initialized empty.

    Parameters

    • filePath: string

    Returns void

lpop

  • lpop(name: string): Value | undefined
  • Pops last element from the list.

    Parameters

    • name: string

    Returns Value | undefined

    The value of the element if the list has any, undefined otherwise.

lpush

  • lpush(name: string, value: Value | Value[]): number
  • Pushes additional value(s) to an existing list.

    Parameters

    Returns number

    New length of the list.

lremove

  • lremove(name: string): void
  • Deletes an existing list with the given name.

    Parameters

    • name: string

    Returns void

random

  • Returns Value

    Random value chosen from all of the available keys in the db.

remove

  • remove(key: Key): void
  • Deletes an existing key.

    Parameters

    Returns void

set

  • set(key: Key, value: any): void
  • Creates a new values or updates an existing one.

    Parameters

    • key: Key
    • value: any

    Returns void

Private throwIfNotArray

  • throwIfNotArray(name: string): void
  • Parameters

    • name: string

    Returns void

Type aliases

DB

DB: {}

Type declaration

  • [key: string]: any

Key

Key: string

Value

Value: any

Legend

  • Constructor
  • Method
  • Private property
  • Private method

Generated using TypeDoc