
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@jnode/dbSimple database package for Node.js.
npm i @jnode/db
// Import from the main entry
const { jdb, dble, ljson } = require('@jnode/db');
// Or import from subpaths
const { JDBFile } = require('@jnode/db/jdb');
const { DBLEFile, DBLEUInt32Field, DBLEStringField } = require('@jnode/db/dble');
const { LJSONFile } = require('@jnode/db/ljson');
LJSON is perfect for small, append-only or simple text-based data.
const { LJSONFile } = require('@jnode/db/ljson');
(async () => {
// Load or create a database
const db = await LJSONFile.load('./data.ljson');
// Push new data
await db.push({ name: 'Alice', score: 10 });
await db.push({ name: 'Bob', score: 15 });
// Update data (adds to numbers/strings, merges objects, etc.)
await db.update(0, { score: 5 }); // Alice's score becomes 15
// Overwrite or delete
await db.overwrite(1, { name: 'Bob', score: 20 });
await db.delete(0); // Deletes Alice
})();
DBLE is a fast, structured, binary-based database with schema definitions.
const { DBLEFile, DBLEUInt32Field, DBLEStringField } = require('@jnode/db/dble');
(async () => {
// Create a new DBLE database with a defined schema
const db = await DBLEFile.create('./users.dble', {
fields:[
new DBLEUInt32Field('id', true), // 'id' is a key (indexed)
new DBLEStringField(255, 'username')
]
});
// Append lines (rows)
await db.appendLine({ id: 1, username: 'justapple' });
await db.appendLine({ id: 2, username: 'nick' });
// Fast query using indexed keys
const nickData = await db.readLineByField('id', 2);
console.log(nickData.fields.username); // 'nick'
// Safely close the database
await db.close();
})();
The @jnode/db package provides three core components to handle different data persistence needs seamlessly:
.jdb): The base binary file format manager. It handles basic file magic headers, versions, and provides raw file access wrappers..dble): Stands for JDB Lite Extended. It is a simple, fast, schema-defined binary database built on top of JDB. It supports fixed-length fields, typed records, automatic indexing, deleted space reuse, and dynamic extended fields..ljson): Stands for LineJSON. It follows the JLD (JustLineData) text-based format. It stores an array of JSON objects line-by-line and processes append-only mutations like updates, deletions, and overwrites, making it extremely durable for logging or small configs.Advanced Usage (DBLE): Because DBLE queues its async file operations internally to ensure data integrity, executing multiple interdependent queries could sometimes face race conditions if another script block appends data concurrently. If you want to run complex logic that involves multiple operations, you can use the internal task queue method ._doTask(async () => { ... }) and pass true to the skipQueue argument of any method called inside. This bypasses the queue check internally and ensures your complex block runs uninterruptedly and safely!
jdb.JDBFileThe base JDB file manager for handling binary file headers.
JDBFile.load(path)path <string> Path to the file.Opens an existing JDB file and verifies its format and magic string.
JDBFile.create(path[, options])path <string> Path to the file.options<Object>
Creates a new JDB file (fails if the file already exists).
JDBFile.forceCreate(path[, options])path <string> Path to the file.options <Object> Same asJDBFile.create().Forces creation of a new JDB file, overwriting if it already exists.
jdb.close()Closes the internal file handle safely.
jdb.sync()Synchronizes the file's data and metadata to the storage device.
jdb.datasync()Synchronizes only the file's data to the storage device.
jdb._init([options])jdb._loadHead()Internal methods to initialize and load file headers.
dble.DBLEFileThe main manager for DBLE files, which extends JDBFile.
DBLEFile.load(path[, options])path<string> Path to the file.options <Object>
DBLEFile.create(path, options)DBLEFile.forceCreate(path, options)path <string> Path to the file.options<Object>
fields <DBLEField[]> Required. An array of field instances defining the table structure.extBaseLength<number> Optional override to calculate extension field base length manually.DBLEFile.load options.Creates (or forcefully overwrites) a DBLE database file.
dble.getField(line, field[, skipQueue])line<number> The index of the line/row.field<string> Field name.skipQueue <boolean> Skip the internal task queue execution lock.Retrieves a specific field from a specific line.
dble.getExt(line[, skipQueue])Retrieves the concatenated binary extended data for a line. Returns a <Buffer>.
dble.getLineByField(field, query[, skipQueue])Finds the numeric line index where the specified field matches the query. If the field was declared with isKey: true, this operation is O(1) via index map. Otherwise, it executes a sequential scan.
dble.readLine(line[, skipQueue])Reads a full line structure at the target index. The resolved object looks like: { type, nextLine, fields: { ... } }.
dble.readLineByField(field, query[, skipQueue])Combination of getLineByField and readLine. Returns the parsed line object.
dble.findLine(fn[, skipQueue])Iterates over all lines and returns the line index when the async callback fn(parsedLine) returns true.
dble.forEachLine(fn, start, to[, skipQueue])Executes the callback fn(parsedLine, lineIndex) on every valid database line starting from start up to to.
dble.setLine(line, fields[, skipQueue])Updates specific fields on an existing line. Pass {} to fields to just touch it, or pass an object with partial properties. Also updates indexes seamlessly. If line is not a number, it behaves like appendLine.
dble.setLineByField(field, query, fields[, skipQueue])Finds the line via field/query matching, and updates it.
dble.appendLine(fields[, skipQueue])Appends a new record to the database, or overwrites an empty (deleted) line dynamically for disk space reuse. Returns the new line index.
dble.deleteLine(line, releaseSpace[, skipQueue])Flags a line as deleted. If releaseSpace is true, it dynamically links the block to the empty line manager to allow future appendLine calls to overwrite this spot.
dble.deleteLineByField(field, query, releaseSpace[, skipQueue])Finds a line by a query and deletes it.
dble.cleanUp([skipQueue])Loops over the DB sequentially, completely clearing up lines marked as deleted and moving them to the empty reusable line linked list.
dble.setExt(line, ext[, skipQueue])Saves an arbitrary binary<Buffer> to a line's extension block. If the buffer is large, it automatically chunks it across multiple linked empty lines.
dble.setExtByField(field, query, ext[, skipQueue])Finds a line by field query and sets its extended buffer data.
dble.close()dble.sync([skipQueue])dble.datasync([skipQueue])File handle operations natively routed to the base JDB class.
dble._doTask(func, skipQueue)Advanced tool. Runs your func exclusively inside the DB task queue, locking other async modifications from messing with your state.
_init, _loadHead, _loadIndices, _getLineBuffer, _writeLineBuffer, _appendLineBuffer, _getLastEmptyLine, _clearLinesFrom, _readlines, _parseLine, etcInternal lifecycle and binary chunking methods.
dble.DBLEFieldThe base interface for field typings in DBLE. You instantiate these classes in the fields array when creating a new database.
Access these via require('@jnode/db/dble') or dble.defaultDBLETypes:
DBLEInt8Field(name, isKey, isRelative) / DBLEUInt8FieldDBLEInt16Field(name, isKey, isRelative) / DBLEUInt16FieldDBLEInt32Field(name, isKey, isRelative) / DBLEUInt32FieldDBLEBigInt64Field(name, isKey, isRelative) / DBLEBigUInt64FieldDBLEFloatField(name, isKey, isRelative) / DBLEDoubleFieldDBLEStringField(maxLength, name, isKey, isRelative)DBLEBufferField(maxLength, name, isKey, isRelative)DBLEAnyField(length, name, isKey, isRelative)DBLEDateField(name, isKey, isRelative)Note: The maxLength argument is required for String and Buffer types to enforce DBLE's fixed-length binary schema standard.
ljson.LJSONFileManages text-based LJSON files. This works by keeping a stateful memory representation of the JSON array, and appending modification operations (like +, =, -) to the file stream iteratively.
LJSONFile.load(file[, options])file <string> Target LJSON file path.options <Object>
disableCleanupOnStart <boolean> Stop LJSON from compacting its mutation logs on load.Loads the JLD formatted LJSON file. If it doesn't exist, an empty file will be created.
LJSONFile.forceCreate(file[, options])Overwrites a file with a fresh, empty LJSON database.
ljson.cleanUp(force)Rewrites the entire file on disk, collapsing all mutation lines (updates, overwrites, deletions) into a clean, flat list of final JSON representations.
ljson.push(json)json [<any>] Valid JSON.Appends a new line with the object directly to the database.
ljson.update(index, json)index <number> The array index to modify.json [<any>] The mutation payload.Applies a mutation diff based on the original data type:
original += updateoriginal = update !== originalObject.assign(original, update)original.push(...update)ljson.overwrite(index, json)Overwrites the target index entirely with the new json payload.
ljson.delete(index)Removes the index element from the database. Note that this shifts subsequent indexes.
ljson._loadData(data)Parses textual JLD lines and applies all operators into the memory array.
---- File Head
[4 Byte] "JDBD"
[UInt8 ] Version, 1
[3 Byte] RSV
[4 Byte] DB Type, "DBLE"
[UInt8 ] DB Version, 1
[3 Byte] RSV
---- DB Head
[Array ] Definition[16 Bit] Flag (isLast, isKey, isRelative RSV...)
[UInt16] Field Length
[UInt8 ] Type Name Length
[String] Type Name
[UInt8 ] Field Name Length
[String] Field Name
[n Byte] (OPTIONAL) Field Relative Data[UInt16] Extend Field Base Length (making each line 2 ** N bytes)
[UInt32] Last Empty Line (0xFFFFFFFF for null)
[n Byte] Padding (making 'File Head' + 'DB Head' N * Line Length)
---- DB Body
[Array ] Lines
[2 Bit ] Type (Normal Start, Extended, Empty, Deleted Start)
[14 Bit] Flag[UInt32] Extended Line At/Last Empty Line (if type is 'Empty', 0xFFFFFFFF for null)
[Array ] Line Data
[n Byte] Field Data
This is a simple text-based, line-based data format.
JLDstands for JustLineData, a subtype of JDB but is text-and-line-based while a.jdbfile is binary based.
@ JLD 01 <DATA-TYPE (4 ASCII Character)> <DATA-VERSION (2 HEX)>
[@ <OTHER-HEADERS...>]...
<ACTUAL-DATA>...
For LJSON, we use:
@ JLD 01 LJSO 01
<JSON> JSON data line. E.G. {"name":"nick"}./ <CONTENT> Comment. Only for temporary use, we won't keep the comment lines.+ <INDEX> <JSON> Update line. Update JSON's data type must be same as original JSON's data type. Works in different ways according to the data type:
original += update.original += update.original = update !== original.Object.assign(original, update)original.push(...update)= <INDEX> <JSON> Overwrite line.- <INDEX> Delete line.FAQs
Simple database package for Node.js.
We found that @jnode/db demonstrated a healthy version release cadence and project activity because the last version was released less than 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.