zormz 1.3.0 → 1.3.1
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 +12 -2
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +92 -10
- package/dist/index.mjs +91 -10
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -93,7 +93,9 @@ export const prueba1 = defineTable("prueba1", {
|
|
|
93
93
|
* **.pk()** define la columna como clave primaria
|
|
94
94
|
* **.Default()** entrega un valor por defecto
|
|
95
95
|
* **.$()** finaliza la definicion y entrega un valor compatible con *$columns*
|
|
96
|
-
|
|
96
|
+
* **.required()** Indica que los valores de la fila no podran ser null, si o si un valor obligatorio
|
|
97
|
+
* **.now()** Solo esta disponible para timestamp , indica fecha automatica de registra
|
|
98
|
+
* **.onUpdate()** Tomara la fecha actual cada ves que se haga un update
|
|
97
99
|
## Generacion de tablas
|
|
98
100
|
```ts
|
|
99
101
|
generateTable(prueba1(), prueba1.$columns);
|
|
@@ -102,6 +104,11 @@ Esto crea la tabla en la base de datos respetando tipos, claves primarias y valo
|
|
|
102
104
|
|
|
103
105
|
---
|
|
104
106
|
|
|
107
|
+
## Eliminar tablas
|
|
108
|
+
```ts
|
|
109
|
+
await dropTable(prueba4());
|
|
110
|
+
```
|
|
111
|
+
|
|
105
112
|
## Insertar Datos
|
|
106
113
|
|
|
107
114
|
```ts
|
|
@@ -156,6 +163,8 @@ const conexion: connecionLocal = {
|
|
|
156
163
|
};
|
|
157
164
|
|
|
158
165
|
getConexion("pg", conexion);
|
|
166
|
+
//MYSQL
|
|
167
|
+
//getConexion("mysql", conexion);
|
|
159
168
|
|
|
160
169
|
const prueba1 = defineTable("prueba1", {
|
|
161
170
|
id: int().Pk().$(),
|
|
@@ -193,7 +202,8 @@ pruebaData().catch(console.error);
|
|
|
193
202
|
* ORM en version inicial con enfoque de tipado y autompletado
|
|
194
203
|
* Compatible con **MYSQL** y **PG**
|
|
195
204
|
* Preparado para extenderse
|
|
196
|
-
|
|
205
|
+
* Las versiones +1.3.0 son mas estables , las anteriores estaban en desarrollo y presentan multiples errores
|
|
206
|
+
* verion mas estable 1.3.1
|
|
197
207
|
## Licencia
|
|
198
208
|
|
|
199
209
|
ISC © Yukio-kayaba
|
package/dist/index.d.mts
CHANGED
|
@@ -41,6 +41,7 @@ interface Consultas {
|
|
|
41
41
|
query: string;
|
|
42
42
|
valores?: any[] | [[]];
|
|
43
43
|
mensaje?: string;
|
|
44
|
+
alertar?: boolean;
|
|
44
45
|
}
|
|
45
46
|
interface connecionRed {
|
|
46
47
|
connectionString: string;
|
|
@@ -53,7 +54,7 @@ declare class BDconnection {
|
|
|
53
54
|
constructor(bd: connectionDB, datos: connecionLocal | connecionRed);
|
|
54
55
|
private conexionMysql;
|
|
55
56
|
private connectionPG;
|
|
56
|
-
executeConsulta({ query, valores, mensaje, }: Consultas): Promise<any>;
|
|
57
|
+
executeConsulta({ query, valores, mensaje, alertar, }: Consultas): Promise<any>;
|
|
57
58
|
}
|
|
58
59
|
declare function getTipoConexion(): connectionDB;
|
|
59
60
|
/**
|
|
@@ -94,6 +95,7 @@ type TableProxy<TCols> = {
|
|
|
94
95
|
*/
|
|
95
96
|
declare function defineTable<T extends Record<string, ColumnDefinition>>(tableName: string, columns: T): TableProxy<T>;
|
|
96
97
|
declare function generateTable<T extends Record<string, ColumnDefinition>>(tabla: string, columns: T): Promise<void>;
|
|
98
|
+
declare function dropTable(nombreTabla: string): Promise<void>;
|
|
97
99
|
|
|
98
100
|
declare class DeleteR {
|
|
99
101
|
#private;
|
|
@@ -428,4 +430,4 @@ declare class Money {
|
|
|
428
430
|
}
|
|
429
431
|
declare function money(presicion?: number, decimales?: number): Money;
|
|
430
432
|
|
|
431
|
-
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 };
|
|
433
|
+
export { AND, BDconnection, CURRENT_TIMESTAMP, type Consultas, DB, DeleteR, ILIKE, MAYOR, MENOR, NOTNULL, NOW, NULL, OR, ORQ, QueryBuilder, Select, type TableProxy, type Tipos, Update, type Valores, type arrayData, type arrayDatas, bool, type connecionLocal, type connecionRed, type connectionDB, defineTable, dropTable, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ interface Consultas {
|
|
|
41
41
|
query: string;
|
|
42
42
|
valores?: any[] | [[]];
|
|
43
43
|
mensaje?: string;
|
|
44
|
+
alertar?: boolean;
|
|
44
45
|
}
|
|
45
46
|
interface connecionRed {
|
|
46
47
|
connectionString: string;
|
|
@@ -53,7 +54,7 @@ declare class BDconnection {
|
|
|
53
54
|
constructor(bd: connectionDB, datos: connecionLocal | connecionRed);
|
|
54
55
|
private conexionMysql;
|
|
55
56
|
private connectionPG;
|
|
56
|
-
executeConsulta({ query, valores, mensaje, }: Consultas): Promise<any>;
|
|
57
|
+
executeConsulta({ query, valores, mensaje, alertar, }: Consultas): Promise<any>;
|
|
57
58
|
}
|
|
58
59
|
declare function getTipoConexion(): connectionDB;
|
|
59
60
|
/**
|
|
@@ -94,6 +95,7 @@ type TableProxy<TCols> = {
|
|
|
94
95
|
*/
|
|
95
96
|
declare function defineTable<T extends Record<string, ColumnDefinition>>(tableName: string, columns: T): TableProxy<T>;
|
|
96
97
|
declare function generateTable<T extends Record<string, ColumnDefinition>>(tabla: string, columns: T): Promise<void>;
|
|
98
|
+
declare function dropTable(nombreTabla: string): Promise<void>;
|
|
97
99
|
|
|
98
100
|
declare class DeleteR {
|
|
99
101
|
#private;
|
|
@@ -428,4 +430,4 @@ declare class Money {
|
|
|
428
430
|
}
|
|
429
431
|
declare function money(presicion?: number, decimales?: number): Money;
|
|
430
432
|
|
|
431
|
-
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 };
|
|
433
|
+
export { AND, BDconnection, CURRENT_TIMESTAMP, type Consultas, DB, DeleteR, ILIKE, MAYOR, MENOR, NOTNULL, NOW, NULL, OR, ORQ, QueryBuilder, Select, type TableProxy, type Tipos, Update, type Valores, type arrayData, type arrayDatas, bool, type connecionLocal, type connecionRed, type connectionDB, defineTable, dropTable, eq, generateTable, getConexion, getRed, getTipoConexion, int, money, timestamp, type valor, varchar };
|
package/dist/index.js
CHANGED
|
@@ -55,6 +55,7 @@ __export(index_exports, {
|
|
|
55
55
|
Update: () => Update,
|
|
56
56
|
bool: () => bool,
|
|
57
57
|
defineTable: () => defineTable,
|
|
58
|
+
dropTable: () => dropTable,
|
|
58
59
|
eq: () => eq,
|
|
59
60
|
generateTable: () => generateTable,
|
|
60
61
|
getConexion: () => getConexion,
|
|
@@ -67,6 +68,22 @@ __export(index_exports, {
|
|
|
67
68
|
});
|
|
68
69
|
module.exports = __toCommonJS(index_exports);
|
|
69
70
|
|
|
71
|
+
// conection/validator.ts
|
|
72
|
+
var Validator = class {
|
|
73
|
+
};
|
|
74
|
+
Validator.isValidTable = (val) => /^(?![0-9_])[a-z][a-z0-9_]{0,62}$/.test(val);
|
|
75
|
+
Validator.isValidColumn = (val) => /^[a-z][a-z0-9_]{0,62}$/.test(val);
|
|
76
|
+
Validator.isValidUsername = (val) => /^[a-zA-Z0-9\-_]+$/.test(val);
|
|
77
|
+
var RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
78
|
+
"select",
|
|
79
|
+
"table",
|
|
80
|
+
"user",
|
|
81
|
+
"order",
|
|
82
|
+
"group",
|
|
83
|
+
"where",
|
|
84
|
+
"join"
|
|
85
|
+
]);
|
|
86
|
+
|
|
70
87
|
// conection/db.ts
|
|
71
88
|
var BDconnection = class {
|
|
72
89
|
constructor(bd, datos) {
|
|
@@ -88,7 +105,9 @@ var BDconnection = class {
|
|
|
88
105
|
});
|
|
89
106
|
return pool;
|
|
90
107
|
} catch (error) {
|
|
91
|
-
throw new Error(
|
|
108
|
+
throw new Error(
|
|
109
|
+
"Mysql no esta instalado . para instalarlo corre : npm install mysql2 "
|
|
110
|
+
);
|
|
92
111
|
}
|
|
93
112
|
}
|
|
94
113
|
async connectionPG() {
|
|
@@ -114,13 +133,16 @@ var BDconnection = class {
|
|
|
114
133
|
console.error(
|
|
115
134
|
"PostgreSQL no esta instalado. para instalarlo corre : npm install pg"
|
|
116
135
|
);
|
|
117
|
-
throw new Error(
|
|
136
|
+
throw new Error(
|
|
137
|
+
"PostgreSQL no esta instalado. para instalarlo corre : npm install pg"
|
|
138
|
+
);
|
|
118
139
|
}
|
|
119
140
|
}
|
|
120
141
|
async executeConsulta({
|
|
121
142
|
query,
|
|
122
143
|
valores = void 0,
|
|
123
|
-
mensaje
|
|
144
|
+
mensaje,
|
|
145
|
+
alertar = true
|
|
124
146
|
}) {
|
|
125
147
|
try {
|
|
126
148
|
if (this.tipo === "mysql") {
|
|
@@ -153,6 +175,7 @@ var BDconnection = class {
|
|
|
153
175
|
}
|
|
154
176
|
} catch (error) {
|
|
155
177
|
console.log(error);
|
|
178
|
+
if (!alertar) return;
|
|
156
179
|
if (typeof error === "object" && error !== null && "code" in error) {
|
|
157
180
|
if (error.code === "ETIMEDOUT") {
|
|
158
181
|
throw new Error(`Su red esta limitando el acceso`);
|
|
@@ -166,14 +189,16 @@ var conexionZORMZ3691;
|
|
|
166
189
|
var tipoConexionZORMZ3691;
|
|
167
190
|
function getTipoConexion() {
|
|
168
191
|
if (!tipoConexionZORMZ3691) {
|
|
169
|
-
throw new Error(
|
|
192
|
+
throw new Error(
|
|
193
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
194
|
+
);
|
|
170
195
|
}
|
|
171
196
|
return tipoConexionZORMZ3691;
|
|
172
197
|
}
|
|
173
198
|
async function getConexion(bd, datos) {
|
|
174
199
|
conexionZORMZ3691 = new BDconnection(bd, datos);
|
|
175
200
|
tipoConexionZORMZ3691 = conexionZORMZ3691.tipo;
|
|
176
|
-
await conexionZORMZ3691.executeConsulta({
|
|
201
|
+
await conexionZORMZ3691.executeConsulta({ query: "select 1+1;" }).then((data) => {
|
|
177
202
|
console.log(`\u{1F44D}\u{1F44D} Conexi\xF3n ${tipoConexionZORMZ3691} exitosa \u{1F61C}`);
|
|
178
203
|
}).catch((err) => {
|
|
179
204
|
console.error(" \u{1F622}\u{1F622} Error al conectar a " + tipoConexionZORMZ3691);
|
|
@@ -182,12 +207,34 @@ async function getConexion(bd, datos) {
|
|
|
182
207
|
}
|
|
183
208
|
function getRed() {
|
|
184
209
|
if (!conexionZORMZ3691) {
|
|
185
|
-
throw new Error(
|
|
210
|
+
throw new Error(
|
|
211
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
212
|
+
);
|
|
186
213
|
}
|
|
187
214
|
return conexionZORMZ3691;
|
|
188
215
|
}
|
|
189
216
|
function defineTable(tableName, columns) {
|
|
190
217
|
const fn = () => tableName;
|
|
218
|
+
if (!Validator.isValidTable(tableName)) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
"El nombre de la tabla no puede contener mayusculas o caracteres especiales"
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (RESERVED_WORDS.has(tableName)) {
|
|
224
|
+
throw new Error(`el nombre ${tableName} es una palabra reservada SQL`);
|
|
225
|
+
}
|
|
226
|
+
for (const campo in columns) {
|
|
227
|
+
if (!Validator.isValidColumn(campo)) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`El campo ${campo} no puede contener caracteres especiales`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
if (RESERVED_WORDS.has(campo)) {
|
|
233
|
+
throw new Error(
|
|
234
|
+
`El campo ${campo} contiene palabras reservadas de sql \u274C\u274C\u274C `
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
191
238
|
const proxy = new Proxy(fn, {
|
|
192
239
|
get(_target, prop) {
|
|
193
240
|
if (prop === "$columns") {
|
|
@@ -246,10 +293,15 @@ async function generateTable(tabla, columns) {
|
|
|
246
293
|
queries += columnDefs.join(", \n");
|
|
247
294
|
queries += ");";
|
|
248
295
|
if (!conexionZORMZ3691 || !tipoConexionZORMZ3691) {
|
|
249
|
-
throw new Error(
|
|
296
|
+
throw new Error(
|
|
297
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
298
|
+
);
|
|
250
299
|
}
|
|
251
300
|
if (tipoConexionZORMZ3691 === "mysql") {
|
|
252
|
-
const response = await conexionZORMZ3691.executeConsulta({
|
|
301
|
+
const response = await conexionZORMZ3691.executeConsulta({
|
|
302
|
+
query: queries,
|
|
303
|
+
mensaje: "Error al crear la tabla"
|
|
304
|
+
});
|
|
253
305
|
if (response.warningStatus > 0) {
|
|
254
306
|
console.log(` La tabla ${tabla} ya existe \u{1F642}\u{1F610} `);
|
|
255
307
|
} else {
|
|
@@ -264,6 +316,33 @@ async function generateTable(tabla, columns) {
|
|
|
264
316
|
console.log(`\u{1F44D}\u{1F44D} Se creo con exito la tabla ${tabla} \u{1F61C}`);
|
|
265
317
|
}
|
|
266
318
|
}
|
|
319
|
+
async function dropTable(nombreTabla) {
|
|
320
|
+
let sql = `DROP TABLE IF EXISTS ${nombreTabla};`;
|
|
321
|
+
if (!conexionZORMZ3691 || !tipoConexionZORMZ3691) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
if (tipoConexionZORMZ3691 === "mysql") {
|
|
327
|
+
const response = await conexionZORMZ3691.executeConsulta({
|
|
328
|
+
query: sql,
|
|
329
|
+
mensaje: "Error al eliminar la tabla",
|
|
330
|
+
alertar: false
|
|
331
|
+
});
|
|
332
|
+
if (response.warningStatus === 0) {
|
|
333
|
+
console.log(`\u{1F44D}\u{1F44D} Se creo con exito la tabla ${nombreTabla} \u{1F44D}`);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
|
|
337
|
+
} else if (tipoConexionZORMZ3691 === "pg") {
|
|
338
|
+
const response = await conexionZORMZ3691.executeConsulta({
|
|
339
|
+
query: sql,
|
|
340
|
+
mensaje: "Error al eliminar la tabla",
|
|
341
|
+
alertar: false
|
|
342
|
+
});
|
|
343
|
+
console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
267
346
|
|
|
268
347
|
// conection/middleware/delete.ts
|
|
269
348
|
var _condicion, _tabla;
|
|
@@ -300,13 +379,15 @@ var DeleteR = class {
|
|
|
300
379
|
if (this.conexion.tipo === "mysql") {
|
|
301
380
|
const respuesta = await this.conexion.executeConsulta({
|
|
302
381
|
query,
|
|
303
|
-
mensaje: "Ocurrio un error al momento de eliminar
|
|
382
|
+
mensaje: "Ocurrio un error al momento de eliminar",
|
|
383
|
+
alertar: false
|
|
304
384
|
});
|
|
305
385
|
return respuesta.affectedRows;
|
|
306
386
|
} else {
|
|
307
387
|
const respuesta = await this.conexion.executeConsulta({
|
|
308
388
|
query,
|
|
309
|
-
mensaje: "Ocurrio un error al momento de eliminar
|
|
389
|
+
mensaje: "Ocurrio un error al momento de eliminar",
|
|
390
|
+
alertar: false
|
|
310
391
|
});
|
|
311
392
|
return respuesta.rowCount;
|
|
312
393
|
}
|
|
@@ -1004,6 +1085,7 @@ function money(presicion = 10, decimales = 2) {
|
|
|
1004
1085
|
Update,
|
|
1005
1086
|
bool,
|
|
1006
1087
|
defineTable,
|
|
1088
|
+
dropTable,
|
|
1007
1089
|
eq,
|
|
1008
1090
|
generateTable,
|
|
1009
1091
|
getConexion,
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,22 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
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);
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
|
|
9
|
+
// conection/validator.ts
|
|
10
|
+
var Validator = class {
|
|
11
|
+
};
|
|
12
|
+
Validator.isValidTable = (val) => /^(?![0-9_])[a-z][a-z0-9_]{0,62}$/.test(val);
|
|
13
|
+
Validator.isValidColumn = (val) => /^[a-z][a-z0-9_]{0,62}$/.test(val);
|
|
14
|
+
Validator.isValidUsername = (val) => /^[a-zA-Z0-9\-_]+$/.test(val);
|
|
15
|
+
var RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
16
|
+
"select",
|
|
17
|
+
"table",
|
|
18
|
+
"user",
|
|
19
|
+
"order",
|
|
20
|
+
"group",
|
|
21
|
+
"where",
|
|
22
|
+
"join"
|
|
23
|
+
]);
|
|
24
|
+
|
|
9
25
|
// conection/db.ts
|
|
10
26
|
var BDconnection = class {
|
|
11
27
|
constructor(bd, datos) {
|
|
@@ -27,7 +43,9 @@ var BDconnection = class {
|
|
|
27
43
|
});
|
|
28
44
|
return pool;
|
|
29
45
|
} catch (error) {
|
|
30
|
-
throw new Error(
|
|
46
|
+
throw new Error(
|
|
47
|
+
"Mysql no esta instalado . para instalarlo corre : npm install mysql2 "
|
|
48
|
+
);
|
|
31
49
|
}
|
|
32
50
|
}
|
|
33
51
|
async connectionPG() {
|
|
@@ -53,13 +71,16 @@ var BDconnection = class {
|
|
|
53
71
|
console.error(
|
|
54
72
|
"PostgreSQL no esta instalado. para instalarlo corre : npm install pg"
|
|
55
73
|
);
|
|
56
|
-
throw new Error(
|
|
74
|
+
throw new Error(
|
|
75
|
+
"PostgreSQL no esta instalado. para instalarlo corre : npm install pg"
|
|
76
|
+
);
|
|
57
77
|
}
|
|
58
78
|
}
|
|
59
79
|
async executeConsulta({
|
|
60
80
|
query,
|
|
61
81
|
valores = void 0,
|
|
62
|
-
mensaje
|
|
82
|
+
mensaje,
|
|
83
|
+
alertar = true
|
|
63
84
|
}) {
|
|
64
85
|
try {
|
|
65
86
|
if (this.tipo === "mysql") {
|
|
@@ -92,6 +113,7 @@ var BDconnection = class {
|
|
|
92
113
|
}
|
|
93
114
|
} catch (error) {
|
|
94
115
|
console.log(error);
|
|
116
|
+
if (!alertar) return;
|
|
95
117
|
if (typeof error === "object" && error !== null && "code" in error) {
|
|
96
118
|
if (error.code === "ETIMEDOUT") {
|
|
97
119
|
throw new Error(`Su red esta limitando el acceso`);
|
|
@@ -105,14 +127,16 @@ var conexionZORMZ3691;
|
|
|
105
127
|
var tipoConexionZORMZ3691;
|
|
106
128
|
function getTipoConexion() {
|
|
107
129
|
if (!tipoConexionZORMZ3691) {
|
|
108
|
-
throw new Error(
|
|
130
|
+
throw new Error(
|
|
131
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
132
|
+
);
|
|
109
133
|
}
|
|
110
134
|
return tipoConexionZORMZ3691;
|
|
111
135
|
}
|
|
112
136
|
async function getConexion(bd, datos) {
|
|
113
137
|
conexionZORMZ3691 = new BDconnection(bd, datos);
|
|
114
138
|
tipoConexionZORMZ3691 = conexionZORMZ3691.tipo;
|
|
115
|
-
await conexionZORMZ3691.executeConsulta({
|
|
139
|
+
await conexionZORMZ3691.executeConsulta({ query: "select 1+1;" }).then((data) => {
|
|
116
140
|
console.log(`\u{1F44D}\u{1F44D} Conexi\xF3n ${tipoConexionZORMZ3691} exitosa \u{1F61C}`);
|
|
117
141
|
}).catch((err) => {
|
|
118
142
|
console.error(" \u{1F622}\u{1F622} Error al conectar a " + tipoConexionZORMZ3691);
|
|
@@ -121,12 +145,34 @@ async function getConexion(bd, datos) {
|
|
|
121
145
|
}
|
|
122
146
|
function getRed() {
|
|
123
147
|
if (!conexionZORMZ3691) {
|
|
124
|
-
throw new Error(
|
|
148
|
+
throw new Error(
|
|
149
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
150
|
+
);
|
|
125
151
|
}
|
|
126
152
|
return conexionZORMZ3691;
|
|
127
153
|
}
|
|
128
154
|
function defineTable(tableName, columns) {
|
|
129
155
|
const fn = () => tableName;
|
|
156
|
+
if (!Validator.isValidTable(tableName)) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
"El nombre de la tabla no puede contener mayusculas o caracteres especiales"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
if (RESERVED_WORDS.has(tableName)) {
|
|
162
|
+
throw new Error(`el nombre ${tableName} es una palabra reservada SQL`);
|
|
163
|
+
}
|
|
164
|
+
for (const campo in columns) {
|
|
165
|
+
if (!Validator.isValidColumn(campo)) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`El campo ${campo} no puede contener caracteres especiales`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (RESERVED_WORDS.has(campo)) {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`El campo ${campo} contiene palabras reservadas de sql \u274C\u274C\u274C `
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
130
176
|
const proxy = new Proxy(fn, {
|
|
131
177
|
get(_target, prop) {
|
|
132
178
|
if (prop === "$columns") {
|
|
@@ -185,10 +231,15 @@ async function generateTable(tabla, columns) {
|
|
|
185
231
|
queries += columnDefs.join(", \n");
|
|
186
232
|
queries += ");";
|
|
187
233
|
if (!conexionZORMZ3691 || !tipoConexionZORMZ3691) {
|
|
188
|
-
throw new Error(
|
|
234
|
+
throw new Error(
|
|
235
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
236
|
+
);
|
|
189
237
|
}
|
|
190
238
|
if (tipoConexionZORMZ3691 === "mysql") {
|
|
191
|
-
const response = await conexionZORMZ3691.executeConsulta({
|
|
239
|
+
const response = await conexionZORMZ3691.executeConsulta({
|
|
240
|
+
query: queries,
|
|
241
|
+
mensaje: "Error al crear la tabla"
|
|
242
|
+
});
|
|
192
243
|
if (response.warningStatus > 0) {
|
|
193
244
|
console.log(` La tabla ${tabla} ya existe \u{1F642}\u{1F610} `);
|
|
194
245
|
} else {
|
|
@@ -203,6 +254,33 @@ async function generateTable(tabla, columns) {
|
|
|
203
254
|
console.log(`\u{1F44D}\u{1F44D} Se creo con exito la tabla ${tabla} \u{1F61C}`);
|
|
204
255
|
}
|
|
205
256
|
}
|
|
257
|
+
async function dropTable(nombreTabla) {
|
|
258
|
+
let sql = `DROP TABLE IF EXISTS ${nombreTabla};`;
|
|
259
|
+
if (!conexionZORMZ3691 || !tipoConexionZORMZ3691) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
"La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero."
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (tipoConexionZORMZ3691 === "mysql") {
|
|
265
|
+
const response = await conexionZORMZ3691.executeConsulta({
|
|
266
|
+
query: sql,
|
|
267
|
+
mensaje: "Error al eliminar la tabla",
|
|
268
|
+
alertar: false
|
|
269
|
+
});
|
|
270
|
+
if (response.warningStatus === 0) {
|
|
271
|
+
console.log(`\u{1F44D}\u{1F44D} Se creo con exito la tabla ${nombreTabla} \u{1F44D}`);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
|
|
275
|
+
} else if (tipoConexionZORMZ3691 === "pg") {
|
|
276
|
+
const response = await conexionZORMZ3691.executeConsulta({
|
|
277
|
+
query: sql,
|
|
278
|
+
mensaje: "Error al eliminar la tabla",
|
|
279
|
+
alertar: false
|
|
280
|
+
});
|
|
281
|
+
console.log(` No existe la tabla ${nombreTabla} \u{1F622}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
206
284
|
|
|
207
285
|
// conection/middleware/delete.ts
|
|
208
286
|
var _condicion, _tabla;
|
|
@@ -239,13 +317,15 @@ var DeleteR = class {
|
|
|
239
317
|
if (this.conexion.tipo === "mysql") {
|
|
240
318
|
const respuesta = await this.conexion.executeConsulta({
|
|
241
319
|
query,
|
|
242
|
-
mensaje: "Ocurrio un error al momento de eliminar
|
|
320
|
+
mensaje: "Ocurrio un error al momento de eliminar",
|
|
321
|
+
alertar: false
|
|
243
322
|
});
|
|
244
323
|
return respuesta.affectedRows;
|
|
245
324
|
} else {
|
|
246
325
|
const respuesta = await this.conexion.executeConsulta({
|
|
247
326
|
query,
|
|
248
|
-
mensaje: "Ocurrio un error al momento de eliminar
|
|
327
|
+
mensaje: "Ocurrio un error al momento de eliminar",
|
|
328
|
+
alertar: false
|
|
249
329
|
});
|
|
250
330
|
return respuesta.rowCount;
|
|
251
331
|
}
|
|
@@ -942,6 +1022,7 @@ export {
|
|
|
942
1022
|
Update,
|
|
943
1023
|
bool,
|
|
944
1024
|
defineTable,
|
|
1025
|
+
dropTable,
|
|
945
1026
|
eq,
|
|
946
1027
|
generateTable,
|
|
947
1028
|
getConexion,
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zormz",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Un ORM que busca ser ligero y facil de usar",
|
|
5
5
|
"author": "yukio-kayaba",
|
|
6
6
|
"license": "ISC",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"orm",
|
|
9
|
+
"database",
|
|
10
|
+
"postgresql",
|
|
11
|
+
"mysql",
|
|
12
|
+
"sql",
|
|
13
|
+
"typescript",
|
|
14
|
+
"zomrz",
|
|
15
|
+
"pg"
|
|
16
|
+
],
|
|
7
17
|
"main": "./dist/index.cjs",
|
|
8
18
|
"module": "./dist/index.js",
|
|
9
19
|
"types": "./dist/index.d.ts",
|