DEV Community

Cover image for 🚀 Introducing LacertaDB: A Simple and Powerful JavaScript Database
Matias Affolter
Matias Affolter

Posted 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)