zormz 1.2.5 → 1.2.7

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
@@ -384,7 +384,7 @@ declare class IntColumn {
384
384
  Required(): this;
385
385
  Pk(): this;
386
386
  Unique(): this;
387
- Unsingned(numeroPositivosInicio?: number): void;
387
+ Unsingned(numeroPositivosInicio?: number): this;
388
388
  AutoIncrement(): this;
389
389
  Default(value: number): this;
390
390
  withType({ defaultData, id, requerido, unique, autoIncrement }: IntType): this;
@@ -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
@@ -384,7 +384,7 @@ declare class IntColumn {
384
384
  Required(): this;
385
385
  Pk(): this;
386
386
  Unique(): this;
387
- Unsingned(numeroPositivosInicio?: number): void;
387
+ Unsingned(numeroPositivosInicio?: number): this;
388
388
  AutoIncrement(): this;
389
389
  Default(value: number): this;
390
390
  withType({ defaultData, id, requerido, unique, autoIncrement }: IntType): this;
@@ -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,144 @@ 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
+ return this;
747
+ }
748
+ AutoIncrement() {
749
+ this.autoIncrement = true;
750
+ this.requerido = true;
751
+ return this;
752
+ }
753
+ Default(value) {
754
+ this.defaultData = value;
755
+ return this;
756
+ }
757
+ withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
758
+ if (defaultData !== void 0) this.Default(defaultData);
759
+ if (requerido) this.Required();
760
+ if (unique) this.Unique();
761
+ if (autoIncrement) this.AutoIncrement();
762
+ return this;
763
+ }
764
+ $() {
765
+ const parts = [];
766
+ const db = getTipoConexion();
767
+ parts.push(db === "mysql" ? "INT" : "INTEGER");
768
+ if (this.unsingned.uso) {
769
+ parts.push(
770
+ db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
771
+ );
772
+ }
773
+ parts.push(
774
+ this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
775
+ );
776
+ if (this.autoIncrement) {
777
+ parts.push(
778
+ db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
779
+ );
780
+ }
781
+ if (this.pk) {
782
+ parts.push("PRIMARY KEY");
783
+ const valor2 = {
784
+ pk: true,
785
+ typo: "int",
786
+ sqlz: parts.join(" ")
787
+ };
788
+ return valor2;
789
+ }
790
+ if (this.defaultData !== void 0 && !this.autoIncrement) {
791
+ parts.push(`DEFAULT ${this.defaultData}`);
792
+ }
793
+ if (this.unique) parts.push("UNIQUE");
794
+ const valor = {
795
+ pk: false,
796
+ typo: "int",
797
+ sqlz: parts.join(" ")
798
+ };
799
+ return valor;
800
+ }
801
+ };
802
+ function int() {
803
+ return new IntColumn();
804
+ }
805
+
806
+ // conection/controls/varchar.ts
807
+ var Varchar = class {
808
+ constructor(cantidad = 100) {
809
+ this.maxLenth = 100;
810
+ this.defaultData = "";
811
+ this.requerido = false;
812
+ this.unique = false;
813
+ this.maxLenth = cantidad;
814
+ }
815
+ withType({
816
+ maxLenth = 100,
817
+ defaultData = "",
818
+ requerido = false,
819
+ unique = false
820
+ }) {
821
+ this.maxLenth = maxLenth;
822
+ this.requerido = requerido;
823
+ this.unique = unique;
824
+ return this.Default(defaultData).$();
825
+ }
826
+ Required() {
827
+ this.requerido = true;
828
+ return this;
829
+ }
830
+ Unique() {
831
+ this.unique = true;
832
+ return this;
833
+ }
834
+ Default(textoDefecto) {
835
+ let opcion = getTipoConexion();
836
+ if (opcion === "mysql") {
837
+ this.defaultData = ` "${textoDefecto}" `;
838
+ } else if (opcion === "pg") {
839
+ this.defaultData = ` '${textoDefecto}' `;
840
+ }
841
+ return this;
842
+ }
843
+ $() {
844
+ let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
845
+ const response = {
846
+ typo: "varchar",
847
+ pk: false,
848
+ sqlz
849
+ };
850
+ return response;
851
+ }
852
+ };
853
+ function varchar(cantidad = 100) {
854
+ return new Varchar(cantidad);
855
+ }
856
+
898
857
  // conection/controls/bool.ts
