@informath/db.js v1.0.0-beta.0
Informa-Db.js
Concept
The concept is to interact with storage units (such as Dbs or JSON files) by using javascript proxies.
How to install it:
npm i --save informa-db.js
How to use it:
Here's a code example on how to use it:
const {LocaleDb} = require('informa-db.js'); // Require the package
const players = new LocaleDb("players.json"); // Uses data.json to store data
// I implemented these functions but they're boring:
if (!players.exist(process.env.PLAYER))
players.add(process.env.PLAYER,{
inventory: Array(20),
equipment: Array(5),
temporaryData: {
hp: 20,
xp: 0
}
});
// Instead, use this more elegant way of doing it:
if(!players.value[process.env.PLAYER])
players.value[process.env.PLAYER]={
inventory: Array(20),
equipment: Array(5),
temporaryData: {
hp: 20,
xp: 0
}
};
Before you ask, those all work.
Docs
new LocaleDb( options{path, defaultString} )
options.path
Path to file. Will throw an error if none provided or if type is incorrect
options.defaultString
Default string to write on file if it doesn't exist. Defaults to '{}'
new RemoteDb( options{path, db, collection} )
options.path
URI to mongo db server. Will throw an error if none provided or if type is incorrect Boolean indicating whether the provided path is a file or a mongodb server Defaults to true if the path starts with "mongodb", false otherwise.
Notice: If you need to interact with a mongodb server, you need to install mongodb yourself
options.db
Database name, defaulting to "db"
options.collection
Collection name, defaulting to "collection"
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!