🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

url2sql

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url2sql

A simple function + express middleware to transform an URL into a database query

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

WIP: A very simple function and express middleware that help you form SQL queries from an URL. Based on Knex.

npm i url2sql

Note: the provided middleware does not include a security mechanism (i.e. we don't check if the user can query the table/database, we just execute the query), you will have to implement that part yourself in another middleware.

Also, this library's intent is not to provide a full-fledged way to query the database from an url, but rather to provide a way to execute simple GET/POST/PUT/DELETE operation on a database. You wont be able to use it to build complex SQL queries from a url, only simple ones.

Here are some examples of what it can do:

URLSQL
/usersSELECT * FROM users
/users?offset=10&limit=20&orderBy=ageSELECT * FROM users OFFSET 10 LIMIT 20 ORDER BY age
/users?where=id.eq.1SELECT * FROM users WHERE id = '1'
/users?where=age.gte.21&where=job.eq.astronautSELECT * FROM users WHERE age >= '21' AND job = 'astronaut'
-- (joins are not implemented)SELECT * FROM users JOIN article on users.id = article.author
-- ("or" in where clause not implemented)SELECT * FROM users where age = '21' OR age = '22'

Middleware Usage example

import { middleware as url2sql } from 'url2sql';

router.all(
  `/:ressource/:ressourceId?`,
  // here, put some middleware to check user authentication and rights
  url2sql(knexInstance), // the middleware will treat the first parameter it receives (here :ressouce) as the table name and the second as the (optionnal) id.
);

Keywords

url

FAQs

Package last updated on 18 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts