1.1.7 • Published 1 year ago

@mathrandom7910/little-db v1.1.7

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Little-DB

A small, simple local and typed database written in typescript for node.js.

Install with npm i @Mathrandom7910/little-db

Javascript example:

    // Import the package
    const { init } = require("@mathrandom7910/little-db");
    // Get entry function
    const { entry } = init();
    // Create a user entry and get the user class, with (optional) default data
    const User = entry("user", {
        info: {
            age: 23
        }
    });

    (async function() {
        // Find a user with the given property string
        const user = await User.findOne("info.age", 25);
        console.log(user);

        // Edit properties and save
        user.data.info.age = 20;
        user.save();

        // Finds a user with the `userName` of joe
        const userJoe = await User.findOne("userName", "joe");
        console.log(user);

        // Find all users that are 25 years old
        const users = await User.find("info.age", 25);
        console.log(users);

        // Get every user in the entries
        const allUsers = await User.all();
        console.log(allUsers);

        // Iterate over the entries
        await User.iter((user, cancelFn) => {
            if(user.data.userName == "joe") {
                // We found joe! Now we can cancel itering over the entries.
                cancelFn();
            }
        });
    })();

TypeScript example:

import { init } from "@mathrandom7910/little-db"
    // Get entry function
    const { entry } = init();

    interface IUser {
        name: string;
        age: number
    }

    // Create a user entry and get the user class, with (optional) default data
    const User = entry<IUser>("user");
1.1.1

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago