Gathering detailed insights and metrics for good.db
Gathering detailed insights and metrics for good.db
Gathering detailed insights and metrics for good.db
Gathering detailed insights and metrics for good.db
good.db is a lightweight Node.js library for simple local database operations with JSON files. Organize, manage, and manipulate data easily.
npm install good.db
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.95%)
JavaScript (0.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
6 Stars
62 Commits
3 Forks
2 Branches
2 Contributors
Updated on Jun 08, 2025
Latest Version
2.4.6
Package Id
good.db@2.4.6
Unpacked Size
410.45 kB
Size
47.01 kB
File Count
77
NPM Version
10.8.2
Node Version
18.20.8
Published on
Jun 08, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
GoodDB is a lightweight and flexible TypeScript database wrapper that simplifies interactions with your database. It offers a simple API, supports various drivers, and is designed with modern TypeScript development in mind.
You can install GoodDB via npm:
1npm install good.db
You can customize the database configuration by passing options to the driver:
1const db = new GoodDB(new JSONDriver({ path: './database.json' }), { 2 table: 'data', 3 nested: '.', 4 nestedIsEnabled: true, 5 cache: { 6 isEnabled: true, 7 capacity: 1024 8 } 9});
table
(string): The name of the table/collection in the database.
nested
(string): The character used to separate nested keys.
nestedIsEnabled
(boolean): Whether to enable nested key handling.
cache
isEnabled
(boolean): Whether to enable caching.capacity
(number): The maximum number of entries to cache.GoodDB supports the following drivers:
The MemoryDriver
stores data in memory. It is suitable for small applications and is easy to set up.
1import { GoodDB, MemoryDriver } from 'good.db'; 2 3const db = new GoodDB(new MemoryDriver());
The SQLiteDriver
stores data in an SQLite database. It is suitable for small to medium-sized applications and is easy to set up.
1import { GoodDB, SQLiteDriver } from 'good.db'; 2 3const db = new GoodDB(new SQLiteDriver({ path: './database.sqlite' }));
The YMLDriver
stores data in a YML file. It is suitable for small to medium-sized applications and is easy to set up.
1import { GoodDB, YMLDriver } from 'good.db'; 2 3const db = new GoodDB(new YMLDriver({ path: './database.yml' }));
The JSONDriver
stores data in a JSON file. It is suitable for small to medium-sized applications and is easy to set up.
1import { GoodDB, JSONDriver } from 'good.db'; 2 3const db = new GoodDB(new JSONDriver({ path: './database.json' }));
The MongoDBDriver
stores data in a MongoDB database. It is suitable for medium to large-sized applications and offers advanced features.
1import { GoodDB, MongoDBDriver } from 'good.db'; 2 3const db = new GoodDB(new MongoDBDriver({ uri: 'mongodb://localhost:27017/mydb' })); 4 5await db.connect();
The PostgreSQLDriver
stores data in a PostgreSQL database. It is suitable for medium to large-sized applications and offers advanced features.
1import { GoodDB, PostgreSQLDriver } from 'good.db'; 2 3const db = new GoodDB(new PostgreSQLDriver({ 4 user: 'user', 5 host: 'localhost', 6})); 7 8await db.connect();
The MySQLDriver
stores data in a MySQL database. It is suitable for medium to large-sized applications and offers advanced features.
1import { GoodDB, MySQLDriver } from 'good.db'; 2 3const db = new GoodDB(new MySQLDriver({ 4 user: 'user', 5 host: 'localhost' 6}));
from
(Driver): The driver to convert from.to
(Driver): The driver to convert to.table
(string): The name of the table/collection to convert.Convert an SQLite database to a JSON file:
1import { Convertor, SQLiteDriver, JSONDriver } from 'good.db'; 2 3const convertor = new Convertor({ 4 from: new SQLiteDriver({ 5 path: './client/database.sqlite' 6 }), 7 to: new JSONDriver({ 8 path: './client/database.json' 9 }), 10 table: 'all_tables', 11}); 12 13convertor.convert().then(console.log).catch(console.error);
set(key: string, value: any, options?: methodOptions)
Set a value in the database:
1// Sync 2db.set('user', { name: 'Alice', age: 25 }); // true
get(key: string, options?: methodOptions)
Get a value from the database:
1db.get('user'); // { name: 'Alice', age: 25 }
has(key: string, options?: methodOptions)
Check if a key exists in the database:
1db.has('user'); // true
delete(key: string, options?: methodOptions)
Delete a key from the database:
1db.delete('user'); // true
push(key: string, value: any, options?: methodOptions)
Push a value to an array in the database:
1db.push('users', { name: 'Alice', age: 25 }); // true 2db.push('users', { name: 'Bob', age: 30 }); // true 3db.push('users', { name: 'Charlie', age: 35 }); // true 4db.get('users'); // [{ name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 }]
shift(key: string, options?: methodOptions)
Remove the first element from an array in the database:
1db.shift('users'); // { name: 'Alice', age: 25 } 2db.get('users'); // [{ name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 }]
unshift(key: string, value: any, options?: methodOptions)
Add an element to the beginning of an array in the database:
1db.unshift('users', { name: 'Alice', age: 25 }); // true 2db.get('users'); // [{ name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 }]
pop(key: string, options?: methodOptions)
Remove the last element from an array in the database:
1db.pop('users'); // { name: 'Charlie', age: 35 } 2db.get('users'); // [{ name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }]
pull(key: string, value: any, options?: methodOptions)
Remove a value from an array in the database:
1db.pull('users', { name: 'Bob', age: 30 }); // true 2db.get('users'); // [{ name: 'Alice', age: 25 }]
1db.pull('users', (element) => element.age > 20); // true 2db.get('users'); // []
find(key: string, callback: (value: any, index: number, obj: any[]) => unknown, options?: methodOptions)
Find a value in an array in the database:
1db.push('users', { name: 'Alice', age: 25 }); 2db.push('users', { name: 'Bob', age: 30 }); 3db.push('users', { name: 'Charlie', age: 35 }); 4db.find('users', (object) => object.name == 'Bob') // { name: 'Bob', age: 30 }
distinct(key: string, value: string, options?: methodOptions)
Get distinct values from an array in the database:
1db.push('users', "Alice"); 2db.push('users', "Alice"); 3db.push('users', "Alice"); 4db.distinct('users', "Alice"); // ['Alice']
add(key: string, operand: number, options?: methodOptions)
Add a number to a value in the database:
1db.set('score', 10); 2db.add('score', 5); // 15
subtract(key: string, operand: number, options?: methodOptions)
Subtract a number from a value in the database:
1db.set('score', 10); 2db.subtract('score', 5); // 5
multiply(key: string, operand: number, options?: methodOptions)
Multiply a value in the database by a number:
1db.set('score', 10); 2db.multiply('score', 5); // 50
divide(key: string, operand: number, options?: methodOptions)
Divide a value in the database by a number:
1db.set('score', 10); 2db.divide('score', 5); // 2
math(key: string, operator: string, operand: number, options?: methodOptions)
Perform a mathematical operation on a value in the database:
1db.set('score', 10); 2db.math('score', '+', 5); // 15 3db.math('score', '-', 5); // 10 4db.math('score', '*', 5); // 50 5db.math('score', '/', 5); // 10
type(key: string, options?: methodOptions)
Get the type of a value in the database:
1db.set('user', { name: 'Alice', age: 25 }); 2db.type('user'); // 'object'
size(key: string, options?: methodOptions)
Get the size of a value in the database:
1db.set('users', [{ name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 }]); 2db.size('users'); // 3
startsWith(key: string, options?: methodsOptions)
Get all the keys that start with a given string:
1db.set('user1', { name: 'Alice', age: 25 }); 2db.set('user2', { name: 'Bob', age: 30 }); 3db.set('user3', { name: 'Charlie', age: 35 }); 4db.startsWith('user'); // { user1: { name: 'Alice', age: 25 }, user2: { name: 'Bob', age: 30 }, user3: { name: 'Charlie', age: 35 } }
endsWith(key: string, options?: methodsOptions)
Get all the keys that end with a given string:
1db.set('user1', { name: 'Alice', age: 25 }); 2db.set('user2', { name: 'Bob', age: 30 }); 3db.set('user3', { name: 'Charlie', age: 35 }); 4db.endsWith('1'); // { user1: { name: 'Alice', age: 25 } }
includes(key: string, options?: methodsOptions)
Get all the keys that include a given string:
1db.set('user1', { name: 'Alice', age: 25 }); 2db.set('user2', { name: 'Bob', age: 30 }); 3db.set('user3', { name: 'Charlie', age: 35 }); 4db.includes('user'); // { user1: { name: 'Alice', age: 25 }, user2: { name: 'Bob', age: 30 }, user3: { name: 'Charlie', age: 35 } }
keys()
Get all the keys in the database:
1db.set('user1', { name: 'Alice', age: 25 }); 2db.set('user2', { name: 'Bob', age: 30 }); 3db.set('user3', { name: 'Charlie', age: 35 }); 4db.keys(); // ['user1', 'user2', 'user3']
values()
Get all the values in the database:
1db.set('user1', { name: 'Alice', age: 25 }); 2db.set('user2', { name: 'Bob', age: 30 }); 3db.set('user3', { name: 'Charlie', age: 35 }); 4db.values(); // [{ name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Charlie', age: 35 }]
all()
Get all the entries in the database:
1db.set('user1', { name: 'Alice', age: 25 }); 2db.set('user2', { name: 'Bob', age: 30 }); 3db.set('user3', { name: 'Charlie', age: 35 }); 4db.all(); // { user1: { name: 'Alice', age: 25 }, user2: { name: 'Bob', age: 30 }, user3: { name: 'Charlie', age: 35 } }
clear()
Clear the database:
1db.clear(); // true
table(name: string)
Make table operations on the database:
1db.table('users').set('user1', { name: 'Alice', age: 25 }); // true 2db.table('users').get('user1'); // { name: 'Alice', age: 25 }
connect()
Connect to the database (for ASYNC drivers like MongoDBDriver
, PostgreSQLDriver
and MySQLDriver
):
1await db.connect();
disconnect()
Disconnect from the database (for ASYNC drivers like MongoDBDriver
, PostgreSQLDriver
and MySQLDriver
):
1await db.disconnect();
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.
If you have any questions or need assistance, please feel free to open an issue or contact us at
GoodDB is licensed under the MIT License. See the LICENSE file for details.
No vulnerabilities found.
No security vulnerabilities found.