Skip to content

Releases: plexidev/quickmongo

v5.2.0

18 Sep 09:04
Compare
Choose a tag to compare

Updates

  • 🚀You can now use mongodb with quick.db via quickmongo's new quick.db compatible mongodb driver
  • new db.watch()
  • new autoConnect option
  • new db.useCollection() alias for db.table
  • filter fn support for db.pull
  • new db.shift/unshift/pop/startsWith/endsWith/sub/addSubtract/getArray api
  • 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

25 Jan 19:49
Compare
Choose a tag to compare

Updates

  • fix TTL bug

Full Changelog: v5.1.1...v5.1.2

v5.1.1

21 Jan 12:50
Compare
Choose a tag to compare

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

21 Jan 07:32
Compare
Choose a tag to compare

Updates

  • add db.table constructor
    • This works different from db.instantiateChild. Example:
      const table = new db.table("myTable");
      table.set("foo", "bar");

Full Changelog: v5.0.1...v5.1.0

v5.0.1

20 Jan 07:23
Compare
Choose a tag to compare

Updates

  • db.fetch()
  • db.all() filter fn now returns object with ID and data props
  • db.stats()
  • db.metadata
  • minor changes

Full Changelog: v5.0.0...v5.0.1

v5.0.0

20 Jan 03:14
8047c9b
Compare
Choose a tag to compare

Updates

  • Restore old api
  • Dot props are now stable
  • Ability to run filter query while calling db.all() (#41)
  • Overall improvements

Contributors

Full Changelog: v4.0.0...v5.0.0

v4.0.0

01 Sep 12:55
47375cb
Compare
Choose a tag to compare

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, import etc.
  • v4 only has 10 methods: has, get, set, delete, push, pull, drop, all, latency and export.
  • Implements the Fields logic, 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

01 Mar 15:18
Compare
Choose a tag to compare

Updates

  • fixed mongodb deprecation warning
  • bump :: Lodash & Mongoose

v3.0.0

21 Dec 13:45
Compare
Choose a tag to compare

Changes

  • added multiple db support

Fix db#get and db#has

03 Nov 08:50
Compare
Choose a tag to compare

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