zormz 1.2.7 → 1.3.0

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
@@ -1,13 +1,3 @@
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
1
  type ColumnTypes =
12
2
  | "varchar"
13
3
  | "int"
@@ -56,16 +46,16 @@ interface connecionRed {
56
46
  connectionString: string;
57
47
  }
58
48
  type connectionDB = "mysql" | "pg";
59
- declare function getTipoConexion(): connectionDB;
60
49
  declare class BDconnection {
61
50
  tipo: connectionDB;
62
51
  pool: any;
63
52
  private connection;
64
53
  constructor(bd: connectionDB, datos: connecionLocal | connecionRed);
65
- private connecionMyql;
54
+ private conexionMysql;
66
55
  private connectionPG;
67
56
  executeConsulta({ query, valores, mensaje, }: Consultas): Promise<any>;
68
57
  }
58
+ declare function getTipoConexion(): connectionDB;
69
59
  /**
70
60
  *
71
61
  * @param bd
@@ -126,8 +116,8 @@ declare class DeleteR {
126
116
  execute(): Promise<number | null>;
127
117
  }
128
118
 
129
- type arrayData = (string | number)[];
130
- type arrayDatas = (string | number)[][];
119
+ type arrayData = (string | number | boolean)[];
120
+ type arrayDatas = (string | number | boolean)[][];
131
121
  declare class QueryBuilder {
132
122
  private tabla;
133
123
  private parametros;
@@ -215,7 +205,7 @@ declare class Select {
215
205
  /**
216
206
  * @returns {Promise<Array<Object>>}
217
207
  */
218
- execute(): Promise<any[] | ResultSetHeaderMysql | undefined>;
208
+ execute(): Promise<any[] | undefined>;
219
209
  }
220
210
 
221
211
  type Valores = Record<string, string | number | undefined>;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,3 @@
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
1
  type ColumnTypes =
12
2
  | "varchar"
13
3
  | "int"
@@ -56,16 +46,16 @@ interface connecionRed {
56
46
  connectionString: string;
57
47
  }
58
48
  type connectionDB = "mysql" | "pg";
59
- declare function getTipoConexion(): connectionDB;
60
49
  declare class BDconnection {
61
50
  tipo: connectionDB;
62
51
  pool: any;
63
52
  private connection;
64
53
  constructor(bd: connectionDB, datos: connecionLocal | connecionRed);
65
- private connecionMyql;
54
+ private conexionMysql;
66
55
  private connectionPG;
67
56
  executeConsulta({ query, valores, mensaje, }: Consultas): Promise<any>;
68
57
  }
58
+ declare function getTipoConexion(): connectionDB;
69
59
  /**
70
60
  *
71
61
  * @param bd
@@ -126,8 +116,8 @@ declare class DeleteR {
126
116
  execute(): Promise<number | null>;
127
117
  }
128
118
 
129
- type arrayData = (string | number)[];
130
- type arrayDatas = (string | number)[][];
119
+ type arrayData = (string | number | boolean)[];
120
+ type arrayDatas = (string | number | boolean)[][];
131
121
  declare class QueryBuilder {
132
122
  private tabla;
133
123
  private parametros;
@@ -215,7 +205,7 @@ declare class Select {
215
205
  /**
216
206
  * @returns {Promise<Array<Object>>}
217
207
  */
218
- execute(): Promise<any[] | ResultSetHeaderMysql | undefined>;
208
+ execute(): Promise<any[] | undefined>;
219
209
  }
220
210
 
221
211
  type Valores = Record<string, string | number | undefined>;
