
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@byte-this/simple-nd-base
Advanced tools
A simple ndjson based database useful for mockups, testing, and quickly getting projects off of the ground.
A simple ndjson based database useful for mockups, testing, and quickly getting projects off of the ground.
This library provides a simple-to-use out-of-the-box file database reader and writer. Each database will have its own ndjson file (newline-deliniated json) which will be the subject of that database's CRUD operations. Useful for:
For our website www.bytethisstore.com, we used this implementation to start coding before we had officially decided upon what database technology to use.
We recommend you use this in conjunction with a data access layer in this manner such as this:
For more information and a deeper analysis of this methodology, visit our article on the topic: https://bytethisstore.com/articles/pg/database-decoupled
npm install @byte-this/simple-nd-base
The FileDatabase class implements both interfaces shown below. When creating connection objects, utilize the functionality provided:
/**
* Interface for the read operations the FileDatabase will provide
* The interface is a generic (parameterized) type:
* -> DataType is the type of the record to be stored (can be set as 'any' if needed)
*/
export interface iFileDatabaseReader<DataType> {
/**
* Get all records at once (can be problematic if the number of records is large)
* @param waitForUnlock: if false, should return result immediately, otherwise, wait for pending operations
*/
getAllRecords(waitForUnlock: boolean): Promise<DataType[]>;
/**
* Find a single record which matches some callback criteria
* @param waitForUnlock: if false, should return result immediately, otherwise, wait for pending operations
*/
findRecord(
callback: (record: DataType) => boolean | Promise<boolean>,
waitForUnlock: boolean
): Promise<DataType | undefined>;
/**
* Find all records which match some callback criteria
* @param waitForUnlock: if false, should return result immediately, otherwise, wait for pending operations
*/
findRecords(
callback: (record: DataType) => boolean | Promise<boolean>,
waitForUnlock: boolean
): Promise<Array<DataType>>;
/**
* Iterate over all records and perform some action. Return false or Promise<false> to stop iterating
* @param waitForUnlock: if false, should return result immediately, otherwise, wait for pending operations
*/
forEachRecord(
callback: (record: DataType) => boolean | Promise<boolean>,
waitForUnlock: boolean
): Promise<void>;
/**
* Get the number of records in the database
* @param waitForUnlock: if false, should return result immediately, otherwise, wait for pending operations
*/
getNumRecords(waitForUnlock: boolean): Promise<number>;
/**
* Get the size of the database on the filesystem
*/
getDatabaseSize(): Promise<number>;
}
/**
* Interface for the write operations the FileDatabase will provide
* The interface is a generic (parameterized) type:
* -> DataType is the type of the record to be stored (can be set as 'any' if needed)
*/
export interface iFileDatabaseWriter<DataType> {
/**
* Add a single record of DataType
* @param record DataType
*/
addRecord(record: DataType): Promise<void>;
/**
* Add many records of DataType
* @param record DataType
*/
addRecords(records: DataType[]): Promise<void>;
/**
* Update multiple records based on some callback
* Will update ALL records where the return of the callback is true or Promise<true>
* @param findCallback
* @param newRecord
*/
updateRecords(
findCallback: (record: DataType) => boolean | Promise<boolean>,
newRecord: DataType
): Promise<void>;
/**
* Delete multiple records based on some callback
* Will delete ALL records where the return of the callback is true or Promise<true>
* @param findCallback
* @param newRecord
*/
deleteRecords(
findCallback: (record: DataType) => boolean | Promise<boolean>
): Promise<void>;
/**
* Delete all records unconditionally
*/
deleteAllRecords(): Promise<void>;
}
FAQs
A simple ndjson based database useful for mockups, testing, and quickly getting projects off of the ground.
The npm package @byte-this/simple-nd-base receives a total of 4 weekly downloads. As such, @byte-this/simple-nd-base popularity was classified as not popular.
We found that @byte-this/simple-nd-base demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.