dbtabla 0.8.7 → 2.0.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/.eslintrc.js CHANGED
@@ -1,30 +1,30 @@
1
- module.exports = {
2
- "env": {
3
- "browser": true,
4
- "es6": true,
5
- "node": true
6
- },
7
- "extends": "eslint:recommended",
8
- "parserOptions": {
9
- "ecmaVersion": 2018,
10
- "sourceType": "module"
11
- },
12
- "rules": {
13
- "indent": [
14
- "error",
15
- 4
16
- ],
17
- "linebreak-style": [
18
- "error",
19
- "windows"
20
- ],
21
- "quotes": [
22
- "error",
23
- "double"
24
- ],
25
- "semi": [
26
- "error",
27
- "never"
28
- ]
29
- }
30
- };
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true,
5
+ "node": true
6
+ },
7
+ "extends": "eslint:recommended",
8
+ "parserOptions": {
9
+ "ecmaVersion": 2018,
10
+ "sourceType": "module"
11
+ },
12
+ "rules": {
13
+ "indent": [
14
+ "error",
15
+ 4
16
+ ],
17
+ "linebreak-style": [
18
+ "error",
19
+ "windows"
20
+ ],
21
+ "quotes": [
22
+ "error",
23
+ "double"
24
+ ],
25
+ "semi": [
26
+ "error",
27
+ "never"
28
+ ]
29
+ }
30
+ };
@@ -0,0 +1,22 @@
1
+ const js = require("@eslint/js");
2
+ const globals = require("globals");
3
+
4
+ module.exports = [
5
+ js.configs.recommended,
6
+ {
7
+ languageOptions: {
8
+ ecmaVersion: 2024,
9
+ sourceType: "module",
10
+ globals: {
11
+ ...globals.node,
12
+ ...globals.browser
13
+ }
14
+ },
15
+ rules: {
16
+ "indent": ["error", 4],
17
+ "linebreak-style": ["error", "windows"],
18
+ "quotes": ["error", "double"],
19
+ "semi": ["error", "never"]
20
+ }
21
+ }
22
+ ];
package/lib/Connect.js CHANGED
@@ -2,12 +2,22 @@ const fs=require("fs")
2
2
  const path=require("path")
3
3
  const dbTablaModel=require("tabla-model")
4
4
  const dbTabla=require(__dirname+"/dbTabla.js")
5
+ const procesingSql = require('./procesingSql')
5
6
  /**
6
7
  * Connect
7
8
  * clase abstracta para crear la clase de conexion a la base de datos
8
9
  */
9
- class Connect
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
21
  /**
12
22
  * constructor de la clase
13
23
  * @param {object} params - parametros de conexion
@@ -15,15 +25,15 @@ class Connect
15
25
  constructor(params,typeDB="")
16
26
  {
17
27
  this.config=params
18
- this.__escapeChar=""
19
- this.__reserveIdentifiers=["*"]
20
- this.__ar_aliased_tables=[]
21
- this.__dbprefix=""
22
- this.__swap_pre=""
23
- this.__information_schema = " "
24
- 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={}
25
35
  this.typeDB=typeDB
26
- this.__caheTablas={}
36
+ this.#caheTablas={}
27
37
  }
28
38
  /**
29
39
  * retorna la configuracion para los helpers
@@ -32,13 +42,13 @@ class Connect
32
42
  helpersConf()
33
43
  {
34
44
  return {
35
- escapeChar:this.__escapeChar,
36
- reserveIdentifiers:this.__reserveIdentifiers,
37
- ar_aliased_tables:this.__ar_aliased_tables,
38
- dbprefix:this.__dbprefix,
39
- 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,
40
50
  typeDB:this.typeDB,
41
- escapeString:typeof this.__escapeString==="function"?e=>this.__escapeString(e):null
51
+ escapeString:typeof this.#escapeString==="function"?e=>this.#escapeString(e):null
42
52
  }
43
53
  }
44
54
  /**
@@ -49,7 +59,7 @@ class Connect
49
59
  model(tabla)
50
60
  {
51
61
 
52
- return this.__models[tabla] instanceof dbTablaModel?this.__models[tabla]:false
62
+ return this.#models[tabla] instanceof dbTablaModel?this.#models[tabla]:false
53
63
  }
54
64
  /**
55
65
  * agrega un modelo a la lista de modelos interna
@@ -59,11 +69,11 @@ class Connect
59
69
  {
60
70
  if(model instanceof dbTablaModel)
61
71
  {
62
- this.__models[model.tabla]=model
72
+ this.#models[model.tabla]=model
63
73
  }else if(typeof model==="object" && model!==null){
64
- this.__models[model.tabla]= new dbTablaModel(model.tabla,model)
74
+ this.#models[model.tabla]= new dbTablaModel(model.tabla,model)
65
75
  }else {
66
- this.__models[model.tabla]= new dbTablaModel(model,this.helpersConf().escapeChar)
76
+ this.#models[model.tabla]= new dbTablaModel(model,this.helpersConf().escapeChar)
67
77
  }
68
78
 
69
79
  }
@@ -113,12 +123,12 @@ class Connect
113
123
  */
114
124
  tabla(tabla,callback,verify=false)
115
125
  {
116
- if(typeof this.__caheTablas[tabla]!=="undefined")
126
+ if(typeof this.#caheTablas[tabla]!=="undefined")
117
127
  {
118
- typeof callback==="function"?callback(this.__caheTablas[tabla]):null
119
- return this.__caheTablas[tabla]
128
+ typeof callback==="function"?callback(this.#caheTablas[tabla]):null
129
+ return this.#caheTablas[tabla]
120
130
  }
121
- return this.__caheTablas[tabla] = new dbTabla({
131
+ return this.#caheTablas[tabla] = new dbTabla({
122
132
  tabla:tabla,
123
133
  connection:this,
124
134
  callback:callback,
@@ -149,7 +159,7 @@ class Connect
149
159
  * @param {string} table - nombre de la tabla
150
160
  * @return {Promise}
151
161
  */
152
- __keysInTable(table)
162
+ #keysInTable(table)
153
163
  {
154
164
  return new Promise((res)=>
155
165
  {
@@ -176,9 +186,11 @@ class Connect
176
186
  rej()
177
187
  }else
178
188
  {
189
+
179
190
  if(create)
180
191
  {
181
- this.__createTable(this.model(tabla))
192
+
193
+ this.#createTable(this.model(tabla))
182
194
  .then(res).catch(rej)
183
195
  }else
184
196
  {
@@ -194,49 +206,54 @@ class Connect
194
206
  * @param {dbTablaModel} model - objeto del modelo
195
207
  * @return {Promise}
196
208
  */
197
- __createTable(model)
209
+ #createTable(model)
198
210
  {
211
+
199
212
  return new Promise((res,rej)=>
200
213
  {
201
- this.__createdTables={}
214
+ this.#createdTables={}
202
215
  let rescursive=(foreingKey,i)=>
203
216
  {
217
+
204
218
  if(foreingKey[i]!==undefined)
205
219
  {
206
220
  try
207
221
  {
208
222
  this.tabla(foreingKey[i].reference,(t)=>
209
223
  {
210
- if(this.__createdTables[foreingKey[i].reference])
211
- this.__initializeTable(t).then(()=>
212
- {
213
- i++
214
- rescursive(foreingKey,i)
215
- }).catch(rej)
224
+ rescursive(foreingKey,++i)
216
225
  },true)
217
226
  }catch(e){rej(e)}
218
227
  }else {
228
+
219
229
  this.query(model.sql(this)).then(()=>{
220
- this.__createdTables[model.tabla]=true
221
- res(model.getData())
230
+ this.#createdTables[model.tabla]=true
231
+ this.#initializeTable(model.tabla).then(()=>
232
+ {
233
+
234
+ res(model.getData())
235
+ }).catch(rej)
222
236
  }).catch(rej)
223
237
  }
224
238
  }
225
239
  rescursive(model.foreingKey(),0)
226
240
  })
227
241
  }
228
- __initializeTable(tab)
242
+ #initializeTable(tab)
229
243
  {
230
244
  return new Promise(async(res)=>
231
245
  {
232
- let init=this.model(tab.tabla).getData().init
246
+
247
+ let sql=new procesingSql(this.model(tab).getData(),this.helpersConf())
248
+ let init=this.model(tab).getData().init
249
+
233
250
  if(init.length<1)
234
251
  {
235
252
  return res()
236
253
  }
237
254
  for(let item of init)
238
255
  {
239
- await tab.insert(item)
256
+ await this.query(sql.insert(item))
240
257
  }
241
258
  res()
242
259
 
package/lib/dbResult.js CHANGED
@@ -20,9 +20,9 @@ class dbResult extends Array
20
20
  Object.defineProperty(this, "$sql", {
21
21
  configurable : true,
22
22
  enumerable : false,
23
- value : dbTabla.__lastSql,
23
+ value : dbTabla.lastSql,
24
24
  })
25
- //this.sql=dbTabla.__lastSql
25
+ //this.sql=dbTabla.lastSql
26
26
  }
27
27
  }
28
28
  module.exports=dbResult
package/lib/dbTabla.js CHANGED
@@ -5,23 +5,30 @@ const dbTablaError = require("./dbTablaError")
5
5
  * dbTabla
6
6
  * representacion de una tabla en la base de datos
7
7
  */
8
- class dbTabla
9
- {
8
+ class dbTabla {
9
+ #connection;
10
+ #lastSql;
11
+ #keys;
12
+ #callbackKey;
13
+ #config;
14
+
15
+ get lastSql() { return this.#lastSql; }
16
+
10
17
  /**
11
18
  * @param {object} tabla, connection, callback, config
12
19
  * @param {boolean} ret indica si verificara la existencia de la tabla o esperara la primera consulta
13
20
  */
14
21
  constructor({tabla,connection,callback,config},ret=false)
15
22
  {
16
- this.__connection=connection
17
- this.__lastSql=""
18
- this.__keys=false
23
+ this.#connection=connection
24
+ this.#lastSql=""
25
+ this.#keys=false
19
26
  this.tabla=tabla || null
20
- this.__callbackKey=callback ||( e=>e)
21
- this.__config=config || {}
27
+ this.#callbackKey=callback ||( e=>e)
28
+ this.#config=config || {}
22
29
  this.typeDB=connection.typeDB
23
30
  if(ret)
24
- this.__verifyKeys()
31
+ this.#verifyKeys()
25
32
  }
26
33
  /**
27
34
  * agrega la propiedad $sql que continen
@@ -29,13 +36,13 @@ class dbTabla
29
36
  * @param {object}
30
37
  * @return {object}
31
38
  */
32
- __PropertyOk(ok)
39
+ #PropertyOk(ok)
33
40
  {
34
41
  if(typeof ok ==="object")
35
42
  Object.defineProperty(ok, "$sql", {
36
43
  configurable : true,
37
44
  enumerable : false,
38
- value : this.__lastSql,
45
+ value : this.#lastSql,
39
46
  })
40
47
  return ok
41
48
  }
@@ -43,28 +50,28 @@ class dbTabla
43
50
  * verifica la existencia de la tabla y obtiene los metadatos
44
51
  * @param {function} call
45
52
  */
46
- __verifyKeys(call=e=>e)
53
+ #verifyKeys(call=e=>e)
47
54
  {
48
- if(!this.__keys)
55
+ if(!this.#keys)
49
56
  {
50
- this.__connection.__keysInTable(this.tabla)
57
+ this.#connection.__keysInTable(this.tabla)
51
58
  .then(keys=>
52
59
  {
53
60
  this.colum=keys.colum
54
- this.sql=new procesingSql(keys, this.__config)
55
- this.__keys=true
61
+ this.sql=new procesingSql(keys, this.#config)
62
+ this.#keys=true
56
63
  if(keys.methods)
57
64
  for(let i in keys.methods)
58
65
  {
59
- this[i]=(...params)=>keys.methods[i](this,this.__connection,...params)
66
+ this[i]=(...params)=>keys.methods[i](this,this.#connection,...params)
60
67
  }
61
68
 
62
- this.__callbackKey(this)
69
+ this.#callbackKey(this)
63
70
  call()
64
71
  }).catch(e=>{
65
72
 
66
73
 
67
- this.__callbackKey(null,e)
74
+ this.#callbackKey(null,e)
68
75
  call(e)
69
76
 
70
77
 
@@ -79,7 +86,7 @@ class dbTabla
79
86
  * @param {array|object} resultado obtenido de la consulta ejecutada
80
87
  * @return {dbResult}
81
88
  */
82
- __formatResult(result)
89
+ #formatResult(result)
83
90
  {
84
91
  return new dbResult(this,result)
85
92
  }
@@ -99,7 +106,7 @@ class dbTabla
99
106
  return new Promise((resolve,reject)=>
100
107
  {
101
108
 
102
- this.__verifyKeys(e=>
109
+ this.#verifyKeys(e=>
103
110
  {
104
111
  if(e)
105
112
  {
@@ -107,14 +114,14 @@ class dbTabla
107
114
  }
108
115
  if(params instanceof Array && params.length==1)
109
116
  {
110
- this.__lastSql=this.sql.insert(params[0])
117
+ this.#lastSql=this.sql.insert(params[0])
111
118
  }else {
112
- this.__lastSql=this.sql.insert(params)
119
+ this.#lastSql=this.sql.insert(params)
113
120
  }
114
121
 
115
- this.__connection.query(this.__lastSql).then(d=>{
122
+ this.#connection.query(this.#lastSql).then(d=>{
116
123
 
117
- resolve(this.__PropertyOk(d))
124
+ resolve(this.#PropertyOk(d))
118
125
  }).catch(e=>reject(e))
119
126
  })
120
127
  })
@@ -151,15 +158,15 @@ class dbTabla
151
158
  {
152
159
  return new Promise((resolve,reject)=>
153
160
  {
154
- this.__verifyKeys(e=>
161
+ this.#verifyKeys(e=>
155
162
  {
156
163
  if(e)
157
164
  {
158
165
  return reject(e)
159
166
  }
160
- this.__lastSql = this.sql.select(...params)
161
- this.__connection.query(this.__lastSql).then(d=>{
162
- resolve(this.__formatResult(d))
167
+ this.#lastSql = this.sql.select(...params)
168
+ this.#connection.query(this.#lastSql).then(d=>{
169
+ resolve(this.#formatResult(d))
163
170
  }).catch(e=>reject(e))
164
171
  })
165
172
 
@@ -271,11 +278,11 @@ class dbTabla
271
278
  {
272
279
  return new Promise((resolve,reject)=>
273
280
  {
274
- this.__verifyKeys(()=>
281
+ this.#verifyKeys(()=>
275
282
  {
276
- this.__lastSql = this.sql.busqueda(cadena,campo_bus,campos,where,joins,group,having,order,limit)
277
- this.__connection.query(this.__lastSql).then(d=>{
278
- 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))
279
286
  }).catch(e=>reject(e))
280
287
  })
281
288
 
@@ -324,18 +331,18 @@ class dbTabla
324
331
  }
325
332
  return new Promise((resolve,reject)=>
326
333
  {
327
- this.__verifyKeys(e=>
334
+ this.#verifyKeys(e=>
328
335
  {
329
336
  if(e)
330
337
  {
331
338
  return reject(e)
332
339
  }
333
- this.__lastSql =this.sql.update(sets,where,reject)
334
- if( this.__lastSql)
340
+ this.#lastSql =this.sql.update(sets,where,reject)
341
+ if( this.#lastSql)
335
342
  {
336
- this.__connection.query(this.__lastSql).then(d=>{
343
+ this.#connection.query(this.#lastSql).then(d=>{
337
344
 
338
- resolve(this.__PropertyOk(d))
345
+ resolve(this.#PropertyOk(d))
339
346
  }).catch(e=>reject(e))
340
347
  }
341
348
  })
@@ -377,16 +384,16 @@ class dbTabla
377
384
  }
378
385
  return new Promise((resolve,reject)=>
379
386
  {
380
- this.__verifyKeys(e=>
387
+ this.#verifyKeys(e=>
381
388
  {
382
389
  if(e)
383
390
  {
384
391
  return reject(e)
385
392
  }
386
- this.__lastSql =this.sql.delete(where)
387
- this.__connection.query(this.__lastSql).then(d=>{
393
+ this.#lastSql =this.sql.delete(where)
394
+ this.#connection.query(this.#lastSql).then(d=>{
388
395
 
389
- resolve(this.__PropertyOk(d))
396
+ resolve(this.#PropertyOk(d))
390
397
  }).catch(e=>reject(e))
391
398
  })
392
399
  })
@@ -4,8 +4,8 @@ const SQLITE3_DB=require("./const").SQLITE3_DB
4
4
  * prosesingSql
5
5
  * crea consultas sql insert, select, update, delete validas para una tabla
6
6
  */
7
- class prosesingSql
8
- {
7
+ class prosesingSql {
8
+ #helpers;
9
9
  /**
10
10
  *
11
11
  * @param {object} colum, prymary, autoincrement, OrderColum, TypeDB - metadadtos de la tabla
@@ -14,7 +14,7 @@ class prosesingSql
14
14
  constructor(keys,config)
15
15
  {
16
16
  this.tabla=keys.tabla
17
- this.__helpers=new dbHelpers(config)
17
+ this.#helpers=new dbHelpers(config)
18
18
  this.colums=keys.colums
19
19
  this.primary=this.colums.filter(p=>p.primary)
20
20
  let auto=this.colums.find(p=>p.autoincrement)
@@ -116,26 +116,26 @@ class prosesingSql
116
116
  {
117
117
  campo_bus=this.OrderColum
118
118
  }
119
- let search=this.__campoBusqueda(this.__helpers.filterSqlI(cadena),campo_bus)
120
- let params=this.__resolveParamsSelect(campos,joins,where,group,having,order,limit)
119
+ let search=this.#campoBusqueda(this.#helpers.filterSqlI(cadena),campo_bus)
120
+ let params=this.#resolveParamsSelect(campos,joins,where,group,having,order,limit)
121
121
  let arrSql=[],
122
- arrJoin=this.__join(params.joins),
123
- w=this.__booleanSql("WHERE",params.where),
124
- g=this.__groupBy(params.group),
125
- h=this.__booleanSql("HAVING",params.having),
126
- o=this.__orderBy(params.order),
127
- l=this.__limit(params.limit)
122
+ arrJoin=this.#join(params.joins),
123
+ w=this.#booleanSql("WHERE",params.where),
124
+ g=this.#groupBy(params.group),
125
+ h=this.#booleanSql("HAVING",params.having),
126
+ o=this.#orderBy(params.order),
127
+ l=this.#limit(params.limit)
128
128
 
129
129
  if(!w)
130
130
  {
131
- w=this.__booleanSql("WHERE",`(${search})>1`)
131
+ w=this.#booleanSql("WHERE",`(${search})>1`)
132
132
  }else {
133
133
 
134
- w =this.__booleanSql("WHERE",`(${w.replace(/^[\s]*where[\s]+(.*)/i,"$1")}) AND (${search})>1`)
134
+ w =this.#booleanSql("WHERE",`(${w.replace(/^[\s]*where[\s]+(.*)/i,"$1")}) AND (${search})>1`)
135
135
  }
136
136
  if(!o)
137
137
  {
138
- o = this.__orderBy("puntaje_busqueda DESC")
138
+ o = this.#orderBy("puntaje_busqueda DESC")
139
139
  }
140
140
  if(params.campos instanceof Array)
141
141
  {
@@ -143,9 +143,9 @@ class prosesingSql
143
143
  }else{
144
144
  params.campos=[`(${search}) as puntaje_busqueda`,this.tabla + ".*"]
145
145
  }
146
- arrSql.push(this.__campos(params.campos))
146
+ arrSql.push(this.#campos(params.campos))
147
147
  arrSql.push("FROM")
148
- arrSql.push(this.__helpers.protectIdentifiers(this.tabla))
148
+ arrSql.push(this.#helpers.protectIdentifiers(this.tabla))
149
149
  if(arrJoin.length>0)
150
150
  arrSql.push(arrJoin.join(" "))
151
151
  if(w)
@@ -166,7 +166,7 @@ class prosesingSql
166
166
  * @param {array} campos en los que se realizara la busqueda
167
167
  * @return {string}
168
168
  */
169
- __campoBusqueda(cadena, campos)
169
+ #campoBusqueda(cadena, campos)
170
170
  {
171
171
  if (cadena instanceof Array)
172
172
  {
@@ -176,7 +176,7 @@ class prosesingSql
176
176
  let select = ""
177
177
  for(let i in campos)
178
178
  {
179
- let campo=this.__helpers.protectIdentifiers(campos[i])
179
+ let campo=this.#helpers.protectIdentifiers(campos[i])
180
180
  select+=`(${campo} is NOT NULL AND ${campo} like '%${cadena}%')+(${campo} is NOT NULL AND ${campo} like '${cadena}%')+`
181
181
  }
182
182
 
@@ -188,7 +188,7 @@ class prosesingSql
188
188
  continue
189
189
  for(let j in campos)
190
190
  {
191
- let campo =this.__helpers.protectIdentifiers(campos[j])
191
+ let campo =this.#helpers.protectIdentifiers(campos[j])
192
192
  select += `(${campo} is NOT NULL AND ${campo} like '%${palabra}%') + (${campo} is NOT NULL AND ${campo} like '${palabra}%')+`
193
193
 
194
194
  }
@@ -202,7 +202,7 @@ class prosesingSql
202
202
  select+="((CONCAT("
203
203
  for(let i in campos)
204
204
  {
205
- let campo=this.__helpers.protectIdentifiers(campos[i])
205
+ let campo=this.#helpers.protectIdentifiers(campos[i])
206
206
  let espace = !/[\d]+/.test(i) ? "''" : "' '"
207
207
  select+=`IF(${campo} IS NOT NULL,${campo},' '),${espace},`
208
208
  }
@@ -211,7 +211,7 @@ class prosesingSql
211
211
  } else if (campos.length == 1)
212
212
  {
213
213
  select+="(0)"
214
- campos[0] = this.__helpers.protectIdentifiers(campos[0])
214
+ campos[0] = this.#helpers.protectIdentifiers(campos[0])
215
215
  // solo=`* (IF(${campos[0]}='${cadena}',0,1))+(IF(${campos[0]}='${cadena}',1,0))`
216
216
  }
217
217
  } else
@@ -227,7 +227,7 @@ class prosesingSql
227
227
  */
228
228
  delete(where)
229
229
  {
230
- return `DELETE FROM ${this.__helpers.protectIdentifiers(this.tabla)} ${this.__booleanSql("WHERE",where)};`
230
+ return `DELETE FROM ${this.#helpers.protectIdentifiers(this.tabla)} ${this.#booleanSql("WHERE",where)};`
231
231
  }
232
232
  /**
233
233
  * genera una sentencia sql update valida
@@ -264,11 +264,11 @@ class prosesingSql
264
264
  data=this.bindDataSmt(i,sets[i])
265
265
  }else
266
266
  {
267
- data=this.__helpers.formatVarInsert(sets[i],i)
267
+ data=this.#helpers.formatVarInsert(sets[i],i)
268
268
  }
269
- col.push(this.__helpers.protectIdentifiers(i) +"="+ data)
269
+ col.push(this.#helpers.protectIdentifiers(i) +"="+ data)
270
270
  }
271
- return `UPDATE ${this.__helpers.protectIdentifiers(this.tabla)} SET ${col.join(",")} ${this.__booleanSql("WHERE",where)};`
271
+ return `UPDATE ${this.#helpers.protectIdentifiers(this.tabla)} SET ${col.join(",")} ${this.#booleanSql("WHERE",where)};`
272
272
  }
273
273
  /**
274
274
  * genera una sentencia insert sql valida
@@ -287,7 +287,7 @@ class prosesingSql
287
287
  {
288
288
  campos[coll.name]=this.nextAutoincrementValue
289
289
  }
290
- if(this.__verifyCampo(coll,campos[coll.name]))
290
+ if(this.#verifyCampo(coll,campos[coll.name]))
291
291
  {
292
292
  attrs.push(coll.name)
293
293
  if(this.smt)
@@ -295,7 +295,7 @@ class prosesingSql
295
295
  col.push(this.bindDataSmt(coll.name,campos[coll.name]))
296
296
  }else
297
297
  {
298
- col.push(this.__helpers.formatVarInsert(campos[coll.name],coll.name))
298
+ col.push(this.#helpers.formatVarInsert(campos[coll.name],coll.name))
299
299
  }
300
300
  }
301
301
  }
@@ -309,7 +309,7 @@ class prosesingSql
309
309
  {
310
310
  campos[i]=this.nextAutoincrementValue
311
311
  }
312
- if(this.__verifyCampo(coll,campos[i]))
312
+ if(this.#verifyCampo(coll,campos[i]))
313
313
  {
314
314
  attrs.push(coll.name)
315
315
  if(this.smt)
@@ -317,7 +317,7 @@ class prosesingSql
317
317
  col.push(this.bindDataSmt(coll.name,campos[i]))
318
318
  }else
319
319
  {
320
- col.push(this.__helpers.formatVarInsert(campos[i],coll.name))
320
+ col.push(this.#helpers.formatVarInsert(campos[i],coll.name))
321
321
  }
322
322
  }
323
323
  }
@@ -325,13 +325,13 @@ class prosesingSql
325
325
  let columnas = ""
326
326
  if (attrs)
327
327
  {
328
- columnas = `(${this.__helpers.campos(attrs) })`
328
+ columnas = `(${this.#helpers.campos(attrs) })`
329
329
  }
330
- return `INSERT INTO ${this.__helpers.protectIdentifiers(this.tabla)} ${columnas} VALUES (${col.join(",")});`
330
+ return `INSERT INTO ${this.#helpers.protectIdentifiers(this.tabla)} ${columnas} VALUES (${col.join(",")});`
331
331
 
332
332
  }
333
333
 
334
- __verifyCampo(coll,value)
334
+ #verifyCampo(coll,value)
335
335
  {
336
336
  return !((
337
337
  (coll.autoincrement || coll.defaultNull) &&
@@ -398,18 +398,18 @@ class prosesingSql
398
398
  {
399
399
  let params=[]
400
400
 
401
- params=this.__resolveParamsSelect(campos,joins,where,group,having,order,limit)
401
+ params=this.#resolveParamsSelect(campos,joins,where,group,having,order,limit)
402
402
  let arrSql=[],
403
- arrJoin=this.__join(params.joins),
404
- w=this.__booleanSql("WHERE",params.where),
405
- g=this.__groupBy(params.group),
406
- h=this.__booleanSql("HAVING",params.having),
407
- o=this.__orderBy(params.order),
408
- l=this.__limit(params.limit)
409
-
410
- arrSql.push(this.__campos(params.campos))
403
+ arrJoin=this.#join(params.joins),
404
+ w=this.#booleanSql("WHERE",params.where),
405
+ g=this.#groupBy(params.group),
406
+ h=this.#booleanSql("HAVING",params.having),
407
+ o=this.#orderBy(params.order),
408
+ l=this.#limit(params.limit)
409
+
410
+ arrSql.push(this.#campos(params.campos))
411
411
  arrSql.push("FROM")
412
- arrSql.push(this.__helpers.protectIdentifiers(this.tabla))
412
+ arrSql.push(this.#helpers.protectIdentifiers(this.tabla))
413
413
  if(arrJoin.length>0)
414
414
  arrSql.push(arrJoin.join(" "))
415
415
  if(w)
@@ -434,7 +434,7 @@ class prosesingSql
434
434
  * es NATURAL
435
435
  * @return {string}
436
436
  */
437
- __join(join)
437
+ #join(join)
438
438
  {
439
439
  let J = []
440
440
  //let keys = this.OrderColum
@@ -454,21 +454,21 @@ class prosesingSql
454
454
  if(typeof v==="string" && /(!=|>=|<=|=|>|<)/.test(v))
455
455
  {
456
456
 
457
- let u=this.__helpers.protectIdentifiersBolean(v)
457
+ let u=this.#helpers.protectIdentifiersBolean(v)
458
458
  using = `ON(${u})`
459
459
  }else if( v instanceof Array)
460
460
  {
461
461
  for(let i in v)
462
462
  {
463
- v[i]=this.__helpers.protectIdentifiers(v[i])
463
+ v[i]=this.#helpers.protectIdentifiers(v[i])
464
464
  }
465
465
  let joined=v.join(",")
466
466
  using = `USING(${joined})`
467
467
  }else if(typeof v==="object")
468
468
  {
469
- using = `ON(${this.__helpers.object2boleandSql(v,true)})`
469
+ using = `ON(${this.#helpers.object2boleandSql(v,true)})`
470
470
  }else {
471
- using = `USING(${this.__helpers.protectIdentifiers(v)})`
471
+ using = `USING(${this.#helpers.protectIdentifiers(v)})`
472
472
  }
473
473
  }else
474
474
  {
@@ -495,7 +495,7 @@ class prosesingSql
495
495
 
496
496
  }
497
497
  //" " . $tipe . " JOIN " . $this->Driver->ProtectIdentifiers($tab->Tabla()) . " " . $using
498
- J.push(`${tipe} JOIN ${this.__helpers.protectIdentifiers(tabla)} ${using}`.replace(/ +$/,""))
498
+ J.push(`${tipe} JOIN ${this.#helpers.protectIdentifiers(tabla)} ${using}`.replace(/ +$/,""))
499
499
 
500
500
  }
501
501
  }
@@ -508,11 +508,11 @@ class prosesingSql
508
508
  * @param {string|object} sql
509
509
  * @return {string}
510
510
  */
511
- __booleanSql(type,sql)
511
+ #booleanSql(type,sql)
512
512
  {
513
513
  if (typeof sql==="object" && sql!==null)
514
514
  {
515
- return type+" " +this.__helpers.object2boleandSql(sql)
515
+ return type+" " +this.#helpers.object2boleandSql(sql)
516
516
  }else if(sql!==undefined && sql!==null)
517
517
  {
518
518
  return type+" " +sql.replace(new RegExp(`^[\\s]*${type}[\\s]+(.*)`,"i"),"$1")
@@ -525,20 +525,20 @@ class prosesingSql
525
525
  * @param {array} campos - lista de campos
526
526
  * @return {string}
527
527
  */
528
- __campos(campos)
528
+ #campos(campos)
529
529
  {
530
530
  if (!(campos instanceof Array) || campos===[])
531
531
  {
532
- return this.__helpers.campos([ this.tabla + ".*"])
532
+ return this.#helpers.campos([ this.tabla + ".*"])
533
533
  }
534
- return this.__helpers.campos(campos)
534
+ return this.#helpers.campos(campos)
535
535
  }
536
536
  /**
537
537
  * genera el sql para pa el group by de una sentencia select
538
538
  * @param {array|string} group - lista de campos
539
539
  * @return {string}
540
540
  */
541
- __groupBy(group)
541
+ #groupBy(group)
542
542
  {
543
543
  if (group instanceof Array)
544
544
  {
@@ -557,7 +557,7 @@ class prosesingSql
557
557
  * @param {array|string} order - lista de campos
558
558
  * @return {string}
559
559
  */
560
- __orderBy(order)
560
+ #orderBy(order)
561
561
  {
562
562
  if (order instanceof Array)
563
563
  {
@@ -576,7 +576,7 @@ class prosesingSql
576
576
  * @param {array|string} limit - lista de campos
577
577
  * @return {string}
578
578
  */
579
- __limit(limit)
579
+ #limit(limit)
580
580
  {
581
581
  if(/^[\s]*LIMIT[\s]+/i.test(limit))
582
582
  {
@@ -599,7 +599,7 @@ class prosesingSql
599
599
  * @param {array|string|object} limit
600
600
  * @return {object} - parametros
601
601
  */
602
- __resolveParamsSelect(campos,joins,where,group,having,order,limit)
602
+ #resolveParamsSelect(campos,joins,where,group,having,order,limit)
603
603
  {
604
604
  if(typeof campos==="object" && campos!==null && !(campos instanceof Array) &&
605
605
  ( campos.campos!==undefined
package/license CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018 Enyerber Franco (enyerverfranco@gmial.com) and contributors
1
+ Copyright (c) 2018 Enyerber Franco (enyerverfranco@gmail.com) and contributors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbtabla",
3
- "version": "0.8.7",
3
+ "version": "2.0.0",
4
4
  "description": "interface de alto nivel para sql",
5
5
  "license": "MIT",
6
6
  "author": "enyerverfranco@gmail.com",
@@ -11,7 +11,7 @@
11
11
  "main": "index.js",
12
12
  "scripts": {
13
13
  "lint": "eslint ./index.js ./lib",
14
- "test": "mocha ./test/index.js"
14
+ "test": "node --test ./test/index.js"
15
15
  },
16
16
  "keywords": [
17
17
  "sql",
@@ -20,10 +20,14 @@
20
20
  "posgresql"
21
21
  ],
22
22
  "devDependencies": {
23
- "eslint": "^5.9.0",
24
- "mocha": "^5.2.0"
23
+ "@eslint/js": "^10.0.1",
24
+ "eslint": "^10.1.0",
25
+ "globals": "^17.4.0"
25
26
  },
26
27
  "dependencies": {
27
- "tabla-model": "^1.0.3"
28
+ "tabla-model": "^2.0.0"
29
+ },
30
+ "engines": {
31
+ "node": ">=18.0.0"
28
32
  }
29
- }
33
+ }
@@ -0,0 +1,36 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const libDir = 'c:/programacion/dbtabla/dbtabla/lib';
5
+
6
+ // 1. Refactor Connect.js
7
+ let connectFile = path.join(libDir, 'Connect.js');
8
+ let connectCode = fs.readFileSync(connectFile, 'utf8');
9
+ connectCode = connectCode.replace(/class Connect\s*\{/, 'class Connect {\n #escapeChar;\n #reserveIdentifiers;\n #ar_aliased_tables;\n #dbprefix;\n #swap_pre;\n #information_schema;\n #models;\n #caheTablas;\n #createdTables;\n #escapeString;');
10
+ connectCode = connectCode.replace(/this\.__/g, 'this.#');
11
+ connectCode = connectCode.replace(/^(\s*)__([a-zA-Z0-9_]+)\s*\(/gm, '$1#$2(');
12
+ fs.writeFileSync(connectFile, connectCode);
13
+
14
+ // 2. Refactor dbTabla.js
15
+ let dbTablaFile = path.join(libDir, 'dbTabla.js');
16
+ let dbTablaCode = fs.readFileSync(dbTablaFile, 'utf8');
17
+ dbTablaCode = dbTablaCode.replace(/class dbTabla\s*\{/, 'class dbTabla {\n #connection;\n #lastSql;\n #keys;\n #callbackKey;\n #config;\n\n get lastSql() { return this.#lastSql; }\n');
18
+ dbTablaCode = dbTablaCode.replace(/this\.__/g, 'this.#');
19
+ dbTablaCode = dbTablaCode.replace(/^(\s*)__([a-zA-Z0-9_]+)\s*\(/gm, '$1#$2(');
20
+ fs.writeFileSync(dbTablaFile, dbTablaCode);
21
+
22
+ // 3. Refactor procesingSql.js
23
+ let procesingSqlFile = path.join(libDir, 'procesingSql.js');
24
+ let procesingSqlCode = fs.readFileSync(procesingSqlFile, 'utf8');
25
+ procesingSqlCode = procesingSqlCode.replace(/class prosesingSql\s*\{/, 'class prosesingSql {\n #helpers;');
26
+ procesingSqlCode = procesingSqlCode.replace(/this\.__/g, 'this.#');
27
+ procesingSqlCode = procesingSqlCode.replace(/^(\s*)__([a-zA-Z0-9_]+)\s*\(/gm, '$1#$2(');
28
+ fs.writeFileSync(procesingSqlFile, procesingSqlCode);
29
+
30
+ // 4. Refactor dbResult.js (read exposed property)
31
+ let dbResultFile = path.join(libDir, 'dbResult.js');
32
+ let dbResultCode = fs.readFileSync(dbResultFile, 'utf8');
33
+ dbResultCode = dbResultCode.replace(/dbTabla\.__lastSql/g, 'dbTabla.lastSql');
34
+ fs.writeFileSync(dbResultFile, dbResultCode);
35
+
36
+ console.log('Refactoring completed successfully.');