Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A lightweight BSON-based, document-oriented database for Javascript — built for speed, simplicity, and happiness.

License

NotificationsYou must be signed in to change notification settings

grinwiz/bisondb

Repository files navigation

BisonDB

The Javascript Database

A lightweight BSON-based, document-oriented database for Javascript — built for speed, simplicity, and happiness.

Introduction

BisonDB is a lightweight, BSON-based, document-oriented database designed to run seamlessly in Node.js, Electron, and the browser. It stores data in a compact binary format ([len][bson]…) and supports a familiar MongoDB-like API —insertOne,find,updateOne,aggregate, and more — without any build step or external dependencies beyondbson.

Why BisonDB?

FeatureBenefit
Zero confignew BisonDB() works instantly
File-based (Node.js)Auto-saves to.bisondb/
IndexedDB (Browser)Full offline support
Streaming engineO(1) memory, no full loads
MongoDB-like APIinsertOne,find,update,aggregate
TransactionsACID guarantees
No build stepPure JS, no TypeScript

Whether you need an embedded datastore for a server, a desktop app, or a client-side web app, BisonDB delivers speed, simplicity, and reliability in a single pure-JavaScript package.


Table of Contents


Installations

Module name on npm isbisondb.

npm install --save bisondb

API Reference

BisonDB

constdb=newBisonDB();
MethodDescription
collection(name)Returns aCollection instance
transaction(collections, fn)ACID transaction

Collection

constusers=db.collection("users");
MethodReturnsExample
insertOne(doc, { returnDocument })doc or{ _id }returnDocument: 'after'
insertMany(docs)[_id]
find(query, { projection })doc[]{ name: 1 }
findOne(query, { projection })doc | null
updateOne(filter, update, options)result$set: { x: 1 }
update(filter, update, options){ acknowledged, matchedCount, modifiedCount }$set: { x: 1 }
deleteOne(filter){ deletedCount }
delete(filter){ deletedCount }
aggregate(pipeline)any[]$match,$group

Usage

Backend (Node.js)

const{ BisonDB}=require("bisondb");constdb=newBisonDB();awaitdb.collection("users").insertOne({name:"Alice"});console.log(awaitdb.collection("users").find());

Saves to.bisondb/users.bson in your project root.

Frontend (Browser / React)

import{BisonDB}from"bisondb/client";constdb=newBisonDB();awaitdb.collection("todos").insertOne({task:"Learn BisonDB"});

UsesIndexedDB — full offline persistence.

More Usage Examples

const{ BisonDB}=require("bisondb");(async()=>{console.log("BisonDB Usage Demo\n");// 1. Initialize DBconstdb=newBisonDB();constusers=db.collection("users");constposts=db.collection("posts");console.log("1. Collections created: users, posts");// 2. insertOne + returnDocument: 'after'constalice=awaitusers.insertOne({name:"Alice",email:"alice@example.com",role:"admin"},{returnDocument:"after"});console.log("2. insertOne (returnDocument:after):",alice);// 3. findById (using _id from insert)constfoundUser=awaitusers.findOne({_id:alice._id});console.log("3. findById:",foundUser);// 4. insertManyconstnewUsers=[{name:"Bob",email:"bob@example.com",role:"user"},{name:"Charlie",email:"charlie@example.com",role:"moderator"},];constinserted=awaitusers.insertMany(newUsers);console.log("4. insertMany result:",inserted);// Returns array of _id strings// 5. insert a postconstpost=awaitposts.insertOne({title:"First Post",authorId:alice._id,content:"Hello BisonDB!"},{returnDocument:"after"});console.log("5. Post inserted:",post);// 6. updateOne with returnDocument: 'after'constupdatedUser=awaitusers.updateOne({_id:"690355f49c12ad51e1721bad"},{$set:{lastLogin:newDate(),status:"online"}},{returnDocument:"after"});console.log("6. updateOne (returnDocument:after):",updatedUser);// 7. updateManyconstupdatedUsers=awaitusers.update({},{$set:{status:"offline"}});console.log("7. updateMany:",updatedUsers);// 8. findOneconstuserByEmail=awaitusers.findOne({email:"bob@example.com"});console.log("8. findOne by email:",userByEmail);// 9. deleteOneconstdeleteResult=awaitusers.deleteOne({email:"charlie@example.com"});console.log("9. deleteOne result:",deleteResult);// 10. deleteManyconstdeleteManyResult=awaitusers.delete({email:"bob@example.com"});console.log("9. deleteOne result:",deleteManyResult);// 10. findOne with projection (name only)constnameOnly=awaitusers.findOne({email:"alice@example.com"},{projection:{name:1}});console.log("10. findOne with projection { name: 1 }:",nameOnly);// Bonus: Aggregation exampleconststats=awaitusers.aggregate([{$match:{role:{$ne:"admin"}}},{$group:{_id:"$role",count:{$sum:1}}},]);console.log("\nBonus: Aggregation $group by role:",stats);console.log("\nAll operations completed successfully!");})();

Performance

DatasetNeDB (Est.)BisonDB
10k docs~80ms loadStreaming: <10ms
100k docsOOM riskStable, low RAM

BisonDB useszero-copy streaming — never loads full file.


Contributing

Contributions, issues, and feature requests are welcome!Feel free to open an issue or submit a pull request on GitHub.

Steps to Contribute

  1. Fork the repository
  2. Create a new branch
    git checkout -b feature/my-new-feature
  3. Commit your changes
    git commit -m"feat(my-new-feature): Add my new feature"
  4. Push to your branch
    git push origin feature/my-new-feature
  5. Open a Pull Request 🚀

Liked BisonDB? Give it a star on GitHub to show your support!https://github.com/grinwiz/bisondb


License

MIT — free for commercial & open-source use.


About

A lightweight BSON-based, document-oriented database for Javascript — built for speed, simplicity, and happiness.

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp