zormz 1.2.4 → 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.
@@ -1,3 +1,45 @@
1
+ interface ResultSetHeaderMysql {
2
+ fieldCount: number;
3
+ affectedRows: number;
4
+ insertId: number;
5
+ info: string;
6
+ serverStatus: number;
7
+ warningStatus: number;
8
+ changedRows: number;
9
+ }
10
+
11
+ type ColumnTypes =
12
+ | "varchar"
13
+ | "int"
14
+ | "double"
15
+ | "bool"
16
+ | "timestamp"
17
+ | "float"
18
+ | "money";
19
+
20
+
21
+ interface ColumnDefinition<T extends ColumnTypes = ColumnTypes> {
22
+ typo: T;
23
+ pk?: boolean;
24
+ sqlz: string;
25
+ }
26
+
27
+ interface VarcharType{
28
+ maxLenth?:number,
29
+ defaultData?:string,
30
+ requerido?:boolean
31
+ unique?:boolean
32
+ }
33
+
34
+ type IntType = {
35
+ defaultData?: number;
36
+ id?:boolean;
37
+ requerido?: boolean;
38
+ unique?: boolean;
39
+ unsingned:number;
40
+ autoIncrement?: boolean;
41
+ };
42
+
1
43
  interface connecionLocal {
2
44
  host: string;
3
45
  port: number;
@@ -14,6 +56,7 @@ interface connecionRed {
14
56
  connectionString: string;
15
57
  }
16
58
  type connectionDB = "mysql" | "pg";
59
+ declare function getTipoConexion(): connectionDB;
17
60
  declare class BDconnection {
18
61
  tipo: connectionDB;
19
62
  pool: any;
@@ -31,23 +74,6 @@ declare class BDconnection {
31
74
  */
32
75
  declare function getConexion(bd: connectionDB, datos: connecionLocal | connecionRed): Promise<void>;
33
76
  declare function getRed(): BDconnection;
34
- type ColumnTypes = "varchar" | "int" | "double" | "bool" | "timestamp" | "float" | "money";
35
- type ColumnTypeMap = {
36
- varchar: string;
37
- double: number;
38
- int: number;
39
- bool: boolean;
40
- timestamp: Date;
41
- float: number;
42
- money: number;
43
- };
44
- interface ColumnDefinition<T extends ColumnTypes = ColumnTypes> {
45
- typo: T;
46
- id?: boolean;
47
- maxLength?: number;
48
- default?: ColumnTypeMap[T];
49
- unique?: boolean;
50
- }
51
77
  type TableProxy<TCols> = {
52
78
  (): string;
53
79
  $columns: TCols;
@@ -132,16 +158,6 @@ declare class QueryBuilder {
132
158
  execute(): Promise<number | any[] | undefined>;
133
159
  }
134
160
 
135
- interface ResultSetHeaderMysql {
136
- fieldCount: number;
137
- affectedRows: number;
138
- insertId: number;
139
- info: string;
140
- serverStatus: number;
141
- warningStatus: number;
142
- changedRows: number;
143
- }
144
-
145
161
  type valor = "ASC" | "DESC";
146
162
  type Tipos = {
147
163
  [clave: string]: valor;
@@ -357,4 +373,69 @@ declare const MENOR: (valor: string, valor2: string) => string;
357
373
  */
358
374
  declare const CURRENT_TIMESTAMP: () => string;
359
375
 
360
- export { AND, BDconnection, CURRENT_TIMESTAMP, type ColumnDefinition, 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, type connecionLocal, type connecionRed, type connectionDB, defineTable, eq, generateTable, getConexion, getRed, type valor };
376
+ declare class IntColumn {
377
+ private requerido;
378
+ private unique;
379
+ private autoIncrement;
380
+ private defaultData?;
381
+ private pk?;
382
+ private unsingned;
383
+ constructor();
384
+ Required(): this;
385
+ Pk(): this;
386
+ Unique(): this;
387
+ Unsingned(numeroPositivosInicio?: number): void;
388
+ AutoIncrement(): this;
389
+ Default(value: number): this;
390
+ withType({ defaultData, id, requerido, unique, autoIncrement }: IntType): this;
391
+ $(): ColumnDefinition;
392
+ }
393
+ declare function int(): IntColumn;
394
+
395
+ declare class Varchar {
396
+ private maxLenth;
397
+ private defaultData;
398
+ private requerido;
399
+ private unique;
400
+ constructor(cantidad?: number);
401
+ withType({ maxLenth, defaultData, requerido, unique, }: VarcharType): ColumnDefinition<ColumnTypes>;
402
+ Required(): this;
403
+ Unique(): this;
404
+ Default(textoDefecto: string): this;
405
+ $(): ColumnDefinition<ColumnTypes>;
406
+ }
407
+ declare function varchar(cantidad?: number): Varchar;
408
+
409
+ declare class BoolColumn {
410
+ private requerido;
411
+ private defaultData?;
412
+ required(): this;
413
+ default(value: boolean): this;
414
+ $(): ColumnDefinition;
415
+ }
416
+ declare function bool(): BoolColumn;
417
+
418
+ declare class Timestamp {
419
+ private requerido;
420
+ private defaultNow;
421
+ private onUpdateNow;
422
+ required(): this;
423
+ now(): this;
424
+ onUpdate(): this;
425
+ $(): ColumnDefinition<ColumnTypes>;
426
+ }
427
+ declare function timestamp(): Timestamp;
428
+
429
+ declare class Money {
430
+ private precision;
431
+ private scale;
432
+ private requerido;
433
+ private defaultData?;
434
+ constructor(presicion?: number, decimales?: number);
435
+ required(): this;
436
+ default(value: number): this;
437
+ $(): ColumnDefinition<ColumnTypes>;
438
+ }
439
+ declare function money(presicion?: number, decimales?: number): Money;
440
+
441
+ 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, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,45 @@
1
+ interface ResultSetHeaderMysql {
2
+ fieldCount: number;
3
+ affectedRows: number;
4
+ insertId: number;
5
+ info: string;
6
+ serverStatus: number;
7
+ warningStatus: number;
8
+ changedRows: number;
9
+ }
10
+
11
+ type ColumnTypes =
12
+ | "varchar"
13
+ | "int"
14
+ | "double"
15
+ | "bool"
16
+ | "timestamp"
17
+ | "float"
18
+ | "money";
19
+
20
+
21
+ interface ColumnDefinition<T extends ColumnTypes = ColumnTypes> {
22
+ typo: T;
23
+ pk?: boolean;
24
+ sqlz: string;
25
+ }
26
+
27
+ interface VarcharType{
28
+ maxLenth?:number,
29
+ defaultData?:string,
30
+ requerido?:boolean
31
+ unique?:boolean
32
+ }
33
+
34
+ type IntType = {
35
+ defaultData?: number;
36
+ id?:boolean;
37
+ requerido?: boolean;
38
+ unique?: boolean;
39
+ unsingned:number;
40
+ autoIncrement?: boolean;
41
+ };
42
+
1
43
  interface connecionLocal {
2
44
  host: string;
3
45
  port: number;
@@ -14,6 +56,7 @@ interface connecionRed {
14
56
  connectionString: string;
15
57
  }
16
58
  type connectionDB = "mysql" | "pg";
59
+ declare function getTipoConexion(): connectionDB;
17
60
  declare class BDconnection {
18
61
  tipo: connectionDB;
19
62
  pool: any;
@@ -31,23 +74,6 @@ declare class BDconnection {
31
74
  */
32
75
  declare function getConexion(bd: connectionDB, datos: connecionLocal | connecionRed): Promise<void>;
33
76
  declare function getRed(): BDconnection;
34
- type ColumnTypes = "varchar" | "int" | "double" | "bool" | "timestamp" | "float" | "money";
35
- type ColumnTypeMap = {
36
- varchar: string;
37
- double: number;
38
- int: number;
39
- bool: boolean;
40
- timestamp: Date;
41
- float: number;
42
- money: number;
43
- };
44
- interface ColumnDefinition<T extends ColumnTypes = ColumnTypes> {
45
- typo: T;
46
- id?: boolean;
47
- maxLength?: number;
48
- default?: ColumnTypeMap[T];
49
- unique?: boolean;
50
- }
51
77
  type TableProxy<TCols> = {
52
78
  (): string;
53
79
  $columns: TCols;
@@ -132,16 +158,6 @@ declare class QueryBuilder {
132
158
  execute(): Promise<number | any[] | undefined>;
133
159
  }
134
160
 
135
- interface ResultSetHeaderMysql {
136
- fieldCount: number;
137
- affectedRows: number;
138
- insertId: number;
139
- info: string;
140
- serverStatus: number;
141
- warningStatus: number;
142
- changedRows: number;
143
- }
144
-
145
161
  type valor = "ASC" | "DESC";
146
162
  type Tipos = {
147
163
  [clave: string]: valor;
@@ -357,4 +373,69 @@ declare const MENOR: (valor: string, valor2: string) => string;
357
373
  */
358
374
  declare const CURRENT_TIMESTAMP: () => string;
359
375
 
360
- export { AND, BDconnection, CURRENT_TIMESTAMP, type ColumnDefinition, 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, type connecionLocal, type connecionRed, type connectionDB, defineTable, eq, generateTable, getConexion, getRed, type valor };
376
+ declare class IntColumn {
377
+ private requerido;
378
+ private unique;
379
+ private autoIncrement;
380
+ private defaultData?;
381
+ private pk?;
382
+ private unsingned;
383
+ constructor();
384
+ Required(): this;
385
+ Pk(): this;
386
+ Unique(): this;
387
+ Unsingned(numeroPositivosInicio?: number): void;
388
+ AutoIncrement(): this;
389
+ Default(value: number): this;
390
+ withType({ defaultData, id, requerido, unique, autoIncrement }: IntType): this;
391
+ $(): ColumnDefinition;
392
+ }
393
+ declare function int(): IntColumn;
394
+
395
+ declare class Varchar {
396
+ private maxLenth;
397
+ private defaultData;
398
+ private requerido;
399
+ private unique;
400
+ constructor(cantidad?: number);
401
+ withType({ maxLenth, defaultData, requerido, unique, }: VarcharType): ColumnDefinition<ColumnTypes>;
402
+ Required(): this;
403
+ Unique(): this;
404
+ Default(textoDefecto: string): this;
405
+ $(): ColumnDefinition<ColumnTypes>;
406
+ }
407
+ declare function varchar(cantidad?: number): Varchar;
408
+
409
+ declare class BoolColumn {
410
+ private requerido;
411
+ private defaultData?;
412
+ required(): this;
413
+ default(value: boolean): this;
414
+ $(): ColumnDefinition;
415
+ }
416
+ declare function bool(): BoolColumn;
417
+
418
+ declare class Timestamp {
419
+ private requerido;
420
+ private defaultNow;
421
+ private onUpdateNow;
422
+ required(): this;
423
+ now(): this;
424
+ onUpdate(): this;
425
+ $(): ColumnDefinition<ColumnTypes>;
426
+ }
427
+ declare function timestamp(): Timestamp;
428
+
429
+ declare class Money {
430
+ private precision;
431
+ private scale;
432
+ private requerido;
433
+ private defaultData?;
434
+ constructor(presicion?: number, decimales?: number);
435
+ required(): this;
436
+ default(value: number): this;
437
+ $(): ColumnDefinition<ColumnTypes>;
438
+ }
439
+ declare function money(presicion?: number, decimales?: number): Money;
440
+
441
+ 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, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
package/dist/index.js CHANGED
@@ -1,14 +1,78 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1
8
  var __typeError = (msg) => {
2
9
  throw TypeError(msg);
3
10
  };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
4
32
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
33
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
34
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
35
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
36
 
37
+ // index.ts
38
+ var index_exports = {};
39
+ __export(index_exports, {
40
+ AND: () => AND,
41
+ BDconnection: () => BDconnection,
42
+ CURRENT_TIMESTAMP: () => CURRENT_TIMESTAMP,
43
+ DB: () => DB,
44
+ DeleteR: () => DeleteR,
45
+ ILIKE: () => ILIKE,
46
+ MAYOR: () => MAYOR,
47
+ MENOR: () => MENOR,
48
+ NOTNULL: () => NOTNULL,
49
+ NOW: () => NOW,
50
+ NULL: () => NULL,
51
+ OR: () => OR,
52
+ ORQ: () => ORQ,
53
+ QueryBuilder: () => QueryBuilder,
54
+ Select: () => Select,
55
+ Update: () => Update,
56
+ bool: () => bool,
57
+ defineTable: () => defineTable,
58
+ eq: () => eq,
59
+ generateTable: () => generateTable,
60
+ getConexion: () => getConexion,
61
+ getRed: () => getRed,
62
+ getTipoConexion: () => getTipoConexion,
63
+ int: () => int,
64
+ money: () => money,
65
+ timestamp: () => timestamp,
66
+ varchar: () => varchar
67
+ });
68
+ module.exports = __toCommonJS(index_exports);
69
+
9
70
  // conection/db.ts
10
71
  var conexionZORMZ3691;
11
72
  var tipoConexionZORMZ3691;
73
+ function getTipoConexion() {
74
+ return tipoConexionZORMZ3691;
75
+ }
12
76
  var BDconnection = class {
13
77
  constructor(bd, datos) {
14
78
  this.tipo = "pg";
@@ -144,29 +208,6 @@ function defineTable(tableName, columns) {
144
208
  });
145
209
  return proxy;
146
210
  }
147
- function ValidacionTypos(columna, id, maxLength) {
148
- let sql = "";
149
- if (columna === "varchar")
150
- sql += `VARCHAR(${maxLength ? maxLength : "100"})`;
151
- if (columna === "int") {
152
- if (tipoConexionZORMZ3691 === "pg") {
153
- sql += id ? " " : " INTEGER ";
154
- } else {
155
- sql += " INT ";
156
- }
157
- }
158
- if (columna === "bool")
159
- sql += tipoConexionZORMZ3691 === "mysql" ? " TINYINT(1) " : " BOOLEAN ";
160
- if (columna === "double")
161
- sql += tipoConexionZORMZ3691 === "mysql" ? " DOUBLE " : " DOUBLE PRECISION ";
162
- if (columna === "timestamp")
163
- sql += tipoConexionZORMZ3691 === "mysql" ? " TIMESTAMP " : " TIMESTAMPTZ ";
164
- if (columna === "float")
165
- sql += tipoConexionZORMZ3691 === "mysql" ? " FLOAT " : " REAL";
166
- if (columna === "money")
167
- sql += tipoConexionZORMZ3691 === "mysql" ? " DECIMAL(10,2) " : " NUMERIC(10,2)";
168
- return sql;
169
- }
170
211
  async function generateTable(tabla, columns) {
171
212
  let queries = "";
172
213
  let columnDefs = [];
@@ -178,17 +219,15 @@ async function generateTable(tabla, columns) {
178
219
  if (!col.typo) {
179
220
  throw new Error(`La columna ${columnName} no tiene el tipo definido`);
180
221
  }
181
- sql += ValidacionTypos(col.typo, col.id, col.maxLength);
182
- if (col.id) {
183
- if (id) throw new Error(`El id no puede repetirse en 2 campos de la tabla '${tabla}'`);
184
- sql += tipoConexionZORMZ3691 === "mysql" ? " NOT NULL AUTO_INCREMENT " : " SERIAL ";
185
- sql += " PRIMARY KEY ";
186
- id = true;
187
- columnDefs.push(sql);
188
- continue;
189
- }
190
- sql += col.unique === void 0 ? " NOT NULL " : " UNIQUE";
191
- sql += col.default === void 0 ? col.unique === void 0 ? " " : " NOT NULL " : ` DEFAULT ${typeof col.default === "string" ? tipoConexionZORMZ3691 === "mysql" ? `"${col.default}"` : `'${col.default}'` : col.default}`;
222
+ if (col.typo === "int") {
223
+ let valorSql = col.sqlz.replace("$ZORMZ", columnName);
224
+ col.sqlz = valorSql;
225
+ }
226
+ if (id && col.pk === true) {
227
+ throw new Error("El id es unico por fila");
228
+ }
229
+ id = col.pk === true ? true : false;
230
+ sql += col.sqlz;
192
231
  columnDefs.push(sql);
193
232
  }
194
233
  queries += `CREATE TABLE IF NOT EXISTS ${tabla} (
@@ -676,7 +715,261 @@ var DB = class {
676
715
  return new DeleteR(conex, nombreTabla);
677
716
  }
678
717
  };
679
- export {
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
+
856
+ // conection/controls/bool.ts
857
+ var BoolColumn = class {
858
+ constructor() {
859
+ this.requerido = false;
860
+ }
861
+ required() {
862
+ this.requerido = true;
863
+ return this;
864
+ }
865
+ default(value) {
866
+ this.defaultData = value;
867
+ return this;
868
+ }
869
+ $() {
870
+ const parts = [];
871
+ const db = getTipoConexion();
872
+ parts.push("BOOLEAN");
873
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
874
+ if (this.defaultData !== void 0) {
875
+ parts.push(
876
+ `DEFAULT ${db === "mysql" ? this.defaultData ? 1 : 0 : this.defaultData}`
877
+ );
878
+ }
879
+ const response = {
880
+ typo: "bool",
881
+ pk: false,
882
+ sqlz: parts.join(" ")
883
+ };
884
+ return response;
885
+ }
886
+ };
887
+ function bool() {
888
+ return new BoolColumn();
889
+ }
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
+ // conection/controls/money.ts
934
+ var Money = class {
935
+ constructor(presicion = 10, decimales = 2) {
936
+ this.precision = 10;
937
+ this.scale = 2;
938
+ this.requerido = false;
939
+ this.precision = presicion;
940
+ this.scale = decimales;
941
+ }
942
+ required() {
943
+ this.requerido = true;
944
+ return this;
945
+ }
946
+ default(value) {
947
+ this.defaultData = value;
948
+ return this;
949
+ }
950
+ $() {
951
+ const parts = [];
952
+ const db = getTipoConexion();
953
+ parts.push(
954
+ db === "mysql" ? `DECIMAL(${this.precision},${this.scale})` : `NUMERIC(${this.precision},${this.scale})`
955
+ );
956
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
957
+ if (this.defaultData !== void 0) {
958
+ parts.push(`DEFAULT ${this.defaultData.toFixed(this.scale)}`);
959
+ }
960
+ const response = {
961
+ typo: "money",
962
+ pk: false,
963
+ sqlz: parts.join(" ")
964
+ };
965
+ return response;
966
+ }
967
+ };
968
+ function money(presicion = 10, decimales = 2) {
969
+ return new Money(presicion, decimales);
970
+ }
971
+ // Annotate the CommonJS export names for ESM import in node:
972
+ 0 && (module.exports = {
680
973
  AND,
681
974
  BDconnection,
682
975
  CURRENT_TIMESTAMP,
@@ -693,9 +986,15 @@ export {
693
986
  QueryBuilder,
694
987
  Select,
695
988
  Update,
989
+ bool,
696
990
  defineTable,
697
991
  eq,
698
992
  generateTable,
699
993
  getConexion,
700
- getRed
701
- };
994
+ getRed,
995
+ getTipoConexion,
996
+ int,
997
+ money,
998
+ timestamp,
999
+ varchar
1000
+ });
@@ -1,69 +1,17 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
1
  var __typeError = (msg) => {
9
2
  throw TypeError(msg);
10
3
  };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
4
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
33
5
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
34
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
35
7
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
36
8
 
37
- // index.ts
38
- var index_exports = {};
39
- __export(index_exports, {
40
- AND: () => AND,
41
- BDconnection: () => BDconnection,
42
- CURRENT_TIMESTAMP: () => CURRENT_TIMESTAMP,
43
- DB: () => DB,
44
- DeleteR: () => DeleteR,
45
- ILIKE: () => ILIKE,
46
- MAYOR: () => MAYOR,
47
- MENOR: () => MENOR,
48
- NOTNULL: () => NOTNULL,
49
- NOW: () => NOW,
50
- NULL: () => NULL,
51
- OR: () => OR,
52
- ORQ: () => ORQ,
53
- QueryBuilder: () => QueryBuilder,
54
- Select: () => Select,
55
- Update: () => Update,
56
- defineTable: () => defineTable,
57
- eq: () => eq,
58
- generateTable: () => generateTable,
59
- getConexion: () => getConexion,
60
- getRed: () => getRed
61
- });
62
- module.exports = __toCommonJS(index_exports);
63
-
64
9
  // conection/db.ts
65
10
  var conexionZORMZ3691;
66
11
  var tipoConexionZORMZ3691;
12
+ function getTipoConexion() {
13
+ return tipoConexionZORMZ3691;
14
+ }
67
15
  var BDconnection = class {
68
16
  constructor(bd, datos) {
69
17
  this.tipo = "pg";
@@ -199,29 +147,6 @@ function defineTable(tableName, columns) {
199
147
  });
200
148
  return proxy;
201
149
  }
202
- function ValidacionTypos(columna, id, maxLength) {
203
- let sql = "";
204
- if (columna === "varchar")
205
- sql += `VARCHAR(${maxLength ? maxLength : "100"})`;
206
- if (columna === "int") {
207
- if (tipoConexionZORMZ3691 === "pg") {
208
- sql += id ? " " : " INTEGER ";
209
- } else {
210
- sql += " INT ";
211
- }
212
- }
213
- if (columna === "bool")
214
- sql += tipoConexionZORMZ3691 === "mysql" ? " TINYINT(1) " : " BOOLEAN ";
215
- if (columna === "double")
216
- sql += tipoConexionZORMZ3691 === "mysql" ? " DOUBLE " : " DOUBLE PRECISION ";
217
- if (columna === "timestamp")
218
- sql += tipoConexionZORMZ3691 === "mysql" ? " TIMESTAMP " : " TIMESTAMPTZ ";
219
- if (columna === "float")
220
- sql += tipoConexionZORMZ3691 === "mysql" ? " FLOAT " : " REAL";
221
- if (columna === "money")
222
- sql += tipoConexionZORMZ3691 === "mysql" ? " DECIMAL(10,2) " : " NUMERIC(10,2)";
223
- return sql;
224
- }
225
150
  async function generateTable(tabla, columns) {
226
151
  let queries = "";
227
152
  let columnDefs = [];
@@ -233,17 +158,15 @@ async function generateTable(tabla, columns) {
233
158
  if (!col.typo) {
234
159
  throw new Error(`La columna ${columnName} no tiene el tipo definido`);
235
160
  }
236
- sql += ValidacionTypos(col.typo, col.id, col.maxLength);
237
- if (col.id) {
238
- if (id) throw new Error(`El id no puede repetirse en 2 campos de la tabla '${tabla}'`);
239
- sql += tipoConexionZORMZ3691 === "mysql" ? " NOT NULL AUTO_INCREMENT " : " SERIAL ";
240
- sql += " PRIMARY KEY ";
241
- id = true;
242
- columnDefs.push(sql);
243
- continue;
244
- }
245
- sql += col.unique === void 0 ? " NOT NULL " : " UNIQUE";
246
- sql += col.default === void 0 ? col.unique === void 0 ? " " : " NOT NULL " : ` DEFAULT ${typeof col.default === "string" ? tipoConexionZORMZ3691 === "mysql" ? `"${col.default}"` : `'${col.default}'` : col.default}`;
161
+ if (col.typo === "int") {
162
+ let valorSql = col.sqlz.replace("$ZORMZ", columnName);
163
+ col.sqlz = valorSql;
164
+ }
165
+ if (id && col.pk === true) {
166
+ throw new Error("El id es unico por fila");
167
+ }
168
+ id = col.pk === true ? true : false;
169
+ sql += col.sqlz;
247
170
  columnDefs.push(sql);
248
171
  }
249
172
  queries += `CREATE TABLE IF NOT EXISTS ${tabla} (
@@ -731,8 +654,260 @@ var DB = class {
731
654
  return new DeleteR(conex, nombreTabla);
732
655
  }
733
656
  };
734
- // Annotate the CommonJS export names for ESM import in node:
735
- 0 && (module.exports = {
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
+
795
+ // conection/controls/bool.ts
796
+ var BoolColumn = class {
797
+ constructor() {
798
+ this.requerido = false;
799
+ }
800
+ required() {
801
+ this.requerido = true;
802
+ return this;
803
+ }
804
+ default(value) {
805
+ this.defaultData = value;
806
+ return this;
807
+ }
808
+ $() {
809
+ const parts = [];
810
+ const db = getTipoConexion();
811
+ parts.push("BOOLEAN");
812
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
813
+ if (this.defaultData !== void 0) {
814
+ parts.push(
815
+ `DEFAULT ${db === "mysql" ? this.defaultData ? 1 : 0 : this.defaultData}`
816
+ );
817
+ }
818
+ const response = {
819
+ typo: "bool",
820
+ pk: false,
821
+ sqlz: parts.join(" ")
822
+ };
823
+ return response;
824
+ }
825
+ };
826
+ function bool() {
827
+ return new BoolColumn();
828
+ }
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
+ // conection/controls/money.ts
873
+ var Money = class {
874
+ constructor(presicion = 10, decimales = 2) {
875
+ this.precision = 10;
876
+ this.scale = 2;
877
+ this.requerido = false;
878
+ this.precision = presicion;
879
+ this.scale = decimales;
880
+ }
881
+ required() {
882
+ this.requerido = true;
883
+ return this;
884
+ }
885
+ default(value) {
886
+ this.defaultData = value;
887
+ return this;
888
+ }
889
+ $() {
890
+ const parts = [];
891
+ const db = getTipoConexion();
892
+ parts.push(
893
+ db === "mysql" ? `DECIMAL(${this.precision},${this.scale})` : `NUMERIC(${this.precision},${this.scale})`
894
+ );
895
+ parts.push(this.requerido ? "NOT NULL" : "NULL");
896
+ if (this.defaultData !== void 0) {
897
+ parts.push(`DEFAULT ${this.defaultData.toFixed(this.scale)}`);
898
+ }
899
+ const response = {
900
+ typo: "money",
901
+ pk: false,
902
+ sqlz: parts.join(" ")
903
+ };
904
+ return response;
905
+ }
906
+ };
907
+ function money(presicion = 10, decimales = 2) {
908
+ return new Money(presicion, decimales);
909
+ }
910
+ export {
736
911
  AND,
737
912
  BDconnection,
738
913
  CURRENT_TIMESTAMP,
@@ -749,9 +924,15 @@ var DB = class {
749
924
  QueryBuilder,
750
925
  Select,
751
926
  Update,
927
+ bool,
752
928
  defineTable,
753
929
  eq,
754
930
  generateTable,
755
931
  getConexion,
756
- getRed
757
- });
932
+ getRed,
933
+ getTipoConexion,
934
+ int,
935
+ money,
936
+ timestamp,
937
+ varchar
938
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zormz",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "ISC",