zormz 1.3.1 → 1.4.0

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 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
- * verion mas estable 1.3.1
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;
@@ -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
@@ -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;
@@ -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
@@ -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,
@@ -144,6 +145,7 @@ var BDconnection = class {
144
145
  mensaje,
145
146
  alertar = true
146
147
  }) {
148
+ console.log(query);
147
149
  try {
148
150
  if (this.tipo === "mysql") {
149
151
  const pool = await this.conexionMysql();
@@ -330,7 +332,7 @@ async function dropTable(nombreTabla) {
330
332
  alertar: false
331
333
  });
332
334
  if (response.warningStatus === 0) {
333
- console.log(`\u{1F44D}\u{1F44D} Se creo con exito la tabla ${nombreTabla} \u{1F44D}`);
335
+ console.log(`\u{1F44D}\u{1F44D} Se elimino con exito la tabla ${nombreTabla} \u{1F44D}`);
334
336
  return;
335
337
  }
336
338
  console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
@@ -544,21 +546,21 @@ var Select = class {
544
546
  if (!tabla || typeof tabla !== "string") {
545
547
  throw new Error("La tabla es un campo obligatorio");
546
548
  }
547
- this.innerJoin += ` INNER JOIN ${tabla} ON ${condition}`;
549
+ this.innerJoin += ` INNER JOIN ${tabla} ON ${condition} `;
548
550
  return this;
549
551
  }
550
552
  leftJoin(tabla, condition) {
551
553
  if (!tabla || typeof tabla !== "string") {
552
554
  throw new Error("La tabla es un campo obligatorio");
553
555
  }
554
- this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition}`;
556
+ this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition} `;
555
557
  return this;
556
558
  }
557
559
  rigthJoin(tabla, condition) {
558
560
  if (!tabla || typeof tabla !== "string") {
559
561
  throw new Error("La tabla es un campo obligatorio");
560
562
  }
561
- this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition}`;
563
+ this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition} `;
562
564
  return this;
563
565
  }
564
566
  /**
@@ -697,6 +699,14 @@ var MENOR = (valor, valor2) => {
697
699
  var CURRENT_TIMESTAMP = () => {
698
700
  return " CURRENT_TIMESTAMP ";
699
701
  };
702
+ var UP = (dataUpdate, newdataUpdate, activo = false) => {
703
+ const tables = {
704
+ campoUp: dataUpdate,
705
+ newCampoUp: newdataUpdate,
706
+ dataTable: activo
707
+ };
708
+ return tables;
709
+ };
700
710
 
701
711
  // conection/middleware/update.ts
702
712
  var Update = class {
@@ -720,19 +730,29 @@ var Update = class {
720
730
  * @param {Valores} valores - valores a actualizar
721
731
  * @example
722
732
  * .set({'campo1':'valor1', 'campo2':'valor2'})
733
+ * .set([UP(producto.stockactual,producto.stockactual)])
734
+ * set([UP(producto.stockactual, `${producto.stockactual} - 4`, true)])
723
735
  */
724
736
  set(valores) {
725
- if (typeof valores !== "object") {
726
- throw new Error("es requerido un objeto");
737
+ const validate = Array.isArray(valores);
738
+ if (valores === null || typeof valores !== "object") {
739
+ throw new Error("es requerido un objeto o un UP array");
727
740
  }
728
741
  let valor = "";
729
- for (const key in valores) {
730
- if (valores.hasOwnProperty(key)) {
731
- const value = valores[key];
732
- if (value === void 0) continue;
733
- valor += eq(key, value);
734
- valor += ",";
742
+ if (typeof valores === "object" && !validate) {
743
+ for (const key in valores) {
744
+ if (valores.hasOwnProperty(key)) {
745
+ const value = valores[key];
746
+ if (value === void 0) continue;
747
+ valor += eq(key, value);
748
+ valor += ",";
749
+ }
735
750
  }
751
+ } else if (validate) {
752
+ valores.forEach((valors) => {
753
+ valor += eq(valors.campoUp, valors.newCampoUp, !valors.dataTable);
754
+ valor += ",";
755
+ });
736
756
  }
737
757
  valor = valor.slice(0, -1);
738
758
  this.valores = valor;
@@ -1082,6 +1102,7 @@ function money(presicion = 10, decimales = 2) {
1082
1102
  ORQ,
1083
1103
  QueryBuilder,
1084
1104
  Select,
1105
+ UP,
1085
1106
  Update,
1086
1107
  bool,
1087
1108
  defineTable,
package/dist/index.mjs CHANGED
@@ -82,6 +82,7 @@ var BDconnection = class {
82
82
  mensaje,
83
83
  alertar = true
84
84
  }) {
85
+ console.log(query);
85
86
  try {
86
87
  if (this.tipo === "mysql") {
87
88
  const pool = await this.conexionMysql();
@@ -268,7 +269,7 @@ async function dropTable(nombreTabla) {
268
269
  alertar: false
269
270
  });
270
271
  if (response.warningStatus === 0) {
271
- console.log(`\u{1F44D}\u{1F44D} Se creo con exito la tabla ${nombreTabla} \u{1F44D}`);
272
+ console.log(`\u{1F44D}\u{1F44D} Se elimino con exito la tabla ${nombreTabla} \u{1F44D}`);
272
273
  return;
273
274
  }
274
275
  console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
@@ -482,21 +483,21 @@ var Select = class {
482
483
  if (!tabla || typeof tabla !== "string") {
483
484
  throw new Error("La tabla es un campo obligatorio");
484
485
  }
485
- this.innerJoin += ` INNER JOIN ${tabla} ON ${condition}`;
486
+ this.innerJoin += ` INNER JOIN ${tabla} ON ${condition} `;
486
487
  return this;
487
488
  }
488
489
  leftJoin(tabla, condition) {
489
490
  if (!tabla || typeof tabla !== "string") {
490
491
  throw new Error("La tabla es un campo obligatorio");
491
492
  }
492
- this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition}`;
493
+ this.leftjoins += ` LEFT JOIN ${tabla} ON ${condition} `;
493
494
  return this;
494
495
  }
495
496
  rigthJoin(tabla, condition) {
496
497
  if (!tabla || typeof tabla !== "string") {
497
498
  throw new Error("La tabla es un campo obligatorio");
498
499
  }
499
- this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition}`;
500
+ this.rigthjoins += ` RIGHT JOIN ${tabla} ON ${condition} `;
500
501
  return this;
501
502
  }
502
503
  /**
@@ -635,6 +636,14 @@ var MENOR = (valor, valor2) => {
635
636
  var CURRENT_TIMESTAMP = () => {
636
637
  return " CURRENT_TIMESTAMP ";
637
638
  };
639
+ var UP = (dataUpdate, newdataUpdate, activo = false) => {
640
+ const tables = {
641
+ campoUp: dataUpdate,
642
+ newCampoUp: newdataUpdate,
643
+ dataTable: activo
644
+ };
645
+ return tables;
646
+ };
638
647
 
639
648
  // conection/middleware/update.ts
640
649
  var Update = class {
@@ -658,19 +667,29 @@ var Update = class {
658
667
  * @param {Valores} valores - valores a actualizar
659
668
  * @example
660
669
  * .set({'campo1':'valor1', 'campo2':'valor2'})
670
+ * .set([UP(producto.stockactual,producto.stockactual)])
671
+ * set([UP(producto.stockactual, `${producto.stockactual} - 4`, true)])
661
672
  */
662
673
  set(valores) {
663
- if (typeof valores !== "object") {
664
- throw new Error("es requerido un objeto");
674
+ const validate = Array.isArray(valores);
675
+ if (valores === null || typeof valores !== "object") {
676
+ throw new Error("es requerido un objeto o un UP array");
665
677
  }
666
678
  let valor = "";
667
- for (const key in valores) {
668
- if (valores.hasOwnProperty(key)) {
669
- const value = valores[key];
670
- if (value === void 0) continue;
671
- valor += eq(key, value);
672
- valor += ",";
679
+ if (typeof valores === "object" && !validate) {
680
+ for (const key in valores) {
681
+ if (valores.hasOwnProperty(key)) {
682
+ const value = valores[key];
683
+ if (value === void 0) continue;
684
+ valor += eq(key, value);
685
+ valor += ",";
686
+ }
673
687
  }
688
+ } else if (validate) {
689
+ valores.forEach((valors) => {
690
+ valor += eq(valors.campoUp, valors.newCampoUp, !valors.dataTable);
691
+ valor += ",";
692
+ });
674
693
  }
675
694
  valor = valor.slice(0, -1);
676
695
  this.valores = valor;
@@ -1019,6 +1038,7 @@ export {
1019
1038
  ORQ,
1020
1039
  QueryBuilder,
1021
1040
  Select,
1041
+ UP,
1022
1042
  Update,
1023
1043
  bool,
1024
1044
  defineTable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zormz",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Un ORM que busca ser ligero y facil de usar",
5
5
  "author": "yukio-kayaba",
6
6
  "license": "ISC",