Skip to content

v5.2.0

Latest
Compare
Choose a tag to compare
@twlite twlite released this 18 Sep 09:04
· 15 commits to main since this release

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