npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@airplanegobrr/database

v2.5.2

Published

A simple database thingy made to save to json

Downloads

26

Readme

Database

Warning 2.0.0 + may have some breaking changes from 1.0.X

Alot of backend code was changed so please check!

This is my custom built database module for nodejs!

Tests:

npm test (this is not a good test.)

How to use

Normal way

const Database = require('@airplanegobrr/database')  
const db1 = new Database()
await db1.set("name", true)
await db1.set("age", 20)

await db1.add("age", 20)
await db1.toggleBoolean("name")

With custom file names

const Database = require('@airplanegobrr/database')  
const db2 = new Database({filename: "data2.json"})
await db2.set("name", true)
await db2.set("age", 20)

await db2.add("age", 20)
await db2.toggleBoolean("name")

Manual Saving (No need for awaits)

const Database = require('@airplanegobrr/database')
const db3 = new Database({ manual: true, filename: "noAwaits.json" })
db3.set("name", true)
db3.set("age", 20)

db3.add("age", 20)
db3.toggleBoolean("name")
if (!db3.saved) await db3.save()

Server

Notes:

  • the null can be replaced by a http server input (you can get the builtin http server via server.express server.app server.http and lastly this.server) (MAKE SURE TO INSTALL express, socket.io, socket.io-client, json-bitmask)
const Database = require('./database')

const server = new Database.server(null, {
    databases: [
        { name: "exampleDatabase", allowedUsers: ["user1", "user2"] }
    ],
    users: [
        { user: "user1", password: "pass", authLevel: 1 },
        { user: "user2", password: "pass", authLevel: 2 }
        // ADMIN: 1, READ: 2, WRITE: 4, DELETE: 8, CREATEDATABASE: 16
        // READ and WRITE example: 6, + CREATEDATABASE: 22
    ],
    allowCreationOfDatabases: true, // allows clients to make databases (DOES NOTHING CURRENTLY)
    loginRequired: true // set to false to disable all this, will be false by default
})
await server.start()
console.log("Server started")
const client = new Database({
    driver: new Database.drivers.online({
        url: "WS://127.0.0.1:3000",
        auth: { user: "user2", password: "pass" },
        database: "exampleDatabase"
    })
})
await client.load()
console.log("Client loaded!")
await client.set("abc", {hello:"eeee"}).catch(e=>{console.log("ERROR", e)})
await client.set("abc.test", {no: false}).catch(e=>{console.log("ERROR", e)})

Have fun!