Developer :
Mullayam
Version :1.0.0
PreSQL is an SQL-language based library containing pre-written code with shortend methods. Say "bye" to writing long query statements.
PreSQL requires the following dependencies to be installed:
- Node.js v16+
- mysql2 - to connect to MySQL database
Install the dependencies and devDependencies and start the server.
npm i presql
- create() , createMany()
- updateOne() , updateMany()
- destroy() , destroyAll()
- Math()
- join()
- In,Between,Alias,Distinct,OrderByGroup -- Adding in Future Versions
create a file index.js
use that code give below, to initiate DB Connection
const { PreSqlClient } = require("presql");
const presql = new PreSqlClient({
pre_user: "root",
pre_password: "",
pre_host: "localhost",
pre_database: "db_name",
pre_port: 3306,
showConnErrors: true, // this will show info that DB is connected or not , by default is false
resultLogs: true, // this will enable to preview result in console log , by default is false
});
async function test() {
const getData = await presql.findMany({ table: "products"
});
console.log(getData)
}
test();
async function test() {
const getData = await presql.create({
table: "users", // required parameter
data: {
firstName: "John",
lastName: "Doe",
}, //data is required parameter only single object
});
// if table and column uses any special character, please pass name in cammelCase e.g first_name to firstName
console.log(getData)
}
test();
async function test() {
const getData = await presql.createMany({
table: "users", // required parameter
data: [
{
firstName: "John",
lastName: "Doe",
},
{
firstName: "David",
lastName: "Olis",
},
{
firstName: "Rachna",
lastName: "Singh",
},
] //data is required parameter, only single object
});
// if table and column uses any special character, please pass name in cammelCase e.g first_name to firstName
console.log(getData)
}
test();
async function test() {
const getData = await presql.updateOne({
table: "users", // required parameter
data: {
firstName: "John",
lastName: "Doe",
}, //data is required parameter only single object
where:{
id:1
},// where field is optional, to update special row please pass this field
});
// if table and column uses any special character, please pass name in cammelCase e.g first_name to firstName
console.log(getData)
}
test();
async function test() {
const getData = await presql.updateMany({
table: "users", // required parameter
data: [
{
firstName: "John",
lastName: "Doe",
},
{
firstName: "David",
lastName: "Olis",
},
{
firstName: "Rachna",
lastName: "Singh",
},
] , //data is required parameter only single object
where:{
id:1
},// where field is optional, to update special row please pass this field
});
// if table and column uses any special character, please pass name in cammelCase e.g first_name to firstName
console.log(getData)
}
test();
async function test() {
const getData = await presql.destroy({
table: "users", // required parameter
where:{
id:1
},// where field is must,
});
// if table and column uses any special character, please pass name in cammelCase e.g first_name to firstName
console.log(getData)
}
test();
async function test() {
const getData = await presql.destroy({
table: "users", // required parameter
where:{
id:1
},// where field is optional,
});
// if table and column uses any special character, please pass name in cammelCase e.g first_name to firstName
console.log(getData)
// this will delete all data form entire table and make it empty
}
test();
async function test() {
const getData = await presql.findById({
table: "users", // required parameter
table: "users",
select: {
firstName:true // use this syntax
},
id:1 // must be string | number | object id:productIid
// no need to pass where filed, or where is optional
// where :{ id : 1}
sortBy: {
id:true,// use this syntax
asc:true
},
// if table and column uses any special character, please pass name in cammelCase e.g first_name to firstName
console.log(getData)
// this will delete all data form entire table and make it empty
}
test();
This project is licensed under MIT
License, please check the LICENSE file for more details.