dbtabla 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
- #escapeChar;
12
- #reserveIdentifiers;
13
- #ar_aliased_tables;
14
- #dbprefix;
15
- #swap_pre;
16
- #information_schema;
17
- #models;
18
- #caheTablas;
19
- #createdTables;
20
- #escapeString;
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.#escapeChar=""
29
- this.#reserveIdentifiers=["*"]
30
- this.#ar_aliased_tables=[]
31
- this.#dbprefix=""
32
- this.#swap_pre=""
33
- this.#information_schema = " "
34
- this.#models={}
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.#caheTablas={}
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.#escapeChar,
46
- reserveIdentifiers:this.#reserveIdentifiers,
47
- ar_aliased_tables:this.#ar_aliased_tables,
48
- dbprefix:this.#dbprefix,
49
- swap_pre:this.#swap_pre,
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.#escapeString==="function"?e=>this.#escapeString(e):null
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.#models[tabla] instanceof dbTablaModel?this.#models[tabla]:false
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.#models[model.tabla]=model
72
+ this._models[model.tabla]=model
73
73
  }else if(typeof model==="object" && model!==null){
74
- this.#models[model.tabla]= new dbTablaModel(model.tabla,model)
74
+ this._models[model.tabla]= new dbTablaModel(model.tabla,model)
75
75
  }else {
76
- this.#models[model.tabla]= new dbTablaModel(model,this.helpersConf().escapeChar)
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.#caheTablas[tabla]!=="undefined")
126
+ if(typeof this._caheTablas[tabla]!=="undefined")
127
127
  {
128
- typeof callback==="function"?callback(this.#caheTablas[tabla]):null
129
- return this.#caheTablas[tabla]
128
+ typeof callback==="function"?callback(this._caheTablas[tabla]):null
129
+ return this._caheTablas[tabla]
130
130
  }
131
- return this.#caheTablas[tabla] = new dbTabla({
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
- #keysInTable(table)
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.#createTable(this.model(tabla))
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
- #createTable(model)
209
+ _createTable(model)
210
210
  {
211
211
 
212
212
  return new Promise((res,rej)=>
213
213
  {
214
- this.#createdTables={}
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.#createdTables[model.tabla]=true
231
- this.#initializeTable(model.tabla).then(()=>
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
- #initializeTable(tab)
242
+ _initializeTable(tab)
243
243
  {
244
244
  return new Promise(async(res)=>
245
245
  {
package/lib/dbTabla.js CHANGED
@@ -6,13 +6,13 @@ const dbTablaError = require("./dbTablaError")
6
6
  * representacion de una tabla en la base de datos
7
7
  */
8
8
  class dbTabla {
9
- #connection;
10
- #lastSql;
11
- #keys;
12
- #callbackKey;
13
- #config;
9
+ _connection;
10
+ _lastSql;
11
+ _keys;
12
+ _callbackKey;
13
+ _config;
14
14
 
15
- get lastSql() { return this.#lastSql; }
15
+ get lastSql() { return this._lastSql; }
16
16
 
17
17
  /**
18
18
  * @param {object} tabla, connection, callback, config
@@ -20,15 +20,15 @@ class dbTabla {
20
20
  */
21
21
  constructor({tabla,connection,callback,config},ret=false)
22
22
  {
23
- this.#connection=connection
24
- this.#lastSql=""
25
- this.#keys=false
23
+ this._connection=connection
24
+ this._lastSql=""
25
+ this._keys=false
26
26
  this.tabla=tabla || null
27
- this.#callbackKey=callback ||( e=>e)
28
- this.#config=config || {}
27
+ this._callbackKey=callback ||( e=>e)
28
+ this._config=config || {}
29
29
  this.typeDB=connection.typeDB
30
30
  if(ret)
31
- this.#verifyKeys()
31
+ this._verifyKeys()
32
32
  }
33
33
  /**
34
34
  * agrega la propiedad $sql que continen
@@ -36,13 +36,13 @@ class dbTabla {
36
36
  * @param {object}
37
37
  * @return {object}
38
38
  */
39
- #PropertyOk(ok)
39
+ _PropertyOk(ok)
40
40
  {
41
41
  if(typeof ok ==="object")
42
42
  Object.defineProperty(ok, "$sql", {
43
43
  configurable : true,
44
44
  enumerable : false,
45
- value : this.#lastSql,
45
+ value : this._lastSql,
46
46
  })
47
47
  return ok
48
48
  }
@@ -50,28 +50,28 @@ class dbTabla {
50
50
  * verifica la existencia de la tabla y obtiene los metadatos
51
51
  * @param {function} call
52
52
  */
53
- #verifyKeys(call=e=>e)
53
+ _verifyKeys(call=e=>e)
54
54
  {
55
- if(!this.#keys)
55
+ if(!this._keys)
56
56
  {
57
- this.#connection.__keysInTable(this.tabla)
57
+ this._connection.__keysInTable(this.tabla)
58
58
  .then(keys=>
59
59
  {
60
60
  this.colum=keys.colum
61
- this.sql=new procesingSql(keys, this.#config)
62
- this.#keys=true
61
+ this.sql=new procesingSql(keys, this._config)
62
+ this._keys=true
63
63
  if(keys.methods)
64
64
  for(let i in keys.methods)
65
65
  {
66
- this[i]=(...params)=>keys.methods[i](this,this.#connection,...params)
66
+ this[i]=(...params)=>keys.methods[i](this,this._connection,...params)
67
67
  }
68
68
 
69
- this.#callbackKey(this)
69
+ this._callbackKey(this)
70
70
  call()
71
71
  }).catch(e=>{
72
72
 
73
73
 
74
- this.#callbackKey(null,e)
74
+ this._callbackKey(null,e)
75
75
  call(e)
76
76
 
77
77
 
@@ -86,7 +86,7 @@ class dbTabla {
86
86
  * @param {array|object} resultado obtenido de la consulta ejecutada
87
87
  * @return {dbResult}
88
88
  */
89
- #formatResult(result)
89
+ _formatResult(result)
90
90
  {
91
91
  return new dbResult(this,result)
92
92
  }
@@ -106,7 +106,7 @@ class dbTabla {
106
106
  return new Promise((resolve,reject)=>
107
107
  {
108
108
 
109
- this.#verifyKeys(e=>
109
+ this._verifyKeys(e=>
110
110
  {
111
111
  if(e)
112
112
  {
@@ -114,14 +114,14 @@ class dbTabla {
114
114
  }
115
115
  if(params instanceof Array && params.length==1)
116
116
  {
117
- this.#lastSql=this.sql.insert(params[0])
117
+ this._lastSql=this.sql.insert(params[0])
118
118
  }else {
119
- this.#lastSql=this.sql.insert(params)
119
+ this._lastSql=this.sql.insert(params)
120
120
  }
121
121
 
122
- this.#connection.query(this.#lastSql).then(d=>{
122
+ this._connection.query(this._lastSql).then(d=>{
123
123
 
124
- resolve(this.#PropertyOk(d))
124
+ resolve(this._PropertyOk(d))
125
125
  }).catch(e=>reject(e))
126
126
  })
127
127
  })
@@ -158,15 +158,15 @@ class dbTabla {
158
158
  {
159
159
  return new Promise((resolve,reject)=>
160
160
  {
161
- this.#verifyKeys(e=>
161
+ this._verifyKeys(e=>
162
162
  {
163
163
  if(e)
164
164
  {
165
165
  return reject(e)
166
166
  }
167
- this.#lastSql = this.sql.select(...params)
168
- this.#connection.query(this.#lastSql).then(d=>{
169
- resolve(this.#formatResult(d))
167
+ this._lastSql = this.sql.select(...params)
168
+ this._connection.query(this._lastSql).then(d=>{
169
+ resolve(this._formatResult(d))
170
170
  }).catch(e=>reject(e))
171
171
  })
172
172
 
@@ -278,11 +278,11 @@ class dbTabla {
278
278
  {
279
279
  return new Promise((resolve,reject)=>
280
280
  {
281
- this.#verifyKeys(()=>
281
+ this._verifyKeys(()=>
282
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))
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
286
  }).catch(e=>reject(e))
287
287
  })
288
288
 
@@ -331,18 +331,18 @@ class dbTabla {
331
331
  }
332
332
  return new Promise((resolve,reject)=>
333
333
  {
334
- this.#verifyKeys(e=>
334
+ this._verifyKeys(e=>
335
335
  {
336
336
  if(e)
337
337
  {
338
338
  return reject(e)
339
339
  }
340
- this.#lastSql =this.sql.update(sets,where,reject)
341
- if( this.#lastSql)
340
+ this._lastSql =this.sql.update(sets,where,reject)
341
+ if( this._lastSql)
342
342
  {
343
- this.#connection.query(this.#lastSql).then(d=>{
343
+ this._connection.query(this._lastSql).then(d=>{
344
344
 
345
- resolve(this.#PropertyOk(d))
345
+ resolve(this._PropertyOk(d))
346
346
  }).catch(e=>reject(e))
347
347
  }
348
348
  })
@@ -384,16 +384,16 @@ class dbTabla {
384
384
  }
385
385
  return new Promise((resolve,reject)=>
386
386
  {
387
- this.#verifyKeys(e=>
387
+ this._verifyKeys(e=>
388
388
  {
389
389
  if(e)
390
390
  {
391
391
  return reject(e)
392
392
  }
393
- this.#lastSql =this.sql.delete(where)
394
- this.#connection.query(this.#lastSql).then(d=>{
393
+ this._lastSql =this.sql.delete(where)
394
+ this._connection.query(this._lastSql).then(d=>{
395
395
 
396
- resolve(this.#PropertyOk(d))
396
+ resolve(this._PropertyOk(d))
397
397
  }).catch(e=>reject(e))
398
398
  })
399
399
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbtabla",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "interface de alto nivel para sql",
5
5
  "license": "MIT",
6
6
  "author": "enyerverfranco@gmail.com",
@@ -30,4 +30,4 @@
30
30
  "engines": {
31
31
  "node": ">=18.0.0"
32
32
  }
33
- }
33
+ }