899
858
  var BoolColumn = class {
900
859
  constructor() {
@@ -930,6 +889,48 @@ function bool() {
930
889
  return new BoolColumn();
931
890
  }
932
891
 
892
+ // conection/controls/timestamp.ts
893
+ var Timestamp = class {
894
+ constructor() {
895
+ this.requerido = false;
896
+ this.defaultNow = false;
897
+ this.onUpdateNow = false;
898
+ }
899
+ required() {
900
+ this.requerido = true;
901
+ return this;
902
+ }
903
+ now() {
904
+ this.defaultNow = true;
905
+ return this;
906
+ }
907
+ onUpdate() {
908
+ this.onUpdateNow = true;
909
+ return this;
910
+ }
911
+ $() {
912
+ const parts = [];
913
+ const db = getTipoConexion();
914
+ parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
915
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
916
+ if (this.defaultNow) {
917
+ parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
918
+ }
919
+ if (this.onUpdateNow && db === "mysql") {
920
+ parts.push("ON UPDATE CURRENT_TIMESTAMP");
921
+ }
922
+ const response = {
923
+ typo: "timestamp",
924
+ pk: false,
925
+ sqlz: parts.join(" ")
926
+ };
927
+ return response;
928
+ }
929
+ };
930
+ function timestamp() {
931
+ return new Timestamp();
932
+ }
933
+
933
934
  // conection/controls/money.ts
934
935
  var Money = class {
935
936
  constructor(presicion = 10, decimales = 2) {
@@ -968,24 +969,6 @@ var Money = class {
968
969
  function money(presicion = 10, decimales = 2) {
969
970
  return new Money(presicion, decimales);
970
971
  }
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
972
  // Annotate the CommonJS export names for ESM import in node:
990
973
  0 && (module.exports = {
991
974
  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,144 @@ 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
+ return this;
686
+ }
687
+ AutoIncrement() {
688
+ this.autoIncrement = true;
689
+ this.requerido = true;
690
+ return this;
691
+ }
692
+ Default(value) {
693
+ this.defaultData = value;
694
+ return this;
695
+ }
696
+ withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
697
+ if (defaultData !== void 0) this.Default(defaultData);
698
+ if (requerido) this.Required();
699
+ if (unique) this.Unique();
700
+ if (autoIncrement) this.AutoIncrement();
701
+ return this;
702
+ }
703
+ $() {
704
+ const parts = [];
705
+ const db = getTipoConexion();
706
+ parts.push(db === "mysql" ? "INT" : "INTEGER");
707
+ if (this.unsingned.uso) {
708
+ parts.push(
709
+ db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
710
+ );
711
+ }
712
+ parts.push(
713
+ this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
714
+ );
715
+ if (this.autoIncrement) {
716
+ parts.push(
717
+ db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
718
+ );
719
+ }
720
+ if (this.pk) {
721
+ parts.push("PRIMARY KEY");
722
+ const valor2 = {
723
+ pk: true,
724
+ typo: "int",
725
+ sqlz: parts.join(" ")
726
+ };
727
+ return valor2;
728
+ }
729
+ if (this.defaultData !== void 0 && !this.autoIncrement) {
730
+ parts.push(`DEFAULT ${this.defaultData}`);
731
+ }
732
+ if (this.unique) parts.push("UNIQUE");
733
+ const valor = {
734
+ pk: false,
735
+ typo: "int",
736
+ sqlz: parts.join(" ")
737
+ };
738
+ return valor;
739
+ }
740
+ };
741
+ function int() {
742
+ return new IntColumn();
743
+ }
744
+
745
+ // conection/controls/varchar.ts
746
+ var Varchar = class {
747
+ constructor(cantidad = 100) {
748
+ this.maxLenth = 100;
749
+ this.defaultData = "";
750
+ this.requerido = false;
751
+ this.unique = false;
752
+ this.maxLenth = cantidad;
753
+ }
754
+ withType({
755
+ maxLenth = 100,
756
+ defaultData = "",
757
+ requerido = false,
758
+ unique = false
759
+ }) {
760
+ this.maxLenth = maxLenth;
761
+ this.requerido = requerido;
762
+ this.unique = unique;
763
+ return this.Default(defaultData).$();
764
+ }
765
+ Required() {
766
+ this.requerido = true;
767
+ return this;
768
+ }
769
+ Unique() {
770
+ this.unique = true;
771
+ return this;
772
+ }
773
+ Default(textoDefecto) {
774
+ let opcion = getTipoConexion();
775
+ if (opcion === "mysql") {
776
+ this.defaultData = ` "${textoDefecto}" `;
777
+ } else if (opcion === "pg") {
778
+ this.defaultData = ` '${textoDefecto}' `;
779
+ }
780
+ return this;
781
+ }
782
+ $() {
783
+ let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
784
+ const response = {
785
+ typo: "varchar",
786
+ pk: false,
787
+ sqlz
788
+ };
789
+ return response;
790
+ }
791
+ };
792
+ function varchar(cantidad = 100) {
793
+ return new Varchar(cantidad);
794
+ }
795
+
837
796
  // conection/controls/bool.ts
838
797
  var BoolColumn = class {
839
798
  constructor() {
@@ -869,6 +828,48 @@ function bool() {
869
828
  return new BoolColumn();
870
829
  }
871
830
 
831
+ // conection/controls/timestamp.ts
832
+ var Timestamp = class {
833
+ constructor() {
834
+ this.requerido = false;
835
+ this.defaultNow = false;
836
+ this.onUpdateNow = false;
837
+ }
838
+ required() {
839
+ this.requerido = true;
840
+ return this;
841
+ }
842
+ now() {
843
+ this.defaultNow = true;
844
+ return this;
845
+ }
846
+ onUpdate() {
847
+ this.onUpdateNow = true;
848
+ return this;
849
+ }
850
+ $() {
851
+ const parts = [];
852
+ const db = getTipoConexion();
853
+ parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
854
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
855
+ if (this.defaultNow) {
856
+ parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
857
+ }
858
+ if (this.onUpdateNow && db === "mysql") {
859
+ parts.push("ON UPDATE CURRENT_TIMESTAMP");
860
+ }
861
+ const response = {
862
+ typo: "timestamp",
863
+ pk: false,
864
+ sqlz: parts.join(" ")
865
+ };
866
+ return response;
867
+ }
868
+ };
869
+ function timestamp() {
870
+ return new Timestamp();
871
+ }
872
+
872
873
  // conection/controls/money.ts
873
874
  var Money = class {
874
875
  constructor(presicion = 10, decimales = 2) {
@@ -907,24 +908,6 @@ var Money = class {
907
908
  function money(presicion = 10, decimales = 2) {
908
909
  return new Money(presicion, decimales);
909
910
  }
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
911
  export {
929
912
  AND,
930
913
  BDconnection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zormz",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "ISC",