zormz 1.2.4 → 1.2.5
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.cts → index.d.mts} +109 -28
- package/dist/index.d.ts +109 -28
- package/dist/index.js +362 -45
- package/dist/{index.cjs → index.mjs} +300 -101
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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<undefined>;
|
|
402
|
+
Required(): this;
|
|
403
|
+
Unique(): this;
|
|
404
|
+
Default(textoDefecto: string): this;
|
|
405
|
+
$(): ColumnDefinition<undefined>;
|
|
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<undefined>;
|
|
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<undefined>;
|
|
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
|
-
|
|
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<undefined>;
|
|
402
|
+
Required(): this;
|
|
403
|
+
Unique(): this;
|
|
404
|
+
Default(textoDefecto: string): this;
|
|
405
|
+
$(): ColumnDefinition<undefined>;
|
|
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<undefined>;
|
|
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<undefined>;
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
id
|
|
187
|
-
|
|
188
|
-
|
|
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} (
|
|
@@ -212,6 +251,185 @@ async function generateTable(tabla, columns) {
|
|
|
212
251
|
}
|
|
213
252
|
}
|
|
214
253
|
|
|
254
|
+
// conection/controls/int.ts
|
|
255
|
+
var IntColumn = class {
|
|
256
|
+
constructor() {
|
|
257
|
+
this.requerido = false;
|
|
258
|
+
this.unique = false;
|
|
259
|
+
this.autoIncrement = false;
|
|
260
|
+
this.unsingned = { uso: false, valor: 0 };
|
|
261
|
+
}
|
|
262
|
+
Required() {
|
|
263
|
+
this.requerido = true;
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
Pk() {
|
|
267
|
+
this.autoIncrement = true;
|
|
268
|
+
this.pk = true;
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
Unique() {
|
|
272
|
+
this.unique = true;
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
Unsingned(numeroPositivosInicio = 0) {
|
|
276
|
+
if (numeroPositivosInicio != void 0 && numeroPositivosInicio < 0) {
|
|
277
|
+
throw new Error(" Unsingned() solo permite numeros positivos ");
|
|
278
|
+
}
|
|
279
|
+
this.unsingned.uso = true;
|
|
280
|
+
this.unsingned.valor = numeroPositivosInicio;
|
|
281
|
+
}
|
|
282
|
+
AutoIncrement() {
|
|
283
|
+
this.autoIncrement = true;
|
|
284
|
+
this.requerido = true;
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
Default(value) {
|
|
288
|
+
this.defaultData = value;
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
|
|
292
|
+
if (defaultData !== void 0) this.Default(defaultData);
|
|
293
|
+
if (requerido) this.Required();
|
|
294
|
+
if (unique) this.Unique();
|
|
295
|
+
if (autoIncrement) this.AutoIncrement();
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
$() {
|
|
299
|
+
const parts = [];
|
|
300
|
+
const db = getTipoConexion();
|
|
301
|
+
parts.push(db === "mysql" ? "INT" : "INTEGER");
|
|
302
|
+
if (this.unsingned.uso) {
|
|
303
|
+
parts.push(
|
|
304
|
+
db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
parts.push(
|
|
308
|
+
this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
|
|
309
|
+
);
|
|
310
|
+
if (this.autoIncrement) {
|
|
311
|
+
parts.push(
|
|
312
|
+
db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
if (this.pk) {
|
|
316
|
+
parts.push("PRIMARY KEY");
|
|
317
|
+
const valor2 = {
|
|
318
|
+
pk: true,
|
|
319
|
+
typo: "int",
|
|
320
|
+
sqlz: parts.join(" ")
|
|
321
|
+
};
|
|
322
|
+
return valor2;
|
|
323
|
+
}
|
|
324
|
+
if (this.defaultData !== void 0 && !this.autoIncrement) {
|
|
325
|
+
parts.push(`DEFAULT ${this.defaultData}`);
|
|
326
|
+
}
|
|
327
|
+
if (this.unique) parts.push("UNIQUE");
|
|
328
|
+
const valor = {
|
|
329
|
+
pk: false,
|
|
330
|
+
typo: "int",
|
|
331
|
+
sqlz: parts.join(" ")
|
|
332
|
+
};
|
|
333
|
+
return valor;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
function int() {
|
|
337
|
+
return new IntColumn();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// conection/controls/timestamp.ts
|
|
341
|
+
var Timestamp = class {
|
|
342
|
+
constructor() {
|
|
343
|
+
this.requerido = false;
|
|
344
|
+
this.defaultNow = false;
|
|
345
|
+
this.onUpdateNow = false;
|
|
346
|
+
}
|
|
347
|
+
required() {
|
|
348
|
+
this.requerido = true;
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
now() {
|
|
352
|
+
this.defaultNow = true;
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
onUpdate() {
|
|
356
|
+
this.onUpdateNow = true;
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
359
|
+
$() {
|
|
360
|
+
const parts = [];
|
|
361
|
+
const db = getTipoConexion();
|
|
362
|
+
parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
|
|
363
|
+
parts.push(this.requerido ? "NOT NULL" : "NULL");
|
|
364
|
+
if (this.defaultNow) {
|
|
365
|
+
parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
|
|
366
|
+
}
|
|
367
|
+
if (this.onUpdateNow && db === "mysql") {
|
|
368
|
+
parts.push("ON UPDATE CURRENT_TIMESTAMP");
|
|
369
|
+
}
|
|
370
|
+
const response = {
|
|
371
|
+
typo: "timestamp",
|
|
372
|
+
pk: false,
|
|
373
|
+
sqlz: parts.join(" ")
|
|
374
|
+
};
|
|
375
|
+
return response;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
function timestamp() {
|
|
379
|
+
return new Timestamp();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// conection/controls/varchar.ts
|
|
383
|
+
var Varchar = class {
|
|
384
|
+
constructor(cantidad = 100) {
|
|
385
|
+
this.maxLenth = 100;
|
|
386
|
+
this.defaultData = "";
|
|
387
|
+
this.requerido = false;
|
|
388
|
+
this.unique = false;
|
|
389
|
+
this.maxLenth = cantidad;
|
|
390
|
+
}
|
|
391
|
+
withType({
|
|
392
|
+
maxLenth = 100,
|
|
393
|
+
defaultData = "",
|
|
394
|
+
requerido = false,
|
|
395
|
+
unique = false
|
|
396
|
+
}) {
|
|
397
|
+
this.maxLenth = maxLenth;
|
|
398
|
+
this.requerido = requerido;
|
|
399
|
+
this.unique = unique;
|
|
400
|
+
return this.Default(defaultData).$();
|
|
401
|
+
}
|
|
402
|
+
Required() {
|
|
403
|
+
this.requerido = true;
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
Unique() {
|
|
407
|
+
this.unique = true;
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
Default(textoDefecto) {
|
|
411
|
+
let opcion = getTipoConexion();
|
|
412
|
+
if (opcion === "mysql") {
|
|
413
|
+
this.defaultData = ` "${textoDefecto}" `;
|
|
414
|
+
} else if (opcion === "pg") {
|
|
415
|
+
this.defaultData = ` '${textoDefecto}' `;
|
|
416
|
+
}
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
419
|
+
$() {
|
|
420
|
+
let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
|
|
421
|
+
const response = {
|
|
422
|
+
typo: "varchar",
|
|
423
|
+
pk: false,
|
|
424
|
+
sqlz
|
|
425
|
+
};
|
|
426
|
+
return response;
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
function varchar(cantidad = 100) {
|
|
430
|
+
return new Varchar(cantidad);
|
|
431
|
+
}
|
|
432
|
+
|
|
215
433
|
// conection/middleware/delete.ts
|
|
216
434
|
var _condicion, _tabla;
|
|
217
435
|
var DeleteR = class {
|
|
@@ -221,12 +439,12 @@ var DeleteR = class {
|
|
|
221
439
|
* @example
|
|
222
440
|
* delete from tabla
|
|
223
441
|
*/
|
|
224
|
-
constructor(
|
|
442
|
+
constructor(conexion2, tabla) {
|
|
225
443
|
__privateAdd(this, _condicion);
|
|
226
444
|
__privateAdd(this, _tabla);
|
|
227
445
|
__privateSet(this, _tabla, tabla);
|
|
228
446
|
__privateSet(this, _condicion, "");
|
|
229
|
-
this.conexion =
|
|
447
|
+
this.conexion = conexion2;
|
|
230
448
|
}
|
|
231
449
|
/**
|
|
232
450
|
*
|
|
@@ -272,7 +490,7 @@ var QueryBuilder = class {
|
|
|
272
490
|
* @param {string} tabla - nombre de la ta tabla - campo obligatorio
|
|
273
491
|
* @param {string[]} values - campo obligatorio
|
|
274
492
|
*/
|
|
275
|
-
constructor(
|
|
493
|
+
constructor(conexion2, tabla, parametros) {
|
|
276
494
|
if (!parametros || !Array.isArray(parametros)) {
|
|
277
495
|
throw new Error(`campos obligatorios`);
|
|
278
496
|
}
|
|
@@ -283,7 +501,7 @@ var QueryBuilder = class {
|
|
|
283
501
|
this.parametros = parametros;
|
|
284
502
|
this.valores = [];
|
|
285
503
|
this.valorRetorno = null;
|
|
286
|
-
this.conexion =
|
|
504
|
+
this.conexion = conexion2;
|
|
287
505
|
}
|
|
288
506
|
/**
|
|
289
507
|
*
|
|
@@ -383,8 +601,8 @@ var Select = class {
|
|
|
383
601
|
* @param {string[]} values - campo obligatorio
|
|
384
602
|
* @param {string} condition - tabla1.id = tabla2.idtabla1 - id='2' - id='2' AND id='3'
|
|
385
603
|
*/
|
|
386
|
-
constructor(
|
|
387
|
-
this.conexion =
|
|
604
|
+
constructor(conexion2, parametros = "*") {
|
|
605
|
+
this.conexion = conexion2;
|
|
388
606
|
this.valores = !Array.isArray(parametros) ? false : true;
|
|
389
607
|
this.parametros = parametros;
|
|
390
608
|
this.tabla = void 0;
|
|
@@ -568,7 +786,7 @@ var Update = class {
|
|
|
568
786
|
/**
|
|
569
787
|
* @param {string} nombreTabla - nombre de la tabla a actualizar
|
|
570
788
|
*/
|
|
571
|
-
constructor(
|
|
789
|
+
constructor(conexion2, nombreTabla) {
|
|
572
790
|
this.nombreTabla = "";
|
|
573
791
|
this.valores = "";
|
|
574
792
|
this.condicion = "";
|
|
@@ -579,7 +797,7 @@ var Update = class {
|
|
|
579
797
|
throw new Error("El nombre de la tabla es requerido");
|
|
580
798
|
}
|
|
581
799
|
this.nombreTabla = nombreTabla;
|
|
582
|
-
this.conexion =
|
|
800
|
+
this.conexion = conexion2;
|
|
583
801
|
}
|
|
584
802
|
/**
|
|
585
803
|
* @param {Valores} valores - valores a actualizar
|
|
@@ -676,7 +894,100 @@ var DB = class {
|
|
|
676
894
|
return new DeleteR(conex, nombreTabla);
|
|
677
895
|
}
|
|
678
896
|
};
|
|
679
|
-
|
|
897
|
+
|
|
898
|
+
// conection/controls/bool.ts
|
|
899
|
+
var BoolColumn = class {
|
|
900
|
+
constructor() {
|
|
901
|
+
this.requerido = false;
|
|
902
|
+
}
|
|
903
|
+
required() {
|
|
904
|
+
this.requerido = true;
|
|
905
|
+
return this;
|
|
906
|
+
}
|
|
907
|
+
default(value) {
|
|
908
|
+
this.defaultData = value;
|
|
909
|
+
return this;
|
|
910
|
+
}
|
|
911
|
+
$() {
|
|
912
|
+
const parts = [];
|
|
913
|
+
const db = getTipoConexion();
|
|
914
|
+
parts.push("BOOLEAN");
|
|
915
|
+
parts.push(this.requerido ? "NOT NULL" : "NULL");
|
|
916
|
+
if (this.defaultData !== void 0) {
|
|
917
|
+
parts.push(
|
|
918
|
+
`DEFAULT ${db === "mysql" ? this.defaultData ? 1 : 0 : this.defaultData}`
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
const response = {
|
|
922
|
+
typo: "bool",
|
|
923
|
+
pk: false,
|
|
924
|
+
sqlz: parts.join(" ")
|
|
925
|
+
};
|
|
926
|
+
return response;
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
function bool() {
|
|
930
|
+
return new BoolColumn();
|
|
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
|
+
|
|
972
|
+
// index.ts
|
|
973
|
+
var conexion = {
|
|
974
|
+
database: "pruebamaster",
|
|
975
|
+
host: "localhost",
|
|
976
|
+
password: "zainmaster123",
|
|
977
|
+
port: 5432,
|
|
978
|
+
user: "postgres"
|
|
979
|
+
};
|
|
980
|
+
getConexion("pg", conexion);
|
|
981
|
+
var prueba1 = defineTable("prueba1", {
|
|
982
|
+
id: int().Pk().$(),
|
|
983
|
+
valor: varchar(200).Default("hola").$(),
|
|
984
|
+
resultado: int().Default(0).$(),
|
|
985
|
+
fechaRegistro: timestamp().required().now().$(),
|
|
986
|
+
fechaUpdate: timestamp().required().now().onUpdate().$()
|
|
987
|
+
});
|
|
988
|
+
generateTable(prueba1(), prueba1.$columns);
|
|
989
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
990
|
+
0 && (module.exports = {
|
|
680
991
|
AND,
|
|
681
992
|
BDconnection,
|
|
682
993
|
CURRENT_TIMESTAMP,
|
|
@@ -693,9 +1004,15 @@ export {
|
|
|
693
1004
|
QueryBuilder,
|
|
694
1005
|
Select,
|
|
695
1006
|
Update,
|
|
1007
|
+
bool,
|
|
696
1008
|
defineTable,
|
|
697
1009
|
eq,
|
|
698
1010
|
generateTable,
|
|
699
1011
|
getConexion,
|
|
700
|
-
getRed
|
|
701
|
-
|
|
1012
|
+
getRed,
|
|
1013
|
+
getTipoConexion,
|
|
1014
|
+
int,
|
|
1015
|
+
money,
|
|
1016
|
+
timestamp,
|
|
1017
|
+
varchar
|
|
1018
|
+
});
|
|
@@ -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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
id
|
|
242
|
-
|
|
243
|
-
|
|
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} (
|
|
@@ -267,6 +190,185 @@ async function generateTable(tabla, columns) {
|
|
|
267
190
|
}
|
|
268
191
|
}
|
|
269
192
|
|
|
193
|
+
// conection/controls/int.ts
|
|
194
|
+
var IntColumn = class {
|
|
195
|
+
constructor() {
|
|
196
|
+
this.requerido = false;
|
|
197
|
+
this.unique = false;
|
|
198
|
+
this.autoIncrement = false;
|
|
199
|
+
this.unsingned = { uso: false, valor: 0 };
|
|
200
|
+
}
|
|
201
|
+
Required() {
|
|
202
|
+
this.requerido = true;
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
Pk() {
|
|
206
|
+
this.autoIncrement = true;
|
|
207
|
+
this.pk = true;
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
Unique() {
|
|
211
|
+
this.unique = true;
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
Unsingned(numeroPositivosInicio = 0) {
|
|
215
|
+
if (numeroPositivosInicio != void 0 && numeroPositivosInicio < 0) {
|
|
216
|
+
throw new Error(" Unsingned() solo permite numeros positivos ");
|
|
217
|
+
}
|
|
218
|
+
this.unsingned.uso = true;
|
|
219
|
+
this.unsingned.valor = numeroPositivosInicio;
|
|
220
|
+
}
|
|
221
|
+
AutoIncrement() {
|
|
222
|
+
this.autoIncrement = true;
|
|
223
|
+
this.requerido = true;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
Default(value) {
|
|
227
|
+
this.defaultData = value;
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
withType({ defaultData, id = false, requerido, unique, autoIncrement }) {
|
|
231
|
+
if (defaultData !== void 0) this.Default(defaultData);
|
|
232
|
+
if (requerido) this.Required();
|
|
233
|
+
if (unique) this.Unique();
|
|
234
|
+
if (autoIncrement) this.AutoIncrement();
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
$() {
|
|
238
|
+
const parts = [];
|
|
239
|
+
const db = getTipoConexion();
|
|
240
|
+
parts.push(db === "mysql" ? "INT" : "INTEGER");
|
|
241
|
+
if (this.unsingned.uso) {
|
|
242
|
+
parts.push(
|
|
243
|
+
db === "mysql" ? "UNSIGNED" : ` CHECK ( $ZORMZ >= ${this.unsingned.valor}) `
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
parts.push(
|
|
247
|
+
this.requerido ? "NOT NULL" : db === "pg" && this.pk ? " " : "NULL"
|
|
248
|
+
);
|
|
249
|
+
if (this.autoIncrement) {
|
|
250
|
+
parts.push(
|
|
251
|
+
db === "pg" ? "GENERATED ALWAYS AS IDENTITY" : "AUTO_INCREMENT"
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
if (this.pk) {
|
|
255
|
+
parts.push("PRIMARY KEY");
|
|
256
|
+
const valor2 = {
|
|
257
|
+
pk: true,
|
|
258
|
+
typo: "int",
|
|
259
|
+
sqlz: parts.join(" ")
|
|
260
|
+
};
|
|
261
|
+
return valor2;
|
|
262
|
+
}
|
|
263
|
+
if (this.defaultData !== void 0 && !this.autoIncrement) {
|
|
264
|
+
parts.push(`DEFAULT ${this.defaultData}`);
|
|
265
|
+
}
|
|
266
|
+
if (this.unique) parts.push("UNIQUE");
|
|
267
|
+
const valor = {
|
|
268
|
+
pk: false,
|
|
269
|
+
typo: "int",
|
|
270
|
+
sqlz: parts.join(" ")
|
|
271
|
+
};
|
|
272
|
+
return valor;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
function int() {
|
|
276
|
+
return new IntColumn();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// conection/controls/timestamp.ts
|
|
280
|
+
var Timestamp = class {
|
|
281
|
+
constructor() {
|
|
282
|
+
this.requerido = false;
|
|
283
|
+
this.defaultNow = false;
|
|
284
|
+
this.onUpdateNow = false;
|
|
285
|
+
}
|
|
286
|
+
required() {
|
|
287
|
+
this.requerido = true;
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
now() {
|
|
291
|
+
this.defaultNow = true;
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
onUpdate() {
|
|
295
|
+
this.onUpdateNow = true;
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
$() {
|
|
299
|
+
const parts = [];
|
|
300
|
+
const db = getTipoConexion();
|
|
301
|
+
parts.push(db === "mysql" ? "TIMESTAMP" : "TIMESTAMPTZ");
|
|
302
|
+
parts.push(this.requerido ? "NOT NULL" : "NULL");
|
|
303
|
+
if (this.defaultNow) {
|
|
304
|
+
parts.push(`DEFAULT ${db === "mysql" ? "CURRENT_TIMESTAMP" : "NOW()"}`);
|
|
305
|
+
}
|
|
306
|
+
if (this.onUpdateNow && db === "mysql") {
|
|
307
|
+
parts.push("ON UPDATE CURRENT_TIMESTAMP");
|
|
308
|
+
}
|
|
309
|
+
const response = {
|
|
310
|
+
typo: "timestamp",
|
|
311
|
+
pk: false,
|
|
312
|
+
sqlz: parts.join(" ")
|
|
313
|
+
};
|
|
314
|
+
return response;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
function timestamp() {
|
|
318
|
+
return new Timestamp();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// conection/controls/varchar.ts
|
|
322
|
+
var Varchar = class {
|
|
323
|
+
constructor(cantidad = 100) {
|
|
324
|
+
this.maxLenth = 100;
|
|
325
|
+
this.defaultData = "";
|
|
326
|
+
this.requerido = false;
|
|
327
|
+
this.unique = false;
|
|
328
|
+
this.maxLenth = cantidad;
|
|
329
|
+
}
|
|
330
|
+
withType({
|
|
331
|
+
maxLenth = 100,
|
|
332
|
+
defaultData = "",
|
|
333
|
+
requerido = false,
|
|
334
|
+
unique = false
|
|
335
|
+
}) {
|
|
336
|
+
this.maxLenth = maxLenth;
|
|
337
|
+
this.requerido = requerido;
|
|
338
|
+
this.unique = unique;
|
|
339
|
+
return this.Default(defaultData).$();
|
|
340
|
+
}
|
|
341
|
+
Required() {
|
|
342
|
+
this.requerido = true;
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
Unique() {
|
|
346
|
+
this.unique = true;
|
|
347
|
+
return this;
|
|
348
|
+
}
|
|
349
|
+
Default(textoDefecto) {
|
|
350
|
+
let opcion = getTipoConexion();
|
|
351
|
+
if (opcion === "mysql") {
|
|
352
|
+
this.defaultData = ` "${textoDefecto}" `;
|
|
353
|
+
} else if (opcion === "pg") {
|
|
354
|
+
this.defaultData = ` '${textoDefecto}' `;
|
|
355
|
+
}
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
$() {
|
|
359
|
+
let sqlz = `VARCHAR(${this.maxLenth}) ${this.requerido ? "NOT NULL" : "NULL"} ${this.defaultData.length > 0 ? ` DEFAULT ${this.defaultData} ` : " "} ${this.unique ? " UNIQUE" : " "} `;
|
|
360
|
+
const response = {
|
|
361
|
+
typo: "varchar",
|
|
362
|
+
pk: false,
|
|
363
|
+
sqlz
|
|
364
|
+
};
|
|
365
|
+
return response;
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
function varchar(cantidad = 100) {
|
|
369
|
+
return new Varchar(cantidad);
|
|
370
|
+
}
|
|
371
|
+
|
|
270
372
|
// conection/middleware/delete.ts
|
|
271
373
|
var _condicion, _tabla;
|
|
272
374
|
var DeleteR = class {
|
|
@@ -276,12 +378,12 @@ var DeleteR = class {
|
|
|
276
378
|
* @example
|
|
277
379
|
* delete from tabla
|
|
278
380
|
*/
|
|
279
|
-
constructor(
|
|
381
|
+
constructor(conexion2, tabla) {
|
|
280
382
|
__privateAdd(this, _condicion);
|
|
281
383
|
__privateAdd(this, _tabla);
|
|
282
384
|
__privateSet(this, _tabla, tabla);
|
|
283
385
|
__privateSet(this, _condicion, "");
|
|
284
|
-
this.conexion =
|
|
386
|
+
this.conexion = conexion2;
|
|
285
387
|
}
|
|
286
388
|
/**
|
|
287
389
|
*
|
|
@@ -327,7 +429,7 @@ var QueryBuilder = class {
|
|
|
327
429
|
* @param {string} tabla - nombre de la ta tabla - campo obligatorio
|
|
328
430
|
* @param {string[]} values - campo obligatorio
|
|
329
431
|
*/
|
|
330
|
-
constructor(
|
|
432
|
+
constructor(conexion2, tabla, parametros) {
|
|
331
433
|
if (!parametros || !Array.isArray(parametros)) {
|
|
332
434
|
throw new Error(`campos obligatorios`);
|
|
333
435
|
}
|
|
@@ -338,7 +440,7 @@ var QueryBuilder = class {
|
|
|
338
440
|
this.parametros = parametros;
|
|
339
441
|
this.valores = [];
|
|
340
442
|
this.valorRetorno = null;
|
|
341
|
-
this.conexion =
|
|
443
|
+
this.conexion = conexion2;
|
|
342
444
|
}
|
|
343
445
|
/**
|
|
344
446
|
*
|
|
@@ -438,8 +540,8 @@ var Select = class {
|
|
|
438
540
|
* @param {string[]} values - campo obligatorio
|
|
439
541
|
* @param {string} condition - tabla1.id = tabla2.idtabla1 - id='2' - id='2' AND id='3'
|
|
440
542
|
*/
|
|
441
|
-
constructor(
|
|
442
|
-
this.conexion =
|
|
543
|
+
constructor(conexion2, parametros = "*") {
|
|
544
|
+
this.conexion = conexion2;
|
|
443
545
|
this.valores = !Array.isArray(parametros) ? false : true;
|
|
444
546
|
this.parametros = parametros;
|
|
445
547
|
this.tabla = void 0;
|
|
@@ -623,7 +725,7 @@ var Update = class {
|
|
|
623
725
|
/**
|
|
624
726
|
* @param {string} nombreTabla - nombre de la tabla a actualizar
|
|
625
727
|
*/
|
|
626
|
-
constructor(
|
|
728
|
+
constructor(conexion2, nombreTabla) {
|
|
627
729
|
this.nombreTabla = "";
|
|
628
730
|
this.valores = "";
|
|
629
731
|
this.condicion = "";
|
|
@@ -634,7 +736,7 @@ var Update = class {
|
|
|
634
736
|
throw new Error("El nombre de la tabla es requerido");
|
|
635
737
|
}
|
|
636
738
|
this.nombreTabla = nombreTabla;
|
|
637
|
-
this.conexion =
|
|
739
|
+
this.conexion = conexion2;
|
|
638
740
|
}
|
|
639
741
|
/**
|
|
640
742
|
* @param {Valores} valores - valores a actualizar
|
|
@@ -731,8 +833,99 @@ var DB = class {
|
|
|
731
833
|
return new DeleteR(conex, nombreTabla);
|
|
732
834
|
}
|
|
733
835
|
};
|
|
734
|
-
|
|
735
|
-
|
|
836
|
+
|
|
837
|
+
// conection/controls/bool.ts
|
|
838
|
+
var BoolColumn = class {
|
|
839
|
+
constructor() {
|
|
840
|
+
this.requerido = false;
|
|
841
|
+
}
|
|
842
|
+
required() {
|
|
843
|
+
this.requerido = true;
|
|
844
|
+
return this;
|
|
845
|
+
}
|
|
846
|
+
default(value) {
|
|
847
|
+
this.defaultData = value;
|
|
848
|
+
return this;
|
|
849
|
+
}
|
|
850
|
+
$() {
|
|
851
|
+
const parts = [];
|
|
852
|
+
const db = getTipoConexion();
|
|
853
|
+
parts.push("BOOLEAN");
|
|
854
|
+
parts.push(this.requerido ? "NOT NULL" : "NULL");
|
|
855
|
+
if (this.defaultData !== void 0) {
|
|
856
|
+
parts.push(
|
|
857
|
+
`DEFAULT ${db === "mysql" ? this.defaultData ? 1 : 0 : this.defaultData}`
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
const response = {
|
|
861
|
+
typo: "bool",
|
|
862
|
+
pk: false,
|
|
863
|
+
sqlz: parts.join(" ")
|
|
864
|
+
};
|
|
865
|
+
return response;
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
function bool() {
|
|
869
|
+
return new BoolColumn();
|
|
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
|
+
|
|
911
|
+
// index.ts
|
|
912
|
+
var conexion = {
|
|
913
|
+
database: "pruebamaster",
|
|
914
|
+
host: "localhost",
|
|
915
|
+
password: "zainmaster123",
|
|
916
|
+
port: 5432,
|
|
917
|
+
user: "postgres"
|
|
918
|
+
};
|
|
919
|
+
getConexion("pg", conexion);
|
|
920
|
+
var prueba1 = defineTable("prueba1", {
|
|
921
|
+
id: int().Pk().$(),
|
|
922
|
+
valor: varchar(200).Default("hola").$(),
|
|
923
|
+
resultado: int().Default(0).$(),
|
|
924
|
+
fechaRegistro: timestamp().required().now().$(),
|
|
925
|
+
fechaUpdate: timestamp().required().now().onUpdate().$()
|
|
926
|
+
});
|
|
927
|
+
generateTable(prueba1(), prueba1.$columns);
|
|
928
|
+
export {
|
|
736
929
|
AND,
|
|
737
930
|
BDconnection,
|
|
738
931
|
CURRENT_TIMESTAMP,
|
|
@@ -749,9 +942,15 @@ var DB = class {
|
|
|
749
942
|
QueryBuilder,
|
|
750
943
|
Select,
|
|
751
944
|
Update,
|
|
945
|
+
bool,
|
|
752
946
|
defineTable,
|
|
753
947
|
eq,
|
|
754
948
|
generateTable,
|
|
755
949
|
getConexion,
|
|
756
|
-
getRed
|
|
757
|
-
|
|
950
|
+
getRed,
|
|
951
|
+
getTipoConexion,
|
|
952
|
+
int,
|
|
953
|
+
money,
|
|
954
|
+
timestamp,
|
|
955
|
+
varchar
|
|
956
|
+
};
|