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

easeql

v0.0.4

Published

Write the documentation and it generates the SQL commands for you

Downloads

3

Readme

EaseQL

A simple command line utility that lets you generate SQL commands from documentation. The command takes in a YAML file (which is as human-readable as it gets) and generates the SQL commands from that.
The command will only create tables that doesn't exist so you can safely add tables to the documentation and run the command again

Installation

npm install -g easeql

Running and using it

In order to run it, simply call the command and pass the .yaml file to the command line utility.

easeql database.yaml

This will print the SQL queries to be executed to the console.

If you require the SQL commands to be written to a file in order to be passed to the SQL as input later on, just pipe the output to a file.

easeql database.yaml > queries.sql

Example YAML format (a piece of code is worth a thousand words)

## Declare tables as list items, with the name compulsorily as "tableName", followed by the actual table name
-   tableName: "users"
    schema:
        # declare columns like so
        username:
            type: "varchar"
            size: 36
            # Declare primary keys like so
            primaryKey: true
        email:
            type: "varchar"
            size: 150
            # Unique and not null identifiers are accepted too
            unique: true
            notNull: true
        password:
            type: "varchar"
            size: 64
        phone:
            # Any SQL accepted data-type is allowed
            type: "int"
            size: 10
        dob:
            type: "int"
            size: 15
        bio:
            # Don't mention the size for data-types without a size
            type: "text"

-   tableName: "password_resets"
    schema:
        username:
            type: "varchar"
            size: 36
            primaryKey: true
            # Declare foreign keys by specifying what table and column it references to
            foreignKey:
                table: "users"
                column: "username"
        token:
            type: "varchar"
            size: 64
        tokenExpiry:
            type: "int"
            size: 15

-   tableName: "blog_comments_likes"
    schema:
        commentId:
            type: "varchar"
            size: 36
            foreignKey:
                table: "comments"
                column: "commentId"
        username:
            type: "varchar"
            size: 36
            foreignKey:
                table: "users"
                column: "username"
    # Composite primary keys are mentioned outside the "schema" object
    primaryKey:
        - commentId
        - username

-   tableName: "i_ran_out_of_ideas_for_table_names_sorry"
    schema:
        someRandomColumnName:
            type: "varchar"
            size: 25
        anotherRandomColumnName:
            type: "bigint"
    # Composite unique keys are allowed too
    unique:
        - someRandomColumnName
        - anotherRandomColumnName

...will translate to the following (prettified for easier readability):

CREATE TABLE IF NOT EXISTS users
(
    username VARCHAR(36) PRIMARY KEY,
    email VARCHAR(150) UNIQUE NOT NULL,
    password VARCHAR(64),
    phone INT(10),
    dob INT(15),
    bio TEXT
);

CREATE TABLE IF NOT EXISTS password_resets
(
    username VARCHAR(36) PRIMARY KEY,
    FOREIGN KEY(username) REFERENCES users(username),
    token VARCHAR(64),
    tokenExpiry INT(15)
);

CREATE TABLE IF NOT EXISTS blog_comments_likes
(
    commentId VARCHAR(36),
    FOREIGN KEY(commentId) REFERENCES comments(commentId),
    username VARHCAR(36),
    FOREIGN KEY(username) REFERENCES users(username),
    PRIMARY KEY(commentId, username)
);

CREATE TABLE IF NOT EXISTS i_ran_out_of_ideas_for_table_names_sorry
(
    someRandomColumnName VARCHAR(25),
    anotherRandomColumnName BIGINT,
    UNIQUE(someRandomColumnName, anotherRandomColumnName)
);

License

This piece of code is distributed under the GNU GPLv3 License.
If you are using this software, please give due credits to the authors.