4.0.1 • Published 7 months ago

@decaded/nyadb v4.0.1

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

NyaDB

Simple JSON "database" for NodeJS.

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


All databases are stored as separate JSON files 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.json'

Inserting data

const mockDatabase = {
	yellow: ['banana', 'citrus'],
	red: ['apple', 'paprika'],
};
nyadb.set('test', mockDatabase); // Saves data in 'test.json'

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 'test.json'

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 non-negative integerSpecify the number of spaces for indentation. Only applicable if formattingStyle is set to "space".
encodingutf8Any valid encoding supported by Node.jsSpecify the encoding for file input/output operations.
enableConsoleLogsfalsetrueEnable or disable logging output to the console. Errors will be logged regardless of this setting.

Example

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

Note

  • Changes to these settings will take effect immediately on initialization.
  • To return to the default values, simply remove the setting.

Migration Guide

Compatibility with previous versions

NyaDB version 4 transitions from a single-file database structure (database.json) to a multi-file storage system, where each database is stored as its own JSON file.

If migrating from version 3.x or earlier, the system will automatically detect an existing database.json file and split it into multiple files.
This migration is one-way and cannot be reversed. The original database.json file will be backed up as database_backup.json in the NyaDB folder. However, it's recommended to create your own backup before upgrading.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Like what I do?

If you find this project helpful or fun to use, consider supporting me on Ko-fi! Your support helps me keep creating and improving.

ko-fi

4.0.1

7 months ago

4.0.0

7 months ago

3.0.0

1 year ago

2.0.0

2 years ago

1.6.0

2 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.2.0

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago