zormz 1.2.5 → 1.2.6

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/dist/index.d.mts CHANGED
@@ -398,11 +398,11 @@ declare class Varchar {
398
398
  private requerido;
399
399
  private unique;
400
400
  constructor(cantidad?: number);
401
- withType({ maxLenth, defaultData, requerido, unique, }: VarcharType): ColumnDefinition<undefined>;
401
+ withType({ maxLenth, defaultData, requerido, unique, }: VarcharType): ColumnDefinition<ColumnTypes>;
402
402
  Required(): this;
403
403
  Unique(): this;
404
404
  Default(textoDefecto: string): this;
405
- $(): ColumnDefinition<undefined>;
405
+ $(): ColumnDefinition<ColumnTypes>;
406
406
  }
407
407
  declare function varchar(cantidad?: number): Varchar;
408
408
 
@@ -422,7 +422,7 @@ declare class Timestamp {
422
422
  required(): this;
423
423
  now(): this;
424
424
  onUpdate(): this;
425
- $(): ColumnDefinition<undefined>;
425
+ $(): ColumnDefinition<ColumnTypes>;
426
426
  }
427
427
  declare function timestamp(): Timestamp;
428
428
 
@@ -434,7 +434,7 @@ declare class Money {
434
434
  constructor(presicion?: number, decimales?: number);
435
435
  required(): this;
436
436
  default(value: number): this;
437
- $(): ColumnDefinition<undefined>;
437
+ $(): ColumnDefinition<ColumnTypes>;
438
438
  }
439
439
  declare function money(presicion?: number, decimales?: number): Money;
440
440
 
package/dist/index.d.ts CHANGED
@@ -398,11 +398,11 @@ declare class Varchar {
398
398
  private requerido;
399
399
  private unique;
400
400
  constructor(cantidad?: number);
401
- withType({ maxLenth, defaultData, requerido, unique, }: VarcharType): ColumnDefinition<undefined>;
401
+ withType({ maxLenth, defaultData, requerido, unique, }: VarcharType): ColumnDefinition<ColumnTypes>;
402
402
  Required(): this;
403
403
  Unique(): this;
404
404
  Default(textoDefecto: string): this;
405
- $(): ColumnDefinition<undefined>;
405
+ $(): ColumnDefinition<ColumnTypes>;
406
406
  }
407
407
  declare function varchar(cantidad?: number): Varchar;
408
408
 
@@ -422,7 +422,7 @@ declare class Timestamp {
422
422
  required(): this;
423
423
  now(): this;
424
424
  onUpdate(): this;
425
- $(): ColumnDefinition<undefined>;
425
+ $(): ColumnDefinition<ColumnTypes>;
426
426
  }
427
427
  declare function timestamp(): Timestamp;
428
428
 
@@ -434,7 +434,7 @@ declare class Money {
434
434
  constructor(presicion?: number, decimales?: number);
435
435
  required(): this;
436
436
  default(value: number): this;
437
- $(): ColumnDefinition<undefined>;
437
+ $(): ColumnDefinition<ColumnTypes>;
438
438
  }
439
439
  declare function money(presicion?: number, decimales?: number): Money;
440
440
 
package/dist/index.js CHANGED
@@ -251,185 +251,6 @@ async function generateTable(tabla, columns) {
251
251
  }
252
252
  }
253
253
 
254
- // conection/controls/int.ts
255
- var IntColumn = class {
256
- constructor() {
257
- this.requerido = false;
258
- this.unique = false;
259
- this.autoIncrement = false;
260
- this.unsingned = { uso: false, valor: 0 };
261
- }
262
- Required() {
263
- this.requerido = true;
264
- return this;
265
- }
266
- Pk() {
267
- this.autoIncrement = true;
268
- this.pk = true;
269
- return this;
270
- }
271
- Unique() {
272
- this.unique = true;
273
- return this;
274
- }
275
- Unsingned(numeroPositivosInicio = 0) {
276
- if (numeroPositivosInicio != void 0 && numeroPositivosInicio < 0) {
277
- throw new Error(" Unsingned() solo permite numeros positivos ");
278
- }
279
- this.unsingned.uso = true;
280
- this.unsingned.valor = numeroPositivosInicio;
281
- }
282
- AutoIncrement() {
283
- this.autoIncrement = true;
284
- this.requerido = true;
285
- return this;
286
- }
287
- Default(value) {
288
- this.defaultData = value;
289
- return this;
290
- }
291
- withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
292
- if (defaultData !== void 0) this.Default(defaultData);
293
- if (requerido) this.Required();
294
- if (unique) this.Unique();
295
- if (autoIncrement) this.AutoIncrement();
296
- return this;
297
- }
298
- $() {
299
- const parts = [];
300
- const db = getTipoConexion();
301
- parts.push(db === "mysql" ? "INT" : "INTEGER");
302
- if (this.unsingned.uso) {
303
- parts.push(
304
- db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
305
- );
306
- }
307
- parts.push(
308
- this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
309
- );
310
- if (this.autoIncrement) {
311
- parts.push(
312
- db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
313
- );
314
- }
315
- if (this.pk) {
316
- parts.push("PRIMARY KEY");
317
- const valor2 = {
318
- pk: true,
319
- typo: "int",
320
- sqlz: parts.join(" ")
321
- };
322
- return valor2;
323
- }
324
- if (this.defaultData !== void 0 && !this.autoIncrement) {
325
- parts.push(`DEFAULT ${this.defaultData}`);
326
- }
327
- if (this.unique) parts.push("UNIQUE");
328
- const valor = {
329
- pk: false,
330
- typo: "int",
331
- sqlz: parts.join(" ")
332
- };
333
- return valor;
334
- }
335
- };
336
- function int() {
337
- return new IntColumn();
338
- }
339
-
340
- // conection/controls/timestamp.ts
341
- var Timestamp = class {
342
- constructor() {
343
- this.requerido = false;
344
- this.defaultNow = false;
345
- this.onUpdateNow = false;
346
- }
347
- required() {
348
- this.requerido = true;
349
- return this;
350
- }
351
- now() {
352
- this.defaultNow = true;
353
- return this;
354
- }
355
- onUpdate() {
356
- this.onUpdateNow = true;
357
- return this;
358
- }
359
- $() {
360
- const parts = [];
361
- const db = getTipoConexion();
362
- parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
363
- parts.push(this.requerido ? "NOT NULL" : "NULL");
364
- if (this.defaultNow) {
365
- parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
366
- }
367
- if (this.onUpdateNow && db === "mysql") {
368
- parts.push("ON UPDATE CURRENT_TIMESTAMP");
369
- }
370
- const response = {
371
- typo: "timestamp",
372
- pk: false,
373
- sqlz: parts.join(" ")
374
- };
375
- return response;
376
- }
377
- };
378
- function timestamp() {
379
- return new Timestamp();
380
- }
381
-
382
- // conection/controls/varchar.ts
383
- var Varchar = class {
384
- constructor(cantidad = 100) {
385
- this.maxLenth = 100;
386
- this.defaultData = "";
387
- this.requerido = false;
388
- this.unique = false;
389
- this.maxLenth = cantidad;
390
- }
391
- withType({
392
- maxLenth = 100,
393
- defaultData = "",
394
- requerido = false,
395
- unique = false
396
- }) {
397
- this.maxLenth = maxLenth;
398
- this.requerido = requerido;
399
- this.unique = unique;
400
- return this.Default(defaultData).$();
401
- }
402
- Required() {
403
- this.requerido = true;
404
- return this;
405
- }
406
- Unique() {
407
- this.unique = true;
408
- return this;
409
- }
410
- Default(textoDefecto) {
411
- let opcion = getTipoConexion();
412
- if (opcion === "mysql") {
413
- this.defaultData = ` "${textoDefecto}" `;
414
- } else if (opcion === "pg") {
415
- this.defaultData = ` '${textoDefecto}' `;
416
- }
417
- return this;
418
- }
419
- $() {
420
- let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
421
- const response = {
422
- typo: "varchar",
423
- pk: false,
424
- sqlz
425
- };
426
- return response;
427
- }
428
- };
429
- function varchar(cantidad = 100) {
430
- return new Varchar(cantidad);
431
- }
432
-
433
254
  // conection/middleware/delete.ts
434
255
  var _condicion, _tabla;
435
256
  var DeleteR = class {
@@ -439,12 +260,12 @@ var DeleteR = class {
439
260
  * @example
440
261
  * delete from tabla
441
262
  */
442
- constructor(conexion2, tabla) {
263
+ constructor(conexion, tabla) {
443
264
  __privateAdd(this, _condicion);
444
265
  __privateAdd(this, _tabla);
445
266
  __privateSet(this, _tabla, tabla);
446
267
  __privateSet(this, _condicion, "");
447
- this.conexion = conexion2;
268
+ this.conexion = conexion;
448
269
  }
449
270
  /**
450
271
  *
@@ -490,7 +311,7 @@ var QueryBuilder = class {
490
311
  * @param {string} tabla - nombre de la ta tabla - campo obligatorio
491
312
  * @param {string[]} values - campo obligatorio
492
313
  */
493
- constructor(conexion2, tabla, parametros) {
314
+ constructor(conexion, tabla, parametros) {
494
315
  if (!parametros || !Array.isArray(parametros)) {
495
316
  throw new Error(`campos obligatorios`);
496
317
  }
@@ -501,7 +322,7 @@ var QueryBuilder = class {
501
322
  this.parametros = parametros;
502
323
  this.valores = [];
503
324
  this.valorRetorno = null;
504
- this.conexion = conexion2;
325
+ this.conexion = conexion;
505
326
  }
506
327
  /**
507
328
  *
@@ -601,8 +422,8 @@ var Select = class {
601
422
  * @param {string[]} values - campo obligatorio
602
423
  * @param {string} condition - tabla1.id = tabla2.idtabla1 - id='2' - id='2' AND id='3'
603
424
  */
604
- constructor(conexion2, parametros = "*") {
605
- this.conexion = conexion2;
425
+ constructor(conexion, parametros = "*") {
426
+ this.conexion = conexion;
606
427
  this.valores = !Array.isArray(parametros) ? false : true;
607
428
  this.parametros = parametros;
608
429
  this.tabla = void 0;
@@ -786,7 +607,7 @@ var Update = class {
786
607
  /**
787
608
  * @param {string} nombreTabla - nombre de la tabla a actualizar
788
609
  */
789
- constructor(conexion2, nombreTabla) {
610
+ constructor(conexion, nombreTabla) {
790
611
  this.nombreTabla = "";
791
612
  this.valores = "";
792
613
  this.condicion = "";
@@ -797,7 +618,7 @@ var Update = class {
797
618
  throw new Error("El nombre de la tabla es requerido");
798
619
  }
799
620
  this.nombreTabla = nombreTabla;
800
- this.conexion = conexion2;
621
+ this.conexion = conexion;
801
622
  }
802
623
  /**
803
624
  * @param {Valores} valores - valores a actualizar
@@ -895,6 +716,143 @@ var DB = class {
895
716
  }
896
717
  };
897
718
 
719
+ // conection/controls/int.ts
720
+ var IntColumn = class {
721
+ constructor() {
722
+ this.requerido = false;
723
+ this.unique = false;
724
+ this.autoIncrement = false;
725
+ this.unsingned = { uso: false, valor: 0 };
726
+ }
727
+ Required() {
728
+ this.requerido = true;
729
+ return this;
730
+ }
731
+ Pk() {
732
+ this.autoIncrement = true;
733
+ this.pk = true;
734
+ return this;
735
+ }
736
+ Unique() {
737
+ this.unique = true;
738
+ return this;
739
+ }
740
+ Unsingned(numeroPositivosInicio = 0) {
741
+ if (numeroPositivosInicio != void 0 && numeroPositivosInicio < 0) {
742
+ throw new Error(" Unsingned() solo permite numeros positivos ");
743
+ }
744
+ this.unsingned.uso = true;
745
+ this.unsingned.valor = numeroPositivosInicio;
746
+ }
747
+ AutoIncrement() {
748
+ this.autoIncrement = true;
749
+ this.requerido = true;
750
+ return this;
751
+ }
752
+ Default(value) {
753
+ this.defaultData = value;
754
+ return this;
755
+ }
756
+ withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
757
+ if (defaultData !== void 0) this.Default(defaultData);
758
+ if (requerido) this.Required();
759
+ if (unique) this.Unique();
760
+ if (autoIncrement) this.AutoIncrement();
761
+ return this;
762
+ }
763
+ $() {
764
+ const parts = [];
765
+ const db = getTipoConexion();
766
+ parts.push(db === "mysql" ? "INT" : "INTEGER");
767
+ if (this.unsingned.uso) {
768
+ parts.push(
769
+ db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
770
+ );
771
+ }
772
+ parts.push(
773
+ this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
774
+ );
775
+ if (this.autoIncrement) {
776
+ parts.push(
777
+ db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
778
+ );
779
+ }
780
+ if (this.pk) {
781
+ parts.push("PRIMARY KEY");
782
+ const valor2 = {
783
+ pk: true,
784
+ typo: "int",
785
+ sqlz: parts.join(" ")
786
+ };
787
+ return valor2;
788
+ }
789
+ if (this.defaultData !== void 0 && !this.autoIncrement) {
790
+ parts.push(`DEFAULT ${this.defaultData}`);
791
+ }
792
+ if (this.unique) parts.push("UNIQUE");
793
+ const valor = {
794
+ pk: false,
795
+ typo: "int",
796
+ sqlz: parts.join(" ")
797
+ };
798
+ return valor;
799
+ }
800
+ };
801
+ function int() {
802
+ return new IntColumn();
803
+ }
804
+
805
+ // conection/controls/varchar.ts
806
+ var Varchar = class {
807
+ constructor(cantidad = 100) {
808
+ this.maxLenth = 100;
809
+ this.defaultData = "";
810
+ this.requerido = false;
811
+ this.unique = false;
812
+ this.maxLenth = cantidad;
813
+ }
814
+ withType({
815
+ maxLenth = 100,
816
+ defaultData = "",
817
+ requerido = false,
818
+ unique = false
819
+ }) {
820
+ this.maxLenth = maxLenth;
821
+ this.requerido = requerido;
822
+ this.unique = unique;
823
+ return this.Default(defaultData).$();
824
+ }
825
+ Required() {
826
+ this.requerido = true;
827
+ return this;
828
+ }
829
+ Unique() {
830
+ this.unique = true;
831
+ return this;
832
+ }
833
+ Default(textoDefecto) {
834
+ let opcion = getTipoConexion();
835
+ if (opcion === "mysql") {
836
+ this.defaultData = ` "${textoDefecto}" `;
837
+ } else if (opcion === "pg") {
838
+ this.defaultData = ` '${textoDefecto}' `;
839
+ }
840
+ return this;
841
+ }
842
+ $() {
843
+ let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
844
+ const response = {
845
+ typo: "varchar",
846
+ pk: false,
847
+ sqlz
848
+ };
849
+ return response;
850
+ }
851
+ };
852
+ function varchar(cantidad = 100) {
853
+ return new Varchar(cantidad);
854
+ }
855
+
898
856
  // conection/controls/bool.ts
899
857
  var BoolColumn = class {
900
858
  constructor() {
@@ -930,6 +888,48 @@ function bool() {
930
888
  return new BoolColumn();
931
889
  }
932
890
 
891
+ // conection/controls/timestamp.ts
892
+ var Timestamp = class {
893
+ constructor() {
894
+ this.requerido = false;
895
+ this.defaultNow = false;
896
+ this.onUpdateNow = false;
897
+ }
898
+ required() {
899
+ this.requerido = true;
900
+ return this;
901
+ }
902
+ now() {
903
+ this.defaultNow = true;
904
+ return this;
905
+ }
906
+ onUpdate() {
907
+ this.onUpdateNow = true;
908
+ return this;
909
+ }
910
+ $() {
911
+ const parts = [];
912
+ const db = getTipoConexion();
913
+ parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
914
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
915
+ if (this.defaultNow) {
916
+ parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
917
+ }
918
+ if (this.onUpdateNow && db === "mysql") {
919
+ parts.push("ON UPDATE CURRENT_TIMESTAMP");
920
+ }
921
+ const response = {
922
+ typo: "timestamp",
923
+ pk: false,
924
+ sqlz: parts.join(" ")
925
+ };
926
+ return response;
927
+ }
928
+ };
929
+ function timestamp() {
930
+ return new Timestamp();
931
+ }
932
+
933
933
  // conection/controls/money.ts
934
934
  var Money = class {
935
935
  constructor(presicion = 10, decimales = 2) {
@@ -968,24 +968,6 @@ var Money = class {
968
968
  function money(presicion = 10, decimales = 2) {
969
969
  return new Money(presicion, decimales);
970
970
  }
971
-
972
- // index.ts
973
- var conexion = {
974
- database: "pruebamaster",
975
- host: "localhost",
976
- password: "zainmaster123",
977
- port: 5432,
978
- user: "postgres"
979
- };
980
- getConexion("pg", conexion);
981
- var prueba1 = defineTable("prueba1", {
982
- id: int().Pk().$(),
983
- valor: varchar(200).Default("hola").$(),
984
- resultado: int().Default(0).$(),
985
- fechaRegistro: timestamp().required().now().$(),
986
- fechaUpdate: timestamp().required().now().onUpdate().$()
987
- });
988
- generateTable(prueba1(), prueba1.$columns);
989
971
  // Annotate the CommonJS export names for ESM import in node:
990
972
  0 && (module.exports = {
991
973
  AND,
package/dist/index.mjs CHANGED
@@ -190,185 +190,6 @@ async function generateTable(tabla, columns) {
190
190
  }
191
191
  }
192
192
 
193
- // conection/controls/int.ts
194
- var IntColumn = class {
195
- constructor() {
196
- this.requerido = false;
197
- this.unique = false;
198
- this.autoIncrement = false;
199
- this.unsingned = { uso: false, valor: 0 };
200
- }
201
- Required() {
202
- this.requerido = true;
203
- return this;
204
- }
205
- Pk() {
206
- this.autoIncrement = true;
207
- this.pk = true;
208
- return this;
209
- }
210
- Unique() {
211
- this.unique = true;
212
- return this;
213
- }
214
- Unsingned(numeroPositivosInicio = 0) {
215
- if (numeroPositivosInicio != void 0 && numeroPositivosInicio < 0) {
216
- throw new Error(" Unsingned() solo permite numeros positivos ");
217
- }
218
- this.unsingned.uso = true;
219
- this.unsingned.valor = numeroPositivosInicio;
220
- }
221
- AutoIncrement() {
222
- this.autoIncrement = true;
223
- this.requerido = true;
224
- return this;
225
- }
226
- Default(value) {
227
- this.defaultData = value;
228
- return this;
229
- }
230
- withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
231
- if (defaultData !== void 0) this.Default(defaultData);
232
- if (requerido) this.Required();
233
- if (unique) this.Unique();
234
- if (autoIncrement) this.AutoIncrement();
235
- return this;
236
- }
237
- $() {
238
- const parts = [];
239
- const db = getTipoConexion();
240
- parts.push(db === "mysql" ? "INT" : "INTEGER");
241
- if (this.unsingned.uso) {
242
- parts.push(
243
- db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
244
- );
245
- }
246
- parts.push(
247
- this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
248
- );
249
- if (this.autoIncrement) {
250
- parts.push(
251
- db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
252
- );
253
- }
254
- if (this.pk) {
255
- parts.push("PRIMARY KEY");
256
- const valor2 = {
257
- pk: true,
258
- typo: "int",
259
- sqlz: parts.join(" ")
260
- };
261
- return valor2;
262
- }
263
- if (this.defaultData !== void 0 && !this.autoIncrement) {
264
- parts.push(`DEFAULT ${this.defaultData}`);
265
- }
266
- if (this.unique) parts.push("UNIQUE");
267
- const valor = {
268
- pk: false,
269
- typo: "int",
270
- sqlz: parts.join(" ")
271
- };
272
- return valor;
273
- }
274
- };
275
- function int() {
276
- return new IntColumn();
277
- }
278
-
279
- // conection/controls/timestamp.ts
280
- var Timestamp = class {
281
- constructor() {
282
- this.requerido = false;
283
- this.defaultNow = false;
284
- this.onUpdateNow = false;
285
- }
286
- required() {
287
- this.requerido = true;
288
- return this;
289
- }
290
- now() {
291
- this.defaultNow = true;
292
- return this;
293
- }
294
- onUpdate() {
295
- this.onUpdateNow = true;
296
- return this;
297
- }
298
- $() {
299
- const parts = [];
300
- const db = getTipoConexion();
301
- parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
302
- parts.push(this.requerido ? "NOT NULL" : "NULL");
303
- if (this.defaultNow) {
304
- parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
305
- }
306
- if (this.onUpdateNow && db === "mysql") {
307
- parts.push("ON UPDATE CURRENT_TIMESTAMP");
308
- }
309
- const response = {
310
- typo: "timestamp",
311
- pk: false,
312
- sqlz: parts.join(" ")
313
- };
314
- return response;
315
- }
316
- };
317
- function timestamp() {
318
- return new Timestamp();
319
- }
320
-
321
- // conection/controls/varchar.ts
322
- var Varchar = class {
323
- constructor(cantidad = 100) {
324
- this.maxLenth = 100;
325
- this.defaultData = "";
326
- this.requerido = false;
327
- this.unique = false;
328
- this.maxLenth = cantidad;
329
- }
330
- withType({
331
- maxLenth = 100,
332
- defaultData = "",
333
- requerido = false,
334
- unique = false
335
- }) {
336
- this.maxLenth = maxLenth;
337
- this.requerido = requerido;
338
- this.unique = unique;
339
- return this.Default(defaultData).$();
340
- }
341
- Required() {
342
- this.requerido = true;
343
- return this;
344
- }
345
- Unique() {
346
- this.unique = true;
347
- return this;
348
- }
349
- Default(textoDefecto) {
350
- let opcion = getTipoConexion();
351
- if (opcion === "mysql") {
352
- this.defaultData = ` "${textoDefecto}" `;
353
- } else if (opcion === "pg") {
354
- this.defaultData = ` '${textoDefecto}' `;
355
- }
356
- return this;
357
- }
358
- $() {
359
- let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
360
- const response = {
361
- typo: "varchar",
362
- pk: false,
363
- sqlz
364
- };
365
- return response;
366
- }
367
- };
368
- function varchar(cantidad = 100) {
369
- return new Varchar(cantidad);
370
- }
371
-
372
193
  // conection/middleware/delete.ts
373
194
  var _condicion, _tabla;
374
195
  var DeleteR = class {
@@ -378,12 +199,12 @@ var DeleteR = class {
378
199
  * @example
379
200
  * delete from tabla
380
201
  */
381
- constructor(conexion2, tabla) {
202
+ constructor(conexion, tabla) {
382
203
  __privateAdd(this, _condicion);
383
204
  __privateAdd(this, _tabla);
384
205
  __privateSet(this, _tabla, tabla);
385
206
  __privateSet(this, _condicion, "");
386
- this.conexion = conexion2;
207
+ this.conexion = conexion;
387
208
  }
388
209
  /**
389
210
  *
@@ -429,7 +250,7 @@ var QueryBuilder = class {
429
250
  * @param {string} tabla - nombre de la ta tabla - campo obligatorio
430
251
  * @param {string[]} values - campo obligatorio
431
252
  */
432
- constructor(conexion2, tabla, parametros) {
253
+ constructor(conexion, tabla, parametros) {
433
254
  if (!parametros || !Array.isArray(parametros)) {
434
255
  throw new Error(`campos obligatorios`);
435
256
  }
@@ -440,7 +261,7 @@ var QueryBuilder = class {
440
261
  this.parametros = parametros;
441
262
  this.valores = [];
442
263
  this.valorRetorno = null;
443
- this.conexion = conexion2;
264
+ this.conexion = conexion;
444
265
  }
445
266
  /**
446
267
  *
@@ -540,8 +361,8 @@ var Select = class {
540
361
  * @param {string[]} values - campo obligatorio
541
362
  * @param {string} condition - tabla1.id = tabla2.idtabla1 - id='2' - id='2' AND id='3'
542
363
  */
543
- constructor(conexion2, parametros = "*") {
544
- this.conexion = conexion2;
364
+ constructor(conexion, parametros = "*") {
365
+ this.conexion = conexion;
545
366
  this.valores = !Array.isArray(parametros) ? false : true;
546
367
  this.parametros = parametros;
547
368
  this.tabla = void 0;
@@ -725,7 +546,7 @@ var Update = class {
725
546
  /**
726
547
  * @param {string} nombreTabla - nombre de la tabla a actualizar
727
548
  */
728
- constructor(conexion2, nombreTabla) {
549
+ constructor(conexion, nombreTabla) {
729
550
  this.nombreTabla = "";
730
551
  this.valores = "";
731
552
  this.condicion = "";
@@ -736,7 +557,7 @@ var Update = class {
736
557
  throw new Error("El nombre de la tabla es requerido");
737
558
  }
738
559
  this.nombreTabla = nombreTabla;
739
- this.conexion = conexion2;
560
+ this.conexion = conexion;
740
561
  }
741
562
  /**
742
563
  * @param {Valores} valores - valores a actualizar
@@ -834,6 +655,143 @@ var DB = class {
834
655
  }
835
656
  };
836
657
 
658
+ // conection/controls/int.ts
659
+ var IntColumn = class {
660
+ constructor() {
661
+ this.requerido = false;
662
+ this.unique = false;
663
+ this.autoIncrement = false;
664
+ this.unsingned = { uso: false, valor: 0 };
665
+ }
666
+ Required() {
667
+ this.requerido = true;
668
+ return this;
669
+ }
670
+ Pk() {
671
+ this.autoIncrement = true;
672
+ this.pk = true;
673
+ return this;
674
+ }
675
+ Unique() {
676
+ this.unique = true;
677
+ return this;
678
+ }
679
+ Unsingned(numeroPositivosInicio = 0) {
680
+ if (numeroPositivosInicio != void 0 && numeroPositivosInicio < 0) {
681
+ throw new Error(" Unsingned() solo permite numeros positivos ");
682
+ }
683
+ this.unsingned.uso = true;
684
+ this.unsingned.valor = numeroPositivosInicio;
685
+ }
686
+ AutoIncrement() {
687
+ this.autoIncrement = true;
688
+ this.requerido = true;
689
+ return this;
690
+ }
691
+ Default(value) {
692
+ this.defaultData = value;
693
+ return this;
694
+ }
695
+ withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
696
+ if (defaultData !== void 0) this.Default(defaultData);
697
+ if (requerido) this.Required();
698
+ if (unique) this.Unique();
699
+ if (autoIncrement) this.AutoIncrement();
700
+ return this;
701
+ }
702
+ $() {
703
+ const parts = [];
704
+ const db = getTipoConexion();
705
+ parts.push(db === "mysql" ? "INT" : "INTEGER");
706
+ if (this.unsingned.uso) {
707
+ parts.push(
708
+ db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
709
+ );
710
+ }
711
+ parts.push(
712
+ this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
713
+ );
714
+ if (this.autoIncrement) {
715
+ parts.push(
716
+ db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
717
+ );
718
+ }
719
+ if (this.pk) {
720
+ parts.push("PRIMARY KEY");
721
+ const valor2 = {
722
+ pk: true,
723
+ typo: "int",
724
+ sqlz: parts.join(" ")
725
+ };
726
+ return valor2;
727
+ }
728
+ if (this.defaultData !== void 0 && !this.autoIncrement) {
729
+ parts.push(`DEFAULT ${this.defaultData}`);
730
+ }
731
+ if (this.unique) parts.push("UNIQUE");
732
+ const valor = {
733
+ pk: false,
734
+ typo: "int",
735
+ sqlz: parts.join(" ")
736
+ };
737
+ return valor;
738
+ }
739
+ };
740
+ function int() {
741
+ return new IntColumn();
742
+ }
743
+
744
+ // conection/controls/varchar.ts
745
+ var Varchar = class {
746
+ constructor(cantidad = 100) {
747
+ this.maxLenth = 100;
748
+ this.defaultData = "";
749
+ this.requerido = false;
750
+ this.unique = false;
751
+ this.maxLenth = cantidad;
752
+ }
753
+ withType({
754
+ maxLenth = 100,
755
+ defaultData = "",
756
+ requerido = false,
757
+ unique = false
758
+ }) {
759
+ this.maxLenth = maxLenth;
760
+ this.requerido = requerido;
761
+ this.unique = unique;
762
+ return this.Default(defaultData).$();
763
+ }
764
+ Required() {
765
+ this.requerido = true;
766
+ return this;
767
+ }
768
+ Unique() {
769
+ this.unique = true;
770
+ return this;
771
+ }
772
+ Default(textoDefecto) {
773
+ let opcion = getTipoConexion();
774
+ if (opcion === "mysql") {
775
+ this.defaultData = ` "${textoDefecto}" `;
776
+ } else if (opcion === "pg") {
777
+ this.defaultData = ` '${textoDefecto}' `;
778
+ }
779
+ return this;
780
+ }
781
+ $() {
782
+ let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
783
+ const response = {
784
+ typo: "varchar",
785
+ pk: false,
786
+ sqlz
787
+ };
788
+ return response;
789
+ }
790
+ };
791
+ function varchar(cantidad = 100) {
792
+ return new Varchar(cantidad);
793
+ }
794
+
837
795
  // conection/controls/bool.ts
838
796
  var BoolColumn = class {
839
797
  constructor() {
@@ -869,6 +827,48 @@ function bool() {
869
827
  return new BoolColumn();
870
828
  }
871
829
 
830
+ // conection/controls/timestamp.ts
831
+ var Timestamp = class {
832
+ constructor() {
833
+ this.requerido = false;
834
+ this.defaultNow = false;
835
+ this.onUpdateNow = false;
836
+ }
837
+ required() {
838
+ this.requerido = true;
839
+ return this;
840
+ }
841
+ now() {
842
+ this.defaultNow = true;
843
+ return this;
844
+ }
845
+ onUpdate() {
846
+ this.onUpdateNow = true;
847
+ return this;
848
+ }
849
+ $() {
850
+ const parts = [];
851
+ const db = getTipoConexion();
852
+ parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
853
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
854
+ if (this.defaultNow) {
855
+ parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
856
+ }
857
+ if (this.onUpdateNow && db === "mysql") {
858
+ parts.push("ON UPDATE CURRENT_TIMESTAMP");
859
+ }
860
+ const response = {
861
+ typo: "timestamp",
862
+ pk: false,
863
+ sqlz: parts.join(" ")
864
+ };
865
+ return response;
866
+ }
867
+ };
868
+ function timestamp() {
869
+ return new Timestamp();
870
+ }
871
+
872
872
  // conection/controls/money.ts
873
873
  var Money = class {
874
874
  constructor(presicion = 10, decimales = 2) {
@@ -907,24 +907,6 @@ var Money = class {
907
907
  function money(presicion = 10, decimales = 2) {
908
908
  return new Money(presicion, decimales);
909
909
  }
910
-
911
- // index.ts
912
- var conexion = {
913
- database: "pruebamaster",
914
- host: "localhost",
915
- password: "zainmaster123",
916
- port: 5432,
917
- user: "postgres"
918
- };
919
- getConexion("pg", conexion);
920
- var prueba1 = defineTable("prueba1", {
921
- id: int().Pk().$(),
922
- valor: varchar(200).Default("hola").$(),
923
- resultado: int().Default(0).$(),
924
- fechaRegistro: timestamp().required().now().$(),
925
- fechaUpdate: timestamp().required().now().onUpdate().$()
926
- });
927
- generateTable(prueba1(), prueba1.$columns);
928
910
  export {
929
911
  AND,
930
912
  BDconnection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zormz",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "ISC",