1.2.11 • Published 4 months ago

axiodb v1.2.11

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

AxioDB

AxioDB is a fast, lightweight, and scalable open-source DBMS designed for modern applications. It supports JSON-based data storage, simple APIs, and secure data management, making it ideal for projects requiring efficient and flexible database solutions.

Features

  • Custom Schema Support: Define custom schemas to structure your data for consistency and validation.
  • Chainable Query Methods: Use familiar methods like .find(), .skip(), and .limit() for powerful query filtering.
  • Node.js Streams for Efficient Read/Write: Seamlessly handle large datasets with Node.js streams to avoid performance bottlenecks.
  • Custom Data Storage: Save and retrieve data directly from JSON files without needing a database server.
  • Flexible Indexing: Implement indexing to speed up query performance.
  • Secure and Reliable: Includes optional encryption to protect sensitive data stored in your JSON files.
  • Simple Setup and Lightweight: No additional database setup required; simply install and start using.

Installation

To get started with AxioDB, install it via npm:

npm install axiodb@latest --save

Usage

CommonJS

const { AxioDB, schemaValidate, SchemaTypes } = require("axiodb");

// Initialize AxioDB
const db = new AxioDB();

// Create a new database
db.createDB("myDatabase").then(async (database) => {
  // Define a schema
  const userSchema = {
    name: SchemaTypes.string().required(),
    age: SchemaTypes.number().required(),
  };

  // Create a new collection with schema
  const users = await database.createCollection("users", userSchema);

  // Insert a document
  users.insert({ name: "John Doe", age: 30 }).then((response) => {
    console.log("Insert Response:", response);
  });

  // Query documents
  users
    .query({ age: { $gt: 25 } })
    .exac()
    .then((response) => {
      console.log("Query Response:", response);
    });
});

ES6

import { AxioDB, schemaValidate, SchemaTypes } from "axiodb";

// Initialize AxioDB
const db = new AxioDB();

// Create a new database
db.createDB("myDatabase").then(async (database) => {
  // Define a schema
  const userSchema = {
    name: SchemaTypes.string().required(),
    age: SchemaTypes.number().required(),
  };

  // Create a new collection with schema
  const users = await database.createCollection("users", userSchema);

  // Insert a document
  users.insert({ name: "John Doe", age: 30 }).then((response) => {
    console.log("Insert Response:", response);
  });

  // Query documents
  users
    .query({ age: { $gt: 25 } })
    .exac()
    .then((response) => {
      console.log("Query Response:", response);
    });
});

Encryption

AxioDB supports optional encryption to protect sensitive data stored in your JSON files. You can enable encryption when creating a collection by passing the crypto flag and an encryption key.

Example with Encryption

import { AxioDB, schemaValidate, SchemaTypes } from "axiodb";

// Initialize AxioDB
const db = new AxioDB();

// Create a new database
db.createDB("myDatabase").then(async (database) => {
  // Define a schema
  const userSchema = {
    name: SchemaTypes.string().required(),
    age: SchemaTypes.number().required(),
  };

  // Create a new collection with schema and encryption
  const users = await database.createCollection(
    "users",
    userSchema,
    true,
    "mySecretKey",
  );

  // Insert a document
  users.insert({ name: "John Doe", age: 30 }).then((response) => {
    console.log("Insert Response:", response);
  });

  // Query documents
  users
    .query({ age: { $gt: 25 } })
    .exac()
    .then((response) => {
      console.log("Query Response:", response);
    });
});

Motivation

As a MERN Stack Developer, I encountered several challenges with existing database solutions:

  1. Complex Setup: Many databases require complex setup and configuration, which can be time-consuming and error-prone.
  2. Performance Bottlenecks: Handling large datasets efficiently was often a challenge, especially with traditional databases.
  3. Flexibility: I needed a flexible solution that could easily adapt to different project requirements without extensive modifications.
  4. Security: Ensuring data security and encryption was crucial, but existing solutions often lacked easy-to-implement encryption features.

These pain points motivated me to develop AxioDB, a DBMS Npm Package that addresses these issues by providing a simple, efficient, and secure database solution for modern applications.

Development Status

Note: This project is currently in development mode and is not stable. Features and APIs may change, and there may be bugs. Use it at your own risk and contribute to its development if possible.

API Reference

AxioDB

  • createDB(dbName: string): Promise
    • Creates a new database with the specified name.

Database

  • createCollection(collectionName: string, schema: object, crypto?: boolean, key?: string): Promise

    • Creates a new collection with the specified name and schema.
  • deleteCollection(collectionName: string): Promise<SuccessInterface | ErrorInterface>

    • Deletes the specified collection from the database.
  • getCollectionInfo(): Promise

    • Retrieves information about all collections in the database.

Collection

  • insert(data: object): Promise<SuccessInterface | ErrorInterface>

    • Inserts a document into the collection.
  • query(query: object): Reader

    • Queries documents in the collection.

Reader

  • exac(callback?: Function): Promise<SuccessInterface | ErrorInterface>

    • Executes the query and returns the results.
  • Limit(limit: number): Reader

    • Sets a limit on the number of documents to return.
  • Skip(skip: number): Reader

    • Sets the number of documents to skip.
  • Sort(sort: object): Reader

    • Sets the sort order for the query.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Thanks to all contributors and supporters of this project.
1.2.10

4 months ago

1.2.11

4 months ago

1.2.8

4 months ago

1.2.7

4 months ago

1.2.6

4 months ago

1.1.5

4 months ago

1.2.9

4 months ago

1.1.4

4 months ago

1.1.3

5 months ago

1.1.1

5 months ago

1.1.2

5 months ago

1.1.0

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

7 months ago

1.0.15-s

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.12

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago