DEV Community

Cover image for ๐Ÿš€ Introducing LacertaDB: A Simple and Powerful JavaScript Database
Matias Affolter
Matias Affolter

Posted on โ€ข Edited on

๐Ÿš€ Introducing LacertaDB: A Simple and Powerful JavaScript Database

Iโ€™m excited to introduce LacertaDB, a new database Iโ€™ve designed thatโ€™s simple, flexible, and powerful. It's still evolving, but even now, it brings some unique capabilities to the table that I think you'll find fascinating.

LacertaDB Javascript Logo

Let me walk you through what makes LacertaDB so interesting:

๐ŸŽฏ Key Features:

  • Effortless Compression & Encryption: Simply by setting the properties _compressed or _encrypted to true, the Document class automatically recognizes the need to compress or encrypt your data. No extra effort required on your part! It handles both packing and unpacking seamlessly.
  • Supports Various Data Types: Thanks to joyson, you can pack any type of JavaScript data into LacertaDBโ€”from TypedArray, to Errors, and everything JSON supports as well.
  • Efficient Metadata Storage with LocalStorage: What makes LacertaDB architecturally unique is that it uses localStorage to store metadata for each database, even when multiple collections exist. Though localStorage is capped at 5MB, thatโ€™s plenty for metadata. Hereโ€™s what we keep track of:
    • ๐Ÿ“ Length of documents
    • ๐Ÿ†” IDs of documents
    • ๐Ÿ“ฆ Sizes of documents
    • ๐Ÿ›ก๏ธ Permanence (_permanent property ensures documents don't get deleted during auto-compaction)

This approach allows LacertaDB to quickly retrieve the database state and automatically compact the database without querying IndexedDBโ€”which, while fast, isnโ€™t as speedy as localStorage.

๐Ÿ”ง The Inner Workings

While LacertaDB needs a bit more work, it already performs remarkably well. You can easily pack and unpack hundreds of documents, whether compressed, encrypted, or not, within milliseconds! ๐Ÿš€

And all of this while managing metadata in a lightweight manner and avoiding unnecessary overhead.

๐Ÿ’ก Why Use LacertaDB?

If you're looking for a simple-to-use database that:

  • Supports any type of JavaScript object ๐Ÿ› ๏ธ
  • Handles data compression/encryption with a single property change ๐Ÿ”’
  • Allows you to easily manage collections using instance methods ๐Ÿ“

Then LacertaDB might just be what you need!


โœจ How to Use It

You can get started by installing it from npm:

npm install lacertadb
Enter fullscreen mode Exit fullscreen mode

Example usage:

import LacertaDB from 'lacertadb';

// Create a database instance and get a (new) collection
const db = new LacertaDB('myDatabase');
const coll = db.getCollection('documents');

// Add a document with encryption and compression
await coll.addDocument({
    _id: 'document1',
    _compressed: true,
    _encrypted: true,
    data: 'Some sensitive data'
}, 'password');

// Display the query result (you'll see it's encrypted)
console.log(await coll.query());

// Display the document as original
console.log(await coll.getDocument('document1', 'password'));
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Want to know more?

Check out the NPM package
or start using LacertaDB in your projects today. Feedback and contributions are always welcome!

If youโ€™ve ever thought, โ€œI just need a simple database to store my JavaScript objects,โ€ look no further. LacertaDB is here to make your life easier. ๐ŸŽ‰


โ€œCode is like humor. When you have to explain it, itโ€™s bad.โ€ โ€“ Cory House

Give LacertaDB a try, and see how it fits into your next project! ๐Ÿ™Œ


This database is evolving, but with its ability to compress, encrypt, and handle various data types in milliseconds, I believe itโ€™s a solid choice for projects that need a lightweight and flexible storage solution. ๐Ÿš€

Top comments (0)