2.0.0 • Published 3 months ago

@decaded/nyadb v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

NyaDB

Simple JSON "database" for NodeJS.

npm (scoped) npm bundle size (scoped) npm GitHub Node.js version


All files (database file and config) will be stored in the NyaDB folder in the project's root directory.


Node.js Version Requirement

This package requires Node.js version 12.x or higher for compatibility with the features and syntax used in the codebase.

Installation

npm install @decaded/nyadb

Usage

Initialize

const NyaDB = require('@decaded/nyadb');
const nyadb = new NyaDB();

You can pass settings on initialization. More information below..

Create new database

nyadb.create('test'); // Creates a new database called 'test'

Inserting data

const mockDatabase = {
	yellow: ['banana', 'citrus'],
	red: ['apple', 'paprika'],
};
nyadb.set('test', mockDatabase); // Sets the database 'test' to the 'mockDatabase' object

Retrieving data

nyadb.get('test'); // Returns the 'test' database

//  {
//    "yellow": ["banana", "citrus"],
//    "red": ["apple", "paprika"],
//  }
nyadb.getList(); // Returns the names of all databases in an array

// ['test']

Deleting data

nyadb.delete('test'); // Deletes the database 'test'

Configuration Settings

You can customize the behavior of the application by modifying the following settings.

SettingDefault ValueOptional ValuesDescription
formattingEnabledtruefalseEnable or disable formatting of output.
formattingStyletabspaceChoose between using tabs or spaces for indentation.
indentSize4Any positive integerSpecify the number of spaces for indentation. Only applicable if formattingStyle is set to "space".
encodingutf8utf16, utf16le, utf16be, ascii, latin1...Specify the encoding for file input/output operations. Any encoding supported by Node.js and JSON should work.
enableConsoleLogsfalsetrueEnable or disable logging output to the console. Errors will be logged regardless of this setting.

The configuration file is created only after passing the data on initialization, like so:

const nyadb = new NyaDB({ formattingStyle: 'space', indentSize: 5 });

Note:

  • Changes to these settings will only take effect after restarting the application, so on the first run it will still have default settings.
  • The JSON file containing these settings is located in the NyaDB folder in the project's root directory and by default is named customDatabaseConfiguration.json.
  • To return to the default configuration values, simply remove custom settings from the initialization.

Migration Guide

Compatibility with Databases from Version 1.x

NyaDB version 2.0 is fully compatible with databases created using version 1.x. No data migration is required when upgrading to version 2.0.

Method Renaming

In version 2.0, some method names have been updated for consistency and clarity. Here's a quick guide on how to update your code:

  • createDatabase() is now create()
  • deleteDatabase() is now delete()
  • setDatabase() is now set()
  • getDatabase() is now get()
  • getDatabaseList() is now getList()

For example, if you previously used nyadb.createDatabase('test'), you should now use nyadb.create('test').

Passing Arguments

Passing arguments on initialization is completely optional and compatible with version 1.x, meaning if you initialized it like this:

const NyaDB = require('@decaded/nyadb');
const nyadb = new NyaDB();

it will still work in version 2.0 the same way as it did before. Just make sure you updated your methods as shown above.

Deprecation Notice

Please note that the previous method names have been deprecated since version 1.5.0 and were removed in 2.0.


Like what i do?

2.0.0

3 months ago

1.6.0

10 months ago

1.5.1

1 year ago

1.5.0

1 year ago

1.2.0

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago