zormz 1.3.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -2
- package/dist/index.d.mts +27 -7
- package/dist/index.d.ts +27 -7
- package/dist/index.js +46 -17
- package/dist/index.mjs +45 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,9 +84,35 @@ export const prueba1 = defineTable("prueba1", {
|
|
|
84
84
|
resultado: int().Default(0).$(),
|
|
85
85
|
fechaRegistro: timestamp().required().now().$(),
|
|
86
86
|
fechaUpdate: timestamp().required().now().onUpdate().$()
|
|
87
|
-
|
|
88
87
|
});
|
|
89
88
|
|
|
89
|
+
```
|
|
90
|
+
o
|
|
91
|
+
```ts
|
|
92
|
+
export function generateTables() {
|
|
93
|
+
return {
|
|
94
|
+
colaborador: defineTable("colaborador", {
|
|
95
|
+
idcolaborador: int().Pk().$(),
|
|
96
|
+
idusuario: int().Required().$(),
|
|
97
|
+
nombrecompleto: varchar(150).$(),
|
|
98
|
+
dni: varchar(9).$(),
|
|
99
|
+
rol: varchar(50).$(),
|
|
100
|
+
diastrabajo: varchar(200).Default("sabado - domingo").$(),
|
|
101
|
+
activo: bool().default(true).$(),
|
|
102
|
+
}),
|
|
103
|
+
permisos: defineTable("permisos", {
|
|
104
|
+
idpermiso: int().Pk().$(),
|
|
105
|
+
nombre: varchar(100).$(),
|
|
106
|
+
descripcion: varchar(250).$(),
|
|
107
|
+
estado: bool().default(true).$(),
|
|
108
|
+
}),
|
|
109
|
+
detallespermisos: defineTable("detallespermisos", {
|
|
110
|
+
iddetallepermiso: int().Pk().$(),
|
|
111
|
+
idcolaborador: int().$(),
|
|
112
|
+
idppermiso: int().Default(0).$(),
|
|
113
|
+
}),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
90
116
|
```
|
|
91
117
|
|
|
92
118
|
### Notas importantes
|
|
@@ -131,6 +157,7 @@ const datos = await DB.select()
|
|
|
131
157
|
---
|
|
132
158
|
|
|
133
159
|
## Update de Datos
|
|
160
|
+
### .set() Recibe un objeto con clave valor de las tablas o un array con UP
|
|
134
161
|
```ts
|
|
135
162
|
await DB.Update(prueba1())
|
|
136
163
|
.set({ valor: "nuevo valor", resultado: 2 })
|
|
@@ -138,6 +165,16 @@ await DB.Update(prueba1())
|
|
|
138
165
|
.execute();
|
|
139
166
|
|
|
140
167
|
```
|
|
168
|
+
o
|
|
169
|
+
```ts
|
|
170
|
+
//Usar la funcion UP
|
|
171
|
+
const response = await DB.Update(producto())
|
|
172
|
+
.set([UP(producto.stockactual, `${producto.stockactual} - 4`, true)])
|
|
173
|
+
.where(eq(producto.idproducto, 4))
|
|
174
|
+
.execute();
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
|
|
141
178
|
---
|
|
142
179
|
## Delete de Datos
|
|
143
180
|
```ts
|
|
@@ -146,7 +183,29 @@ await DB.Delete(prueba1())
|
|
|
146
183
|
.execute();
|
|
147
184
|
|
|
148
185
|
```
|
|
186
|
+
## JOINS
|
|
187
|
+
```ts
|
|
188
|
+
const { detallespermisos, colaborador, permisos } = generateTables();
|
|
189
|
+
|
|
190
|
+
const response = await DB.Select([
|
|
191
|
+
detallespermisos.iddetallepermiso,
|
|
192
|
+
colaborador.nombrecompleto,
|
|
193
|
+
colaborador.dni,
|
|
194
|
+
permisos.nombre,
|
|
195
|
+
permisos.estado,
|
|
196
|
+
])
|
|
197
|
+
.from(detallespermisos())
|
|
198
|
+
.innerJOIN(
|
|
199
|
+
colaborador(),
|
|
200
|
+
eq(colaborador.idcolaborador, detallespermisos.idcolaborador, false),
|
|
201
|
+
)
|
|
202
|
+
.innerJOIN(
|
|
203
|
+
permisos(),
|
|
204
|
+
eq(permisos.idpermiso, detallespermisos.idppermiso, false),
|
|
205
|
+
)
|
|
206
|
+
.execute();
|
|
149
207
|
|
|
208
|
+
```
|
|
150
209
|
---
|
|
151
210
|
|
|
152
211
|
## Ejemplo de Uso
|
|
@@ -203,7 +262,7 @@ pruebaData().catch(console.error);
|
|
|
203
262
|
* Compatible con **MYSQL** y **PG**
|
|
204
263
|
* Preparado para extenderse
|
|
205
264
|
* Las versiones +1.3.0 son mas estables , las anteriores estaban en desarrollo y presentan multiples errores
|
|
206
|
-
*
|
|
265
|
+
* version estable 1.4.0
|
|
207
266
|
## Licencia
|
|
208
267
|
|
|
209
268
|
ISC © Yukio-kayaba
|
package/dist/index.d.mts
CHANGED
|
@@ -28,7 +28,14 @@ type IntType = {
|
|
|
28
28
|
unique?: boolean;
|
|
29
29
|
unsingned:number;
|
|
30
30
|
autoIncrement?: boolean;
|
|
31
|
-
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
interface UpdateParams {
|
|
35
|
+
campoUp: string;
|
|
36
|
+
newCampoUp: string;
|
|
37
|
+
dataTable?: boolean;
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
interface connecionLocal {
|
|
34
41
|
host: string;
|
|
@@ -115,7 +122,7 @@ declare class DeleteR {
|
|
|
115
122
|
* DB.Delete(tabla).WHERE(AND(eq(valor,valor), eq(valor2,valor2)))
|
|
116
123
|
*/
|
|
117
124
|
where(condicion: string): this;
|
|
118
|
-
execute(): Promise<number | null>;
|
|
125
|
+
execute(seeQuery?: boolean): Promise<number | null>;
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
type arrayData = (string | number | boolean)[];
|
|
@@ -147,7 +154,7 @@ declare class QueryBuilder {
|
|
|
147
154
|
* @returns
|
|
148
155
|
*/
|
|
149
156
|
Values(values: arrayData | arrayDatas): this;
|
|
150
|
-
execute(): Promise<number | any[] | undefined>;
|
|
157
|
+
execute(see?: boolean): Promise<number | any[] | undefined>;
|
|
151
158
|
}
|
|
152
159
|
|
|
153
160
|
type valor = "ASC" | "DESC";
|
|
@@ -207,7 +214,7 @@ declare class Select {
|
|
|
207
214
|
/**
|
|
208
215
|
* @returns {Promise<Array<Object>>}
|
|
209
216
|
*/
|
|
210
|
-
execute(): Promise<any[] | undefined>;
|
|
217
|
+
execute(see?: boolean): Promise<any[] | undefined>;
|
|
211
218
|
}
|
|
212
219
|
|
|
213
220
|
type Valores = Record<string, string | number | undefined>;
|
|
@@ -224,8 +231,10 @@ declare class Update {
|
|
|
224
231
|
* @param {Valores} valores - valores a actualizar
|
|
225
232
|
* @example
|
|
226
233
|
* .set({'campo1':'valor1', 'campo2':'valor2'})
|
|
234
|
+
* .set([UP(producto.stockactual,producto.stockactual)])
|
|
235
|
+
* set([UP(producto.stockactual, `${producto.stockactual} - 4`, true)])
|
|
227
236
|
*/
|
|
228
|
-
set(valores: Valores): this;
|
|
237
|
+
set(valores: Valores | UpdateParams[]): this;
|
|
229
238
|
/**
|
|
230
239
|
* @param {string} condicion - valor condicional
|
|
231
240
|
* @example
|
|
@@ -236,7 +245,7 @@ declare class Update {
|
|
|
236
245
|
* where(ORQ())
|
|
237
246
|
*/
|
|
238
247
|
where(condicion: string): this;
|
|
239
|
-
execute(): Promise<any>;
|
|
248
|
+
execute(seeQuery?: boolean): Promise<any>;
|
|
240
249
|
}
|
|
241
250
|
|
|
242
251
|
declare class DB {
|
|
@@ -364,6 +373,17 @@ declare const MENOR: (valor: string, valor2: string) => string;
|
|
|
364
373
|
* @returns
|
|
365
374
|
*/
|
|
366
375
|
declare const CURRENT_TIMESTAMP: () => string;
|
|
376
|
+
/**
|
|
377
|
+
* @param {string} dataUpdate - campo a actualizar
|
|
378
|
+
* @param {string} newdataUpdate - valor del campo a actualizar
|
|
379
|
+
* @param {boolean} activo - en caso de realizar operaciones matematicas con el mismo campo [true]
|
|
380
|
+
* @example
|
|
381
|
+
*
|
|
382
|
+
*UP(producto.stockactual, `${producto.stockactual} - 4`, true)
|
|
383
|
+
* UP(producto.stockactual,producto.stockactual, true)
|
|
384
|
+
* @returns
|
|
385
|
+
*/
|
|
386
|
+
declare const UP: (dataUpdate: string, newdataUpdate: string, activo?: boolean) => UpdateParams;
|
|
367
387
|
|
|
368
388
|
declare class IntColumn {
|
|
369
389
|
private requerido;
|
|
@@ -430,4 +450,4 @@ declare class Money {
|
|
|
430
450
|
}
|
|
431
451
|
declare function money(presicion?: number, decimales?: number): Money;
|
|
432
452
|
|
|
433
|
-
export { AND, BDconnection, CURRENT_TIMESTAMP, type Consultas, DB, DeleteR, ILIKE, MAYOR, MENOR, NOTNULL, NOW, NULL, OR, ORQ, QueryBuilder, Select, type TableProxy, type Tipos, Update, type Valores, type arrayData, type arrayDatas, bool, type connecionLocal, type connecionRed, type connectionDB, defineTable, dropTable, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
|
|
453
|
+
export { AND, BDconnection, CURRENT_TIMESTAMP, type Consultas, DB, DeleteR, ILIKE, MAYOR, MENOR, NOTNULL, NOW, NULL, OR, ORQ, QueryBuilder, Select, type TableProxy, type Tipos, UP, Update, type Valores, type arrayData, type arrayDatas, bool, type connecionLocal, type connecionRed, type connectionDB, defineTable, dropTable, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
|
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,14 @@ type IntType = {
|
|
|
28
28
|
unique?: boolean;
|
|
29
29
|
unsingned:number;
|
|
30
30
|
autoIncrement?: boolean;
|
|
31
|
-
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
interface UpdateParams {
|
|
35
|
+
campoUp: string;
|
|
36
|
+
newCampoUp: string;
|
|
37
|
+
dataTable?: boolean;
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
interface connecionLocal {
|
|
34
41
|
host: string;
|
|
@@ -115,7 +122,7 @@ declare class DeleteR {
|
|
|
115
122
|
* DB.Delete(tabla).WHERE(AND(eq(valor,valor), eq(valor2,valor2)))
|
|
116
123
|
*/
|
|
117
124
|
where(condicion: string): this;
|
|
118
|
-
execute(): Promise<number | null>;
|
|
125
|
+
execute(seeQuery?: boolean): Promise<number | null>;
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
type arrayData = (string | number | boolean)[];
|
|
@@ -147,7 +154,7 @@ declare class QueryBuilder {
|
|
|
147
154
|
* @returns
|
|
148
155
|
*/
|
|
149
156
|
Values(values: arrayData | arrayDatas): this;
|
|
150
|
-
execute(): Promise<number | any[] | undefined>;
|
|
157
|
+
execute(see?: boolean): Promise<number | any[] | undefined>;
|
|
151
158
|
}
|
|
152
159
|
|
|
153
160
|
type valor = "ASC" | "DESC";
|
|
@@ -207,7 +214,7 @@ declare class Select {
|
|
|
207
214
|
/**
|
|
208
215
|
* @returns {Promise<Array<Object>>}
|
|
209
216
|
*/
|
|
210
|
-
execute(): Promise<any[] | undefined>;
|
|
217
|
+
execute(see?: boolean): Promise<any[] | undefined>;
|
|
211
218
|
}
|
|
212
219
|
|
|
213
220
|
type Valores = Record<string, string | number | undefined>;
|
|
@@ -224,8 +231,10 @@ declare class Update {
|
|
|
224
231
|
* @param {Valores} valores - valores a actualizar
|
|
225
232
|
* @example
|
|
226
233
|
* .set({'campo1':'valor1', 'campo2':'valor2'})
|
|
234
|
+
* .set([UP(producto.stockactual,producto.stockactual)])
|
|
235
|
+
* set([UP(producto.stockactual, `${producto.stockactual} - 4`, true)])
|
|
227
236
|
*/
|
|
228
|
-
set(valores: Valores): this;
|
|
237
|
+
set(valores: Valores | UpdateParams[]): this;
|
|
229
238
|
/**
|
|
230
239
|
* @param {string} condicion - valor condicional
|
|
231
240
|
* @example
|
|
@@ -236,7 +245,7 @@ declare class Update {
|
|
|
236
245
|
* where(ORQ())
|
|
237
246
|
*/
|
|
238
247
|
where(condicion: string): this;
|
|
239
|
-
execute(): Promise<any>;
|
|
248
|
+
execute(seeQuery?: boolean): Promise<any>;
|
|
240
249
|
}
|
|
241
250
|
|
|
242
251
|
declare class DB {
|
|
@@ -364,6 +373,17 @@ declare const MENOR: (valor: string, valor2: string) => string;
|
|
|
364
373
|
* @returns
|
|
365
374
|
*/
|
|
366
375
|
declare const CURRENT_TIMESTAMP: () => string;
|
|
376
|
+
/**
|
|
377
|
+
* @param {string} dataUpdate - campo a actualizar
|
|
378
|
+
* @param {string} newdataUpdate - valor del campo a actualizar
|
|
379
|
+
* @param {boolean} activo - en caso de realizar operaciones matematicas con el mismo campo [true]
|
|
380
|
+
* @example
|
|
381
|
+
*
|
|
382
|
+
*UP(producto.stockactual, `${producto.stockactual} - 4`, true)
|
|
383
|
+
* UP(producto.stockactual,producto.stockactual, true)
|
|
384
|
+
* @returns
|
|
385
|
+
*/
|
|
386
|
+
declare const UP: (dataUpdate: string, newdataUpdate: string, activo?: boolean) => UpdateParams;
|
|
367
387
|
|
|
368
388
|
declare class IntColumn {
|
|
369
389
|
private requerido;
|
|
@@ -430,4 +450,4 @@ declare class Money {
|
|
|
430
450
|
}
|
|
431
451
|
declare function money(presicion?: number, decimales?: number): Money;
|
|
432
452
|
|
|
433
|
-
export { AND, BDconnection, CURRENT_TIMESTAMP, type Consultas, DB, DeleteR, ILIKE, MAYOR, MENOR, NOTNULL, NOW, NULL, OR, ORQ, QueryBuilder, Select, type TableProxy, type Tipos, Update, type Valores, type arrayData, type arrayDatas, bool, type connecionLocal, type connecionRed, type connectionDB, defineTable, dropTable, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
|
|
453
|
+
export { AND, BDconnection, CURRENT_TIMESTAMP, type Consultas, DB, DeleteR, ILIKE, MAYOR, MENOR, NOTNULL, NOW, NULL, OR, ORQ, QueryBuilder, Select, type TableProxy, type Tipos, UP, Update, type Valores, type arrayData, type arrayDatas, bool, type connecionLocal, type connecionRed, type connectionDB, defineTable, dropTable, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,7 @@ __export(index_exports, {
|
|
|
52
52
|
ORQ: () => ORQ,
|
|
53
53
|
QueryBuilder: () => QueryBuilder,
|
|
54
54
|
Select: () => Select,
|
|
55
|
+
UP: () => UP,
|
|
55
56
|
Update: () => Update,
|
|
56
57
|
bool: () => bool,
|
|
57
58
|
defineTable: () => defineTable,
|
|
@@ -174,7 +175,6 @@ var BDconnection = class {
|
|
|
174
175
|
return respuesta;
|
|
175
176
|
}
|
|
176
177
|
} catch (error) {
|
|
177
|
-
console.log(error);
|
|
178
178
|
if (!alertar) return;
|
|
179
179
|
if (typeof error === "object" && error !== null && "code" in error) {
|
|
180
180
|
if (error.code === "ETIMEDOUT") {
|
|
@@ -330,7 +330,7 @@ async function dropTable(nombreTabla) {
|
|
|
330
330
|
alertar: false
|
|
331
331
|
});
|
|
332
332
|
if (response.warningStatus === 0) {
|
|
333
|
-
console.log(`\u{1F44D}\u{1F44D} Se
|
|
333
|
+
console.log(`\u{1F44D}\u{1F44D} Se elimino con exito la tabla ${nombreTabla} \u{1F44D}`);
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
336
336
|
console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
|
|
@@ -374,8 +374,9 @@ var DeleteR = class {
|
|
|
374
374
|
__privateSet(this, _condicion, ` where ${condicion}`);
|
|
375
375
|
return this;
|
|
376
376
|
}
|
|
377
|
-
async execute() {
|
|
377
|
+
async execute(seeQuery = false) {
|
|
378
378
|
const query = `DELETE FROM ${__privateGet(this, _tabla)} ${__privateGet(this, _condicion)}`;
|
|
379
|
+
if (seeQuery) console.log(query);
|
|
379
380
|
if (this.conexion.tipo === "mysql") {
|
|
380
381
|
const respuesta = await this.conexion.executeConsulta({
|
|
381
382
|
query,
|
|
@@ -437,7 +438,7 @@ var QueryBuilder = class {
|
|
|
437
438
|
this.valores = values;
|
|
438
439
|
return this;
|
|
439
440
|
}
|
|
440
|
-
async execute() {
|
|
441
|
+
async execute(see = false) {
|
|
441
442
|
this.valorRetorno = 1;
|
|
442
443
|
let query1 = `INSERT INTO ${this.tabla} `;
|
|
443
444
|
let param = "";
|
|
@@ -491,6 +492,9 @@ var QueryBuilder = class {
|
|
|
491
492
|
} else {
|
|
492
493
|
query += paramespaces;
|
|
493
494
|
}
|
|
495
|
+
if (see) {
|
|
496
|
+
console.log(query);
|
|
497
|
+
}
|
|
494
498
|
if (this.conexion.tipo === "mysql") {
|
|
495
499
|
const respuesta = await this.conexion.executeConsulta({
|
|
496
500
|
query,
|
|
@@ -544,21 +548,21 @@ var Select = class {
|
|
|
544
548
|
if (!tabla || typeof tabla !== "string") {
|
|
545
549
|
throw new Error("La tabla es un campo obligatorio");
|
|
546
550
|
}
|
|
547
|
-
this.innerJoin += ` INNER JOIN ${tabla} ON ${condition}`;
|
|
551
|
+
this.innerJoin += ` INNER JOIN ${tabla} ON ${condition} `;
|
|
548
552
|
return this;
|
|
549
553
|
}
|
|
550
554
|
leftJoin(tabla, condition) {
|
|
551
555
|
if (!tabla || typeof tabla !== "string") {
|
|
552
556
|
throw new Error("La tabla es un campo obligatorio");
|
|
553
557
|
}
|
|
554
|
-
this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition}`;
|
|
558
|
+
this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition} `;
|
|
555
559
|
return this;
|
|
556
560
|
}
|
|
557
561
|
rigthJoin(tabla, condition) {
|
|
558
562
|
if (!tabla || typeof tabla !== "string") {
|
|
559
563
|
throw new Error("La tabla es un campo obligatorio");
|
|
560
564
|
}
|
|
561
|
-
this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition}`;
|
|
565
|
+
this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition} `;
|
|
562
566
|
return this;
|
|
563
567
|
}
|
|
564
568
|
/**
|
|
@@ -618,7 +622,7 @@ var Select = class {
|
|
|
618
622
|
/**
|
|
619
623
|
* @returns {Promise<Array<Object>>}
|
|
620
624
|
*/
|
|
621
|
-
async execute() {
|
|
625
|
+
async execute(see = false) {
|
|
622
626
|
let selectFields = "*";
|
|
623
627
|
if (this.valores) {
|
|
624
628
|
if (typeof this.parametros !== "undefined" && typeof this.parametros !== "string") {
|
|
@@ -626,6 +630,9 @@ var Select = class {
|
|
|
626
630
|
}
|
|
627
631
|
}
|
|
628
632
|
const query = `SELECT ${selectFields} from ${this.tabla} ${this.innerJoin} ${this.leftjoins} ${this.rigthjoins} ${this.condicion} ${this.orderBy} ${this.limit};`;
|
|
633
|
+
if (see) {
|
|
634
|
+
console.log(query);
|
|
635
|
+
}
|
|
629
636
|
if (this.conexion.tipo === "mysql") {
|
|
630
637
|
const respuesta = await this.conexion.executeConsulta({
|
|
631
638
|
query,
|
|
@@ -697,6 +704,14 @@ var MENOR = (valor, valor2) => {
|
|
|
697
704
|
var CURRENT_TIMESTAMP = () => {
|
|
698
705
|
return " CURRENT_TIMESTAMP ";
|
|
699
706
|
};
|
|
707
|
+
var UP = (dataUpdate, newdataUpdate, activo = false) => {
|
|
708
|
+
const tables = {
|
|
709
|
+
campoUp: dataUpdate,
|
|
710
|
+
newCampoUp: newdataUpdate,
|
|
711
|
+
dataTable: activo
|
|
712
|
+
};
|
|
713
|
+
return tables;
|
|
714
|
+
};
|
|
700
715
|
|
|
701
716
|
// conection/middleware/update.ts
|
|
702
717
|
var Update = class {
|
|
@@ -720,19 +735,29 @@ var Update = class {
|
|
|
720
735
|
* @param {Valores} valores - valores a actualizar
|
|
721
736
|
* @example
|
|
722
737
|
* .set({'campo1':'valor1', 'campo2':'valor2'})
|
|
738
|
+
* .set([UP(producto.stockactual,producto.stockactual)])
|
|
739
|
+
* set([UP(producto.stockactual, `${producto.stockactual} - 4`, true)])
|
|
723
740
|
*/
|
|
724
741
|
set(valores) {
|
|
725
|
-
|
|
726
|
-
|
|
742
|
+
const validate = Array.isArray(valores);
|
|
743
|
+
if (valores === null || typeof valores !== "object") {
|
|
744
|
+
throw new Error("es requerido un objeto o un UP array");
|
|
727
745
|
}
|
|
728
746
|
let valor = "";
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
747
|
+
if (typeof valores === "object" && !validate) {
|
|
748
|
+
for (const key in valores) {
|
|
749
|
+
if (valores.hasOwnProperty(key)) {
|
|
750
|
+
const value = valores[key];
|
|
751
|
+
if (value === void 0) continue;
|
|
752
|
+
valor += eq(key, value);
|
|
753
|
+
valor += ",";
|
|
754
|
+
}
|
|
735
755
|
}
|
|
756
|
+
} else if (validate) {
|
|
757
|
+
valores.forEach((valors) => {
|
|
758
|
+
valor += eq(valors.campoUp, valors.newCampoUp, !valors.dataTable);
|
|
759
|
+
valor += ",";
|
|
760
|
+
});
|
|
736
761
|
}
|
|
737
762
|
valor = valor.slice(0, -1);
|
|
738
763
|
this.valores = valor;
|
|
@@ -758,8 +783,11 @@ var Update = class {
|
|
|
758
783
|
}
|
|
759
784
|
return this;
|
|
760
785
|
}
|
|
761
|
-
async execute() {
|
|
786
|
+
async execute(seeQuery = false) {
|
|
762
787
|
const query = `UPDATE ${this.nombreTabla} SET ${this.valores} ${this.condicion};`;
|
|
788
|
+
if (seeQuery) {
|
|
789
|
+
console.log(seeQuery);
|
|
790
|
+
}
|
|
763
791
|
const respuesta = await this.conexion.executeConsulta({
|
|
764
792
|
query,
|
|
765
793
|
mensaje: "Error Update"
|
|
@@ -1082,6 +1110,7 @@ function money(presicion = 10, decimales = 2) {
|
|
|
1082
1110
|
ORQ,
|
|
1083
1111
|
QueryBuilder,
|
|
1084
1112
|
Select,
|
|
1113
|
+
UP,
|
|
1085
1114
|
Update,
|
|
1086
1115
|
bool,
|
|
1087
1116
|
defineTable,
|
package/dist/index.mjs
CHANGED
|
@@ -112,7 +112,6 @@ var BDconnection = class {
|
|
|
112
112
|
return respuesta;
|
|
113
113
|
}
|
|
114
114
|
} catch (error) {
|
|
115
|
-
console.log(error);
|
|
116
115
|
if (!alertar) return;
|
|
117
116
|
if (typeof error === "object" && error !== null && "code" in error) {
|
|
118
117
|
if (error.code === "ETIMEDOUT") {
|
|
@@ -268,7 +267,7 @@ async function dropTable(nombreTabla) {
|
|
|
268
267
|
alertar: false
|
|
269
268
|
});
|
|
270
269
|
if (response.warningStatus === 0) {
|
|
271
|
-
console.log(`\u{1F44D}\u{1F44D} Se
|
|
270
|
+
console.log(`\u{1F44D}\u{1F44D} Se elimino con exito la tabla ${nombreTabla} \u{1F44D}`);
|
|
272
271
|
return;
|
|
273
272
|
}
|
|
274
273
|
console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
|
|
@@ -312,8 +311,9 @@ var DeleteR = class {
|
|
|
312
311
|
__privateSet(this, _condicion, ` where ${condicion}`);
|
|
313
312
|
return this;
|
|
314
313
|
}
|
|
315
|
-
async execute() {
|
|
314
|
+
async execute(seeQuery = false) {
|
|
316
315
|
const query = `DELETE FROM ${__privateGet(this, _tabla)} ${__privateGet(this, _condicion)}`;
|
|
316
|
+
if (seeQuery) console.log(query);
|
|
317
317
|
if (this.conexion.tipo === "mysql") {
|
|
318
318
|
const respuesta = await this.conexion.executeConsulta({
|
|
319
319
|
query,
|
|
@@ -375,7 +375,7 @@ var QueryBuilder = class {
|
|
|
375
375
|
this.valores = values;
|
|
376
376
|
return this;
|
|
377
377
|
}
|
|
378
|
-
async execute() {
|
|
378
|
+
async execute(see = false) {
|
|
379
379
|
this.valorRetorno = 1;
|
|
380
380
|
let query1 = `INSERT INTO ${this.tabla} `;
|
|
381
381
|
let param = "";
|
|
@@ -429,6 +429,9 @@ var QueryBuilder = class {
|
|
|
429
429
|
} else {
|
|
430
430
|
query += paramespaces;
|
|
431
431
|
}
|
|
432
|
+
if (see) {
|
|
433
|
+
console.log(query);
|
|
434
|
+
}
|
|
432
435
|
if (this.conexion.tipo === "mysql") {
|
|
433
436
|
const respuesta = await this.conexion.executeConsulta({
|
|
434
437
|
query,
|
|
@@ -482,21 +485,21 @@ var Select = class {
|
|
|
482
485
|
if (!tabla || typeof tabla !== "string") {
|
|
483
486
|
throw new Error("La tabla es un campo obligatorio");
|
|
484
487
|
}
|
|
485
|
-
this.innerJoin += ` INNER JOIN ${tabla} ON ${condition}`;
|
|
488
|
+
this.innerJoin += ` INNER JOIN ${tabla} ON ${condition} `;
|
|
486
489
|
return this;
|
|
487
490
|
}
|
|
488
491
|
leftJoin(tabla, condition) {
|
|
489
492
|
if (!tabla || typeof tabla !== "string") {
|
|
490
493
|
throw new Error("La tabla es un campo obligatorio");
|
|
491
494
|
}
|
|
492
|
-
this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition}`;
|
|
495
|
+
this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition} `;
|
|
493
496
|
return this;
|
|
494
497
|
}
|
|
495
498
|
rigthJoin(tabla, condition) {
|
|
496
499
|
if (!tabla || typeof tabla !== "string") {
|
|
497
500
|
throw new Error("La tabla es un campo obligatorio");
|
|
498
501
|
}
|
|
499
|
-
this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition}`;
|
|
502
|
+
this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition} `;
|
|
500
503
|
return this;
|
|
501
504
|
}
|
|
502
505
|
/**
|
|
@@ -556,7 +559,7 @@ var Select = class {
|
|
|
556
559
|
/**
|
|
557
560
|
* @returns {Promise<Array<Object>>}
|
|
558
561
|
*/
|
|
559
|
-
async execute() {
|
|
562
|
+
async execute(see = false) {
|
|
560
563
|
let selectFields = "*";
|
|
561
564
|
if (this.valores) {
|
|
562
565
|
if (typeof this.parametros !== "undefined" && typeof this.parametros !== "string") {
|
|
@@ -564,6 +567,9 @@ var Select = class {
|
|
|
564
567
|
}
|
|
565
568
|
}
|
|
566
569
|
const query = `SELECT ${selectFields} from ${this.tabla} ${this.innerJoin} ${this.leftjoins} ${this.rigthjoins} ${this.condicion} ${this.orderBy} ${this.limit};`;
|
|
570
|
+
if (see) {
|
|
571
|
+
console.log(query);
|
|
572
|
+
}
|
|
567
573
|
if (this.conexion.tipo === "mysql") {
|
|
568
574
|
const respuesta = await this.conexion.executeConsulta({
|
|
569
575
|
query,
|
|
@@ -635,6 +641,14 @@ var MENOR = (valor, valor2) => {
|
|
|
635
641
|
var CURRENT_TIMESTAMP = () => {
|
|
636
642
|
return " CURRENT_TIMESTAMP ";
|
|
637
643
|
};
|
|
644
|
+
var UP = (dataUpdate, newdataUpdate, activo = false) => {
|
|
645
|
+
const tables = {
|
|
646
|
+
campoUp: dataUpdate,
|
|
647
|
+
newCampoUp: newdataUpdate,
|
|
648
|
+
dataTable: activo
|
|
649
|
+
};
|
|
650
|
+
return tables;
|
|
651
|
+
};
|
|
638
652
|
|
|
639
653
|
// conection/middleware/update.ts
|
|
640
654
|
var Update = class {
|
|
@@ -658,19 +672,29 @@ var Update = class {
|
|
|
658
672
|
* @param {Valores} valores - valores a actualizar
|
|
659
673
|
* @example
|
|
660
674
|
* .set({'campo1':'valor1', 'campo2':'valor2'})
|
|
675
|
+
* .set([UP(producto.stockactual,producto.stockactual)])
|
|
676
|
+
* set([UP(producto.stockactual, `${producto.stockactual} - 4`, true)])
|
|
661
677
|
*/
|
|
662
678
|
set(valores) {
|
|
663
|
-
|
|
664
|
-
|
|
679
|
+
const validate = Array.isArray(valores);
|
|
680
|
+
if (valores === null || typeof valores !== "object") {
|
|
681
|
+
throw new Error("es requerido un objeto o un UP array");
|
|
665
682
|
}
|
|
666
683
|
let valor = "";
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
684
|
+
if (typeof valores === "object" && !validate) {
|
|
685
|
+
for (const key in valores) {
|
|
686
|
+
if (valores.hasOwnProperty(key)) {
|
|
687
|
+
const value = valores[key];
|
|
688
|
+
if (value === void 0) continue;
|
|
689
|
+
valor += eq(key, value);
|
|
690
|
+
valor += ",";
|
|
691
|
+
}
|
|
673
692
|
}
|
|
693
|
+
} else if (validate) {
|
|
694
|
+
valores.forEach((valors) => {
|
|
695
|
+
valor += eq(valors.campoUp, valors.newCampoUp, !valors.dataTable);
|
|
696
|
+
valor += ",";
|
|
697
|
+
});
|
|
674
698
|
}
|
|
675
699
|
valor = valor.slice(0, -1);
|
|
676
700
|
this.valores = valor;
|
|
@@ -696,8 +720,11 @@ var Update = class {
|
|
|
696
720
|
}
|
|
697
721
|
return this;
|
|
698
722
|
}
|
|
699
|
-
async execute() {
|
|
723
|
+
async execute(seeQuery = false) {
|
|
700
724
|
const query = `UPDATE ${this.nombreTabla} SET ${this.valores} ${this.condicion};`;
|
|
725
|
+
if (seeQuery) {
|
|
726
|
+
console.log(seeQuery);
|
|
727
|
+
}
|
|
701
728
|
const respuesta = await this.conexion.executeConsulta({
|
|
702
729
|
query,
|
|
703
730
|
mensaje: "Error Update"
|
|
@@ -1019,6 +1046,7 @@ export {
|
|
|
1019
1046
|
ORQ,
|
|
1020
1047
|
QueryBuilder,
|
|
1021
1048
|
Select,
|
|
1049
|
+
UP,
|
|
1022
1050
|
Update,
|
|
1023
1051
|
bool,
|
|
1024
1052
|
defineTable,
|