Socket
Socket
Sign inDemoInstall

@krishnapawar/kp-mysql-models

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@krishnapawar/kp-mysql-models - npm Package Compare versions

Comparing version 1.2.4 to 1.2.5

87

lib/index.js

@@ -59,3 +59,3 @@ var pool;

if (isTable(data.table)) return reject(isTable(data.table));
let resw = [];
let response = [];
pool.query(

@@ -81,5 +81,5 @@ `SELECT ${selectOption(data)} FROM ${data.table} ${whereClause(

const item = await withdataForGet(reject, iterator, data);
resw.push(item);
response.push(item);
}
return resolve({ resw, paginate });
return resolve({ response, paginate });
}

@@ -90,5 +90,5 @@ );

const item = await withdataForGet(reject, iterator, data);
resw.push(item);
response.push(item);
}
return resolve(resw);
return resolve(response);
}

@@ -359,5 +359,5 @@ }

if (isCheck(data)) return "";
if (isCheck(data.limit)) return "";
if (data.limit != undefined && data.limit != null && data.limit != "")
return `order by ${data.limit} DESC`;
if (isCheck(data.latest)) return "";
if (data.latest != undefined && data.latest != null && data.latest != "")
return `order by ${data.latest} DESC`;
return "";

@@ -654,3 +654,3 @@ };

return "";
return `OFFSET ${parseInt(data.pagination) * parseInt(data)}`;
return `OFFSET ${parseInt(data.pagination>=1 ? data.pagination-1:data.pagination) * parseInt(data.limit)}`;
};

@@ -661,13 +661,14 @@

let pageCountExce =
totalData > 0 && totalData > data ? totalData / data : 0;
let pageCount =
totalData > 0 ? totalData / data.limit : 0;
let totalPage =
isInt(pageCountExce) == 0
? pageCountExce
: pageCountExce - isInt(pageCountExce) + 1;
let currentPage = data.pagination;
let currentPage = data.pagination>0?data.pagination:1;
let pagelenth = [];
for (let index = 0; index < pageCount; index++) {
for (let index = 1; index <= totalPage; index++) {
pagelenth.push(index);
}
return { pageCount, currentPage, pagelenth, totalData };
let pageDataLimit=data.limit;
return {pageDataLimit, totalPage, totalData, currentPage, pagelenth };
};

@@ -898,5 +899,6 @@ const joinTable = (data) => {

class BaseModels {
constructor(){
this._table="";
this._connection="";
constructor(db=""){
this._table= this.constructor.name.toUpperCase()+'s';
this._softDelete=false;
this._connection=db;
}

@@ -910,3 +912,3 @@ //start

if (isTable(this._table)) return reject(isTable(this._table));
let resw = [];
let response = [];
this._connection.query(

@@ -932,5 +934,5 @@ `SELECT ${selectOption(data)} FROM ${this._table} ${whereClause(

const item = await withdataForGet(reject, iterator, data,this._connection);
resw.push(item);
response.push(item);
}
return resolve({ resw, paginate });
return resolve({ response, paginate });
}

@@ -941,5 +943,5 @@ );

const item = await withdataForGet(reject, iterator, data,this._connection);
resw.push(item);
response.push(item);
}
return resolve(resw);
return resolve(response);
}

@@ -1206,2 +1208,4 @@ }

