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

restfulsql

v1.4.0

Published

Easily convert a SQL database into a REST API using Express.js.

Downloads

28

Readme

Easily convert your SQL database into a REST API.

This is a lightweight Express.js middleware library that is able to convert SQL databases into a REST API. This library also works seamlessly with the Form.io platform where you can build Angular.js and React.js applications on top of your SQL database. Please go to https://form.io to learn more.

This library currently supports Microsoft SQL Server, MySQL, and PostgreSQL.

How it works

This module works by assigning routes to specific queries, which you define, that are executed when the routes are triggered. For example, lets say you have the following customer table.

customer

  • firstName
  • lastName
  • email

This library is able to convert this into the following REST API.

  • GET: /customer - Returns a list of all customers.
  • GET: /customer/:customerId - Returns a single customer
  • POST: /customer - Creates a new customer
  • PUT: /customer/:customerId - Updates a customer
  • DELETE: /customer/:customerId - Deletes a customer.

Please refer to the example folder to see how this library is used to achieve the following.

How to use

This library is pretty simple. You include it in your Express.js application like the following.

var express = require('express');
var resquel = require('resquel');

// Create the Express.js application.
var app = express();

// Include the resquel library.
app.use(resquel(config));

// Listen to port 3000.
app.listen(3000);

The configuration passed into the resquel library is where the magic happens.

{
  "db": {
    "user": "-- YOUR DATABASE USERNAME --",
    "password": "-- YOUR DATABASE PASSWORD --",
    "server": "-- YOUR DATABASE SERVER --",
    "database": "-- YOUR DATABASE NAME --",
    "options": {
      "instanceName": "-- THE SERVER INSTANCE --"
    }
  },
  "routes": [
    {
      "method": "get",
      "endpoint": "/customer",
      "query": "SELECT * FROM customers;"
    },
    {
      "method": "post",
      "endpoint": "/customer",
      "query": "INSERT INTO customers (firstName, lastName, email) VALUES ('{{ data.firstName }}', '{{ data.lastName }}', '{{ data.email }}');SELECT * FROM customers WHERE id=SCOPE_IDENTITY();"
    },
    {
      "method": "get",
      "endpoint": "/customer/:customerId",
      "query": "SELECT * FROM customers WHERE id={{ params.customerId }};"
    },
    {
      "method": "put",
      "endpoint": "/customer/:customerId",
      "query": "UPDATE customers SET firstName='{{ data.firstName }}', lastName='{{ data.lastName }}', email='{{ data.email }}' WHERE id={{ params.customerId }};SELECT * FROM customers WHERE id={{ params.customerId }};"
    },
    {
      "method": "delete",
      "endpoint": "/customer/:customerId",
      "query": "DELETE FROM customers WHERE id={{ params.customerId }};"
    }
  ]
}

Each route defines a new endpoint and maps a query to that enpoint. Within the query, you have access to the following.

  • data - The req.body of the request.
  • params - The req.params of the request. Like when you use /customer/:customerId
  • query - The req.query of the request. Used with GET parameters like this /customer?company=1234

Enjoy!

  • The Form.io Team