@builderbot/database-mysql 1.0.16-alpha.0 → 1.0.17-alpha.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/dist/index.cjs CHANGED
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var mysql = require('mysql2');
4
+ var bot = require('@builderbot/bot');
4
5
 
5
- class MysqlAdapter {
6
+ class MysqlAdapter extends bot.MemoryDB {
6
7
  constructor(_credentials) {
8
+ super();
7
9
  this.listHistory = [];
8
10
  this.credentials = { host: null, user: null, database: null, password: null };
9
11
  this.getPrevByNumber = async (from) => {
10
- // TODO:pendiente valida _closing, lanza error
11
- // if (this.db._closing) await this.init()
12
12
  return await new Promise((resolve, reject) => {
13
13
  const sql = `SELECT * FROM history WHERE phone='${from}' ORDER BY id DESC`;
14
14
  this.db.query(sql, (error, rows) => {
@@ -21,7 +21,7 @@ class MysqlAdapter {
21
21
  resolve(row);
22
22
  }
23
23
  if (!rows.length) {
24
- resolve(null);
24
+ resolve({});
25
25
  }
26
26
  });
27
27
  });
@@ -34,14 +34,13 @@ class MysqlAdapter {
34
34
  this.db.query(sql, [values], (err) => {
35
35
  if (err)
36
36
  throw err;
37
- console.log('Guardado en DB...', values);
38
37
  });
39
38
  };
40
39
  this.createTable = () => new Promise((resolve) => {
41
40
  const tableName = 'history';
42
41
  const sql = `CREATE TABLE ${tableName}
43
42
  (id INT AUTO_INCREMENT PRIMARY KEY,
44
- ref varchar(255) NOT NULL,
43
+ ref varchar(255) DEFAULT NULL,
45
44
  keyword varchar(255) NULL,
46
45
  answer longtext NOT NULL,
47
46
  refSerialize varchar(255) NOT NULL,
@@ -52,7 +51,7 @@ class MysqlAdapter {
52
51
  this.db.query(sql, (err) => {
53
52
  if (err)
54
53
  throw err;
55
- console.log(`Tabla ${tableName} creada correctamente `);
54
+ console.log(`Table ${tableName} created successfully`);
56
55
  resolve(true);
57
56
  });
58
57
  });
@@ -72,13 +71,13 @@ class MysqlAdapter {
72
71
  }
73
72
  async init() {
74
73
  this.db = mysql.createConnection(this.credentials);
75
- await this.db.connect(async (error) => {
74
+ this.db.connect(async (error) => {
76
75
  if (!error) {
77
- console.log(`Solicitud de conexión a base de datos exitosa`);
76
+ console.log(`Successful database connection request`);
78
77
  await this.checkTableExists();
79
78
  }
80
79
  if (error) {
81
- console.log(`Solicitud de conexión fallida ${error.stack}`);
80
+ console.log(`Failed connection request ${error.stack}`);
82
81
  }
83
82
  });
84
83
  }
@@ -1,13 +1,14 @@
1
+ import { MemoryDB } from '@builderbot/bot';
1
2
  import { Connection } from 'mysql2';
2
3
 
3
4
  import { HistoryRow, MysqlAdapterCredentials } from './types';
4
- declare class MysqlAdapter {
5
+ declare class MysqlAdapter extends MemoryDB {
5
6
  db: Connection;
6
7
  listHistory: any[];
7
8
  credentials: MysqlAdapterCredentials;
8
9
  constructor(_credentials: MysqlAdapterCredentials);
9
10
  init(): Promise<void>;
10
- getPrevByNumber: (from: any) => Promise<HistoryRow | null>;
11
+ getPrevByNumber: (from: any) => Promise<HistoryRow>;
11
12
  save: (ctx: {
12
13
  ref: string;
13
14
  keyword: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mysqlAdapter.d.ts","sourceRoot":"","sources":["../src/mysqlAdapter.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAA2B,MAAM,QAAQ,CAAA;AAEnE,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAE7D,cAAM,YAAY;IACd,EAAE,EAAE,UAAU,CAAA;IACd,WAAW,QAAK;IAChB,WAAW,EAAE,uBAAuB,CAA6D;gBAErF,YAAY,EAAE,uBAAuB;IAK3C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAe3B,eAAe,SAAgB,GAAG,KAAG,QAAQ,UAAU,GAAG,IAAI,CAAC,CAoB9D;IAED,IAAI,QAAe;QACf,GAAG,EAAE,MAAM,CAAA;QACX,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,GAAG,CAAA;QACX,YAAY,EAAE,MAAM,CAAA;QACpB,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,GAAG,CAAA;KACf,KAAG,QAAQ,IAAI,CAAC,CAUhB;IAED,WAAW,QAAO,QAAQ,OAAO,CAAC,CAoB5B;IAEN,gBAAgB,QAAO,QAAQ,OAAO,CAAC,CAYjC;CACT;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"mysqlAdapter.d.ts","sourceRoot":"","sources":["../src/mysqlAdapter.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAA2B,MAAM,QAAQ,CAAA;AAEnE,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE1C,cAAM,YAAa,SAAQ,QAAQ;IAC/B,EAAE,EAAE,UAAU,CAAA;IACd,WAAW,QAAK;IAChB,WAAW,EAAE,uBAAuB,CAA6D;gBAErF,YAAY,EAAE,uBAAuB;IAM3C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAe3B,eAAe,SAAgB,GAAG,KAAG,QAAQ,UAAU,CAAC,CAiBvD;IAED,IAAI,QAAe;QACf,GAAG,EAAE,MAAM,CAAA;QACX,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,GAAG,CAAA;QACX,YAAY,EAAE,MAAM,CAAA;QACpB,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,GAAG,CAAA;KACf,KAAG,QAAQ,IAAI,CAAC,CAShB;IAED,WAAW,QAAO,QAAQ,OAAO,CAAC,CAoB5B;IAEN,gBAAgB,QAAO,QAAQ,OAAO,CAAC,CAYjC;CACT;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builderbot/database-mysql",
3
- "version": "1.0.16-alpha.0",
3
+ "version": "1.0.17-alpha.0",
4
4
  "description": "Esto es el conector a Mysql",
5
5
  "keywords": [],
6
6
  "author": "Leifer Mendez <leifer33@gmail.com>",
@@ -30,6 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
32
32
  "dependencies": {
33
+ "@builderbot/bot": "^1.0.17-alpha.0",
33
34
  "mysql2": "^2.3.3"
34
35
  },
35
36
  "devDependencies": {
@@ -45,5 +46,5 @@
45
46
  "tslib": "^2.6.2",
46
47
  "tsm": "^2.3.0"
47
48
  },
48
- "gitHead": "c4e161de0befb91b56a6c85866462abbaf462f43"
49
+ "gitHead": "b1b245c7a9733a9e9de1f8a92ff152ed42f4f501"
49
50
  }