mielk-api 1.2.1 → 1.3.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.
@@ -0,0 +1,5 @@
1
+ import { RawData } from 'msnodesqlv8/types';
2
+ import { DbConfig } from '../types/DbConfig.js';
3
+ export declare const initDb: (dbConfig: DbConfig) => void;
4
+ export declare const query: (queryText: string) => Promise<any[]>;
5
+ export declare const spExecute: (sqlText: string, params: MsNodeSqlV8.sqlQueryParamType[]) => Promise<RawData | undefined>;
@@ -0,0 +1,33 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import sql from 'msnodesqlv8';
3
+ let connectionString = '';
4
+ export const initDb = (dbConfig) => {
5
+ const { host, database, user, password, driver } = dbConfig;
6
+ connectionString = `Server=${host};Database=${database};UID=${user};PWD=${password};Driver=${driver}`;
7
+ };
8
+ export const query = (queryText) => {
9
+ return new Promise((resolve, reject) => {
10
+ sql.query(connectionString, queryText, (err, rows) => {
11
+ if (err)
12
+ reject(err);
13
+ if (rows === undefined)
14
+ reject();
15
+ else
16
+ resolve(rows);
17
+ });
18
+ });
19
+ };
20
+ export const spExecute = (sqlText, params) => {
21
+ return new Promise((resolve, reject) => {
22
+ sql.open(connectionString, (err, conn) => {
23
+ if (err)
24
+ return reject(err);
25
+ conn.queryRaw(sqlText, params, (err, results) => {
26
+ if (err)
27
+ reject(err);
28
+ else
29
+ resolve(results);
30
+ });
31
+ });
32
+ });
33
+ };
@@ -1 +1,4 @@
1
- export {};
1
+ import { initDb, query, spExecute } from './connection/pool.js';
2
+ import { DbConfig } from './types/DbConfig.js';
3
+ export { initDb, query, spExecute };
4
+ export { DbConfig };
@@ -1 +1,2 @@
1
- export {};
1
+ import { initDb, query, spExecute } from './connection/pool.js';
2
+ export { initDb, query, spExecute };
@@ -0,0 +1,7 @@
1
+ export interface DbConfig {
2
+ host: string;
3
+ database: string;
4
+ user: string;
5
+ password: string;
6
+ driver: string;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,15 +1,15 @@
1
1
  const PARENT_FOLDER = 'api/';
2
- const ___API_STATUS___ = `${PARENT_FOLDER}/ApiStatus`;
3
- const ___CONNECTION___ = `${PARENT_FOLDER}/Connection`;
2
+ const ___HTTP_STATUS___ = `${PARENT_FOLDER}/httpStatus`;
3
+ const ___CONNECTION___ = `${PARENT_FOLDER}/connection`;
4
4
  export const Msg = {
5
5
  apiStatus: {
6
- ok: `${___API_STATUS___}:ok`,
7
- created: `${___API_STATUS___}:created`,
8
- unauthorized: `${___API_STATUS___}:unauthorized`,
9
- badRequest: `${___API_STATUS___}:badRequest`,
10
- notFound: `${___API_STATUS___}:notFound`,
11
- conflict: `${___API_STATUS___}:conflict`,
12
- serverError: `${___API_STATUS___}:serverError`,
6
+ ok: `${___HTTP_STATUS___}:ok`,
7
+ created: `${___HTTP_STATUS___}:created`,
8
+ unauthorized: `${___HTTP_STATUS___}:unauthorized`,
9
+ badRequest: `${___HTTP_STATUS___}:badRequest`,
10
+ notFound: `${___HTTP_STATUS___}:notFound`,
11
+ conflict: `${___HTTP_STATUS___}:conflict`,
12
+ serverError: `${___HTTP_STATUS___}:serverError`,
13
13
  },
14
14
  connection: {
15
15
  corsBlocked: `${___CONNECTION___}:corsBlocked`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mielk-api",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "keywords": [],
5
5
  "author": "mielk",
6
6
  "description": "Wrapper for API operations",
@@ -77,6 +77,7 @@
77
77
  "dependencies": {
78
78
  "cors": "^2.8.6",
79
79
  "mielk-fn": "^1.1.1",
80
+ "msnodesqlv8": "^5.1.3",
80
81
  "pg": "^8.20.0",
81
82
  "tunnel-ssh": "^5.2.0"
82
83
  }