@campxdev/server-shared 1.6.3 → 1.6.4

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.
@@ -1,4 +1,5 @@
1
1
  export * from './constants';
2
2
  export * from './mongoose-fn';
3
+ export * from './sql-fn';
3
4
  export * from './utils';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./constants"), exports);
18
18
  __exportStar(require("./mongoose-fn"), exports);
19
+ __exportStar(require("./sql-fn"), exports);
19
20
  __exportStar(require("./utils"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B;AAC9B,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B;AAC9B,2CAAyB;AACzB,0CAAwB"}
@@ -0,0 +1,8 @@
1
+ import { EntityManager } from 'typeorm';
2
+ export declare function createIndex(props: {
3
+ manager: EntityManager;
4
+ tableName: string;
5
+ indexName: string;
6
+ createQuery: string;
7
+ }): Promise<void>;
8
+ //# sourceMappingURL=sql-fn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-fn.d.ts","sourceRoot":"","sources":["../../src/utils/sql-fn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,wBAAsB,WAAW,CAAC,KAAK,EAAE;IACvC,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,iBAyBA"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIndex = void 0;
4
+ async function createIndex(props) {
5
+ const { manager, tableName, indexName, createQuery } = props;
6
+ const tableSchema = manager.connection.options.database;
7
+ if (!tableSchema) {
8
+ throw new Error('Table schema not found');
9
+ }
10
+ const indexExists = await manager
11
+ .query(`
12
+ select
13
+ count(*) as index_count
14
+ from information_schema.statistics
15
+ where table_schema = '${tableSchema}'
16
+ and table_name = '${tableName}'
17
+ and index_name = '${indexName}';
18
+ `)
19
+ .then((result) => Number(result[0]?.index_count ?? 0) > 0);
20
+ if (indexExists) {
21
+ await manager.query(`alter table ${tableName} drop index ${indexName};`);
22
+ }
23
+ await manager.query(createQuery);
24
+ }
25
+ exports.createIndex = createIndex;
26
+ //# sourceMappingURL=sql-fn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-fn.js","sourceRoot":"","sources":["../../src/utils/sql-fn.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,WAAW,CAAC,KAKjC;IACC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC;IACxD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,OAAO;SAC9B,KAAK,CACJ;;;;4BAIsB,WAAW;wBACf,SAAS;wBACT,SAAS;KAC5B,CACA;SACA,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7D,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,OAAO,CAAC,KAAK,CAAC,eAAe,SAAS,eAAe,SAAS,GAAG,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AA9BD,kCA8BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/server-shared",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "Campx server shared files",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",