Octavia DB
OctaviaDB is a lightweight Node.js module for creating encrypted collections of data on the filesystem. It provides basic CRUD (Create, Read, Update, Delete) operations for collections and supports encryption for data security.
Authors
Installation
To install the OctaviaDB module, run the following command in your terminal:
npm install octavia-db
Features
-
Encryption: OctaviaDB provides built-in encryption for your database to ensure data security.
-
CRUD Operations: Perform Create, Read, Update, and Delete operations on collections.
-
Database Information: Retrieve information about the database, collections, and file sizes.
Getting Started
Create a new database with a name and password
const myDatabase = new OctaviaDB({
databaseName: 'myDatabase',
databasePassword: 'mySecretPassword',
logging: true // Set to false to disable logging
});
databaseName.collection()
Create a collection. const userCollection = myDatabase.collection(
'users', // collection name
true // encryption, default true
);
collectionName.insert()
Insert data into the collection. const user1 = {
username: 'john_doe',
email: 'john.doe@example.com',
age: 30
};
const result = userCollection.insert(user1);
if(result) {
console.log(`inserted successfully`)
} else {
console.log(`error while inserting the data`)
}
collectionName.insertMany()
Insert multiple data objects into the collection. const multipleUserData = [
{
username: "patrick_williams",
email: "patrick.williams@example.com",
age: 25
},
{
username: "jane_smith",
email: "jane.smith@example.com",
age: 25
},
{
username: "alex_johnson",
email: "alex.johnson@example.com",
age: 35
},
{
username: 'john_doe',
email: 'john.doe@example.com',
age: 25
}
];
const insertResult = userCollection.insertMany(multipleUserData);
if(insertResult) {
console.log("success")
} else {
console.log(`error while inserting the data`)
}
collectionName.find()
Find a user in the collection. const foundUser = userCollection.find({ username: 'john_doe' });
if (foundUser) {
console.log('Found User:', foundUser);
} else {
console.log('User not found.');
}
collectionName.findMany()
Find many users in the collection. const foundUser = userCollection.findMany({ age: 25 });
if (foundUser) {
console.log('Found User:', foundUser);
} else {
console.log('User not found.');
}
collectionName.update()
Update user information. const updatedUserData = {
age: 31,
city: 'New York'
};
const updated = userCollection.update({ username: 'alex_johnson' }, updatedUserData);
if (updated) {
console.log("success");
} else {
console.log("failed");
}
collectionName.updateMany()
Update many user information. const updatedUserData = {
status: "active"
};
const updated = userCollection.updateMany({ age: 25 }, updatedUserData);
if (updated) {
console.log("success");
} else {
console.log("failed");
}
collectionName.remove()
Remove a user from the collection. const removed = userCollection.remove({ username: 'alex_johnson' });
if (removed) {
console.log("success");
} else {
console.log("failed");
}
collectionName.removeMany()
Remove many user from the collection. const removed = userCollection.removeMany({ username: 'john_doe' });
if (removed) {
console.log("success");
} else {
console.log("failed");
}
collectionName.info()
Get information about the collection. const collectionInfo = userCollection.info();
if (collectionInfo) {
console.log('Collection Information:', collectionInfo);
} else {
console.log('Collection not found.');
}
databaseName.info()
Get information about the entire database. const databaseInfo = myDatabase.info();
if (databaseInfo) {
console.log('Database Information:', databaseInfo);
} else {
console.log('Database not found.');
}
Delete the collection
const isUserCollectionDeleted = userCollection.delete();
if (isUserCollectionDeleted) {
console.log('Collection deleted successfully.');
} else {
console.log('Error deleting collection.');
}
Delete the entire database
const isDatabaseDeleted = myDatabase.delete();
if (isDatabaseDeleted) {
console.log('Database deleted successfully.');
} else {
console.log('Error deleting database.');
}