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

megasql.db

v0.3.1

Published

A simple sqlite database that allows you to interact with databases with 0 knowledge.

Downloads

83

Readme

Functions of megasql.db:

.fetch(userid, variable, valueIfNull(optional), newValue(optional)) - fetchs a variable and gets his value to a let, var, const function.

.get(userid, variable) - gets a variable value from given user id.

.add(userid, variable, value) - adds a value to given variable name and user id.

.subtract(userid, variable, value) - subtracts a value to given variable name and user id.

.cooldown(userid, command, time(ms)) - adds a cooldown to the command, you'll have to use a variable.

.sortData(variable) - returns all the values of a variable sortered

.set(userid, variable, value) - sets a new value for given variable name.

.condition(userid, variable, condition, number) - used to make a condition with a variable value, itll return true or false.

.removeCooldown(userid, command) - removes a cooldown from given command name and user id.

.addEvent(event, duration) - adds an event where event is the event name and duration is the duration of the event in milliseconds.

.getEvent(event, parse(optional)) - gets an event with given event name. If you set parse to true, it'll return the time in hours, minutes, seconds... If it isn't setted, it'll return the milliseconds left of that event.

.map(userid, ["var1", "var2", ...], valueIfNull(optional)) - mainly used for load multiple variables from given user id and put them in an array, if valueIfNull is setted, variables with null values will be replaced with valueIfNull.

.setVars(userid, ["var1", "var2", ...], [0 , 50, ...]) - sets multiple variables to given values of chosen userid.

.addToVars(userid, ["var1", "var2", ...], [2 , 10, ...], valueIfNull(optional)) - add to multiple variables the given values of chosen userid.

.subtractToVars(userid, ["var1", "var2", ...], [5 , 13, ...], valueIfNull(optional)) - subtract to multiple variables the given values of chosen userid.

Examples using megasql.db:

Imagine we want to add a cooldown for a command, here we go:

client.on("message", async message => {

if (message.content.startsWith("!test")) {

let cooldown = await db.cooldown(message.author.id, "test", 60000)

if (cooldown == 0) {

message.channel.send("Cooldown Expired")

} else {

let time = ms(cooldown)

message.channel.send(\`${message.author.username} please wait ${time.seconds} seconds.\`)
}
}})

Or maybe we want to do a leaderboard:

client.on('message', async message => {

if (message.content.startsWith("!leaderboard")) {

let content = ``

let position = 1

let array = await db.sortData("money")

for (let i = 0;i < array.length;i++) {

if (client.users.get(array[i].ID.split("_")[1])) {

let user = client.users.get(array[i].ID.split("_")[1]).username

content += `${position} - ${user} - Money: ${array[i].data}\n`
 }
}
message.channel.send("Top Money:\n" + content)
}})

What about a condition?

client.on('message', async message => {

if (message.content.startsWith('!condition')) {

let item = await db.condition(message.author.id, "messages", ">=", 100)

if (item == true) {

message.channel.send(message.author + ' nice! you have sent more than 100 messages!')

} else {

message.channel.send(message.author + " you don't have more than 100 messages sent.")
}
}})

What about an event:

client.on('message', async message => {

if (message.content.startsWith('!addEvent')) {

db.addEvent("event1", 120000) //2 minutes in milliseconds
  
message.channel.send("Successfully added an event!")
}})

//next command would be:

client.on('message', async message => {

if (message.content.startsWith('!getEvent')) {

let key = await db.getEvent("event1", true)

if (event1 == -1) return message.channel.send("There isn't any event right now.")

message.channel.send("Event duration: " + key)
}})

Now, let's gonna get multiple variable values:

client.on("message", async message => {
  
  if (message.content.startsWith("!map")) {
    
    let vars = await db.map(message.author.id, ["money", "messages", "health"], 0)
    //vars will contain 3 values, money, messages and health
    //if we want to get the messages value, we'll do vars[1]
    message.channel.send("Money: " + vars[0] + "\nMessages sent: " +  vars[1] + "\nHealth: " + vars[2])
    
}})

Isn't it easy? :D

Remember to use async because megasql.db takes some milliseconds to load the values.

If you need more help contact us on our Discord Server.