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

faux-sql

v0.3.1

Published

A local JSON database using standard MySQL queries. The fastest way to get a database into your project.

Downloads

7

Readme

faux-sql

A local JSON database using standard MySQL queries. The fastest way to get a database into your project.

  • Human readable, easy to edit data files
  • Super easy to swap out for a real DB connection whenever you're ready
  • Database files can be checked-in with git/svn for easy collaboration

Install

$ npm install faux-sql

Get started via command line

$ npx faux-sql "CREATE TABLE users (id int AUTO_INCREMENT, name varchar(100), age int)"
$ npx faux-sql "INSERT INTO users VALUES (1, 'Bill', 17), (2, 'Ted', 21)"
$ npx faux-sql "SELECT * FROM users"
[
  { id: 1, name: 'Bill', age: 17 },
  { id: 2, name: 'Ted', age: 21 },
]

Use in code

import FauxSQL from 'faux-sql';

const sql = new FauxSQL();

(async () => {
    await sql('INSERT INTO users (name, age) VALUES ("Neo", 33)');
    const results = await sql('SELECT * FROM users');
    console.log(results);
})();

or

import FauxSQL from 'faux-sql';

const sql = new FauxSQL();

sql('INSERT INTO users (name, age) VALUES ("Neo", 33)')
    .then(results => sql('SELECT * FROM users'))
    .then((results) => {
        console.log(results);
    });

Data Files

Each table gets saved into its own JSON file. The default file path for these files is <root>/database, however, the file path can be customized in the constructor's Options if desired.

Options

new FauxSQL({
    filePath: `${process.cwd()}/special/path`,
})

Multiple Databases

Each table's data file will be stored in the default database at the root of the database directory ./database/users.json unless a database name is specified in the query.

For example:

sql('CREATE TABLE p2.users (id int, name varchar(100))');
sql('INSERT INTO p2.users VALUES (1, "Bill"), (2, "Ted")');
sql('SELECT * FROM p2.users');

The above data will instead be stored at ./database/p2/users.json and is distinct from any data stored in the default database.

======

Supported Query Types

In most cases, you can just use MySQL as you would normally and everything will just work

SELECT

sql(`
SELECT age, count(*) as total
FROM users
WHERE age > 18 AND name != NULL
GROUP BY age
ORDER BY age DESC
LIMIT 10
`)

CREATE

sql(`
CREATE TABLE users (
id int AUTO_INCREMENT,
name varchar(100),
age int
)`)

INSERT

sql(`
INSERT INTO users (name, age)
VALUES ('Bill', 17), ('Ted', 21)
`)

DELETE

sql(`
DELETE FROM users
WHERE id > 1
`)

UPDATE

sql(`
UPDATE users
SET age = 23
WHERE id = 2
`)

TRUNCATE

sql(`
TRUNCATE TABLE users
`)

ALTER

sql(`
ALTER TABLE users
ADD email varchar(255) PRIMARY KEY
`)

sql(`
ALTER TABLE users
DROP name
`)

DROP

sql(`
DROP TABLE users
`)

SHOW

sql(`
SHOW DATABASES
`)

sql(`
SHOW TABLES
`)

INNER JOIN

sql(`
SELECT t1.name, t2.fav_animal, t2.fav_food AS snack
FROM users t1
INNER JOIN favorites t2
ON t1.id = t2.user_id
`)

LEFT JOIN

sql(`
SELECT t1.name, t3.hobby
FROM users t1
LEFT JOIN hobbies t3
ON t1.id = t3.user_id
ORDER BY 1
`)

RIGHT JOIN

sql(`
SELECT t1.name, t3.hobby
FROM users t1
RIGHT JOIN hobbies t3
ON t1.id = t3.user_id
ORDER BY 2
`)

CROSS JOIN

sql(`
SELECT *
FROM hobbies
CROSS JOIN skills
`)

Currently Unsupported

There are some MySQL features that are not yet supported. Please create an issue if you'd like to see a certain feature added.

  • UNION
  • HAVING