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

buffalo-tongue-db

v0.2.1

Published

A TypeScript database library with built-in type checking

Downloads

15

Readme

Buffalo Tongue DB

(go to documentation.md for documentation)

Buffalo Tongue DB is a fun, very small database with built-in type checking that stores everything in memory (not persistent).

It also supports certain database functions, including:

  • Create Table
  • Insert
  • Select
  • Select Distinct
  • Select Count
  • Update
  • Delete

(and of course, conditions can be optionally included for select and update).

Using Buffalo Tongue is EXTREMELY simple. Installation is just like any other pacakge:

npm install buffalo-tongue-db

You can create a database with the following:

const buffalo = require("buffalo-tongue-db");
//OR
import * as buffalo from "buffalo-tongue-db";

let db = new buffalo.Database();

Buffalo Tongue is structured like a traditional relational database, meaning that it has tables. Because it performs type checking, you need to provide type information upon table creation. Here's a simple example:

// We could also say db.create("users"...
db.create_table("users", {
  columns: [
    { name: "username", type: buffalo.STRING, unique: true },
    { name: "age", type: buffalo.INT, unique: false },
  ],
});

We've created a table to store some user information. Obviously, two users are allowed to be the same age, but each username MUST be unique. We can see that with this example of inserting data:

db.insert("users", { age: 1, username: "Kiyaan" });
//Runs fine because age was not a unique column
db.insert("users", { age: 1, username: "Bob Smith" });
db.insert("users", { age: 10, username: "Sam" });
//The following throws an error because username "Kiyaan" already exists.
db.insert("users", { age: 100, username: "Kiyaan" });
//The following throws an error because the column age was not provided
db.insert("users", { username: "Kaneshka" });
//The following is alright because even though there are unnecessary columns, all the required columns are there
db.insert("users", { garbage: true, age: 10, username: "Jane Doe" });

Getting data is just as easy. We can grab all the rows with ages greater than 6 by executing:

db.select("users", { age: { gte: 7 } });

//Which then returns:
[{ age: 100, username: "Kiyaan" }];

Buffalo Tongue also supports default values. Here's an example where we store info about the items in a shop:

db.create_table("products", {
  columns: [
    //Note that we aren't specifying unique: false here. Columns default to not being unique
    { name: "name", type: BuffaloTongue.STRING },
    { name: "cost", type: BuffaloTongue.DOUBLE, default: 5.0 },
  ],
});

If we then store two products like so:

db.insert("products", { name: "shoes", cost: 100 });
db.insert("products", { name: "gloves" });

And log the records:

console.log(db.select("products"));

We see that the default of 5 activated for the gloves:

[
  { name: "shoes", cost: 100 },
  { name: "gloves", cost: 5 },
];

Go to documentation.md to see all the neat features of Buffalo Tongue!