zormz 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -74
- package/dist/index.d.mts +47 -18
- package/dist/index.d.ts +47 -18
- package/dist/index.js +108 -17
- package/dist/index.mjs +107 -17
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
10
10
|
var Validator = class {
|
|
11
11
|
};
|
|
12
12
|
Validator.isValidTable = (val) => /^(?![0-9_])[a-z][a-z0-9_]{0,62}$/.test(val);
|
|
13
|
-
Validator.isValidColumn = (val) => /^[a-
|
|
13
|
+
Validator.isValidColumn = (val) => /^[a-zA-Z][a-zA-Z0-9]{0,62}$/.test(val);
|
|
14
14
|
Validator.isValidUsername = (val) => /^[a-zA-Z0-9\-_]+$/.test(val);
|
|
15
15
|
var RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
16
16
|
"select",
|
|
@@ -154,7 +154,7 @@ function defineTable(tableName, columns) {
|
|
|
154
154
|
const fn = () => tableName;
|
|
155
155
|
if (!Validator.isValidTable(tableName)) {
|
|
156
156
|
throw new Error(
|
|
157
|
-
"El nombre de la tabla no puede contener mayusculas o caracteres especiales"
|
|
157
|
+
"El nombre de la tabla no puede contener mayusculas o caracteres especiales : " + tableName
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
160
|
if (RESERVED_WORDS.has(tableName)) {
|
|
@@ -181,7 +181,7 @@ function defineTable(tableName, columns) {
|
|
|
181
181
|
if (prop === "toString") return () => tableName;
|
|
182
182
|
if (prop === "valueOf") return () => tableName;
|
|
183
183
|
if (prop in columns) {
|
|
184
|
-
return `${tableName}
|
|
184
|
+
return tipoConexionZORMZ3691 === "mysql" ? `${tableName}.\`${prop.toString()}\` ` : `${tableName}."${prop.toString()}" `;
|
|
185
185
|
}
|
|
186
186
|
return void 0;
|
|
187
187
|
},
|
|
@@ -203,14 +203,15 @@ function defineTable(tableName, columns) {
|
|
|
203
203
|
});
|
|
204
204
|
return proxy;
|
|
205
205
|
}
|
|
206
|
-
async function generateTable(tabla, columns) {
|
|
206
|
+
async function generateTable(tabla, columns, seeSQL = false) {
|
|
207
207
|
let queries = "";
|
|
208
208
|
let columnDefs = [];
|
|
209
|
+
let cheksOut = [];
|
|
209
210
|
let sql = "";
|
|
210
211
|
let id = false;
|
|
211
212
|
for (const columnName in columns) {
|
|
212
213
|
const col = columns[columnName];
|
|
213
|
-
sql = ` ${columnName} `;
|
|
214
|
+
sql = tipoConexionZORMZ3691 === "mysql" ? `\`${columnName}\` ` : `"${columnName}" `;
|
|
214
215
|
if (!col.typo) {
|
|
215
216
|
throw new Error(`La columna ${columnName} no tiene el tipo definido`);
|
|
216
217
|
}
|
|
@@ -224,16 +225,28 @@ async function generateTable(tabla, columns) {
|
|
|
224
225
|
id = col.pk === true ? true : false;
|
|
225
226
|
sql += col.sqlz;
|
|
226
227
|
columnDefs.push(sql);
|
|
228
|
+
if (col.check !== void 0) {
|
|
229
|
+
cheksOut.push(
|
|
230
|
+
`CONSTRAINT chk_${columnName} CHECK (${columnName} IN ( ${col.check}))`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
227
233
|
}
|
|
228
234
|
queries += `CREATE TABLE IF NOT EXISTS ${tabla} (
|
|
229
235
|
`;
|
|
230
236
|
queries += columnDefs.join(", \n");
|
|
237
|
+
if (cheksOut.length > 0) {
|
|
238
|
+
queries += ",\n";
|
|
239
|
+
}
|
|
240
|
+
queries += cheksOut.join(",\n");
|
|
231
241
|
queries += ");";
|
|
232
242
|
if (!conexionZORMZ3691 || !tipoConexionZORMZ3691) {
|
|
233
243
|
throw new Error(
|
|
234
244
|
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
235
245
|
);
|
|
236
246
|
}
|
|
247
|
+
if (seeSQL) {
|
|
248
|
+
console.log(queries);
|
|
249
|
+
}
|
|
237
250
|
if (tipoConexionZORMZ3691 === "mysql") {
|
|
238
251
|
const response = await conexionZORMZ3691.executeConsulta({
|
|
239
252
|
query: queries,
|
|
@@ -354,7 +367,6 @@ var QueryBuilder = class {
|
|
|
354
367
|
this.tabla = tabla;
|
|
355
368
|
this.parametros = parametros;
|
|
356
369
|
this.valores = [];
|
|
357
|
-
this.valorRetorno = null;
|
|
358
370
|
this.conexion = conexion;
|
|
359
371
|
}
|
|
360
372
|
/**
|
|
@@ -375,8 +387,11 @@ var QueryBuilder = class {
|
|
|
375
387
|
this.valores = values;
|
|
376
388
|
return this;
|
|
377
389
|
}
|
|
390
|
+
Returning(idRetorno) {
|
|
391
|
+
this.returning = idRetorno;
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
378
394
|
async execute(see = false) {
|
|
379
|
-
this.valorRetorno = 1;
|
|
380
395
|
let query1 = `INSERT INTO ${this.tabla} `;
|
|
381
396
|
let param = "";
|
|
382
397
|
let arrayArrays = false;
|
|
@@ -438,15 +453,26 @@ var QueryBuilder = class {
|
|
|
438
453
|
valores: arrayArrays ? [this.valores] : this.valores,
|
|
439
454
|
mensaje: `Ocurrio un error al ingresar datos a ${this.tabla} `
|
|
440
455
|
});
|
|
441
|
-
|
|
456
|
+
let response = [];
|
|
457
|
+
if (this.returning !== void 0) {
|
|
458
|
+
for (let i = 0; i < this.valores.length; i++) {
|
|
459
|
+
response.push(respuesta.insertId + i);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return response;
|
|
442
463
|
} else if (this.conexion.tipo === "pg") {
|
|
443
|
-
|
|
464
|
+
if (this.returning !== void 0)
|
|
465
|
+
query += ` RETURNING ${this.returning} `;
|
|
444
466
|
const respuesta = await this.conexion.executeConsulta({
|
|
445
467
|
query,
|
|
446
468
|
valores: this.valores,
|
|
447
469
|
mensaje: `Ocurrio un error al ingresar datos a ${this.tabla} `
|
|
448
470
|
});
|
|
449
|
-
|
|
471
|
+
let response = [];
|
|
472
|
+
if (respuesta.rows !== void 0) {
|
|
473
|
+
response = respuesta.rows.map((obj) => Object.values(obj)[0]);
|
|
474
|
+
}
|
|
475
|
+
return response;
|
|
450
476
|
}
|
|
451
477
|
}
|
|
452
478
|
};
|
|
@@ -632,6 +658,14 @@ var eq = (valor1, valor2, literal = true) => {
|
|
|
632
658
|
}
|
|
633
659
|
return `${valor1} = '${valor2}'`;
|
|
634
660
|
};
|
|
661
|
+
var neq = (valor1, valor2, literal = true) => {
|
|
662
|
+
if (typeof valor1 === "string") valor1 = valor1.trim();
|
|
663
|
+
if (typeof valor2 === "string") valor2 = valor2.trim();
|
|
664
|
+
if (!literal) {
|
|
665
|
+
return `${valor1} != ${valor2}`;
|
|
666
|
+
}
|
|
667
|
+
return `${valor1} != '${valor2}'`;
|
|
668
|
+
};
|
|
635
669
|
var MAYOR = (valor, valor2) => {
|
|
636
670
|
return ` ${valor} > ${valor2} `;
|
|
637
671
|
};
|
|
@@ -692,7 +726,7 @@ var Update = class {
|
|
|
692
726
|
}
|
|
693
727
|
} else if (validate) {
|
|
694
728
|
valores.forEach((valors) => {
|
|
695
|
-
valor += eq(valors.campoUp, valors.newCampoUp, !valors.dataTable);
|
|
729
|
+
valor += eq(valors.campoUp.replace(`${this.nombreTabla}.`, ""), valors.newCampoUp.replace(`${this.nombreTabla}.`, ""), !valors.dataTable);
|
|
696
730
|
valor += ",";
|
|
697
731
|
});
|
|
698
732
|
}
|
|
@@ -723,7 +757,7 @@ var Update = class {
|
|
|
723
757
|
async execute(seeQuery = false) {
|
|
724
758
|
const query = `UPDATE ${this.nombreTabla} SET ${this.valores} ${this.condicion};`;
|
|
725
759
|
if (seeQuery) {
|
|
726
|
-
console.log(
|
|
760
|
+
console.log(query);
|
|
727
761
|
}
|
|
728
762
|
const respuesta = await this.conexion.executeConsulta({
|
|
729
763
|
query,
|
|
@@ -732,9 +766,7 @@ var Update = class {
|
|
|
732
766
|
if (this.conexion.tipo === "mysql") {
|
|
733
767
|
return respuesta.affectedRows;
|
|
734
768
|
} else {
|
|
735
|
-
return
|
|
736
|
-
resultado: respuesta.rowCount
|
|
737
|
-
};
|
|
769
|
+
return respuesta.rowCount;
|
|
738
770
|
}
|
|
739
771
|
}
|
|
740
772
|
};
|
|
@@ -784,6 +816,7 @@ var IntColumn = class {
|
|
|
784
816
|
this.unique = false;
|
|
785
817
|
this.autoIncrement = false;
|
|
786
818
|
this.unsingned = { uso: false, valor: 0 };
|
|
819
|
+
this.comentario = "";
|
|
787
820
|
}
|
|
788
821
|
Required() {
|
|
789
822
|
this.requerido = true;
|
|
@@ -794,6 +827,10 @@ var IntColumn = class {
|
|
|
794
827
|
this.pk = true;
|
|
795
828
|
return this;
|
|
796
829
|
}
|
|
830
|
+
Comment(comentario) {
|
|
831
|
+
this.comentario = comentario;
|
|
832
|
+
return this;
|
|
833
|
+
}
|
|
797
834
|
Unique() {
|
|
798
835
|
this.unique = true;
|
|
799
836
|
return this;
|
|
@@ -852,6 +889,9 @@ var IntColumn = class {
|
|
|
852
889
|
parts.push(`DEFAULT ${this.defaultData}`);
|
|
853
890
|
}
|
|
854
891
|
if (this.unique) parts.push("UNIQUE");
|
|
892
|
+
if (db === "mysql" && this.comentario.length > 2) {
|
|
893
|
+
parts.push(` COMMENT '${this.comentario}' `);
|
|
894
|
+
}
|
|
855
895
|
const valor = {
|
|
856
896
|
pk: false,
|
|
857
897
|
typo: "int",
|
|
@@ -871,6 +911,9 @@ var Varchar = class {
|
|
|
871
911
|
this.defaultData = "";
|
|
872
912
|
this.requerido = false;
|
|
873
913
|
this.unique = false;
|
|
914
|
+
this.enum = "";
|
|
915
|
+
this.campo = "";
|
|
916
|
+
this.comentarios = "";
|
|
874
917
|
this.maxLenth = cantidad;
|
|
875
918
|
}
|
|
876
919
|
withType({
|
|
@@ -884,10 +927,27 @@ var Varchar = class {
|
|
|
884
927
|
this.unique = unique;
|
|
885
928
|
return this.Default(defaultData).$();
|
|
886
929
|
}
|
|
930
|
+
/**
|
|
931
|
+
*
|
|
932
|
+
* @param {string} campo
|
|
933
|
+
* @param {string[]} datos
|
|
934
|
+
* @example
|
|
935
|
+
* Check("example", ["operativo","denegado","revisando"])
|
|
936
|
+
*
|
|
937
|
+
* @returns
|
|
938
|
+
*/
|
|
939
|
+
Check(datos) {
|
|
940
|
+
this.enum = datos.map((caracter) => `'${caracter}'`).join(",");
|
|
941
|
+
return this;
|
|
942
|
+
}
|
|
887
943
|
Required() {
|
|
888
944
|
this.requerido = true;
|
|
889
945
|
return this;
|
|
890
946
|
}
|
|
947
|
+
Comment(comentario) {
|
|
948
|
+
this.comentarios = comentario;
|
|
949
|
+
return this;
|
|
950
|
+
}
|
|
891
951
|
Unique() {
|
|
892
952
|
this.unique = true;
|
|
893
953
|
return this;
|
|
@@ -902,11 +962,16 @@ var Varchar = class {
|
|
|
902
962
|
return this;
|
|
903
963
|
}
|
|
904
964
|
$() {
|
|
905
|
-
let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "}
|
|
965
|
+
let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "}`;
|
|
966
|
+
const db = getTipoConexion();
|
|
967
|
+
if (db === "mysql" && this.comentarios.length > 2) {
|
|
968
|
+
sqlz += ` COMMENT '${this.comentarios}' `;
|
|
969
|
+
}
|
|
906
970
|
const response = {
|
|
907
971
|
typo: "varchar",
|
|
908
972
|
pk: false,
|
|
909
|
-
sqlz
|
|
973
|
+
sqlz,
|
|
974
|
+
check: this.enum.length > 2 ? this.enum : void 0
|
|
910
975
|
};
|
|
911
976
|
return response;
|
|
912
977
|
}
|
|
@@ -919,11 +984,16 @@ function varchar(cantidad = 100) {
|
|
|
919
984
|
var BoolColumn = class {
|
|
920
985
|
constructor() {
|
|
921
986
|
this.requerido = false;
|
|
987
|
+
this.comentario = "";
|
|
922
988
|
}
|
|
923
989
|
required() {
|
|
924
990
|
this.requerido = true;
|
|
925
991
|
return this;
|
|
926
992
|
}
|
|
993
|
+
Comment(comentario) {
|
|
994
|
+
this.comentario = comentario;
|
|
995
|
+
return this;
|
|
996
|
+
}
|
|
927
997
|
default(value) {
|
|
928
998
|
this.defaultData = value;
|
|
929
999
|
return this;
|
|
@@ -938,6 +1008,9 @@ var BoolColumn = class {
|
|
|
938
1008
|
`DEFAULT ${db === "mysql" ? this.defaultData ? 1 : 0 : this.defaultData}`
|
|
939
1009
|
);
|
|
940
1010
|
}
|
|
1011
|
+
if (db === "mysql" && this.comentario.length > 2) {
|
|
1012
|
+
parts.push(` COMMENT '${this.comentario}' `);
|
|
1013
|
+
}
|
|
941
1014
|
const response = {
|
|
942
1015
|
typo: "bool",
|
|
943
1016
|
pk: false,
|
|
@@ -956,11 +1029,16 @@ var Timestamp = class {
|
|
|
956
1029
|
this.requerido = false;
|
|
957
1030
|
this.defaultNow = false;
|
|
958
1031
|
this.onUpdateNow = false;
|
|
1032
|
+
this.comentario = "";
|
|
959
1033
|
}
|
|
960
1034
|
required() {
|
|
961
1035
|
this.requerido = true;
|
|
962
1036
|
return this;
|
|
963
1037
|
}
|
|
1038
|
+
comment(comentario) {
|
|
1039
|
+
this.comentario = comentario;
|
|
1040
|
+
return this;
|
|
1041
|
+
}
|
|
964
1042
|
now() {
|
|
965
1043
|
this.defaultNow = true;
|
|
966
1044
|
return this;
|
|
@@ -980,6 +1058,9 @@ var Timestamp = class {
|
|
|
980
1058
|
if (this.onUpdateNow && db === "mysql") {
|
|
981
1059
|
parts.push("ON UPDATE CURRENT_TIMESTAMP");
|
|
982
1060
|
}
|
|
1061
|
+
if (db === "mysql" && this.comentario.length > 2) {
|
|
1062
|
+
parts.push(` COMMENT '${this.comentario}' `);
|
|
1063
|
+
}
|
|
983
1064
|
const response = {
|
|
984
1065
|
typo: "timestamp",
|
|
985
1066
|
pk: false,
|
|
@@ -998,6 +1079,7 @@ var Money = class {
|
|
|
998
1079
|
this.precision = 10;
|
|
999
1080
|
this.scale = 2;
|
|
1000
1081
|
this.requerido = false;
|
|
1082
|
+
this.comentario = "";
|
|
1001
1083
|
this.precision = presicion;
|
|
1002
1084
|
this.scale = decimales;
|
|
1003
1085
|
}
|
|
@@ -1009,6 +1091,10 @@ var Money = class {
|
|
|
1009
1091
|
this.defaultData = value;
|
|
1010
1092
|
return this;
|
|
1011
1093
|
}
|
|
1094
|
+
comment(comentario) {
|
|
1095
|
+
this.comentario = comentario;
|
|
1096
|
+
return this;
|
|
1097
|
+
}
|
|
1012
1098
|
$() {
|
|
1013
1099
|
const parts = [];
|
|
1014
1100
|
const db = getTipoConexion();
|
|
@@ -1019,6 +1105,9 @@ var Money = class {
|
|
|
1019
1105
|
if (this.defaultData !== void 0) {
|
|
1020
1106
|
parts.push(`DEFAULT ${this.defaultData.toFixed(this.scale)}`);
|
|
1021
1107
|
}
|
|
1108
|
+
if (db === "mysql" && this.comentario.length > 2) {
|
|
1109
|
+
parts.push(` COMMENT '${this.comentario}' `);
|
|
1110
|
+
}
|
|
1022
1111
|
const response = {
|
|
1023
1112
|
typo: "money",
|
|
1024
1113
|
pk: false,
|
|
@@ -1058,6 +1147,7 @@ export {
|
|
|
1058
1147
|
getTipoConexion,
|
|
1059
1148
|
int,
|
|
1060
1149
|
money,
|
|
1150
|
+
neq,
|
|
1061
1151
|
timestamp,
|
|
1062
1152
|
varchar
|
|
1063
1153
|
};
|