npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

orbdb

v1.1.9

Published

OrbDB is highly flexible, fast, light weight ORM suitable for prototyping whilst giving the flexibility of easly updating your database schema on the go to suit project chages and the flexibility to use a database of your choice

Downloads

733

Readme

orbDB

OrbDB Test CI OrbDB

alt text

Installation

npm i orbdb@latest


json Adapter

How to us

const OrbDB = require('orb'); 
const OrbDBSchema = require('orb/schema');
const fs = require('fs').promises;
const path = require('path');

// Define JSON Adapter
const adapter = require('orb/adapters/jsonAdapter');
const dbPath = path.join(__dirname, './db.json');

let orbDB;

orbDB = new OrbDB.Json(new adapter(dbPath));
const schemaInstance = new OrbDBSchema(orbDB);

// Define your model here
const userModel = {
  name: 'User',
  fields: {
  id: { type: 'number', required: true },
  name: { type: 'string', required: true },
  age: { type: 'number', required: false }
  }
};


let init = ( async () => {
    // initialize database
    schemaInstance.addModel(userModel);
    await schemaInstance.createSchema();
})

init();
 

// Example usage: Add a user
const newUser = { id: 1, name: 'John Doe', age: 30 };
orbDB.insert(userModel.name, newUser);

const dbData = await fs.readFile(dbPath, 'utf8');
const jsonData = JSON.parse(dbData);

// Fetch all users from the database
const users = await orbDB.get(userModel.name);
console.log('Users:', users);

// Example usage: Update a user
const updatedUser = { name: 'Blaze' };
orbDB.update(userModel.name, 1, updatedUser);

const dbData = await orbDB.get(userModel.name);
const updatedUserData = dbData.find(user => user.id === 1);

// Fetch updated users from the database
const updatedUsers = await orbDB.get(userModel.name);
console.log('Updated Users:', updatedUsers);

// Example usage: Delete a user
orbDB.delete(userModel.name, 1);

const dbData = await orbDB.get(userModel.name);
const deletedUserData = dbData.find(user => user.id === 1);

Sqlite Adapter

How to use

const OrbDB = require('orb');
const sqlite3 = require('sqlite3').verbose();
const fs = require('fs').promises;
const path = require('path');
const adapterModule = require('orb/adapters/sqliteAdapter'); // Import the adapter class

let orbDB;
let sqliteAdapterInstance;
const dbPath = path.join(__dirname, './db.sqlite3');

sqliteAdapterInstance = new adapterModule(dbPath); // Create an instance of SQLiteAdapter
await sqliteAdapterInstance.init(); // Initialize SQLite connection

// Create the schema for the test table
await sqliteAdapterInstance.createSchema('test_table', {
   id: { type: 'integer' },
   name: { type: 'string' },
   isActive: { type: 'boolean' },
});

// Initialize OrbDB with the SQLite adapter instance
orbDB = new OrbDB.Sql(sqliteAdapterInstance);

// Add record 
const newUser = { id: 1, name: 'John Doe', isActive: false };
await orbDB.insert('test_table', newUser);

// Update reord
const updatedUser = { name: 'Blaze' };
await orbDB.update('test_table', 1, updatedUser);

// Delete record
await orbDB.delete('test_table', 1);

Hashing data

how to use:

const HashUtility = require("orbdb/utils/hash");

const sampleData = "Data to be hashed";
const hash = HashUtility.hash(sampleData);
const isMatch = HashUtility.verify(sampleData, hash);

if(isMatch){
   console.log("Hash match");

}

Sanitizing Data

Added data sanitization. special characters from input data will now be striped and only clean data is stored in the database
making sure your system is secure and data integrity is intact 

Adaptors:

Now json and sqlite adapters are fully functional and ready for use

Why OrbDB?

Here are the advantages of using OrbDB, based on its features and design principles:

1. JSON and SQLite Adapter Support

OrbDB allows developers to choose between lightweight JSON-based storage or robust SQLite databases, offering flexibility for various project requirements.

2. Dynamic Schema Management

  • OrbDB provides dynamic schema creation, making it easier to define and manage models directly within your application.
  • Developers can work with multiple models simultaneously without additional setup.

3. Custom Session Management

  • With its session class, OrbDB introduces commit and rollback functionality, making it easier to manage transactions and ensure data integrity.

4. Simplified Development

  • By abstracting away database operations, OrbDB lets developers focus on writing application logic rather than low-level database queries.

5. Auto Incrementing IDs

  • Automatically assigns and increments IDs for entries in tables, reducing the overhead of managing primary keys.

6. Error Handling and Validation

  • Ensures schema compliance by validating data types and properties at runtime.
  • Provides meaningful error messages, helping developers debug effectively.

7. Cross Platform Compatibility

  • Designed to work seamlessly across operating systems, including Linux, Windows, and MacOS.

8. Lightweight and Scalable

  • OrbDB is ideal for small to medium-sized applications and can scale effectively by switching between adapters.

9. Easy Integration

  • With a modular design, OrbDB can be integrated into existing applications with minimal effort.
  • Future-proofed for additional adapters or features, making it a long-term investment.

10. Developer Friendly APIs

  • Intuitive and concise APIs make it easier for developers to perform operations like inserts, updates, and schema management without a steep learning curve.

11. Open Source and Community Driven

  • The project being open source fosters community contributions, ensuring continuous improvement and access to a wider knowledge base.

These advantages position OrbDB as a versatile ORM that caters to both beginner and experienced developers, promoting productivity and efficiency. It is particularly appealing for projects requiring lightweight and flexible data management solutions.

Contributing

We welcome contributions to the project! Here’s how you can help:

How to Contribute

  1. Fork the Repository: Click on the fork button at the top-right corner of this page. This will create a copy of the repository under your GitHub account.

  2. Clone Your Fork: Clone your forked repository to your local machine:

    git clone https://github.com/taqsblaze/OrbDB
    cd OrbDB
  3. Create a New Branch: It’s important to create a new branch for your changes:

    git checkout -b feature-branch-name

    (Use a descriptive name for your branch to indicate the feature or fix you are working on.)

  4. Make Your Changes: Open the project in your favorite code editor and make your changes.

  5. Write Tests: If you are adding new features or making changes, please ensure that your code is tested. Place your tests in the test directory.

  6. Run Tests: Make sure all tests pass. (Adjust this command based on your testing framework.)

    npm test
  7. Commit Your Changes: Once you are satisfied with your changes, commit them with a descriptive message:

    git add .
    git commit -m "Add a brief description of your changes"
  8. Push Your Changes: Push your changes to your forked repository:

    git push origin feature-branch-name
  9. Create a Pull Request: Go to the original repository where you want to propose your changes. Click on the "Pull Requests" tab, and then click on "New Pull Request". Select your branch and submit your pull request.

For more detailed instructions, please see CONTRIBUTING.md.

Code of Conduct

Please adhere to this project's Code of Conduct in all interactions.

Issues

If you encounter any problems, feel free to open an issue in the issues tab. Please provide as much detail as possible.

Discussion

For any major changes, please create an issue first to discuss it. This helps maintainers and collaborators understand your intentions.

new featers soon Thank you for your interest in contributing!