An open API service indexing awesome lists of open source software.

https://github.com/marcuwynu23/mingledb

Lightweight file based NoSQL DB
https://github.com/marcuwynu23/mingledb

bson compressed database embedded flatfile local tinydb

Last synced: 8 months ago
JSON representation

Lightweight file based NoSQL DB

Awesome Lists containing this project

README

          


MingleDB



Stars Badge
Forks Badge
Issues Badge
License Badge

**MingleDB** is a lightweight, file-based NoSQL database built on top of the [BSON](https://bsonspec.org/) serialization format with support for:

- ๐Ÿ” Basic authentication
- โœ… Schema validation
- ๐Ÿ”Ž Query filters (including regex, range, `$in`, etc.)
- ๐Ÿ“ฆ BSON + Zlib compression
- ๐Ÿ’พ Flat file-based persistence

Designed for fast prototyping, embedded use, CLI apps, or offline-first environments.

---

## ๐Ÿ“ฆ Installation

```bash
npm install mingledb
```

---

## ๐Ÿš€ Features

| Feature | Description |
| ------------------------------- | -------------------------------------------------------------------- |
| ๐Ÿ” **User Authentication** | Register, login, logout, and session tracking using SHA256 hashing |
| ๐Ÿงพ **Schema Definition** | Define required fields, types, and unique constraints per collection |
| ๐Ÿง  **Smart Querying** | Supports advanced query filters like `$gt`, `$in`, `$regex`, etc. |
| ๐Ÿ’จ **Compression** | Uses zlib + BSON to store entries compactly |
| ๐Ÿ“ **Flatfile Storage** | Saves data in `.mingleDB` files with a binary header and metadata |
| ๐Ÿ”„ **Update/Delete Operations** | Simple CRUD support with updateOne and deleteOne |
| ๐Ÿ“ƒ **Minimal Dependencies** | Zero external DB needed, runs anywhere Node.js runs |

---

## ๐Ÿงช Example Usage

```js
import MingleDB from "mingledb"; // For ES Modules
// const MingleDB = require("mingledb"); // For CommonJS

const db = new MingleDB(); // Optional: pass custom directory path

// ๐Ÿ” 1. Register & Login
db.registerUser("admin", "secure123");
db.login("admin", "secure123");

// โœ… 2. Define schema
db.defineSchema("users", {
name: { type: "string", required: true },
email: { type: "string", required: true, unique: true },
age: { type: "number" },
});

// ๐Ÿ“ฅ 3. Insert documents
db.insertOne("users", {
name: "Wayne",
email: "wayne@mingle.com",
age: 25,
});

// ๐Ÿ”Ž 4. Read operations
console.log(db.findAll("users")); // All documents
console.log(db.findOne("users", { email: "wayne@mingle.com" })); // Exact match
console.log(db.find("users", { age: { $gte: 18, $lt: 30 } })); // Range filter

// ๐Ÿ“ 5. Update a document
db.updateOne("users", { name: "Wayne" }, { age: 26 });

// ๐Ÿ—‘๏ธ 6. Delete a document
db.deleteOne("users", { email: "wayne@mingle.com" });

// ๐Ÿšช 7. Logout
db.logout("admin");
```

---

## ๐Ÿง  Query Operators Supported

| Operator | Description |
| ---------------------------- | ----------------------------------------------------------------------- |
| `$gt`, `$gte`, `$lt`, `$lte` | Greater/Less Than (or Equal) |
| `$eq`, `$ne` | Equals / Not Equals |
| `$in`, `$nin` | Matches any in list / not in list |
| `$regex` | Regular Expression matching (case-insensitive supported via `$options`) |

---

## ๐Ÿ” Authentication API

```ts
registerUser(username: string, password: string): void
login(username: string, password: string): boolean
isAuthenticated(username: string): boolean
logout(username: string): void
```

---

## ๐Ÿ“‚ Schema Example

```js
db.defineSchema("posts", {
title: { type: "string", required: true },
slug: { type: "string", unique: true },
views: { type: "number" },
});
```

> `required` will throw error if missing
> `unique` will scan the whole collection to ensure no duplicates

---

## ๐Ÿ’ก Use Cases

- Embedded/local-first database
- Desktop apps (Electron)
- CLI tools or utilities
- Offline PWA storage simulation
- Rapid prototyping with schema validation
- Lightweight admin panel backend

---

## ๐Ÿ”ง Configuration

```js
const db = new MingleDB("./data"); // Change default directory
```

Each collection will be stored as a `.mingleDB` binary file with compressed records.

---

## ๐Ÿ“ File Format

Each collection file contains:

1. Header (`MINGLEDBv1`)
2. JSON metadata (collection name, version)
3. Repeated entries of:
- 4-byte length
- zlib-compressed BSON document

---

## โœ… Roadmap (Future Ideas)

- [ ] Auto-indexing for faster unique validation
- [ ] Nested field queries
- [ ] Export/import data as JSON
- [ ] File-level locking for concurrent writes
- [ ] Optional encryption
- [ ] WebSocket sync module

---

## ๐Ÿ‘จโ€๐Ÿ’ป Development

```bash
npm install
npm run test
```

---

## ๐Ÿ“œ License

MIT ยฉ 2025 Mark Wayne Menorca

---

## ๐Ÿ’ฌ Feedback

Feel free to open issues or submit pull requests to suggest improvements or report bugs!