@adtrackify/at-service-common 3.0.41 → 3.0.42

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.
@@ -5,3 +5,4 @@ export * from './s3-client.js';
5
5
  export * from './cognito-client.js';
6
6
  export * from './sqs-client.js';
7
7
  export * from './location-client.js';
8
+ export * from './singlestore-db-client.js';
@@ -21,4 +21,5 @@ __exportStar(require("./s3-client.js"), exports);
21
21
  __exportStar(require("./cognito-client.js"), exports);
22
22
  __exportStar(require("./sqs-client.js"), exports);
23
23
  __exportStar(require("./location-client.js"), exports);
24
+ __exportStar(require("./singlestore-db-client.js"), exports);
24
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/clients/generic/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,0DAAwC;AACxC,mDAAiC;AACjC,iDAA+B;AAC/B,sDAAoC;AACpC,kDAAgC;AAChC,uDAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/clients/generic/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,0DAAwC;AACxC,mDAAiC;AACjC,iDAA+B;AAC/B,sDAAoC;AACpC,kDAAgC;AAChC,uDAAqC;AACrC,6DAA2C"}
@@ -0,0 +1,14 @@
1
+ import * as mysql from 'mysql2/promise';
2
+ export declare const getPool: () => mysql.Pool;
3
+ export declare class SingleStoreDBClient {
4
+ conn: mysql.Connection;
5
+ constructor();
6
+ private getConnection;
7
+ executeQuery(query: string, values?: any): Promise<{
8
+ rows: mysql.QueryResult;
9
+ success: boolean;
10
+ } | {
11
+ success: boolean;
12
+ rows?: undefined;
13
+ }>;
14
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.SingleStoreDBClient = exports.getPool = void 0;
27
+ const mysql = __importStar(require("mysql2/promise"));
28
+ const helpers_1 = require("../../helpers");
29
+ const host = process.env.SINGLESTORE_HOST;
30
+ const user = process.env.SINGLESTORE_USER;
31
+ const password = process.env.SINGLESTORE_PASSWORD;
32
+ const database = process.env.SINGLESTORE_DATABASE;
33
+ const port = process.env.PORT;
34
+ const getPool = () => {
35
+ let pool = null;
36
+ pool = mysql.createPool({
37
+ host: host,
38
+ port: +port,
39
+ user: user,
40
+ password: password,
41
+ database: database,
42
+ multipleStatements: true,
43
+ });
44
+ return pool;
45
+ };
46
+ exports.getPool = getPool;
47
+ const _pool = (0, exports.getPool)();
48
+ class SingleStoreDBClient {
49
+ conn;
50
+ constructor() {
51
+ if (!host || !user || !password || !database || !port) {
52
+ throw new Error('SingleStore env values not found');
53
+ }
54
+ }
55
+ async getConnection() {
56
+ return _pool;
57
+ }
58
+ async executeQuery(query, values) {
59
+ try {
60
+ const pool = await this.getConnection();
61
+ helpers_1.Logger.debug('executing query', { query, values });
62
+ const [rows, fields] = await pool.query(query, values);
63
+ helpers_1.Logger.debug('query response', { rows, fields });
64
+ return { rows, success: true };
65
+ }
66
+ catch (error) {
67
+ helpers_1.Logger.error('Error executing query', { query, error });
68
+ return { success: false };
69
+ }
70
+ }
71
+ }
72
+ exports.SingleStoreDBClient = SingleStoreDBClient;
73
+ //# sourceMappingURL=singlestore-db-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singlestore-db-client.js","sourceRoot":"","sources":["../../../../src/clients/generic/singlestore-db-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,2CAAuC;AAEvC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAc,CAAC;AAEjC,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;QACtB,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,CAAC,IAAI;QACX,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ;QAClB,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAXW,QAAA,OAAO,WAWlB;AAEF,MAAM,KAAK,GAAG,IAAA,eAAO,GAAE,CAAC;AAExB,MAAa,mBAAmB;IAC9B,IAAI,CAAoB;IAExB;QACE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;IACH,CAAC;IAEO,KAAK,CAAC,aAAa;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,MAAY;QAC5C,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACxC,gBAAM,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YACnD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACvD,gBAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAEjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;SAChC;QAAC,OAAO,KAAK,EAAE;YACd,gBAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACxD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;SAC3B;IACH,CAAC;CACF;AA1BD,kDA0BC"}
@@ -5,3 +5,4 @@ export * from './s3-client.js';
5
5
  export * from './cognito-client.js';
6
6
  export * from './sqs-client.js';
7
7
  export * from './location-client.js';
8
+ export * from './singlestore-db-client.js';
@@ -5,4 +5,5 @@ export * from './s3-client.js';
5
5
  export * from './cognito-client.js';
6
6
  export * from './sqs-client.js';
7
7
  export * from './location-client.js';
8
+ export * from './singlestore-db-client.js';
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/clients/generic/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/clients/generic/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import * as mysql from 'mysql2/promise';
2
+ export declare const getPool: () => mysql.Pool;
3
+ export declare class SingleStoreDBClient {
4
+ conn: mysql.Connection;
5
+ constructor();
6
+ private getConnection;
7
+ executeQuery(query: string, values?: any): Promise<{
8
+ rows: mysql.QueryResult;
9
+ success: boolean;
10
+ } | {
11
+ success: boolean;
12
+ rows?: undefined;
13
+ }>;
14
+ }
@@ -0,0 +1,45 @@
1
+ import * as mysql from 'mysql2/promise';
2
+ import { Logger } from '../../helpers';
3
+ const host = process.env.SINGLESTORE_HOST;
4
+ const user = process.env.SINGLESTORE_USER;
5
+ const password = process.env.SINGLESTORE_PASSWORD;
6
+ const database = process.env.SINGLESTORE_DATABASE;
7
+ const port = process.env.PORT;
8
+ export const getPool = () => {
9
+ let pool = null;
10
+ pool = mysql.createPool({
11
+ host: host,
12
+ port: +port,
13
+ user: user,
14
+ password: password,
15
+ database: database,
16
+ multipleStatements: true,
17
+ });
18
+ return pool;
19
+ };
20
+ const _pool = getPool();
21
+ export class SingleStoreDBClient {
22
+ conn;
23
+ constructor() {
24
+ if (!host || !user || !password || !database || !port) {
25
+ throw new Error('SingleStore env values not found');
26
+ }
27
+ }
28
+ async getConnection() {
29
+ return _pool;
30
+ }
31
+ async executeQuery(query, values) {
32
+ try {
33
+ const pool = await this.getConnection();
34
+ Logger.debug('executing query', { query, values });
35
+ const [rows, fields] = await pool.query(query, values);
36
+ Logger.debug('query response', { rows, fields });
37
+ return { rows, success: true };
38
+ }
39
+ catch (error) {
40
+ Logger.error('Error executing query', { query, error });
41
+ return { success: false };
42
+ }
43
+ }
44
+ }
45
+ //# sourceMappingURL=singlestore-db-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singlestore-db-client.js","sourceRoot":"","sources":["../../../../src/clients/generic/singlestore-db-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,gBAA0B,CAAC;AACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAA8B,CAAC;AAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAc,CAAC;AAExC,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;QACtB,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,CAAC,IAAI;QACX,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ;QAClB,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC;AAExB,MAAM,OAAO,mBAAmB;IAC9B,IAAI,CAAoB;IAExB;QACE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;IACH,CAAC;IAEO,KAAK,CAAC,aAAa;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,MAAY;QAC5C,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACxC,MAAM,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YACnD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACvD,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAEjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;SAChC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACxD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;SAC3B;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adtrackify/at-service-common",
3
- "version": "3.0.41",
3
+ "version": "3.0.42",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist/*"
@@ -48,7 +48,8 @@
48
48
  "luxon": "^3.0.3",
49
49
  "postmark": "^3.0.14",
50
50
  "ua-parser-js": "^1.0.2",
51
- "uuid": "^9.0.0"
51
+ "uuid": "^9.0.0",
52
+ "mysql2": "^3.11.0"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@adtrackify/at-tracking-event-types": "^3.0.98",