return new Promise( async(resolve,reject)=>{
if(isCheck(this._softDelete)) return reject("this._softDelete is not true!");
if(isCheck(whereClause(data))) return reject("Where condition is required!");
try {

@@ -1225,2 +1229,24 @@ if (sqlConnect(this._connection)) {

}
trashedAll(data){
if (isTable(this._table)) return reject(isTable(this._table));
return new Promise( async(resolve,reject)=>{
if(isCheck(this._softDelete)) return reject("this._softDelete is not true!");
try {
if (sqlConnect(this._connection)) {
return reject(sqlConnect(this._connection));
}
let colunm = await addDeletedAt(this._table,this._connection);
if (colunm) {
this._connection.query(`UPDATE ${this._table} SET deleted_at = NOW() ${whereClause(data)}`, (err, res) => {
if (err) {
return reject(err);
}
return resolve(res);
});
}
} catch (error) {
return reject(error);
}
});
}
restore(data){

@@ -1232,2 +1258,4 @@ if (isTable(this._table)) return reject(isTable(this._table));

return new Promise( async(resolve,reject)=>{
if(isCheck(this._softDelete)) return reject("this._softDelete is not true!");
if(isCheck(whereClause(data))) return reject("Where condition is required!");
this._connection.query(`UPDATE ${this._table} SET deleted_at = NULL ${whereClause(data)}`, (err, res) => {

@@ -1241,2 +1269,17 @@ if (err) {

}
restoreAll(data){
if (isTable(this._table)) return reject(isTable(this._table));
if (sqlConnect(this._connection)) {
return reject(sqlConnect(this._connection));
}
return new Promise( async(resolve,reject)=>{
if(isCheck(this._softDelete)) return reject("this._softDelete is not true!");
this._connection.query(`UPDATE ${this._table} SET deleted_at = NULL ${whereClause(data)}`, (err, res) => {
if (err) {
return reject(err);
}
return resolve(res);
});
});
}
}

@@ -1243,0 +1286,0 @@ module.exports = {

{
"name": "@krishnapawar/kp-mysql-models",
"version": "1.2.4",
"version": "1.2.5",
"description": "The `kp-mysql-models` library simplifies MySQL database interaction, streamlining tasks such as creating, inserting, updating, and deleting records, as well as handling complex queries like joins, pagination, and conditional operations. By offering an intuitive and efficient approach, it significantly reduces development time and effort.",

@@ -14,3 +14,3 @@ "main": "lib/index.js",

"keywords": [
"kp-mysql-models","@krishnapawar/kp-mysql-models","mysql models","mysql query builder","query builder","mysql builder","kp","krishna pawar","krishnapawar"
"kp-mysql-models","@krishnapawar/kp-mysql-models","models","mysql","query","builder","model","mysql models","mysql query builder","query builder","mysql builder","kp","krishna pawar","krishnapawar"
],

@@ -17,0 +17,0 @@ "author": "krishna pawar <krishnapawar90906@gmail.com>",

# kp-mysql-models
>The `kp-mysql-models` is a mysql query builder library that simplifies interactions with MySQL databases. It streamlines tasks such as creating, inserting, updating, and deleting records, and handles complex operations like joins, pagination, and conditionals. Its intuitive and efficient approach can greatly expedite development, saving both time and effort.
>The `kp-mysql-models` is a mysql query builder light weight library that simplifies interactions with MySQL databases. It streamlines tasks such as creating, inserting, updating, and deleting records, and handles complex operations like joins, pagination, and conditionals. Its intuitive and efficient approach can greatly expedite development, saving both time and effort.

@@ -292,2 +292,28 @@ > npm i kp-mysql-models

```
>No need to connect table name if class name same as table name but without s. for exmaple we have users table then we make User model class. also we sort hand connet database by using super() method;
```JavaScript
const { BaseModels } = require("kp-mysql-models");
const { pool } =require("./db");
>exm 1
class User extends BaseModels{
constructor(){
super();
this._connection=pool;
}
}
>OR exm. 2
class User extends BaseModels{
constructor(){
super(pool);
}
}
module.exports= User;
```
>You can access all methods after make User class object for Example

@@ -299,2 +325,22 @@ ```JavaScript

let data = await user.get();
//deleting data
let data = await user.delele({
where: {
id: 585,
}
});
let data = await user.deleleAll();
let data = await user.destroy({
where: {
id: 585,
}
});
//trucate table
let data = await user.trunCate();
```

@@ -305,2 +351,8 @@

let user = new User;
class User extends BaseModels{
constructor(){
super(pool);
this._softDelete=true;
}
}

@@ -315,2 +367,5 @@ //for soft deleteing data

//for soft deleteing All data
let data = await user.trashedAll();
//for soft deleteing restoring data

@@ -323,2 +378,5 @@ let data = await user.restore({

//for soft deleteing restoring All data
let data = await user.restoreAll();
//for fetch soft deleted data useing onlyTrashed:true;

@@ -378,4 +436,7 @@ let data = await user.first({

* dbWith,
* tracested,
* trasted,
* restore,
* trastedAll,
* restoreAll,
* trunCate,

@@ -382,0 +443,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc