@medyll/idae-db 0.82.0 → 0.83.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.
@@ -8,7 +8,7 @@ export interface IdaeDbAdapterInterface<T extends object> {
8
8
  find(params: IdaeDbParams<T>): Promise<T[]>;
9
9
  findOne(params: IdaeDbParams<T>): Promise<T | null>;
10
10
  update(id: string, updateData: Partial<T>): Promise<unknown>;
11
- updateWhere<OPT = unknown>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<unknown>;
11
+ updateWhere<OPT = never>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<unknown>;
12
12
  deleteById(id: string): Promise<unknown>;
13
13
  deleteWhere(params: IdaeDbParams<T>): Promise<{
14
14
  deletedCount?: number;
@@ -42,7 +42,7 @@ export declare abstract class AbstractIdaeDbAdapter<T extends object> implements
42
42
  abstract find(params: IdaeDbParams<T>): Promise<T[]>;
43
43
  abstract findOne(params: IdaeDbParams<T>): Promise<T | null>;
44
44
  abstract update(id: string, updateData: Partial<T>): Promise<unknown>;
45
- abstract updateWhere<OPT = unknown>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<unknown>;
45
+ abstract updateWhere<OPT = never>(params: IdaeDbParams<T>, updateData: Partial<T>, options?: OPT): Promise<unknown>;
46
46
  abstract deleteById(id: string): Promise<unknown>;
47
47
  abstract deleteWhere(params: IdaeDbParams<T>): Promise<{
48
48
  deletedCount?: number;
@@ -23,7 +23,7 @@ export declare class IdaeDbConnection {
23
23
  * @returns The database instance.
24
24
  * @throws Error if the database is not connected.
25
25
  */
26
- getDb(): any;
26
+ getDb(): {};
27
27
  /**
28
28
  * Gets the model for a collection.
29
29
  * @param collectionName The name of the collection.
@@ -1,5 +1,5 @@
1
1
  // packages\idae-db\lib\IdaeDbConnection.ts
2
- import { DbType } from './@types/types.js';
2
+ import { DbType, IdaeDbAdapterStaticMethods } from './@types/types.js';
3
3
  import { IdaeDBModel } from './IdaeDBModel.js';
4
4
  import { IdaeDb } from './idaeDb.js';
5
5
  /**
@@ -1,7 +1,7 @@
1
1
  import { AbstractIdaeDbAdapter, type IdaeDbParams } from '../@types/types.js';
2
2
  import { IdaeDbConnection } from '../IdaeDbConnection.js';
3
3
  import mysql from 'mysql2/promise';
4
- export declare class MySQLAdapter<T extends Record<string, any>> implements AbstractIdaeDbAdapter<T> {
4
+ export declare class MySQLAdapter<T extends Record<string, unknown>> implements AbstractIdaeDbAdapter<T> {
5
5
  private model;
6
6
  private connection;
7
7
  private fieldId;
@@ -11,12 +11,13 @@ export declare class MySQLAdapter<T extends Record<string, any>> implements Abst
11
11
  find(params: IdaeDbParams<T>): Promise<T[]>;
12
12
  findOne(params: IdaeDbParams<T>): Promise<T | null>;
13
13
  create(data: Partial<T>): Promise<T>;
14
- update(id: string, updateData: Partial<T>, options?: any): Promise<any>;
15
- updateWhere(params: IdaeDbParams<T>, updateData: Partial<T>, options?: any): Promise<any>;
16
- deleteById(id: string | number): Promise<any>;
14
+ update(id: string, updateData: Partial<T>, options?: unknown): Promise<unknown>;
15
+ updateWhere(params: IdaeDbParams<T>, updateData: Partial<T>, options?: unknown): Promise<unknown>;
16
+ deleteById(id: string | number): Promise<unknown>;
17
17
  deleteWhere(params: IdaeDbParams<T>): Promise<{
18
18
  deletedCount?: number;
19
19
  }>;
20
20
  transaction<TResult>(callback: (session: mysql.Connection) => Promise<TResult>): Promise<TResult>;
21
+ createIndex(fieldOrSpec: string, options?: unknown): Promise<string>;
21
22
  private parseSortOptions;
22
23
  }
@@ -59,6 +59,7 @@ export class MySQLAdapter {
59
59
  const insertId = result.insertId;
60
60
  return { ...data, [this.fieldId]: insertId };
61
61
  }
62
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
63
  async update(id, updateData, options) {
63
64
  const setClause = Object.keys(updateData)
64
65
  .map((key) => `${key} = ?`)
@@ -69,7 +70,9 @@ export class MySQLAdapter {
69
70
  .execute(`UPDATE ${this.tableName} SET ${setClause} WHERE ${this.fieldId} = ?`, values);
70
71
  return result;
71
72
  }
72
- async updateWhere(params, updateData, options = {}) {
73
+ async updateWhere(params, updateData,
74
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
+ options = {}) {
73
76
  const { query = {} } = params;
74
77
  const setClause = Object.keys(updateData)
75
78
  .map((key) => `${key} = ?`)
@@ -113,6 +116,12 @@ export class MySQLAdapter {
113
116
  throw error;
114
117
  }
115
118
  }
119
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
120
+ async createIndex(fieldOrSpec, options) {
121
+ const sql = `CREATE INDEX idx_${fieldOrSpec} ON ${this.tableName} (${fieldOrSpec})`;
122
+ await this.connection.getClient().execute(sql);
123
+ return `idx_${fieldOrSpec}`;
124
+ }
116
125
  parseSortOptions(sortBy) {
117
126
  return sortBy
118
127
  .split(',')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medyll/idae-db",
3
- "version": "0.82.0",
3
+ "version": "0.83.0",
4
4
  "description": "@medyll/idae-db is a flexible and powerful library for interacting with various databases, with a particular focus on MongoDB support. It offers robust connection management, an intuitive API, and simplified CRUD operations.",
5
5
  "scripts": {
6
6
  "dev": "vite dev",