dbtabla 2.0.0 → 2.1.2
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/lib/Connect.js +39 -39
- package/lib/dbTabla.js +402 -402
- package/package.json +2 -2
- package/test_results.txt +65 -0
package/lib/Connect.js
CHANGED
|
@@ -8,16 +8,16 @@ const procesingSql = require('./procesingSql')
|
|
|
8
8
|
* clase abstracta para crear la clase de conexion a la base de datos
|
|
9
9
|
*/
|
|
10
10
|
class Connect {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
_escapeChar;
|
|
12
|
+
_reserveIdentifiers;
|
|
13
|
+
_ar_aliased_tables;
|
|
14
|
+
_dbprefix;
|
|
15
|
+
_swap_pre;
|
|
16
|
+
_information_schema;
|
|
17
|
+
_models;
|
|
18
|
+
_caheTablas;
|
|
19
|
+
_createdTables;
|
|
20
|
+
_escapeString;
|
|
21
21
|
/**
|
|
22
22
|
* constructor de la clase
|
|
23
23
|
* @param {object} params - parametros de conexion
|
|
@@ -25,15 +25,15 @@ class Connect {
|
|
|
25
25
|
constructor(params,typeDB="")
|
|
26
26
|
{
|
|
27
27
|
this.config=params
|
|
28
|
-
this
|
|
29
|
-
this
|
|
30
|
-
this
|
|
31
|
-
this
|
|
32
|
-
this
|
|
33
|
-
this
|
|
34
|
-
this
|
|
28
|
+
this._escapeChar=""
|
|
29
|
+
this._reserveIdentifiers=["*"]
|
|
30
|
+
this._ar_aliased_tables=[]
|
|
31
|
+
this._dbprefix=""
|
|
32
|
+
this._swap_pre=""
|
|
33
|
+
this._information_schema = " "
|
|
34
|
+
this._models={}
|
|
35
35
|
this.typeDB=typeDB
|
|
36
|
-
this
|
|
36
|
+
this._caheTablas={}
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* retorna la configuracion para los helpers
|
|
@@ -42,13 +42,13 @@ class Connect {
|
|
|
42
42
|
helpersConf()
|
|
43
43
|
{
|
|
44
44
|
return {
|
|
45
|
-
escapeChar:this
|
|
46
|
-
reserveIdentifiers:this
|
|
47
|
-
ar_aliased_tables:this
|
|
48
|
-
dbprefix:this
|
|
49
|
-
swap_pre:this
|
|
45
|
+
escapeChar:this._escapeChar,
|
|
46
|
+
reserveIdentifiers:this._reserveIdentifiers,
|
|
47
|
+
ar_aliased_tables:this._ar_aliased_tables,
|
|
48
|
+
dbprefix:this._dbprefix,
|
|
49
|
+
swap_pre:this._swap_pre,
|
|
50
50
|
typeDB:this.typeDB,
|
|
51
|
-
escapeString:typeof this
|
|
51
|
+
escapeString:typeof this._escapeString==="function"?e=>this._escapeString(e):null
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -59,7 +59,7 @@ class Connect {
|
|
|
59
59
|
model(tabla)
|
|
60
60
|
{
|
|
61
61
|
|
|
62
|
-
return this
|
|
62
|
+
return this._models[tabla] instanceof dbTablaModel?this._models[tabla]:false
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* agrega un modelo a la lista de modelos interna
|
|
@@ -69,11 +69,11 @@ class Connect {
|
|
|
69
69
|
{
|
|
70
70
|
if(model instanceof dbTablaModel)
|
|
71
71
|
{
|
|
72
|
-
this
|
|
72
|
+
this._models[model.tabla]=model
|
|
73
73
|
}else if(typeof model==="object" && model!==null){
|
|
74
|
-
this
|
|
74
|
+
this._models[model.tabla]= new dbTablaModel(model.tabla,model)
|
|
75
75
|
}else {
|
|
76
|
-
this
|
|
76
|
+
this._models[model.tabla]= new dbTablaModel(model,this.helpersConf().escapeChar)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
}
|
|
@@ -123,12 +123,12 @@ class Connect {
|
|
|
123
123
|
*/
|
|
124
124
|
tabla(tabla,callback,verify=false)
|
|
125
125
|
{
|
|
126
|
-
if(typeof this
|
|
126
|
+
if(typeof this._caheTablas[tabla]!=="undefined")
|
|
127
127
|
{
|
|
128
|
-
typeof callback==="function"?callback(this
|
|
129
|
-
return this
|
|
128
|
+
typeof callback==="function"?callback(this._caheTablas[tabla]):null
|
|
129
|
+
return this._caheTablas[tabla]
|
|
130
130
|
}
|
|
131
|
-
return this
|
|
131
|
+
return this._caheTablas[tabla] = new dbTabla({
|
|
132
132
|
tabla:tabla,
|
|
133
133
|
connection:this,
|
|
134
134
|
callback:callback,
|
|
@@ -159,7 +159,7 @@ class Connect {
|
|
|
159
159
|
* @param {string} table - nombre de la tabla
|
|
160
160
|
* @return {Promise}
|
|
161
161
|
*/
|
|
162
|
-
|
|
162
|
+
_keysInTable(table)
|
|
163
163
|
{
|
|
164
164
|
return new Promise((res)=>
|
|
165
165
|
{
|
|
@@ -190,7 +190,7 @@ class Connect {
|
|
|
190
190
|
if(create)
|
|
191
191
|
{
|
|
192
192
|
|
|
193
|
-
this
|
|
193
|
+
this._createTable(this.model(tabla))
|
|
194
194
|
.then(res).catch(rej)
|
|
195
195
|
}else
|
|
196
196
|
{
|
|
@@ -206,12 +206,12 @@ class Connect {
|
|
|
206
206
|
* @param {dbTablaModel} model - objeto del modelo
|
|
207
207
|
* @return {Promise}
|
|
208
208
|
*/
|
|
209
|
-
|
|
209
|
+
_createTable(model)
|
|
210
210
|
{
|
|
211
211
|
|
|
212
212
|
return new Promise((res,rej)=>
|
|
213
213
|
{
|
|
214
|
-
this
|
|
214
|
+
this._createdTables={}
|
|
215
215
|
let rescursive=(foreingKey,i)=>
|
|
216
216
|
{
|
|
217
217
|
|
|
@@ -227,8 +227,8 @@ class Connect {
|
|
|
227
227
|
}else {
|
|
228
228
|
|
|
229
229
|
this.query(model.sql(this)).then(()=>{
|
|
230
|
-
this
|
|
231
|
-
this
|
|
230
|
+
this._createdTables[model.tabla]=true
|
|
231
|
+
this._initializeTable(model.tabla).then(()=>
|
|
232
232
|
{
|
|
233
233
|
|
|
234
234
|
res(model.getData())
|
|
@@ -239,7 +239,7 @@ class Connect {
|
|
|
239
239
|
rescursive(model.foreingKey(),0)
|
|
240
240
|
})
|
|
241
241
|
}
|
|
242
|
-
|
|
242
|
+
_initializeTable(tab)
|
|
243
243
|
{
|
|
244
244
|
return new Promise(async(res)=>
|
|
245
245
|
{
|
package/lib/dbTabla.js
CHANGED
|
@@ -1,404 +1,404 @@
|
|
|
1
|
-
const dbResult= require("./dbResult")
|
|
2
|
-
const procesingSql = require("./procesingSql")
|
|
3
|
-
const dbTablaError = require("./dbTablaError")
|
|
4
|
-
/**
|
|
5
|
-
* dbTabla
|
|
6
|
-
* representacion de una tabla en la base de datos
|
|
7
|
-
*/
|
|
1
|
+
const dbResult= require("./dbResult")
|
|
2
|
+
const procesingSql = require("./procesingSql")
|
|
3
|
+
const dbTablaError = require("./dbTablaError")
|
|
4
|
+
/**
|
|
5
|
+
* dbTabla
|
|
6
|
+
* representacion de una tabla en la base de datos
|
|
7
|
+
*/
|
|
8
8
|
class dbTabla {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
_connection;
|
|
10
|
+
_lastSql;
|
|
11
|
+
_keys;
|
|
12
|
+
_callbackKey;
|
|
13
|
+
_config;
|
|
14
14
|
|
|
15
|
-
get lastSql() { return this
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param {object} tabla, connection, callback, config
|
|
19
|
-
* @param {boolean} ret indica si verificara la existencia de la tabla o esperara la primera consulta
|
|
20
|
-
*/
|
|
21
|
-
constructor({tabla,connection,callback,config},ret=false)
|
|
22
|
-
{
|
|
23
|
-
this
|
|
24
|
-
this
|
|
25
|
-
this
|
|
26
|
-
this.tabla=tabla || null
|
|
27
|
-
this
|
|
28
|
-
this
|
|
29
|
-
this.typeDB=connection.typeDB
|
|
30
|
-
if(ret)
|
|
31
|
-
this
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* agrega la propiedad $sql que continen
|
|
35
|
-
* el sql de la ultima consulta al objeto pasado
|
|
36
|
-
* @param {object}
|
|
37
|
-
* @return {object}
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
if(typeof ok ==="object")
|
|
42
|
-
Object.defineProperty(ok, "$sql", {
|
|
43
|
-
configurable : true,
|
|
44
|
-
enumerable : false,
|
|
45
|
-
value : this
|
|
46
|
-
})
|
|
47
|
-
return ok
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* verifica la existencia de la tabla y obtiene los metadatos
|
|
51
|
-
* @param {function} call
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
if(!this
|
|
56
|
-
{
|
|
57
|
-
this
|
|
58
|
-
.then(keys=>
|
|
59
|
-
{
|
|
60
|
-
this.colum=keys.colum
|
|
61
|
-
this.sql=new procesingSql(keys, this
|
|
62
|
-
this
|
|
63
|
-
if(keys.methods)
|
|
64
|
-
for(let i in keys.methods)
|
|
65
|
-
{
|
|
66
|
-
this[i]=(...params)=>keys.methods[i](this,this
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this
|
|
70
|
-
call()
|
|
71
|
-
}).catch(e=>{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this
|
|
75
|
-
call(e)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
}else {
|
|
81
|
-
call()
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* construlle el objeto de resultado para consultas select
|
|
86
|
-
* @param {array|object} resultado obtenido de la consulta ejecutada
|
|
87
|
-
* @return {dbResult}
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
return new dbResult(this,result)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* envia una sentencia insert a la base de datos
|
|
97
|
-
* @param {array|object|string} ...campos - campos a insertar
|
|
98
|
-
* @retuen {Promise}
|
|
99
|
-
*/
|
|
100
|
-
insert(...params)
|
|
101
|
-
{
|
|
102
|
-
if(params.length===0)
|
|
103
|
-
{
|
|
104
|
-
throw new dbTablaError("debe pasar almenos un parametro")
|
|
105
|
-
}
|
|
106
|
-
return new Promise((resolve,reject)=>
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
this
|
|
110
|
-
{
|
|
111
|
-
if(e)
|
|
112
|
-
{
|
|
113
|
-
return reject(e)
|
|
114
|
-
}
|
|
115
|
-
if(params instanceof Array && params.length==1)
|
|
116
|
-
{
|
|
117
|
-
this
|
|
118
|
-
}else {
|
|
119
|
-
this
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this
|
|
123
|
-
|
|
124
|
-
resolve(this
|
|
125
|
-
}).catch(e=>reject(e))
|
|
126
|
-
})
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* envia una sentencia select a la base de datos
|
|
131
|
-
* @param {array|object|string} campos - campos de la tabla que se seleccionaran si es un object
|
|
132
|
-
* se tomara con el parametro join si es un string entonces se utilisara como el parametro
|
|
133
|
-
* where y todos los parametros se correran hacia la izquierda
|
|
134
|
-
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
135
|
-
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
136
|
-
* < sera para left join
|
|
137
|
-
* > sera para ringt join
|
|
138
|
-
* = sera innert join
|
|
139
|
-
* si no se antepone nada sera natural join
|
|
140
|
-
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
141
|
-
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
142
|
-
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
143
|
-
* y para la exprecion 'on' un string con la exprecion
|
|
144
|
-
* si joins es un string entonces se utilisara el parametro where y
|
|
145
|
-
* todos los parametros se correran hacia la izquierda
|
|
146
|
-
* @param {string|object} where - clausula where desde este parametro se puede indicar
|
|
147
|
-
* explicitamente las clausulas GROUP BY, OERDER BY, HAVING, LIMIT y los parametros siguentes se correran hacia la izquierda
|
|
148
|
-
* segun la posicion del parametro indicado
|
|
149
|
-
* ejemplo: <em>si en el parametro where se coloca grup by micampo entonces where sera tomado
|
|
150
|
-
* como group y group como having y asi sucesivamente </em>
|
|
151
|
-
* @param {string} group - clausula group
|
|
152
|
-
* @param {string} having - clausula having
|
|
153
|
-
* @param {string} order - clausula order
|
|
154
|
-
* @param {string} limit - clausula limit
|
|
155
|
-
* @return {Promise} la sentencia sql generada
|
|
156
|
-
*/
|
|
157
|
-
select(...params)
|
|
158
|
-
{
|
|
159
|
-
return new Promise((resolve,reject)=>
|
|
160
|
-
{
|
|
161
|
-
this
|
|
162
|
-
{
|
|
163
|
-
if(e)
|
|
164
|
-
{
|
|
165
|
-
return reject(e)
|
|
166
|
-
}
|
|
167
|
-
this
|
|
168
|
-
this
|
|
169
|
-
resolve(this
|
|
170
|
-
}).catch(e=>reject(e))
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* envia una sentencia select a la base de datos y obtiene la primera fila
|
|
177
|
-
* @param {array|object|string} campos - campos de la tabla que se seleccionaran si es un object
|
|
178
|
-
* se tomara con el parametro join si es un string entonces se utilisara como el parametro
|
|
179
|
-
* where y todos los parametros se correran hacia la izquierda
|
|
180
|
-
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
181
|
-
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
182
|
-
* < sera para left join
|
|
183
|
-
* > sera para ringt join
|
|
184
|
-
* = sera innert join
|
|
185
|
-
* si no se antepone nada sera natural join
|
|
186
|
-
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
187
|
-
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
188
|
-
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
189
|
-
* y para la exprecion 'on' un string con la exprecion
|
|
190
|
-
* si joins es un string entonces se utilisara el parametro where y
|
|
191
|
-
* todos los parametros se correran hacia la izquierda
|
|
192
|
-
* @param {string|object} where - clausula where desde este parametro se puede indicar
|
|
193
|
-
* explicitamente las clausulas GROUP BY, OERDER BY, HAVING, LIMIT y los parametros siguentes se correran hacia la izquierda
|
|
194
|
-
* segun la posicion del parametro indicado
|
|
195
|
-
* ejemplo: <em>si en el parametro where se coloca grup by micampo entonces where sera tomado
|
|
196
|
-
* como group y group como having y asi sucesivamente </em>
|
|
197
|
-
* @param {string} group - clausula group
|
|
198
|
-
* @param {string} having - clausula having
|
|
199
|
-
* @param {string} order - clausula order
|
|
200
|
-
* @return {Promise} la sentencia sql generada
|
|
201
|
-
*/
|
|
202
|
-
selectOne(campos,joins,where,group,having,order)
|
|
203
|
-
{
|
|
204
|
-
return this.select(campos,joins,where,group,having,order,1).then(d=>typeof d[0]!==undefined?d[0]:null)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* selecciona un elemento de la tabla comparando la primera clave primaria con el
|
|
209
|
-
* parametro proporcionado
|
|
210
|
-
* @param {array|string} campos - campos de la tabla que se seleccionaran si es un
|
|
211
|
-
* object entonces se utilisara como la clausula join y todos los parametros se
|
|
212
|
-
* correran hacia la izquierda
|
|
213
|
-
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
214
|
-
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
215
|
-
* < sera para left join
|
|
216
|
-
* > sera para ringt join
|
|
217
|
-
* = sera innert join
|
|
218
|
-
* si no se antepone nada sera natural join
|
|
219
|
-
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
220
|
-
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
221
|
-
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
222
|
-
* y para la exprecion 'on' un string con la exprecion
|
|
223
|
-
* si joins no es un objeto entonces se utilisara como el parametro id
|
|
224
|
-
* @param {string|numeric} id - clave primaria a buscar
|
|
225
|
-
* @return {Promise}
|
|
226
|
-
*/
|
|
227
|
-
selectById(campos,joins,id)
|
|
228
|
-
{
|
|
229
|
-
if(typeof campos==="string" || typeof campos==="number")
|
|
230
|
-
{
|
|
231
|
-
id=campos
|
|
232
|
-
joins=undefined
|
|
233
|
-
campos=undefined
|
|
234
|
-
}
|
|
235
|
-
if(typeof campos==="string" || typeof campos==="number")
|
|
236
|
-
{
|
|
237
|
-
id=joins
|
|
238
|
-
joins=campos
|
|
239
|
-
campos=undefined
|
|
240
|
-
}
|
|
241
|
-
if(id===undefined)
|
|
242
|
-
{
|
|
243
|
-
throw new dbTablaError("falta el parametro id no es opcional")
|
|
244
|
-
}
|
|
245
|
-
return this.selectOne(campos,joins,this.sql.whereId(id))
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* envia una sentencia select a la base de datos con un sencillo algoritmo de busqueda
|
|
249
|
-
* @param {string} cadena - palabra o serie de palabras a buscar en la tabla
|
|
250
|
-
* @param {array} campo_bus - campos en los que se buscara el contenido del primer parametro
|
|
251
|
-
* @param {array|object|string} campos - campos de la tabla que se seleccionaran si es un object
|
|
252
|
-
* se tomara con el parametro join si es un string entonces se utilisara como el parametro
|
|
253
|
-
* where y todos los parametros se correran hacia la izquierda
|
|
254
|
-
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
255
|
-
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
256
|
-
* < sera para left join
|
|
257
|
-
* > sera para ringt join
|
|
258
|
-
* = sera innert join
|
|
259
|
-
* si no se antepone nada sera natural join
|
|
260
|
-
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
261
|
-
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
262
|
-
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
263
|
-
* y para la exprecion 'on' un string con la exprecion
|
|
264
|
-
* si joins es un string entonces se utilisara el parametro where y
|
|
265
|
-
* todos los parametros se correran hacia la izquierda
|
|
266
|
-
* @param {string|object} where - clausula where desde este parametro se puede indicar
|
|
267
|
-
* explicitamente las clausulas GROUP BY, OERDER BY, HAVING, LIMIT y los parametros siguentes se correran hacia la izquierda
|
|
268
|
-
* segun la posicion del parametro indicado
|
|
269
|
-
* ejemplo: <em>si en el parametro where se coloca grup by micampo entonces where sera tomado
|
|
270
|
-
* como group y group como having y asi sucesivamente </em>
|
|
271
|
-
* @param {string} group - clausula group
|
|
272
|
-
* @param {string} having - clausula having
|
|
273
|
-
* @param {string} order - clausula order
|
|
274
|
-
* @param {string} limit - clausula limit
|
|
275
|
-
* @return {string} la sentencia sql generada
|
|
276
|
-
*/
|
|
277
|
-
busqueda(cadena,campo_bus,campos,where,joins,group,having,order,limit)
|
|
278
|
-
{
|
|
279
|
-
return new Promise((resolve,reject)=>
|
|
280
|
-
{
|
|
281
|
-
this
|
|
282
|
-
{
|
|
283
|
-
this
|
|
284
|
-
this
|
|
285
|
-
resolve(this
|
|
286
|
-
}).catch(e=>reject(e))
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
})
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* envia una sentencia update en la base de datos
|
|
293
|
-
* que edita la fila con la clave primaria pasada en el segundo parametro
|
|
294
|
-
* @param {object} sets - elementos a modificar
|
|
295
|
-
* @param {string|numeric} id - clave primaria
|
|
296
|
-
* @return {Promise}
|
|
297
|
-
*/
|
|
298
|
-
updateById(sets,id)
|
|
299
|
-
{
|
|
300
|
-
if(sets===undefined )
|
|
301
|
-
{
|
|
302
|
-
throw new dbTablaError("Falta el parametro numero 1 sets no es opcional")
|
|
303
|
-
}else if(typeof sets!=="object")
|
|
304
|
-
{
|
|
305
|
-
throw new dbTablaError("El parametro numero 1 sets debe ser un de tipo object")
|
|
306
|
-
}
|
|
307
|
-
if(id===undefined)
|
|
308
|
-
{
|
|
309
|
-
throw new dbTablaError("falta el parametro numero 2 id no es opcional")
|
|
310
|
-
}
|
|
311
|
-
return this.update(sets,this.sql.whereId(id))
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* envia una sentencia update en la base de datos
|
|
315
|
-
* @param {object} sets - elementos a modificar
|
|
316
|
-
* @param {string|object} where - exprecion booleana sql
|
|
317
|
-
* @return {Promise}
|
|
318
|
-
*/
|
|
319
|
-
update(sets,where)
|
|
320
|
-
{
|
|
321
|
-
if(sets===undefined )
|
|
322
|
-
{
|
|
323
|
-
throw new dbTablaError("Falta el parametro numero 1 sets no es opcional")
|
|
324
|
-
}else if(typeof sets!=="object")
|
|
325
|
-
{
|
|
326
|
-
throw new dbTablaError("El parametro numero 1 sets debe ser un de tipo object")
|
|
327
|
-
}
|
|
328
|
-
if(where===undefined)
|
|
329
|
-
{
|
|
330
|
-
throw new dbTablaError("falta el parametro numero 2 where no es opcional")
|
|
331
|
-
}
|
|
332
|
-
return new Promise((resolve,reject)=>
|
|
333
|
-
{
|
|
334
|
-
this
|
|
335
|
-
{
|
|
336
|
-
if(e)
|
|
337
|
-
{
|
|
338
|
-
return reject(e)
|
|
339
|
-
}
|
|
340
|
-
this
|
|
341
|
-
if( this
|
|
342
|
-
{
|
|
343
|
-
this
|
|
344
|
-
|
|
345
|
-
resolve(this
|
|
346
|
-
}).catch(e=>reject(e))
|
|
347
|
-
}
|
|
348
|
-
})
|
|
349
|
-
})
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* genera una sentencia sql deleteen la base de datos
|
|
353
|
-
* que elimina la fila con la clave primaria pasada en el segundo parametro
|
|
354
|
-
* @param {object} sets - elementos a modificar
|
|
355
|
-
* @param {string|numeric} id - clave prpimaria a eliminar
|
|
356
|
-
* @return {Promise}
|
|
357
|
-
*/
|
|
358
|
-
deleteById(sets,id)
|
|
359
|
-
{
|
|
360
|
-
if(sets===undefined )
|
|
361
|
-
{
|
|
362
|
-
throw new dbTablaError("Falta el parametro numero1 sets no es opcional")
|
|
363
|
-
}else if(typeof sets!=="object")
|
|
364
|
-
{
|
|
365
|
-
throw new dbTablaError("El parametro numero 1 sets debe ser un de tipo object")
|
|
366
|
-
}
|
|
367
|
-
if(id===undefined)
|
|
368
|
-
{
|
|
369
|
-
throw new dbTablaError("falta el parametro numero 2 id no es opcional")
|
|
370
|
-
}
|
|
371
|
-
return this.delete(sets,this.sql.whereId(id))
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* genera una sentencia sql delete en la base de datos
|
|
375
|
-
* @param {string|object} where - exprecion booleana sql
|
|
376
|
-
* @return {Promise} - sentencia sql
|
|
377
|
-
*/
|
|
378
|
-
|
|
379
|
-
delete(where)
|
|
380
|
-
{
|
|
381
|
-
if(where===undefined)
|
|
382
|
-
{
|
|
383
|
-
throw new dbTablaError("falta el parametro 1 where no es opcional")
|
|
384
|
-
}
|
|
385
|
-
return new Promise((resolve,reject)=>
|
|
386
|
-
{
|
|
387
|
-
this
|
|
388
|
-
{
|
|
389
|
-
if(e)
|
|
390
|
-
{
|
|
391
|
-
return reject(e)
|
|
392
|
-
}
|
|
393
|
-
this
|
|
394
|
-
this
|
|
395
|
-
|
|
396
|
-
resolve(this
|
|
397
|
-
}).catch(e=>reject(e))
|
|
398
|
-
})
|
|
399
|
-
})
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
module.exports=dbTabla
|
|
15
|
+
get lastSql() { return this._lastSql; }
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} tabla, connection, callback, config
|
|
19
|
+
* @param {boolean} ret indica si verificara la existencia de la tabla o esperara la primera consulta
|
|
20
|
+
*/
|
|
21
|
+
constructor({tabla,connection,callback,config},ret=false)
|
|
22
|
+
{
|
|
23
|
+
this._connection=connection
|
|
24
|
+
this._lastSql=""
|
|
25
|
+
this._keys=false
|
|
26
|
+
this.tabla=tabla || null
|
|
27
|
+
this._callbackKey=callback ||( e=>e)
|
|
28
|
+
this._config=config || {}
|
|
29
|
+
this.typeDB=connection.typeDB
|
|
30
|
+
if(ret)
|
|
31
|
+
this._verifyKeys()
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* agrega la propiedad $sql que continen
|
|
35
|
+
* el sql de la ultima consulta al objeto pasado
|
|
36
|
+
* @param {object}
|
|
37
|
+
* @return {object}
|
|
38
|
+
*/
|
|
39
|
+
_PropertyOk(ok)
|
|
40
|
+
{
|
|
41
|
+
if(typeof ok ==="object")
|
|
42
|
+
Object.defineProperty(ok, "$sql", {
|
|
43
|
+
configurable : true,
|
|
44
|
+
enumerable : false,
|
|
45
|
+
value : this._lastSql,
|
|
46
|
+
})
|
|
47
|
+
return ok
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* verifica la existencia de la tabla y obtiene los metadatos
|
|
51
|
+
* @param {function} call
|
|
52
|
+
*/
|
|
53
|
+
_verifyKeys(call=e=>e)
|
|
54
|
+
{
|
|
55
|
+
if(!this._keys)
|
|
56
|
+
{
|
|
57
|
+
this._connection._keysInTable(this.tabla)
|
|
58
|
+
.then(keys=>
|
|
59
|
+
{
|
|
60
|
+
this.colum=keys.colum
|
|
61
|
+
this.sql=new procesingSql(keys, this._config)
|
|
62
|
+
this._keys=true
|
|
63
|
+
if(keys.methods)
|
|
64
|
+
for(let i in keys.methods)
|
|
65
|
+
{
|
|
66
|
+
this[i]=(...params)=>keys.methods[i](this,this._connection,...params)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this._callbackKey(this)
|
|
70
|
+
call()
|
|
71
|
+
}).catch(e=>{
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
this._callbackKey(null,e)
|
|
75
|
+
call(e)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
}else {
|
|
81
|
+
call()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* construlle el objeto de resultado para consultas select
|
|
86
|
+
* @param {array|object} resultado obtenido de la consulta ejecutada
|
|
87
|
+
* @return {dbResult}
|
|
88
|
+
*/
|
|
89
|
+
_formatResult(result)
|
|
90
|
+
{
|
|
91
|
+
return new dbResult(this,result)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* envia una sentencia insert a la base de datos
|
|
97
|
+
* @param {array|object|string} ...campos - campos a insertar
|
|
98
|
+
* @retuen {Promise}
|
|
99
|
+
*/
|
|
100
|
+
insert(...params)
|
|
101
|
+
{
|
|
102
|
+
if(params.length===0)
|
|
103
|
+
{
|
|
104
|
+
throw new dbTablaError("debe pasar almenos un parametro")
|
|
105
|
+
}
|
|
106
|
+
return new Promise((resolve,reject)=>
|
|
107
|
+
{
|
|
108
|
+
|
|
109
|
+
this._verifyKeys(e=>
|
|
110
|
+
{
|
|
111
|
+
if(e)
|
|
112
|
+
{
|
|
113
|
+
return reject(e)
|
|
114
|
+
}
|
|
115
|
+
if(params instanceof Array && params.length==1)
|
|
116
|
+
{
|
|
117
|
+
this._lastSql=this.sql.insert(params[0])
|
|
118
|
+
}else {
|
|
119
|
+
this._lastSql=this.sql.insert(params)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this._connection.query(this._lastSql).then(d=>{
|
|
123
|
+
|
|
124
|
+
resolve(this._PropertyOk(d))
|
|
125
|
+
}).catch(e=>reject(e))
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* envia una sentencia select a la base de datos
|
|
131
|
+
* @param {array|object|string} campos - campos de la tabla que se seleccionaran si es un object
|
|
132
|
+
* se tomara con el parametro join si es un string entonces se utilisara como el parametro
|
|
133
|
+
* where y todos los parametros se correran hacia la izquierda
|
|
134
|
+
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
135
|
+
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
136
|
+
* < sera para left join
|
|
137
|
+
* > sera para ringt join
|
|
138
|
+
* = sera innert join
|
|
139
|
+
* si no se antepone nada sera natural join
|
|
140
|
+
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
141
|
+
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
142
|
+
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
143
|
+
* y para la exprecion 'on' un string con la exprecion
|
|
144
|
+
* si joins es un string entonces se utilisara el parametro where y
|
|
145
|
+
* todos los parametros se correran hacia la izquierda
|
|
146
|
+
* @param {string|object} where - clausula where desde este parametro se puede indicar
|
|
147
|
+
* explicitamente las clausulas GROUP BY, OERDER BY, HAVING, LIMIT y los parametros siguentes se correran hacia la izquierda
|
|
148
|
+
* segun la posicion del parametro indicado
|
|
149
|
+
* ejemplo: <em>si en el parametro where se coloca grup by micampo entonces where sera tomado
|
|
150
|
+
* como group y group como having y asi sucesivamente </em>
|
|
151
|
+
* @param {string} group - clausula group
|
|
152
|
+
* @param {string} having - clausula having
|
|
153
|
+
* @param {string} order - clausula order
|
|
154
|
+
* @param {string} limit - clausula limit
|
|
155
|
+
* @return {Promise} la sentencia sql generada
|
|
156
|
+
*/
|
|
157
|
+
select(...params)
|
|
158
|
+
{
|
|
159
|
+
return new Promise((resolve,reject)=>
|
|
160
|
+
{
|
|
161
|
+
this._verifyKeys(e=>
|
|
162
|
+
{
|
|
163
|
+
if(e)
|
|
164
|
+
{
|
|
165
|
+
return reject(e)
|
|
166
|
+
}
|
|
167
|
+
this._lastSql = this.sql.select(...params)
|
|
168
|
+
this._connection.query(this._lastSql).then(d=>{
|
|
169
|
+
resolve(this._formatResult(d))
|
|
170
|
+
}).catch(e=>reject(e))
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* envia una sentencia select a la base de datos y obtiene la primera fila
|
|
177
|
+
* @param {array|object|string} campos - campos de la tabla que se seleccionaran si es un object
|
|
178
|
+
* se tomara con el parametro join si es un string entonces se utilisara como el parametro
|
|
179
|
+
* where y todos los parametros se correran hacia la izquierda
|
|
180
|
+
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
181
|
+
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
182
|
+
* < sera para left join
|
|
183
|
+
* > sera para ringt join
|
|
184
|
+
* = sera innert join
|
|
185
|
+
* si no se antepone nada sera natural join
|
|
186
|
+
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
187
|
+
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
188
|
+
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
189
|
+
* y para la exprecion 'on' un string con la exprecion
|
|
190
|
+
* si joins es un string entonces se utilisara el parametro where y
|
|
191
|
+
* todos los parametros se correran hacia la izquierda
|
|
192
|
+
* @param {string|object} where - clausula where desde este parametro se puede indicar
|
|
193
|
+
* explicitamente las clausulas GROUP BY, OERDER BY, HAVING, LIMIT y los parametros siguentes se correran hacia la izquierda
|
|
194
|
+
* segun la posicion del parametro indicado
|
|
195
|
+
* ejemplo: <em>si en el parametro where se coloca grup by micampo entonces where sera tomado
|
|
196
|
+
* como group y group como having y asi sucesivamente </em>
|
|
197
|
+
* @param {string} group - clausula group
|
|
198
|
+
* @param {string} having - clausula having
|
|
199
|
+
* @param {string} order - clausula order
|
|
200
|
+
* @return {Promise} la sentencia sql generada
|
|
201
|
+
*/
|
|
202
|
+
selectOne(campos,joins,where,group,having,order)
|
|
203
|
+
{
|
|
204
|
+
return this.select(campos,joins,where,group,having,order,1).then(d=>typeof d[0]!==undefined?d[0]:null)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* selecciona un elemento de la tabla comparando la primera clave primaria con el
|
|
209
|
+
* parametro proporcionado
|
|
210
|
+
* @param {array|string} campos - campos de la tabla que se seleccionaran si es un
|
|
211
|
+
* object entonces se utilisara como la clausula join y todos los parametros se
|
|
212
|
+
* correran hacia la izquierda
|
|
213
|
+
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
214
|
+
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
215
|
+
* < sera para left join
|
|
216
|
+
* > sera para ringt join
|
|
217
|
+
* = sera innert join
|
|
218
|
+
* si no se antepone nada sera natural join
|
|
219
|
+
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
220
|
+
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
221
|
+
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
222
|
+
* y para la exprecion 'on' un string con la exprecion
|
|
223
|
+
* si joins no es un objeto entonces se utilisara como el parametro id
|
|
224
|
+
* @param {string|numeric} id - clave primaria a buscar
|
|
225
|
+
* @return {Promise}
|
|
226
|
+
*/
|
|
227
|
+
selectById(campos,joins,id)
|
|
228
|
+
{
|
|
229
|
+
if(typeof campos==="string" || typeof campos==="number")
|
|
230
|
+
{
|
|
231
|
+
id=campos
|
|
232
|
+
joins=undefined
|
|
233
|
+
campos=undefined
|
|
234
|
+
}
|
|
235
|
+
if(typeof campos==="string" || typeof campos==="number")
|
|
236
|
+
{
|
|
237
|
+
id=joins
|
|
238
|
+
joins=campos
|
|
239
|
+
campos=undefined
|
|
240
|
+
}
|
|
241
|
+
if(id===undefined)
|
|
242
|
+
{
|
|
243
|
+
throw new dbTablaError("falta el parametro id no es opcional")
|
|
244
|
+
}
|
|
245
|
+
return this.selectOne(campos,joins,this.sql.whereId(id))
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* envia una sentencia select a la base de datos con un sencillo algoritmo de busqueda
|
|
249
|
+
* @param {string} cadena - palabra o serie de palabras a buscar en la tabla
|
|
250
|
+
* @param {array} campo_bus - campos en los que se buscara el contenido del primer parametro
|
|
251
|
+
* @param {array|object|string} campos - campos de la tabla que se seleccionaran si es un object
|
|
252
|
+
* se tomara con el parametro join si es un string entonces se utilisara como el parametro
|
|
253
|
+
* where y todos los parametros se correran hacia la izquierda
|
|
254
|
+
* @param {object|string} joins - clausulas jois utilizando un object con las tablas que se
|
|
255
|
+
* relacionaran ateponiendo los singnos <,>,= al nombre de la tabla foranea
|
|
256
|
+
* < sera para left join
|
|
257
|
+
* > sera para ringt join
|
|
258
|
+
* = sera innert join
|
|
259
|
+
* si no se antepone nada sera natural join
|
|
260
|
+
* sera tomado de las claves primarias que contengan las tablas para la clausula using
|
|
261
|
+
* para la clausula 'on' o 'using' se coloca el nombre de la tabla como atributo
|
|
262
|
+
* y el valor 'using' si es uno como valor string si son varios en un array
|
|
263
|
+
* y para la exprecion 'on' un string con la exprecion
|
|
264
|
+
* si joins es un string entonces se utilisara el parametro where y
|
|
265
|
+
* todos los parametros se correran hacia la izquierda
|
|
266
|
+
* @param {string|object} where - clausula where desde este parametro se puede indicar
|
|
267
|
+
* explicitamente las clausulas GROUP BY, OERDER BY, HAVING, LIMIT y los parametros siguentes se correran hacia la izquierda
|
|
268
|
+
* segun la posicion del parametro indicado
|
|
269
|
+
* ejemplo: <em>si en el parametro where se coloca grup by micampo entonces where sera tomado
|
|
270
|
+
* como group y group como having y asi sucesivamente </em>
|
|
271
|
+
* @param {string} group - clausula group
|
|
272
|
+
* @param {string} having - clausula having
|
|
273
|
+
* @param {string} order - clausula order
|
|
274
|
+
* @param {string} limit - clausula limit
|
|
275
|
+
* @return {string} la sentencia sql generada
|
|
276
|
+
*/
|
|
277
|
+
busqueda(cadena,campo_bus,campos,where,joins,group,having,order,limit)
|
|
278
|
+
{
|
|
279
|
+
return new Promise((resolve,reject)=>
|
|
280
|
+
{
|
|
281
|
+
this._verifyKeys(()=>
|
|
282
|
+
{
|
|
283
|
+
this._lastSql = this.sql.busqueda(cadena,campo_bus,campos,where,joins,group,having,order,limit)
|
|
284
|
+
this._connection.query(this._lastSql).then(d=>{
|
|
285
|
+
resolve(this._formatResult(d))
|
|
286
|
+
}).catch(e=>reject(e))
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* envia una sentencia update en la base de datos
|
|
293
|
+
* que edita la fila con la clave primaria pasada en el segundo parametro
|
|
294
|
+
* @param {object} sets - elementos a modificar
|
|
295
|
+
* @param {string|numeric} id - clave primaria
|
|
296
|
+
* @return {Promise}
|
|
297
|
+
*/
|
|
298
|
+
updateById(sets,id)
|
|
299
|
+
{
|
|
300
|
+
if(sets===undefined )
|
|
301
|
+
{
|
|
302
|
+
throw new dbTablaError("Falta el parametro numero 1 sets no es opcional")
|
|
303
|
+
}else if(typeof sets!=="object")
|
|
304
|
+
{
|
|
305
|
+
throw new dbTablaError("El parametro numero 1 sets debe ser un de tipo object")
|
|
306
|
+
}
|
|
307
|
+
if(id===undefined)
|
|
308
|
+
{
|
|
309
|
+
throw new dbTablaError("falta el parametro numero 2 id no es opcional")
|
|
310
|
+
}
|
|
311
|
+
return this.update(sets,this.sql.whereId(id))
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* envia una sentencia update en la base de datos
|
|
315
|
+
* @param {object} sets - elementos a modificar
|
|
316
|
+
* @param {string|object} where - exprecion booleana sql
|
|
317
|
+
* @return {Promise}
|
|
318
|
+
*/
|
|
319
|
+
update(sets,where)
|
|
320
|
+
{
|
|
321
|
+
if(sets===undefined )
|
|
322
|
+
{
|
|
323
|
+
throw new dbTablaError("Falta el parametro numero 1 sets no es opcional")
|
|
324
|
+
}else if(typeof sets!=="object")
|
|
325
|
+
{
|
|
326
|
+
throw new dbTablaError("El parametro numero 1 sets debe ser un de tipo object")
|
|
327
|
+
}
|
|
328
|
+
if(where===undefined)
|
|
329
|
+
{
|
|
330
|
+
throw new dbTablaError("falta el parametro numero 2 where no es opcional")
|
|
331
|
+
}
|
|
332
|
+
return new Promise((resolve,reject)=>
|
|
333
|
+
{
|
|
334
|
+
this._verifyKeys(e=>
|
|
335
|
+
{
|
|
336
|
+
if(e)
|
|
337
|
+
{
|
|
338
|
+
return reject(e)
|
|
339
|
+
}
|
|
340
|
+
this._lastSql =this.sql.update(sets,where,reject)
|
|
341
|
+
if( this._lastSql)
|
|
342
|
+
{
|
|
343
|
+
this._connection.query(this._lastSql).then(d=>{
|
|
344
|
+
|
|
345
|
+
resolve(this._PropertyOk(d))
|
|
346
|
+
}).catch(e=>reject(e))
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
})
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* genera una sentencia sql deleteen la base de datos
|
|
353
|
+
* que elimina la fila con la clave primaria pasada en el segundo parametro
|
|
354
|
+
* @param {object} sets - elementos a modificar
|
|
355
|
+
* @param {string|numeric} id - clave prpimaria a eliminar
|
|
356
|
+
* @return {Promise}
|
|
357
|
+
*/
|
|
358
|
+
deleteById(sets,id)
|
|
359
|
+
{
|
|
360
|
+
if(sets===undefined )
|
|
361
|
+
{
|
|
362
|
+
throw new dbTablaError("Falta el parametro numero1 sets no es opcional")
|
|
363
|
+
}else if(typeof sets!=="object")
|
|
364
|
+
{
|
|
365
|
+
throw new dbTablaError("El parametro numero 1 sets debe ser un de tipo object")
|
|
366
|
+
}
|
|
367
|
+
if(id===undefined)
|
|
368
|
+
{
|
|
369
|
+
throw new dbTablaError("falta el parametro numero 2 id no es opcional")
|
|
370
|
+
}
|
|
371
|
+
return this.delete(sets,this.sql.whereId(id))
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* genera una sentencia sql delete en la base de datos
|
|
375
|
+
* @param {string|object} where - exprecion booleana sql
|
|
376
|
+
* @return {Promise} - sentencia sql
|
|
377
|
+
*/
|
|
378
|
+
|
|
379
|
+
delete(where)
|
|
380
|
+
{
|
|
381
|
+
if(where===undefined)
|
|
382
|
+
{
|
|
383
|
+
throw new dbTablaError("falta el parametro 1 where no es opcional")
|
|
384
|
+
}
|
|
385
|
+
return new Promise((resolve,reject)=>
|
|
386
|
+
{
|
|
387
|
+
this._verifyKeys(e=>
|
|
388
|
+
{
|
|
389
|
+
if(e)
|
|
390
|
+
{
|
|
391
|
+
return reject(e)
|
|
392
|
+
}
|
|
393
|
+
this._lastSql =this.sql.delete(where)
|
|
394
|
+
this._connection.query(this._lastSql).then(d=>{
|
|
395
|
+
|
|
396
|
+
resolve(this._PropertyOk(d))
|
|
397
|
+
}).catch(e=>reject(e))
|
|
398
|
+
})
|
|
399
|
+
})
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
module.exports=dbTabla
|
package/package.json
CHANGED
package/test_results.txt
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
> dbtabla@2.1.1 test
|
|
3
|
+
> node --test ./test/index.js
|
|
4
|
+
|
|
5
|
+
ÔûÂ test de dbTabla
|
|
6
|
+
ÔûÂ Test de la clase prosessingSql
|
|
7
|
+
Ô£ö verificacion de metodos (1.2094ms)
|
|
8
|
+
Ô£ö metodo busqueda (2.2858ms)
|
|
9
|
+
Ô£ö metodo select (1.1186ms)
|
|
10
|
+
Ô£ö metodo select (0.2998ms)
|
|
11
|
+
Ô£ö metodo insert (0.6902ms)
|
|
12
|
+
Ô£ö metodo update (0.4324ms)
|
|
13
|
+
Ô£ö metodo delete (0.3132ms)
|
|
14
|
+
Ô£ö Test de la clase prosessingSql (7.4947ms)
|
|
15
|
+
ÔûÂ Test de la clase Connect
|
|
16
|
+
Ô£ö verificacion de metodos (0.2097ms)
|
|
17
|
+
Ô£ö verificacion de modelos (2.2262ms)
|
|
18
|
+
Ô£ö verificacion de tabla (0.3958ms)
|
|
19
|
+
Ô£ö Test de la clase Connect (3.0674ms)
|
|
20
|
+
ÔûÂ Test de la clase dbRow
|
|
21
|
+
Ô£ö verificacion de metodos (0.2598ms)
|
|
22
|
+
Ô£û metodo update (1.4786ms)
|
|
23
|
+
Ô£ö metodo update sin claves primarias (0.367ms)
|
|
24
|
+
Ô£û metodo delete (0.6469ms)
|
|
25
|
+
Ô£ö metodo delete sin claves primarias (0.246ms)
|
|
26
|
+
Ô£û Test de la clase dbRow (3.3226ms)
|
|
27
|
+
Ô£û test de dbTabla (14.5938ms)
|
|
28
|
+
Ôä╣ tests 15
|
|
29
|
+
Ôä╣ suites 4
|
|
30
|
+
Ôä╣ pass 13
|
|
31
|
+
Ôä╣ fail 2
|
|
32
|
+
Ôä╣ cancelled 0
|
|
33
|
+
Ôä╣ skipped 0
|
|
34
|
+
Ôä╣ todo 0
|
|
35
|
+
Ôä╣ duration_ms 168.9837
|
|
36
|
+
|
|
37
|
+
Ô£û failing tests:
|
|
38
|
+
|
|
39
|
+
test at test\dbRow.js:74:5
|
|
40
|
+
Ô£û metodo update (1.4786ms)
|
|
41
|
+
AssertionError [ERR_ASSERTION]: "UPDATE test1 SET col1=2343 WHERE id=1 AND col1=234 AND col2='row';" == 'UPDATE test1 SET col1=2343 WHERE id=1;'
|
|
42
|
+
at C:\programacion\dbtabla\dbtabla\test\dbRow.js:90:20
|
|
43
|
+
at async Test.run (node:internal/test_runner/test:1125:7)
|
|
44
|
+
at async Suite.processPendingSubtests (node:internal/test_runner/test:787:7) {
|
|
45
|
+
generatedMessage: true,
|
|
46
|
+
code: 'ERR_ASSERTION',
|
|
47
|
+
actual: "UPDATE test1 SET col1=2343 WHERE id=1 AND col1=234 AND col2='row';",
|
|
48
|
+
expected: 'UPDATE test1 SET col1=2343 WHERE id=1;',
|
|
49
|
+
operator: '==',
|
|
50
|
+
diff: 'simple'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
test at test\dbRow.js:111:5
|
|
54
|
+
Ô£û metodo delete (0.6469ms)
|
|
55
|
+
AssertionError [ERR_ASSERTION]: "DELETE FROM test1 WHERE id=1 AND col1=234 AND col2='row';" == 'DELETE FROM test1 WHERE id=1;'
|
|
56
|
+
at C:\programacion\dbtabla\dbtabla\test\dbRow.js:122:20
|
|
57
|
+
at async Test.run (node:internal/test_runner/test:1125:7)
|
|
58
|
+
at async Suite.processPendingSubtests (node:internal/test_runner/test:787:7) {
|
|
59
|
+
generatedMessage: true,
|
|
60
|
+
code: 'ERR_ASSERTION',
|
|
61
|
+
actual: "DELETE FROM test1 WHERE id=1 AND col1=234 AND col2='row';",
|
|
62
|
+
expected: 'DELETE FROM test1 WHERE id=1;',
|
|
63
|
+
operator: '==',
|
|
64
|
+
diff: 'simple'
|
|
65
|
+
}
|