3.1.6 β€’ Published 7 months ago

hyperiondb v3.1.6

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

HyperionDB

npm version license downloads HyperionDB Logo

A minimalist Rust-based sharded database client for Node.js. HyperionDB offers high-performance data storage and retrieval with sharding support, making it suitable for scalable applications.


πŸš€ Features

  • High Performance: Built with Rust for speed and efficiency.
  • Sharding Support: Distribute data across multiple shards for scalability.
  • Easy Integration: Simple API for Node.js applications.
  • Custom Indexing: Define indexed fields for faster queries.
  • Cross-Platform: Works on Windows, macOS, and Linux.

πŸ“Š Benchmark Results

The benchmarks for HyperionDB were conducted based on the performance testing methodology outlined in the article "A Performance Comparison of SQL and NoSQL Databases". Following similar operations and record counts (1000, 10,000, and 100,000), we evaluated HyperionDB's INSERT, QUERY, UPDATE, and DELETE performance. These results demonstrate HyperionDB's speed and performance, especially in query operations.

Mean Performance Time (ms) for CRUD Operations

INSERT Operation

Database1000 records10,000 records100,000 records
Microsoft SQL Server530.15516.251075.7
MySQL757.17326.476705.7
PostgreSQL80.9798.710476.7
MongoDB54.9533.85282.5
CouchDB1.3919.7141.95
Couchbase77.5783.679188.13
HyperionDB3.2036.80409.20

Insert Benchmark

QUERY (SELECT) Operation

Database1000 records10,000 records100,000 records
Microsoft SQL Server35.3243.62313.4
MySQL4.1117.8844.8
PostgreSQL3.719.4663.5
MongoDB1.06.043.5
CouchDB2.1430.44307.54
Couchbase4.3434.89345.77
HyperionDB0.800.801.00

Query Benchmark

UPDATE Operation

Database1000 records10,000 records100,000 records
Microsoft SQL Server36.1286.52764.8
MySQL87.71264.010620.5
PostgreSQL77.32385.225421.5
MongoDB17.3265.42875.9
CouchDB1.5618.64266.68
Couchbase73.16731.3910414.85
HyperionDB3.2036.40399.40

Update Benchmark

DELETE Operation

Database1000 records10,000 records100,000 records
Microsoft SQL Server127.0482.95715.4
MySQL78.3825.818794.4
PostgreSQL35.5582.611479.8
MongoDB9.0133.81530.9
CouchDB1.1915.57132.7
Couchbase39.37405.576579.23
HyperionDB6.8017.40130.00

Delete Benchmark

The benchmark results show that HyperionDB provides competitive performance across all CRUD operations, particularly excelling in query operations. HyperionDB is well-suited for high-performance applications where rapid data access and updates are crucial.

πŸ“¦ Installation

Install HyperionDB via npm:

npm install hyperiondb

πŸ› οΈ Setup and Usage

1. Import HyperionDBClient

const HyperionDBClient = require('hyperiondb/hyperiondb-client');

2. Configuration

Create a configuration object specifying the number of shards, data directory, indexed fields, server address, and primary key field.

const config = {
  numShards: 8,
  dataDir: './hyperiondb_data',
  indexedFields: [
    ["name", "String"],
    ["price", "Numeric"],
    ["city", "String"],
    // Add other indexed fields as needed
  ],
  address: '127.0.0.1:8080'
};
const primaryKey = 'id';` 

3. Initialize the Client

Instantiate the HyperionDBClient with the configuration and primary key.

const client = new HyperionDBClient(config, primaryKey);` 

4. Initialize the Database and Start the Server

(async () => {
  try {
    // Initialize the database
    await client.initialize();
    console.log('Database initialized.');

    // Start the server
    await client.startServer();
    console.log('Server started.');
  } catch (error) {
    console.error('Initialization error:', error);
  }
})();

πŸ”„ CRUD Operations

Write a Record (Insert or Update)

The writeRecord method allows you to insert or update records based on the specified primary key. If a record with the same key exists, it merges the new data with the existing one; otherwise, it creates a new entry.

const record = {
  id: 'prod1748',
  name: 'Sample Product',
  price: 355.00,
  // other fields...
};

(async () => {
  const response = await client.writeRecord(record);
  console.log('Write response:', response); // Output: 'OK'
})();

