Releases: plexidev/quickmongo
Releases · plexidev/quickmongo
v5.2.0
Updates
- 🚀You can now use mongodb with quick.db via quickmongo's new quick.db compatible mongodb driver
- new
db.watch() - new
autoConnectoption - new
db.useCollection()alias fordb.table - filter fn support for
db.pull - new db.
shift/unshift/pop/startsWith/endsWith/sub/addSubtract/getArrayapi - other various changes
MongoDriver example
const { QuickDB } = require("quick.db");
// get mongo driver
const { MongoDriver } = require("quickmongo");
const driver = new MongoDriver("mongodb://localhost/quickdb");
driver.connect().then(() => {
console.log(`Connected to the database!`);
init();
});
async function init() {
// use quickdb with mongo driver
// make sure this part runs after connecting to mongodb
const db = new QuickDB({ driver });
// self calling async function just to get async
// Setting an object in the database:
console.log(await db.set("userInfo", { difficulty: "Easy" }));
// -> { difficulty: 'Easy' }
// Getting an object from the database:
console.log(await db.get("userInfo"));
// -> { difficulty: 'Easy' }
// Getting an object property from the database:
console.log(await db.get("userInfo.difficulty"));
// -> 'Easy'
// Pushing an element to an array (that doesn't exist yet) in an object:
console.log(await db.push("userInfo.items", "Sword"));
// -> { difficulty: 'Easy', items: ['Sword'] }
// Adding to a number (that doesn't exist yet) in an object:
console.log(await db.add("userInfo.balance", 500));
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
// Repeating previous examples:
console.log(await db.push("userInfo.items", "Watch"));
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
console.log(await db.add("userInfo.balance", 500));
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
// Fetching individual properties
console.log(await db.get("userInfo.balance")); // -> 1000
console.log(await db.get("userInfo.items")); // ['Sword', 'Watch']
// disconnect from the database
await driver.close();
}Full Changelog: v5.1.2...v5.2.0
v5.1.2
v5.1.1
Updates
- TTL support
// permanent await db.set("test", 123); // set the data and automatically delete it after 1 minute await db.set("foo", "bar", 60); // 60 seconds = 1 minute // fetch the temporary data after a minute setTimeout(async () => { await db.get("foo"); // null await db.get("test"); // 123 }, 60_000);
Full Changelog: v5.1.0...v5.1.1
v5.1.0
Updates
- add
db.tableconstructor- This works different from
db.instantiateChild. Example:const table = new db.table("myTable"); table.set("foo", "bar");
- This works different from
Full Changelog: v5.0.1...v5.1.0
v5.0.1
Updates
db.fetch()db.all()filter fn now returns object withIDanddatapropsdb.stats()db.metadata- minor changes
Full Changelog: v5.0.0...v5.0.1
v5.0.0
Updates
- Restore old api
- Dot props are now stable
- Ability to run filter query while calling
db.all()(#41) - Overall improvements
Contributors
- This update is based on #42 by @DevAndromeda
Full Changelog: v4.0.0...v5.0.0
v4.0.0
Updates
QuickMongo v4 is completely rewritten in TypeScript. v4 is completely different from what older versions looked like.
Breaking Changes
- QuickMongo no longer exports
Database, instead it is a collection - Removed methods like
add,subtract,math,divide,multiply,keyArray,valueArray,importetc. - v4 only has 10 methods:
has,get,set,delete,push,pull,drop,all,latencyandexport. - Implements the
Fieldslogic, which is now required. - QuickMongo now works as a utility layer, adding key-value interface to existing mongodb collection
- Dot notations are no longer parsed from the key, instead it needs to be supplied separately as a parameter.
- Database states are no longer handled by QuickMongo.
- v4 is strongly typed, providing better experience to TypeScript users.
- It supports exporting the collection as raw json, in better form.
- v4 does implement the old data structure of quick.db, i.e.
{ ID: string; data: any; }however, users must use Fields.
Basic Example
const { Collection: MongoCollection, MongoClient } = require("mongodb");
const { Collection, Fields } = require("quickmongo");
const mongo = new MongoClient("mongodb://localhost/quickmongo");
const schema = new Fields.ObjectField({
difficulty: new Fields.StringField(),
items: new Fields.ArrayField(new Fields.StringField()),
balance: new Fields.NumberField()
});
mongo.connect()
.then(() => {
console.log("Connected to the database!");
doStuff();
});
function doStuff() {
const mongoCollection = mongo.db().collection("JSON");
const db = new Collection(mongoCollection, schema);
db.set("userInfo", { difficulty: "Easy", items: [], balance: 0 }).then(console.log);
// -> { difficulty: 'Easy', items: [], balance: 0 }
db.push("userInfo", "Sword", "items").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword'], balance: 0 }
db.set("userInfo", 500, "balance").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }
// Repeating previous examples:
db.push("userInfo", "Watch", "items").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
const previousBalance = await db.get("userInfo", "balance");
db.set("userInfo", previousBalance + 500, "balance").then(console.log);
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }
// Fetching individual properties
db.get("userInfo", "balance").then(console.log);
// -> 1000
db.get("userInfo", "items").then(console.log);
// -> ['Sword', 'Watch']
// remove item
db.pull("userInfo", "Sword", "items").then(console.log);
// -> { difficulty: 'Easy', items: ['Watch'], balance: 1000 }
}v3.0.2
v3.0.0
Fix db#get and db#has
QuickMongo v2.0.6 is released 🎉
- db#table() has been deprecated and will be removed in next update. Please switch to db#createModel() instead
- Fixed a bug : db#get used to return null for false values | db#has used to return false for false values which includes false, 0 etc.
- Other minor changes
Docs: https://quickmongo.js.org
GitHub: https://github.com/DevSnowflake/quickmongo
NPM: https://npmjs.com/package/quickmongo