PeperQL
A very easy to use node framework to manage your backend. Create a fresh server within 5 minutes and directly send API requests with a simple object.
const obj = {
type: "select",
tables: {
book: ["id", "name", "description"]
}
}
Installation
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 0.10 or higher is required.
Installation is done using the
npm install
command:
$ npm install peperql
Features
- Write queries fast in the body of a request
- Data is formatted in the way you requested it
- Easy access with a single route for all your requests
- MySQL and MariaDB support (New coming soon!)
- One-time easy setup
Quick Start
Install PeperQL
$ npm install peperql
After PeperQL is installed you can create a new file and copy this code below into that file. After the code is copied you can set the database credentials:
var peperql = require('peperql');
peperql.route.create({
route: "/peperql",
port: 5000
})
peperql.database.connect({
host: "localhost",
port: 3306,
user: "user",
password: "test",
database: "test"
});
Start PeperQL by running the file you've just created:
$ node [YOUR_FILE]
When the server has started and you've recieved no error you are ready to go.
it's time to send your first request, create a new javascript object and convert it to a JSON object as the code shows below:
const obj = {
type: "select",
tables: {
book: ["id", "name", "description"]
}
}
var jsonQuery = JSON.stringify(obj);
Now you can add the JSON object to the body of the request which points to url: "http://localhost:5000/peperql". You can change this in the settings file you've created.
fetch('http://localhost:5000/peperql', {
method: 'POST',
body: jsonQuery,
headers: { 'Content-Type': 'application/json' }
}).then(res => res.json())
.then(json => console.log(json));
Documentation
Delete
const obj = {
type: "delete",
table: "book",
conditionals: [
["book.id", ">", "40"]
]
}
Update
const obj = {
type: "update",
table: "book",
columns: {
name: "This is a updated book",
description: "This is the updated description of a book"
},
conditionals: [
["book.name", "=", "This is a book"]
]
}
Insert
const obj = {
type: "insert",
table: "book",
columns: {
name: "This is a book",
description: "This is the description of a book"
}
}
Select
Limit
I think there is no explanation necessary.
const obj = {
type: "select",
limit: 2,
tables: {
book: ["id", "name", "description"]
}
}
order by
In the first column you set the order by (asc or desc)
. After that you can add as many columns as you like which will be affected by the order.
const obj = {
type: "select",
order: ["desc", "book.id", "book.name"],
tables: {
book: ["id", "name", "description"]
}
}
joins
If you want to make use of joins you can! Under the relations you can add as many joins as you like. In the first column of each join you set the type (inner, left, right or full)
. Then you enter the two columns you want to join on.
const obj = {
type: "select",
tables: {
teacher: ["firstname", "birthdate"],
classroom: ["id", "roomID"]
},
relations: [
["inner", "teacher.roomID", "classroom.roomID"]
]
}
Where
Ofcourse you can make use of conditionals like and
and or
. Below are some examples how you would use them.
const obj = {
type: "select",
tables: {
book: ["id", "name", "description"]
},
conditionals: [
["book.name", "like", "%ee%"],
["book.id", "=", "3"],
["or"],
["book.id", "=", "1"]
]
}
Testing
If you want to test the api on your local machine with for example Postman you just need to add a JSON object to the body!
{
"type": "select",
"tables": {
"book:": ["id", "name", "description"]
}
}