Retrieve a Record

(async () => {
  const record = await client.get('prod1748');
  console.log('Retrieved record:', record);
})();

Delete a Record

(async () => {
  const success = await client.delete('id = "prod1748"');
  console.log('Delete successful:', success); // Output: true
})();

πŸ” Querying the Database

(async () => {
  const results = await client.query('price > 300 AND city = "New York"');
  console.log('Query results:', results);
})();

πŸ“„ API Reference

Constructor

new HyperionDBClient(config, primaryKey)

  • config: An object containing configuration settings.
    • numShards: Number of shards.
    • dataDir: Directory where shards are stored.
    • indexedFields: Array of indexed fields, each as [fieldName, indexType].
    • address: Address and port of the HyperionDB server (e.g., '127.0.0.1:8080').
  • primaryKey: The primary key field for records (e.g., 'id').

Methods

initialize()

Initializes the database with the provided configuration.

startServer()

Starts the HyperionDB server on the specified address and port.

writeRecord(record)

Inserts or updates a record in the database. If the record exists (based on the primary key), updates the record by merging the new fields. If it doesn't exist, inserts the new record.

  • record: The record object to insert or update.

get(id)

Retrieves a record by its ID.

  • id: The ID of the record to retrieve.

delete(condition)

Deletes records matching the specified condition.

  • condition: A string representing the deletion condition (e.g., 'price < 100').

list()

Lists all records in the database.

query(queryStr)

Queries the database with complex conditions.

  • queryStr: The query string (e.g., 'name CONTAINS "John" AND age > 30').

πŸ“ Examples

Example: Insert and Query

(async () => {
  // Insert multiple records
  await client.writeRecord({ id: '1', name: 'Alice', age: 30 });
  await client.writeRecord({ id: '2', name: 'Bob', age: 25 });
  await client.writeRecord({ id: '3', name: 'Charlie', age: 35 });

  // Query records where age is greater than 28
  const results = await client.query('age > 28');
  console.log('Query results:', results);
  // Output: [{ id: '1', name: 'Alice', age: 30 }, { id: '3', name: 'Charlie', age: 35 }]
})();

βš™οΈ Configuration Options

  • Sharding: Adjust numShards based on your performance and scaling needs.
  • Indexed Fields: Index fields that are frequently used in queries to improve performance.
  • Data Directory: Ensure the dataDir has sufficient permissions and storage space.

πŸ“Œ Notes

  • Server Readiness: After starting the server, ensure it's ready before performing operations.
  • Error Handling: Wrap your operations in try...catch blocks to handle exceptions.
  • Data Types: Ensure data types of fields match those specified in indexedFields.

πŸ› οΈ Development

Building from Source

Clone the repository:

git clone https://github.com/yourusername/hyperiondb.git

Install dependencies:

cd hyperiondb
npm install

Build the module:

npm run build

πŸ–₯️ Compatibility

  • Node.js: Requires Node.js version >= 10.
  • Platforms: Windows, macOS, Linux (including ARM architectures).

πŸ“„ License

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


πŸ™ Acknowledgements

  • Built with ❀️ using Rust and Node.js.
  • Thanks to the open-source community for their contributions.

πŸ“« Contact

For questions or support, please open an issue on GitHub or contact me at hi@pailletjp.com


🌟 Contributions

Contributions are welcome! Please read the contributing guidelines before submitting a pull request.


πŸ›‘οΈ Security

If you discover any security-related issues, please email your.email@example.com instead of using the issue tracker.


πŸ—ΊοΈ Roadmap

  • Implement authentication and authorization.
  • Add support for more data types.
  • Improve documentation and examples.
  • Integrate with popular frameworks.

πŸ’‘ Tips

  • Performance: For better performance, adjust the number of shards based on your system's capabilities.
  • Data Backup: Regularly backup your dataDir to prevent data loss.
  • Logging: Implement logging mechanisms for debugging and monitoring.

❓ FAQ

Q: Can I use HyperionDB in a production environment?

A: While HyperionDB is designed for high performance, please thoroughly test it in your environment before deploying to production.

Q: Does HyperionDB support transactions?

A: Currently, HyperionDB does not support transactions, but this feature is planned for future releases.


Happy coding!