Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Magmadb is a package that offers a user-friendly solution for storing and accessing data in a low to medium volume environment, suitable for individuals with varying levels of expertise. The data is stored locally and persistently in json format, and the package also provides a variety of convenient features to enhance the user experience.
npm i magmadb
//Importing Magmadb
const MagmaDatabase = require("magmadb");
//Create a new database named "db1"
const db = new MagmaDatabase("db1");
//Create a new collection named "accounts" inside "db1" to store user account data
const accounts = db.CreateCollection("accounts");
//Now we want to create a user account
//Create a new data document inside the collection "accounts"
accounts.CreateData({
id: 38437838728397,
name: "Jacob",
email: "example@domain.com",
password: "password123"
});
//Now for looking up a user inside a collection
//Find a document inside "accounts" by its id
const jacob = accounts.GetData({ id: 38437838728397 });
console.log(jacob);
/*
This will return the following object:
{
id: 38437838728397,
name: "Jacob",
email: "example@domain.com",
password: "password123"
}
*/
//Now Jacob wants to change his email from to "example4@domain.net"
//First we get Jacob's account to update his email
const jacob = accounts.GetData({ id: 38437838728397 });
//Then we call the function Collection.UpdateData() to make changes to Jacob's account
//Our Collection here is "accounts" so:
accounts.UpdateData(jacob, {
email: "example4@domain.net"
});
console.log(jacob);
/*
This will return the following object:
{
id: 38437838728397,
name: "Jacob",
email: "example4@domain.net",
password: "password123"
}
As you can see Jacob's email has been changed from "example@domain.com" to "example4@domain.net"
*/
//Lets create another account so we can have multiple documents inside our collection
accounts.CreateData({
id: 49845168798135,
name: "Walter",
email: "example2@domain.com",
password: "password123"
});
//You can also get all documents in a collection using Collection.GetAllData();
const allAccounts = accounts.GetAllData();
console.log(allAccounts);
/*
This will return the following Array of documents:
[
{
id: 38437838728397,
name: "Jacob",
email: "example@domain.com",
password: "password123"
},
{
id: 49845168798135,
name: "Walter",
email: "example2@domain.com",
password: "password123"
}
]
*/
//Lets try finding all users with the password "password123"
let usersWithSamePassword = accounts.Find({ password: "password123" });
console.log(usersWithSamePassword);
/*
This will return the following Array of documents:
[
{
id: 38437838728397,
name: "Jacob",
email: "example@domain.com",
password: "password123"
},
{
id: 49845168798135,
name: "Walter",
email: "example2@domain.com",
password: "password123"
}
]
Because Jacob and Walter has the same password ("password123")
*/
//Jacob wants to get his account deleted! Let's make his wish true.
//Lets get Jacobs account by his id
const jacob = accounts.GetData({ id: 38437838728397 });
accounts.DeleteData(jacob) //Here called Collection.DeleteData(jacob) to delete Jacob's account from the database.
//Now we check if Jacob's account is deleted by console logging all accounts
console.log(accounts.GetAllData());
/*
This will return the following Array of documents:
[
{
id: 49845168798135,
name: "Walter",
email: "example2@domain.com",
password: "password123"
}
]
//Jacob is out!
*/
//If you want to delete the whole accounts collection from your database use Database.DeleteCollection(collection)
//in our case here, Database is "db" and Collection is "accounts"
db.DeleteCollection(accounts);
//lets try console logging "accounts" after deleting it
console.log(accounts.GetAllData()); //This will return undefined
FAQs
Magmadb, a user-friendly solution for storing and accessing data.
The npm package magmadb receives a total of 4 weekly downloads. As such, magmadb popularity was classified as not popular.
We found that magmadb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.