Totally (well, almost) serverless concept that allows you to query DB from front-end. Krang! π
Concept of Krang is to "open the portal" to database, so it can be (almost) directly accessed from front-end. At first that sounds like totally Krang-ish idea and totally unsafe option, by configuring user roles in your database (for example allowing read-only particular tables) or if you trust your users (in Krang you can integrate some authentication mechanism) to give some write permissions too.
Another use of Krang would be for boostrapping an app, you can design your schema and move queries to backend later (very nice if it's Node).
Idea of writing plain SQL in javascript is also very Krang-ish but Squel.js can be good option.
IMPORTANT: Using Krang in production environment can worsen Global Warming!
git clone https://github.com/radenkovic/krang
cd krang
yarn
ornpm i
- Open
krang.js
and set up your database (or you can use.env
file) npm start
To query Krang you there is only one endpoint:
POST /krang
which uses only one parameter: query
.
Needless to say it's written in one file (krang.js
), runs on Node/Express
, and connected to MySQL database (but it can be anything else, literally). Frontend sample is written with jQuery so everyone can understand it.
You can set up your environment variables in .env
(dotenv) file:
- DB_HOST=localhost
- DB_USER=root
- DB_PASSWORD=""
- DB_DATABASE=krang
- DB_PORT=3306
If you find this idea interesting, you can fork it and contribute. Krang will love it.