zormz 1.2.2 → 1.2.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/dist/index.cjs CHANGED
@@ -199,6 +199,29 @@ function defineTable(tableName, columns) {
199
199
  });
200
200
  return proxy;
201
201
  }
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
+ }
202
225
  async function generateTable(tabla, columns) {
203
226
  let queries = "";
204
227
  let columnDefs = [];
@@ -210,14 +233,7 @@ async function generateTable(tabla, columns) {
210
233
  if (!col.typo) {
211
234
  throw new Error(`La columna ${columnName} no tiene el tipo definido`);
212
235
  }
213
- if (col.typo === "varchar") sql += `VARCHAR(${col.maxLength ? col.maxLength : "100"})`;
214
- if (col.typo === "int") {
215
- sql += col.id && tipoConexionZORMZ3691 === "pg" ? " " : ` INT `;
216
- }
217
- if (col.typo === "DateTime") sql += " DATETIME ";
218
- if (col.typo === "bool") sql += " TINYINT ";
219
- if (col.typo === "double") sql += " DOUBLE ";
220
- if (col.typo === "Timestamp") sql += tipoConexionZORMZ3691 === "mysql" ? " TIMESTAMP " : " TIMESTAMPTZ ";
236
+ sql += ValidacionTypos(col.typo, col.id, col.maxLength);
221
237
  if (col.id) {
222
238
  if (id) throw new Error(`El id no puede repetirse en 2 campos de la tabla '${tabla}'`);
223
239
  sql += tipoConexionZORMZ3691 === "mysql" ? " NOT NULL AUTO_INCREMENT " : " SERIAL ";
package/dist/index.d.cts CHANGED
@@ -31,14 +31,15 @@ declare class BDconnection {
31
31
  */
32
32
  declare function getConexion(bd: connectionDB, datos: connecionLocal | connecionRed): Promise<void>;
33
33
  declare function getRed(): BDconnection;
34
- type ColumnTypes = "varchar" | "int" | "double" | "bool" | "DateTime" | "Timestamp";
34
+ type ColumnTypes = "varchar" | "int" | "double" | "bool" | "timestamp" | "float" | "money";
35
35
  type ColumnTypeMap = {
36
36
  varchar: string;
37
37
  double: number;
38
- DateTime: Date;
39
38
  int: number;
40
39
  bool: boolean;
41
- Timestamp: Date;
40
+ timestamp: Date;
41
+ float: number;
42
+ money: number;
42
43
  };
43
44
  interface ColumnDefinition<T extends ColumnTypes = ColumnTypes> {
44
45
  typo: T;
@@ -348,7 +349,7 @@ declare const MENOR: (valor: string, valor2: string) => string;
348
349
  * @example
349
350
  *
350
351
  * FechaRegistro: {
351
- typo: "Timestamp ",
352
+ typo: "timestamp ",
352
353
  default: CURRENT_TIMESTAMP()
353
354
  },
354
355
  *
package/dist/index.d.ts CHANGED
@@ -31,14 +31,15 @@ declare class BDconnection {
31
31
  */
32
32
  declare function getConexion(bd: connectionDB, datos: connecionLocal | connecionRed): Promise<void>;
33
33
  declare function getRed(): BDconnection;
34
- type ColumnTypes = "varchar" | "int" | "double" | "bool" | "DateTime" | "Timestamp";
34
+ type ColumnTypes = "varchar" | "int" | "double" | "bool" | "timestamp" | "float" | "money";
35
35
  type ColumnTypeMap = {
36
36
  varchar: string;
37
37
  double: number;
38
- DateTime: Date;
39
38
  int: number;
40
39
  bool: boolean;
41
- Timestamp: Date;
40
+ timestamp: Date;
41
+ float: number;
42
+ money: number;
42
43
  };
43
44
  interface ColumnDefinition<T extends ColumnTypes = ColumnTypes> {
44
45
  typo: T;
@@ -348,7 +349,7 @@ declare const MENOR: (valor: string, valor2: string) => string;
348
349
  * @example
349
350
  *
350
351
  * FechaRegistro: {
351
- typo: "Timestamp ",
352
+ typo: "timestamp ",
352
353
  default: CURRENT_TIMESTAMP()
353
354
  },
354
355
  *
package/dist/index.js CHANGED
@@ -144,6 +144,29 @@ function defineTable(tableName, columns) {
144
144
  });
145
145
  return proxy;
146
146
  }
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
+ }
147
170
  async function generateTable(tabla, columns) {
148
171
  let queries = "";
149
172
  let columnDefs = [];
@@ -155,14 +178,7 @@ async function generateTable(tabla, columns) {
155
178
  if (!col.typo) {
156
179
  throw new Error(`La columna ${columnName} no tiene el tipo definido`);
157
180
  }
158
- if (col.typo === "varchar") sql += `VARCHAR(${col.maxLength ? col.maxLength : "100"})`;
159
- if (col.typo === "int") {
160
- sql += col.id && tipoConexionZORMZ3691 === "pg" ? " " : ` INT `;
161
- }
162
- if (col.typo === "DateTime") sql += " DATETIME ";
163
- if (col.typo === "bool") sql += " TINYINT ";
164
- if (col.typo === "double") sql += " DOUBLE ";
165
- if (col.typo === "Timestamp") sql += tipoConexionZORMZ3691 === "mysql" ? " TIMESTAMP " : " TIMESTAMPTZ ";
181
+ sql += ValidacionTypos(col.typo, col.id, col.maxLength);
166
182
  if (col.id) {
167
183
  if (id) throw new Error(`El id no puede repetirse en 2 campos de la tabla '${tabla}'`);
168
184
  sql += tipoConexionZORMZ3691 === "mysql" ? " NOT NULL AUTO_INCREMENT " : " SERIAL ";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zormz",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "ISC",