package/dist/index.js CHANGED
@@ -68,18 +68,13 @@ __export(index_exports, {
68
68
  module.exports = __toCommonJS(index_exports);
69
69
 
70
70
  // conection/db.ts
71
- var conexionZORMZ3691;
72
- var tipoConexionZORMZ3691;
73
- function getTipoConexion() {
74
- return tipoConexionZORMZ3691;
75
- }
76
71
  var BDconnection = class {
77
72
  constructor(bd, datos) {
78
73
  this.tipo = "pg";
79
74
  this.tipo = bd;
80
75
  this.connection = datos;
81
76
  }
82
- async connecionMyql() {
77
+ async conexionMysql() {
83
78
  try {
84
79
  const mysql = await import("mysql2/promise");
85
80
  if ("connectionString" in this.connection)
@@ -119,6 +114,7 @@ var BDconnection = class {
119
114
  console.error(
120
115
  "PostgreSQL no esta instalado. para instalarlo corre : npm install pg"
121
116
  );
117
+ throw new Error("PostgreSQL no esta instalado. para instalarlo corre : npm install pg");
122
118
  }
123
119
  }
124
120
  async executeConsulta({
@@ -128,8 +124,8 @@ var BDconnection = class {
128
124
  }) {
129
125
  try {
130
126
  if (this.tipo === "mysql") {
131
- const pool = await this.connecionMyql();
132
- const [rows] = await pool.query(query, [valores]);
127
+ const pool = await this.conexionMysql();
128
+ const [rows] = await pool.query(query, valores);
133
129
  return rows;
134
130
  } else if (this.tipo === "pg") {
135
131
  let query2 = query;
@@ -146,6 +142,9 @@ var BDconnection = class {
146
142
  }
147
143
  }
148
144
  const pool2 = await this.connectionPG();
145
+ if (!pool2) {
146
+ throw new Error("No se pudo establecer la conexi\xF3n con PostgreSQL");
147
+ }
149
148
  const respuesta = await pool2.query(query2, valores);
150
149
  if (!respuesta) {
151
150
  throw new Error(` Este usuario no esta registrado `);
@@ -163,6 +162,14 @@ var BDconnection = class {
163
162
  }
164
163
  }
165
164
  };
165
+ var conexionZORMZ3691;
166
+ var tipoConexionZORMZ3691;
167
+ function getTipoConexion() {
168
+ if (!tipoConexionZORMZ3691) {
169
+ throw new Error("La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero.");
170
+ }
171
+ return tipoConexionZORMZ3691;
172
+ }
166
173
  async function getConexion(bd, datos) {
167
174
  conexionZORMZ3691 = new BDconnection(bd, datos);
168
175
  tipoConexionZORMZ3691 = conexionZORMZ3691.tipo;
@@ -170,9 +177,13 @@ async function getConexion(bd, datos) {
170
177
  console.log(`\u{1F44D}\u{1F44D} Conexi\xF3n ${tipoConexionZORMZ3691} exitosa \u{1F61C}`);
171
178
  }).catch((err) => {
172
179
  console.error(" \u{1F622}\u{1F622} Error al conectar a " + tipoConexionZORMZ3691);
180
+ console.log(err);
173
181
  });
174
182
  }
175
183
  function getRed() {
184
+ if (!conexionZORMZ3691) {
185
+ throw new Error("La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero.");
186
+ }
176
187
  return conexionZORMZ3691;
177
188
  }
178
189
  function defineTable(tableName, columns) {
@@ -234,6 +245,9 @@ async function generateTable(tabla, columns) {
234
245
  `;
235
246
  queries += columnDefs.join(", \n");
236
247
  queries += ");";
248
+ if (!conexionZORMZ3691 || !tipoConexionZORMZ3691) {
249
+ throw new Error("La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero.");
250
+ }
237
251
  if (tipoConexionZORMZ3691 === "mysql") {
238
252
  const response = await conexionZORMZ3691.executeConsulta({ query: queries, mensaje: "Error al crear la base de datos" });
239
253
  if (response.warningStatus > 0) {
@@ -350,7 +364,9 @@ var QueryBuilder = class {
350
364
  let paramespaces = "";
351
365
  if (this.conexion.tipo === "mysql") {
352
366
  if (typeof this.parametros !== "string") {
353
- if (Array.isArray(this.valores[0])) arrayArrays = true;
367
+ if (Array.isArray(this.valores[0])) {
368
+ arrayArrays = true;
369
+ }
354
370
  this.parametros.forEach((valor, index) => {
355
371
  param += valor;
356
372
  paramespaces += `?`;
@@ -397,10 +413,9 @@ var QueryBuilder = class {
397
413
  if (this.conexion.tipo === "mysql") {
398
414
  const respuesta = await this.conexion.executeConsulta({
399
415
  query,
400
- valores: this.valores,
416
+ valores: arrayArrays ? [this.valores] : this.valores,
401
417
  mensaje: `Ocurrio un error al ingresar datos a ${this.tabla} `
402
418
  });
403
- console.log(respuesta);
404
419
  return respuesta.insertId;
405
420
  } else if (this.conexion.tipo === "pg") {
406
421
  query += " RETURNING id ";
package/dist/index.mjs CHANGED
@@ -7,18 +7,13 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
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
9
  // conection/db.ts
10
- var conexionZORMZ3691;
11
- var tipoConexionZORMZ3691;
12
- function getTipoConexion() {
13
- return tipoConexionZORMZ3691;
14
- }
15
10
  var BDconnection = class {
16
11
  constructor(bd, datos) {
17
12
  this.tipo = "pg";
18
13
  this.tipo = bd;
19
14
  this.connection = datos;
20
15
  }
21
- async connecionMyql() {
16
+ async conexionMysql() {
22
17
  try {
23
18
  const mysql = await import("mysql2/promise");
24
19
  if ("connectionString" in this.connection)
@@ -58,6 +53,7 @@ var BDconnection = class {
58
53
  console.error(
59
54
  "PostgreSQL no esta instalado. para instalarlo corre : npm install pg"
60
55
  );
56
+ throw new Error("PostgreSQL no esta instalado. para instalarlo corre : npm install pg");
61
57
  }
62
58
  }
63
59
  async executeConsulta({
@@ -67,8 +63,8 @@ var BDconnection = class {
67
63
  }) {
68
64
  try {
69
65
  if (this.tipo === "mysql") {
70
- const pool = await this.connecionMyql();
71
- const [rows] = await pool.query(query, [valores]);
66
+ const pool = await this.conexionMysql();
67
+ const [rows] = await pool.query(query, valores);
72
68
  return rows;
73
69
  } else if (this.tipo === "pg") {
74
70
  let query2 = query;
@@ -85,6 +81,9 @@ var BDconnection = class {
85
81
  }
86
82
  }
87
83
  const pool2 = await this.connectionPG();
84
+ if (!pool2) {
85
+ throw new Error("No se pudo establecer la conexi\xF3n con PostgreSQL");
86
+ }
88
87
  const respuesta = await pool2.query(query2, valores);
89
88
  if (!respuesta) {
90
89
  throw new Error(` Este usuario no esta registrado `);
@@ -102,6 +101,14 @@ var BDconnection = class {
102
101
  }
103
102
  }
104
103
  };
104
+ var conexionZORMZ3691;
105
+ var tipoConexionZORMZ3691;
106
+ function getTipoConexion() {
107
+ if (!tipoConexionZORMZ3691) {
108
+ throw new Error("La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero.");
109
+ }
110
+ return tipoConexionZORMZ3691;
111
+ }
105
112
  async function getConexion(bd, datos) {
106
113
  conexionZORMZ3691 = new BDconnection(bd, datos);
107
114
  tipoConexionZORMZ3691 = conexionZORMZ3691.tipo;
@@ -109,9 +116,13 @@ async function getConexion(bd, datos) {
109
116
  console.log(`\u{1F44D}\u{1F44D} Conexi\xF3n ${tipoConexionZORMZ3691} exitosa \u{1F61C}`);
110
117
  }).catch((err) => {
111
118
  console.error(" \u{1F622}\u{1F622} Error al conectar a " + tipoConexionZORMZ3691);
119
+ console.log(err);
112
120
  });
113
121
  }
114
122
  function getRed() {
123
+ if (!conexionZORMZ3691) {
124
+ throw new Error("La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero.");
125
+ }
115
126
  return conexionZORMZ3691;
116
127
  }
117
128
  function defineTable(tableName, columns) {
@@ -173,6 +184,9 @@ async function generateTable(tabla, columns) {
173
184
  `;
174
185
  queries += columnDefs.join(", \n");
175
186
  queries += ");";
187
+ if (!conexionZORMZ3691 || !tipoConexionZORMZ3691) {
188
+ throw new Error("La conexi\xF3n no ha sido inicializada. Por favor, llama a getConexion() primero.");
189
+ }
176
190
  if (tipoConexionZORMZ3691 === "mysql") {
177
191
  const response = await conexionZORMZ3691.executeConsulta({ query: queries, mensaje: "Error al crear la base de datos" });
178
192
  if (response.warningStatus > 0) {
@@ -289,7 +303,9 @@ var QueryBuilder = class {
289
303
  let paramespaces = "";
290
304
  if (this.conexion.tipo === "mysql") {
291
305
  if (typeof this.parametros !== "string") {
292
- if (Array.isArray(this.valores[0])) arrayArrays = true;
306
+ if (Array.isArray(this.valores[0])) {
307
+ arrayArrays = true;
308
+ }
293
309
  this.parametros.forEach((valor, index) => {
294
310
  param += valor;
295
311
  paramespaces += `?`;
@@ -336,10 +352,9 @@ var QueryBuilder = class {
336
352
  if (this.conexion.tipo === "mysql") {
337
353
  const respuesta = await this.conexion.executeConsulta({
338
354
  query,
339
- valores: this.valores,
355
+ valores: arrayArrays ? [this.valores] : this.valores,
340
356
  mensaje: `Ocurrio un error al ingresar datos a ${this.tabla} `
341
357
  });
342
- console.log(respuesta);
343
358
  return respuesta.insertId;
344
359
  } else if (this.conexion.tipo === "pg") {
345
360
  query += " RETURNING id ";
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "zormz",
3
- "version": "1.2.7",
4
- "description": "",
5
- "author": "",
3
+ "version": "1.3.0",
4
+ "description": "Un ORM que busca ser ligero y facil de usar",
5
+ "author": "yukio-kayaba",
6
6
  "license": "ISC",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
9
9
  "types": "./dist/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
12
+ "require": "./dist/index.js",
13
+ "import": "./dist/index.mjs"
14
14
  }
15
15
  },
16
16
  "files": [