tspace-mysql 1.9.0-beta.1 → 1.9.0-beta.2
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/README.md +73 -1
- package/dist/lib/config/index.d.ts +2 -2
- package/dist/lib/config/index.js +8 -6
- package/dist/lib/config/index.js.map +1 -1
- package/dist/lib/constants/index.d.ts +4 -0
- package/dist/lib/constants/index.js +5 -1
- package/dist/lib/constants/index.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +3 -2
- package/dist/lib/core/Abstracts/AbstractBuilder.js +2 -1
- package/dist/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/dist/lib/core/Builder.d.ts +215 -2
- package/dist/lib/core/Builder.js +688 -342
- package/dist/lib/core/Builder.js.map +1 -1
- package/dist/lib/core/Cache/DBCache.d.ts +4 -3
- package/dist/lib/core/Cache/DBCache.js +94 -97
- package/dist/lib/core/Cache/DBCache.js.map +1 -1
- package/dist/lib/core/Cache/MemoryCache.js +5 -10
- package/dist/lib/core/Cache/MemoryCache.js.map +1 -1
- package/dist/lib/core/Cache/RedisCache.js +16 -9
- package/dist/lib/core/Cache/RedisCache.js.map +1 -1
- package/dist/lib/core/Cache/index.js +5 -4
- package/dist/lib/core/Cache/index.js.map +1 -1
- package/dist/lib/core/Contracts/AlterTable.d.ts +138 -9
- package/dist/lib/core/Contracts/AlterTable.js +193 -9
- package/dist/lib/core/Contracts/AlterTable.js.map +1 -1
- package/dist/lib/core/Contracts/Audit.js +2 -5
- package/dist/lib/core/Contracts/Audit.js.map +1 -1
- package/dist/lib/core/DB.d.ts +61 -1
- package/dist/lib/core/DB.js +92 -7
- package/dist/lib/core/DB.js.map +1 -1
- package/dist/lib/core/Driver/index.d.ts +5 -1
- package/dist/lib/core/Driver/index.js +9 -7
- package/dist/lib/core/Driver/index.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js +52 -24
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.d.ts +8 -2
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js +62 -8
- package/dist/lib/core/Driver/mariadb/MariadbQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +24 -0
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js +255 -0
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -0
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.d.ts +140 -0
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js +553 -0
- package/dist/lib/core/Driver/mongodb/MongodbQueryBuilder.js.map +1 -0
- package/dist/lib/core/Driver/mysql/MysqlDriver.js +84 -73
- package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.d.ts +8 -2
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js +62 -8
- package/dist/lib/core/Driver/mysql/MysqlQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.js +80 -70
- package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.d.ts +10 -3
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js +184 -36
- package/dist/lib/core/Driver/postgres/PostgresQueryBuilder.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +20 -0
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js +192 -0
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -0
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.d.ts +143 -0
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js +685 -0
- package/dist/lib/core/Driver/sqlite/SqliteQueryBuilder.js.map +1 -0
- package/dist/lib/core/JoinModel.js +2 -2
- package/dist/lib/core/JoinModel.js.map +1 -1
- package/dist/lib/core/Model.d.ts +54 -76
- package/dist/lib/core/Model.js +311 -416
- package/dist/lib/core/Model.js.map +1 -1
- package/dist/lib/{tool/index.d.ts → core/Package.d.ts} +11 -6
- package/dist/lib/{tool/index.js → core/Package.js} +15 -26
- package/dist/lib/core/Package.js.map +1 -0
- package/dist/lib/core/Pool.js +16 -6
- package/dist/lib/core/Pool.js.map +1 -1
- package/dist/lib/core/Queue.d.ts +239 -0
- package/dist/lib/core/Queue.js +665 -0
- package/dist/lib/core/Queue.js.map +1 -0
- package/dist/lib/core/RelationManager.js +6 -6
- package/dist/lib/core/RelationManager.js.map +1 -1
- package/dist/lib/core/Repository.js +7 -0
- package/dist/lib/core/Repository.js.map +1 -1
- package/dist/lib/core/Schema.d.ts +27 -13
- package/dist/lib/core/Schema.js +29 -21
- package/dist/lib/core/Schema.js.map +1 -1
- package/dist/lib/core/StateManager.d.ts +24 -10
- package/dist/lib/core/StateManager.js +8 -2
- package/dist/lib/core/StateManager.js.map +1 -1
- package/dist/lib/core/UtilityTypes.d.ts +12 -34
- package/dist/lib/core/UtilityTypes.js.map +1 -1
- package/dist/lib/core/index.d.ts +4 -0
- package/dist/lib/core/index.js +6 -2
- package/dist/lib/core/index.js.map +1 -1
- package/dist/lib/types/index.d.ts +32 -2
- package/dist/lib/utils/index.d.ts +9 -1
- package/dist/lib/utils/index.js +40 -2
- package/dist/lib/utils/index.js.map +1 -1
- package/package.json +6 -3
- package/dist/lib/tool/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ tspace-mysql is an Object-Relational Mapping (ORM) tool designed to run seamless
|
|
|
10
10
|
|
|
11
11
|
| **Feature** | **Description** |
|
|
12
12
|
|--------------------------------|---------------------------------------------------------------------------------------------------------|
|
|
13
|
-
| **Supports Driver** | MySQL ✅ / MariaDB ✅ / Postgres / ✅
|
|
13
|
+
| **Supports Driver** | MySQL ✅ / MariaDB ✅ / Postgres ✅ / SQLite ✅ / Mongodb ✅ (yes, even MongoDB 😏) / MSSQL ⏳ |
|
|
14
14
|
| **Query Builder** | Create flexible queries like `SELECT`, `INSERT`, `UPDATE`, and `DELETE`. You can also use raw SQL. |
|
|
15
15
|
| **Join Clauses** | Use `INNER JOIN`, `LEFT JOIN`, `RIGHT JOIN`, and `CROSS JOIN` to combine data from multiple tables. |
|
|
16
16
|
| **Model** | Provides a way to interact with database records as objects in code. You can perform create, read, update, and delete (CRUD) operations. Models also support soft deletes and relationship methods. |
|
|
@@ -24,6 +24,7 @@ tspace-mysql is an Object-Relational Mapping (ORM) tool designed to run seamless
|
|
|
24
24
|
| **Repository** | Follows a pattern for managing database operations like `SELECT`, `INSERT`, `UPDATE`, and `DELETE`. It helps keep the code organized. |
|
|
25
25
|
| **Decorators** | Use decorators to add extra functionality or information to model classes and methods, making the code easier to read. |
|
|
26
26
|
| **Caching** | Improves performance by storing frequently requested data. Supports in-memory caching (like memory DB) and Redis for distributed caching. |
|
|
27
|
+
| **Queue** | Job queue for background and async processing. Runs on top of databases for distributed workers (similar to pg-boss). |
|
|
27
28
|
| **Migrations** | Use CLI commands to create models, make migrations, and apply changes to the database structure. |
|
|
28
29
|
| **Blueprints** | Create a clear layout of the database structure and how models and tables relate to each other. |
|
|
29
30
|
| **CLI** | A Command Line Interface for managing models, running migrations, executing queries, and performing other tasks using commands (like `make:model`, `migrate`, and `query`). |
|
|
@@ -163,6 +164,7 @@ npm install -D typescript@5.9.3
|
|
|
163
164
|
- [Repository Delete Statements](#repository-delete-statements)
|
|
164
165
|
- [Repository Transactions](#repository-transactions)
|
|
165
166
|
- [Repository Relations](#repository-relations)
|
|
167
|
+
- [Queue](#queue)
|
|
166
168
|
- [View](#view)
|
|
167
169
|
- [Stored Procedure](#stored-procedure)
|
|
168
170
|
- [Blueprint](#blueprint)
|
|
@@ -3841,6 +3843,76 @@ const phoneBelongUser = await phoneRepository.findOne({
|
|
|
3841
3843
|
|
|
3842
3844
|
```
|
|
3843
3845
|
|
|
3846
|
+
## Queue
|
|
3847
|
+
A lightweight, high-performance job queue built for ORM-based systems,
|
|
3848
|
+
designed to run on top of database layers with support for concurrency,
|
|
3849
|
+
retries, priorities, and job inspection.
|
|
3850
|
+
|
|
3851
|
+
- Concurrency Each worker can process multiple jobs at the same time.
|
|
3852
|
+
|
|
3853
|
+
- Priority Higher priority jobs are executed first.
|
|
3854
|
+
|
|
3855
|
+
- Retry Failed jobs are automatically retried up to maxAttempts.
|
|
3856
|
+
|
|
3857
|
+
- Delay Jobs can be scheduled for future execution using delayMs.
|
|
3858
|
+
|
|
3859
|
+
- Idle / Wake Workers automatically go idle when no jobs are available, and wake up instantly when new jobs arrive.
|
|
3860
|
+
|
|
3861
|
+
```js
|
|
3862
|
+
import { Queue, Job } from 'tspace-mysql';
|
|
3863
|
+
|
|
3864
|
+
const fakeSendEmail = async (job: Job) => {
|
|
3865
|
+
if(Math.random() < 0.5) throw new Error(`Failed job ${job.id}`)
|
|
3866
|
+
await new Promise<void>((ok) => setTimeout(ok, 2000));
|
|
3867
|
+
return `Send email Completed job ${job.id}`;
|
|
3868
|
+
}
|
|
3869
|
+
|
|
3870
|
+
// start the Queue
|
|
3871
|
+
await Queue.start({
|
|
3872
|
+
inspect : true,
|
|
3873
|
+
flush : false, // flush = true -> remove all jobs
|
|
3874
|
+
hostname: 'pod1'
|
|
3875
|
+
});
|
|
3876
|
+
|
|
3877
|
+
const worker = 20;
|
|
3878
|
+
|
|
3879
|
+
// register process send email 20
|
|
3880
|
+
for(let i = 1; i <= worker; i++) {
|
|
3881
|
+
|
|
3882
|
+
Queue.process(`send-email-(${i})`, async(job) => {
|
|
3883
|
+
return await fakeSendEmail(job)
|
|
3884
|
+
} , { concurrency : 10 }) // 1 process / 10 concurrency
|
|
3885
|
+
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3888
|
+
// add jobs 10_000 records
|
|
3889
|
+
for(let j = 1; j <= worker * 500; j++) {
|
|
3890
|
+
|
|
3891
|
+
const i = Math.floor((Math.random() * worker) + 1);
|
|
3892
|
+
|
|
3893
|
+
Queue.add(`send-email-(${i})`, {
|
|
3894
|
+
email: `John-${i}@gmail.com`,
|
|
3895
|
+
name: `John-${i}`
|
|
3896
|
+
}, {
|
|
3897
|
+
delayMs : 1000 * Math.random() * 10,
|
|
3898
|
+
priority : i % 2 ? 9999 + Math.floor((Math.random() * 9999) + 1) : 0,
|
|
3899
|
+
maxAttempts : 3,
|
|
3900
|
+
metadata : {
|
|
3901
|
+
userId : j,
|
|
3902
|
+
name : `John-${i}`
|
|
3903
|
+
}
|
|
3904
|
+
})
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
// for view stats Jobs
|
|
3908
|
+
// await Queue.getJobOverallStats()
|
|
3909
|
+
// await Queue.getJobStats()
|
|
3910
|
+
|
|
3911
|
+
// if you want to end the Queue
|
|
3912
|
+
// await Queue.end()
|
|
3913
|
+
|
|
3914
|
+
```
|
|
3915
|
+
|
|
3844
3916
|
## View
|
|
3845
3917
|
|
|
3846
3918
|
Your database schema can also use views. These views are represented by classes that behave similarly to models,
|
|
@@ -13,11 +13,11 @@ declare const Config: Readonly<{
|
|
|
13
13
|
readonly USERNAME: string | undefined;
|
|
14
14
|
readonly PASSWORD: string;
|
|
15
15
|
readonly DATABASE: string | undefined;
|
|
16
|
-
readonly CONNECTION_LIMIT: string |
|
|
16
|
+
readonly CONNECTION_LIMIT: string | 10;
|
|
17
17
|
readonly DATE_STRINGS: string | false;
|
|
18
18
|
readonly CLUSTER: string | false;
|
|
19
19
|
readonly DRIVER: string;
|
|
20
|
-
readonly CACHE:
|
|
20
|
+
readonly CACHE: "memory" | "db" | "redis";
|
|
21
21
|
readonly CONNECTION_ERROR: string | false;
|
|
22
22
|
readonly CONNECTION_SUCCESS: string | false;
|
|
23
23
|
}>;
|
package/dist/lib/config/index.js
CHANGED
|
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Config = exports.loadOptionsEnv = void 0;
|
|
7
|
-
const
|
|
7
|
+
const Package_1 = require("../core/Package");
|
|
8
8
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
9
|
const resolveEnvPath = (customEnv) => {
|
|
10
10
|
const NODE_ENV = customEnv ?? process.env?.NODE_ENV;
|
|
11
|
-
const env =
|
|
11
|
+
const env = Package_1.Package.path.join(Package_1.Package.path.resolve(), ".env");
|
|
12
12
|
if (NODE_ENV == null) {
|
|
13
13
|
return env;
|
|
14
14
|
}
|
|
15
|
-
const envWithNodeEnv =
|
|
16
|
-
if (
|
|
15
|
+
const envWithNodeEnv = Package_1.Package.path.join(Package_1.Package.path.resolve(), `.env.${NODE_ENV}`);
|
|
16
|
+
if (Package_1.Package.fs.existsSync(envWithNodeEnv)) {
|
|
17
17
|
return envWithNodeEnv;
|
|
18
18
|
}
|
|
19
19
|
return env;
|
|
@@ -21,17 +21,19 @@ const resolveEnvPath = (customEnv) => {
|
|
|
21
21
|
dotenv_1.default.config({ path: resolveEnvPath() });
|
|
22
22
|
const ENV = process.env;
|
|
23
23
|
const rawEnv = {
|
|
24
|
+
// general
|
|
24
25
|
HOST: ENV.DB_HOST ?? "localhost",
|
|
25
26
|
PORT: ENV.DB_PORT ?? 3306,
|
|
26
27
|
USERNAME: ENV.DB_USERNAME ?? ENV.DB_USER,
|
|
27
28
|
PASSWORD: ENV.DB_PASSWORD ?? "",
|
|
28
29
|
DATABASE: ENV.DB_DATABASE,
|
|
29
|
-
CONNECTION_LIMIT: ENV.DB_CONNECTION_LIMIT ??
|
|
30
|
+
CONNECTION_LIMIT: ENV.DB_CONNECTION_LIMIT ?? 10,
|
|
30
31
|
// for mysql2 only
|
|
31
32
|
DATE_STRINGS: ENV.DB_DATE_STRINGS ?? false,
|
|
33
|
+
// options
|
|
32
34
|
CLUSTER: ENV.DB_CLUSTER ?? false,
|
|
33
35
|
DRIVER: ENV.DB_DRIVER ?? "mysql2",
|
|
34
|
-
CACHE: ENV.DB_CACHE
|
|
36
|
+
CACHE: ENV.DB_CACHE,
|
|
35
37
|
CONNECTION_ERROR: ENV.DB_CONNECTION_ERROR ?? false,
|
|
36
38
|
CONNECTION_SUCCESS: ENV.DB_CONNECTION_SUCCESS ?? false,
|
|
37
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/config/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/config/index.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA0C;AAC1C,oDAA4B;AAE5B,MAAM,cAAc,GAAG,CAAC,SAAkB,EAAU,EAAE;IACpD,MAAM,QAAQ,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;IACpD,MAAM,GAAG,GAAG,iBAAO,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;IAE9D,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,cAAc,GAAG,iBAAO,CAAC,IAAI,CAAC,IAAI,CACtC,iBAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EACtB,QAAQ,QAAQ,EAAE,CACnB,CAAC;IAEF,IAAI,iBAAO,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAC1C,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,gBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC;AAE1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;AAExB,MAAM,MAAM,GAAG;IACb,UAAU;IACV,IAAI,EAAe,GAAG,CAAC,OAAO,IAAI,WA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BAAM;AACf,kBAAe,MAAM,CAAC"}
|
|
@@ -105,6 +105,8 @@ declare const CONSTANTS: Readonly<{
|
|
|
105
105
|
NULLIF: "NULLIF";
|
|
106
106
|
INFORMATION_SCHEMA: "INFORMATION_SCHEMA";
|
|
107
107
|
STATISTICS: "STATISTICS";
|
|
108
|
+
TYPE: "TYPE";
|
|
109
|
+
COLUMN: "COLUMN";
|
|
108
110
|
RELATIONSHIP: {
|
|
109
111
|
hasOne: string;
|
|
110
112
|
hasMany: string;
|
|
@@ -120,6 +122,8 @@ declare const CONSTANTS: Readonly<{
|
|
|
120
122
|
ROW_LEVEL_LOCK: {
|
|
121
123
|
update: string;
|
|
122
124
|
share: string;
|
|
125
|
+
skipLocked: string;
|
|
126
|
+
nowait: string;
|
|
123
127
|
};
|
|
124
128
|
}>;
|
|
125
129
|
export { CONSTANTS };
|
|
@@ -108,6 +108,8 @@ const CONSTANTS = Object.freeze({
|
|
|
108
108
|
NULLIF: 'NULLIF',
|
|
109
109
|
INFORMATION_SCHEMA: 'INFORMATION_SCHEMA',
|
|
110
110
|
STATISTICS: 'STATISTICS',
|
|
111
|
+
TYPE: 'TYPE',
|
|
112
|
+
COLUMN: 'COLUMN',
|
|
111
113
|
RELATIONSHIP: {
|
|
112
114
|
hasOne: 'hasOne',
|
|
113
115
|
hasMany: 'hasMany',
|
|
@@ -122,7 +124,9 @@ const CONSTANTS = Object.freeze({
|
|
|
122
124
|
},
|
|
123
125
|
ROW_LEVEL_LOCK: {
|
|
124
126
|
update: 'FOR UPDATE',
|
|
125
|
-
share: 'LOCK IN SHARE MODE'
|
|
127
|
+
share: 'LOCK IN SHARE MODE',
|
|
128
|
+
skipLocked: 'SKIP LOCKED',
|
|
129
|
+
nowait: 'NOWAIT'
|
|
126
130
|
}
|
|
127
131
|
});
|
|
128
132
|
exports.CONSTANTS = CONSTANTS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/constants/index.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
|
|
@@ -24,6 +24,7 @@ declare abstract class AbstractBuilder {
|
|
|
24
24
|
set: Function;
|
|
25
25
|
get: Function;
|
|
26
26
|
queryBuilder: Function;
|
|
27
|
+
transaction: Function;
|
|
27
28
|
};
|
|
28
29
|
abstract void(): this;
|
|
29
30
|
abstract debug(): this;
|
|
@@ -51,8 +52,8 @@ declare abstract class AbstractBuilder {
|
|
|
51
52
|
abstract whereSubQuery(column: string, subQuery: string): this;
|
|
52
53
|
abstract whereNotSubQuery(column: string, subQuery: string): this;
|
|
53
54
|
abstract orWhereSubQuery(column: string, subQuery: string): this;
|
|
54
|
-
abstract whereBetween(column: string, arrayValue: any
|
|
55
|
-
abstract whereNotBetween(column: string, arrayValue: any
|
|
55
|
+
abstract whereBetween(column: string, arrayValue: [any, any]): this;
|
|
56
|
+
abstract whereNotBetween(column: string, arrayValue: [any, any]): this;
|
|
56
57
|
abstract having(condition: string): this;
|
|
57
58
|
abstract join(pk: string | ((join: Join) => Join), fk?: string): this;
|
|
58
59
|
abstract rightJoin(pk: string | ((join: Join) => Join), fk?: string): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractBuilder.js","sourceRoot":"","sources":["../../../../src/lib/core/Abstracts/AbstractBuilder.ts"],"names":[],"mappings":";;;AAGA,yCAA4C;AAM5C,MAAe,eAAe;IAEhB,MAAM,CAAU;IAEhB,SAAS,GAAY,MAAM,CAAC,eAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAEnD,YAAY,GAAG;QACrB,IAAI,EAAO,eAAM,CAAC,IAAI;QACtB,IAAI,EAAO,MAAM,CAAC,eAAM,CAAC,IAAI,CAAC;QAC9B,QAAQ,EAAG,MAAM,CAAC,eAAM,CAAC,QAAQ,CAAC;QAClC,QAAQ,EAAG,MAAM,CAAC,eAAM,CAAC,QAAQ,CAAC;QAClC,QAAQ,EAAG,eAAM,CAAC,QAAQ;KAC7B,CAAA;IAES,OAAO,GAAI,MAAM,CAAC,eAAM,CAAC,MAAM,IAAI,OAAO,CAAY,CAAC;IAEvD,QAAQ,GAAa,OAAO,CAAC,eAAM,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;IAEtD,UAAU,CAGlB;IAEQ,MAAM,CAAgB;IAEtB,KAAK,
|
|
1
|
+
{"version":3,"file":"AbstractBuilder.js","sourceRoot":"","sources":["../../../../src/lib/core/Abstracts/AbstractBuilder.ts"],"names":[],"mappings":";;;AAGA,yCAA4C;AAM5C,MAAe,eAAe;IAEhB,MAAM,CAAU;IAEhB,SAAS,GAAY,MAAM,CAAC,eAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAEnD,YAAY,GAAG;QACrB,IAAI,EAAO,eAAM,CAAC,IAAI;QACtB,IAAI,EAAO,MAAM,CAAC,eAAM,CAAC,IAAI,CAAC;QAC9B,QAAQ,EAAG,MAAM,CAAC,eAAM,CAAC,QAAQ,CAAC;QAClC,QAAQ,EAAG,MAAM,CAAC,eAAM,CAAC,QAAQ,CAAC;QAClC,QAAQ,EAAG,eAAM,CAAC,QAAQ;KAC7B,CAAA;IAES,OAAO,GAAI,MAAM,CAAC,eAAM,CAAC,MAAM,IAAI,OAAO,CAAY,CAAC;IAEvD,QAAQ,GAAa,OAAO,CAAC,eAAM,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;IAEtD,UAAU,CAGlB;IAEQ,MAAM,CAAgB;IAEtB,KAAK,GAMX;QACA,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,GAAE,CAAC;QAC1B,GAAG,EAAE,CAAC,IAAU,EAAE,EAAE,GAAE,CAAC;QACvB,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;QACb,YAAY,EAAE,GAAG,EAAE,GAAE,CAAC;QACtB,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;KACxB,CAAA;CAyFJ;AAES,0CAAe;AACzB,kBAAe,eAAe,CAAA"}
|
|
@@ -23,12 +23,61 @@ declare class Builder extends AbstractBuilder {
|
|
|
23
23
|
*/
|
|
24
24
|
database(): string;
|
|
25
25
|
/**
|
|
26
|
-
* The 'rowLock' method is used to row level locks
|
|
26
|
+
* The 'rowLock' method is used to row level locks (`FOR UPDATE` or `FOR SHARE`) to the query.
|
|
27
27
|
*
|
|
28
28
|
* @param {string} mode
|
|
29
29
|
* @returns {this} this
|
|
30
30
|
*/
|
|
31
|
-
rowLock(mode: "FOR_UPDATE" | "FOR_SHARE"
|
|
31
|
+
rowLock(mode: "FOR_UPDATE" | "FOR_SHARE", opts?: {
|
|
32
|
+
skipLocked?: boolean;
|
|
33
|
+
nowait?: boolean;
|
|
34
|
+
}): this;
|
|
35
|
+
/**
|
|
36
|
+
* The 'forUpdate' method is used to applies a row-level exclusive lock (`FOR UPDATE`) to the query.
|
|
37
|
+
*
|
|
38
|
+
* This lock prevents other transactions from modifying or acquiring
|
|
39
|
+
* conflicting locks on the selected rows until the current transaction
|
|
40
|
+
* is committed or rolled back.
|
|
41
|
+
*
|
|
42
|
+
* Commonly used in queue systems or critical sections to safely
|
|
43
|
+
* select and update rows without race conditions.
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} [opts] - Locking options
|
|
46
|
+
* @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions.
|
|
47
|
+
* Useful for building non-blocking workers (e.g., job queues).
|
|
48
|
+
* @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired.
|
|
49
|
+
*
|
|
50
|
+
* @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time.
|
|
51
|
+
*
|
|
52
|
+
* @returns {this} Returns the query builder instance for chaining.
|
|
53
|
+
*/
|
|
54
|
+
forUpdate(opts?: {
|
|
55
|
+
skipLocked?: boolean;
|
|
56
|
+
nowait?: boolean;
|
|
57
|
+
}): this;
|
|
58
|
+
/**
|
|
59
|
+
* The 'forShare' method is used to applies a row-level exclusive lock (`FOR SHARE`) to the query.
|
|
60
|
+
*
|
|
61
|
+
* This lock prevents other transactions from modifying or acquiring
|
|
62
|
+
* conflicting locks on the selected rows until the current transaction
|
|
63
|
+
* is committed or rolled back.
|
|
64
|
+
*
|
|
65
|
+
* Commonly used in queue systems or critical sections to safely
|
|
66
|
+
* select and update rows without race conditions.
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} [opts] - Locking options
|
|
69
|
+
* @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions.
|
|
70
|
+
* Useful for building non-blocking workers (e.g., job queues).
|
|
71
|
+
* @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired.
|
|
72
|
+
*
|
|
73
|
+
* @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time.
|
|
74
|
+
*
|
|
75
|
+
* @returns {this} Returns the query builder instance for chaining.
|
|
76
|
+
*/
|
|
77
|
+
forShare(opts?: {
|
|
78
|
+
skipLocked?: boolean;
|
|
79
|
+
nowait?: boolean;
|
|
80
|
+
}): this;
|
|
32
81
|
/**
|
|
33
82
|
* The 'unset' method is used to drop a property as desired.
|
|
34
83
|
* @param {object} options
|
|
@@ -1162,6 +1211,40 @@ declare class Builder extends AbstractBuilder {
|
|
|
1162
1211
|
ParentTable: string;
|
|
1163
1212
|
ParentColumn: string;
|
|
1164
1213
|
}[]>;
|
|
1214
|
+
/**
|
|
1215
|
+
* Adds a foreign key constraint to a table.
|
|
1216
|
+
*
|
|
1217
|
+
* This method checks whether the specified foreign key constraint already exists
|
|
1218
|
+
* on the table before attempting to create it. If the constraint exists, an error
|
|
1219
|
+
* will be thrown to prevent duplication.
|
|
1220
|
+
*
|
|
1221
|
+
* @async
|
|
1222
|
+
* @method addFK
|
|
1223
|
+
* @param {Object} params - Parameters for creating the foreign key.
|
|
1224
|
+
* @param {string} params.table - The name of the table where the foreign key will be added.
|
|
1225
|
+
* @param {string} params.tableRef - The referenced table name.
|
|
1226
|
+
* @param {string} params.key - The column in the current table that will act as the foreign key.
|
|
1227
|
+
* @param {string} params.constraint - The name of the foreign key constraint.
|
|
1228
|
+
* @param {Object} params.foreign - Foreign key configuration.
|
|
1229
|
+
* @param {string} params.foreign.references - The referenced column in the referenced table.
|
|
1230
|
+
* @param {string} params.foreign.onDelete - Action when a referenced row is deleted (e.g. CASCADE, SET NULL).
|
|
1231
|
+
* @param {string} params.foreign.onUpdate - Action when a referenced row is updated (e.g. CASCADE, RESTRICT).
|
|
1232
|
+
*
|
|
1233
|
+
* @throws {Error} If the specified foreign key constraint already exists.
|
|
1234
|
+
*
|
|
1235
|
+
* @returns {Promise<void>} Resolves when the foreign key constraint is successfully created.
|
|
1236
|
+
*/
|
|
1237
|
+
addFK({ table, tableRef, key, constraint, foreign }: {
|
|
1238
|
+
table: string;
|
|
1239
|
+
tableRef: string;
|
|
1240
|
+
key: string;
|
|
1241
|
+
constraint: string;
|
|
1242
|
+
foreign: {
|
|
1243
|
+
references: string;
|
|
1244
|
+
onDelete: string;
|
|
1245
|
+
onUpdate: string;
|
|
1246
|
+
};
|
|
1247
|
+
}): Promise<void>;
|
|
1165
1248
|
/**
|
|
1166
1249
|
* The `dropFK` method is used to remove a foreign key constraint from the database.
|
|
1167
1250
|
* If a table name is provided, the constraint will be dropped from that table;
|
|
@@ -1212,35 +1295,165 @@ declare class Builder extends AbstractBuilder {
|
|
|
1212
1295
|
name: string;
|
|
1213
1296
|
table?: string;
|
|
1214
1297
|
}): Promise<boolean>;
|
|
1298
|
+
/**
|
|
1299
|
+
* Adds an index to a table.
|
|
1300
|
+
*
|
|
1301
|
+
* This method checks whether the specified index already exists on the table
|
|
1302
|
+
* before attempting to create it. If the index exists, an error will be thrown
|
|
1303
|
+
* to prevent duplication.
|
|
1304
|
+
*
|
|
1305
|
+
* @async
|
|
1306
|
+
* @method addIndex
|
|
1307
|
+
* @param {Object} params - Parameters for creating the index.
|
|
1308
|
+
* @param {string} params.name - The name of the index.
|
|
1309
|
+
* @param {string} [params.table] - The table where the index will be created. Defaults to the current model table.
|
|
1310
|
+
* @param {string[]} params.columns - The columns included in the index.
|
|
1311
|
+
*
|
|
1312
|
+
* @throws {Error} If the specified index already exists.
|
|
1313
|
+
*
|
|
1314
|
+
* @returns {Promise<void>} Resolves when the index has been successfully created.
|
|
1315
|
+
*/
|
|
1215
1316
|
addIndex({ name, table, columns }: {
|
|
1216
1317
|
name: string;
|
|
1217
1318
|
table?: string;
|
|
1218
1319
|
columns: string[];
|
|
1219
1320
|
}): Promise<void>;
|
|
1321
|
+
/**
|
|
1322
|
+
* Drops an index from a table.
|
|
1323
|
+
*
|
|
1324
|
+
* This method checks whether the specified index exists on the table
|
|
1325
|
+
* before attempting to drop it. If the index does not exist, an error
|
|
1326
|
+
* will be thrown.
|
|
1327
|
+
*
|
|
1328
|
+
* @async
|
|
1329
|
+
* @method dropIndex
|
|
1330
|
+
* @param {Object} params - Parameters for dropping the index.
|
|
1331
|
+
* @param {string} params.name - The name of the index to drop.
|
|
1332
|
+
* @param {string} [params.table] - The table from which the index will be removed. Defaults to the current model table.
|
|
1333
|
+
*
|
|
1334
|
+
* @throws {Error} If the specified index was not found.
|
|
1335
|
+
*
|
|
1336
|
+
* @returns {Promise<void>} Resolves when the index has been successfully dropped.
|
|
1337
|
+
*/
|
|
1220
1338
|
dropIndex({ name, table }: {
|
|
1221
1339
|
name: string;
|
|
1222
1340
|
table?: string;
|
|
1223
1341
|
}): Promise<void>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Checks whether a unique constraint exists on a table.
|
|
1344
|
+
*
|
|
1345
|
+
* This method queries the database metadata to determine if the specified
|
|
1346
|
+
* unique constraint exists on the given table.
|
|
1347
|
+
*
|
|
1348
|
+
* @async
|
|
1349
|
+
* @method hasUnique
|
|
1350
|
+
* @param {Object} params - Parameters for checking the unique constraint.
|
|
1351
|
+
* @param {string} params.name - The name of the unique constraint.
|
|
1352
|
+
* @param {string} [params.table] - The table to check. Defaults to the current model table.
|
|
1353
|
+
*
|
|
1354
|
+
* @returns {Promise<boolean>} Returns `true` if the unique constraint exists, otherwise `false`.
|
|
1355
|
+
*/
|
|
1224
1356
|
hasUnique({ name, table }: {
|
|
1225
1357
|
name: string;
|
|
1226
1358
|
table?: string;
|
|
1227
1359
|
}): Promise<boolean>;
|
|
1360
|
+
/**
|
|
1361
|
+
* Adds a unique constraint to a table.
|
|
1362
|
+
*
|
|
1363
|
+
* This method checks whether the specified unique constraint already exists
|
|
1364
|
+
* on the table before attempting to create it. If the constraint already exists,
|
|
1365
|
+
* an error will be thrown to prevent duplication.
|
|
1366
|
+
*
|
|
1367
|
+
* @async
|
|
1368
|
+
* @method addUnique
|
|
1369
|
+
* @param {Object} params - Parameters for creating the unique constraint.
|
|
1370
|
+
* @param {string} params.name - The name of the unique constraint.
|
|
1371
|
+
* @param {string} [params.table] - The table where the unique constraint will be added. Defaults to the current model table.
|
|
1372
|
+
* @param {string[]} params.columns - The columns that will be included in the unique constraint.
|
|
1373
|
+
*
|
|
1374
|
+
* @throws {Error} If the specified unique constraint already exists.
|
|
1375
|
+
*
|
|
1376
|
+
* @returns {Promise<void>} Resolves when the unique constraint has been successfully created.
|
|
1377
|
+
*/
|
|
1228
1378
|
addUnique({ name, table, columns }: {
|
|
1229
1379
|
name: string;
|
|
1230
1380
|
table?: string;
|
|
1231
1381
|
columns: string[];
|
|
1232
1382
|
}): Promise<void>;
|
|
1383
|
+
/**
|
|
1384
|
+
* Drops a unique constraint from a table.
|
|
1385
|
+
*
|
|
1386
|
+
* This method checks whether the specified unique constraint exists
|
|
1387
|
+
* on the table before attempting to remove it. If the constraint does
|
|
1388
|
+
* not exist, an error will be thrown.
|
|
1389
|
+
*
|
|
1390
|
+
* @async
|
|
1391
|
+
* @method dropUnique
|
|
1392
|
+
* @param {Object} params - Parameters for dropping the unique constraint.
|
|
1393
|
+
* @param {string} params.name - The name of the unique constraint to drop.
|
|
1394
|
+
* @param {string} [params.table] - The table from which the unique constraint will be removed. Defaults to the current model table.
|
|
1395
|
+
*
|
|
1396
|
+
* @throws {Error} If the specified unique constraint was not found.
|
|
1397
|
+
*
|
|
1398
|
+
* @returns {Promise<void>} Resolves when the unique constraint has been successfully dropped.
|
|
1399
|
+
*/
|
|
1233
1400
|
dropUnique({ name, table }: {
|
|
1234
1401
|
name: string;
|
|
1235
1402
|
table?: string;
|
|
1236
1403
|
}): Promise<void>;
|
|
1404
|
+
/**
|
|
1405
|
+
* Checks whether a primary key constraint exists on a table.
|
|
1406
|
+
*
|
|
1407
|
+
* This method queries the database metadata to determine if the specified
|
|
1408
|
+
* table contains a primary key constraint.
|
|
1409
|
+
*
|
|
1410
|
+
* @async
|
|
1411
|
+
* @method hasPrimaryKey
|
|
1412
|
+
* @param {Object} [params={}] - Parameters for checking the primary key.
|
|
1413
|
+
* @param {string} [params.table] - The table to check. Defaults to the current model table.
|
|
1414
|
+
*
|
|
1415
|
+
* @returns {Promise<boolean>} Returns `true` if the table has a primary key constraint,
|
|
1416
|
+
* otherwise `false`.
|
|
1417
|
+
*/
|
|
1237
1418
|
hasPrimaryKey({ table }?: {
|
|
1238
1419
|
table?: string;
|
|
1239
1420
|
}): Promise<boolean>;
|
|
1421
|
+
/**
|
|
1422
|
+
* Adds a primary key constraint to a table.
|
|
1423
|
+
*
|
|
1424
|
+
* This method checks whether the table already has a primary key
|
|
1425
|
+
* before attempting to create one. If a primary key already exists,
|
|
1426
|
+
* an error will be thrown.
|
|
1427
|
+
*
|
|
1428
|
+
* @async
|
|
1429
|
+
* @method addPrimaryKey
|
|
1430
|
+
* @param {Object} params - Parameters for creating the primary key.
|
|
1431
|
+
* @param {string} [params.table] - The table where the primary key will be added. Defaults to the current model table.
|
|
1432
|
+
* @param {string[]} params.columns - The column(s) that will form the primary key.
|
|
1433
|
+
*
|
|
1434
|
+
* @throws {Error} If the table already has a primary key constraint.
|
|
1435
|
+
*
|
|
1436
|
+
* @returns {Promise<void>} Resolves when the primary key has been successfully created.
|
|
1437
|
+
*/
|
|
1240
1438
|
addPrimaryKey({ table, columns }: {
|
|
1241
1439
|
table?: string;
|
|
1242
1440
|
columns: string[];
|
|
1243
1441
|
}): Promise<void>;
|
|
1442
|
+
/**
|
|
1443
|
+
* Drops the primary key constraint from a table.
|
|
1444
|
+
*
|
|
1445
|
+
* This method checks whether the table has a primary key before
|
|
1446
|
+
* attempting to remove it. If no primary key exists, an error will be thrown.
|
|
1447
|
+
*
|
|
1448
|
+
* @async
|
|
1449
|
+
* @method dropPrimaryKey
|
|
1450
|
+
* @param {Object} [params={}] - Parameters for dropping the primary key.
|
|
1451
|
+
* @param {string} [params.table] - The table from which the primary key will be removed. Defaults to the current model table.
|
|
1452
|
+
*
|
|
1453
|
+
* @throws {Error} If the specified primary key constraint was not found.
|
|
1454
|
+
*
|
|
1455
|
+
* @returns {Promise<void>} Resolves when the primary key constraint has been successfully removed.
|
|
1456
|
+
*/
|
|
1244
1457
|
dropPrimaryKey({ table }?: {
|
|
1245
1458
|
table?: string;
|
|
1246
1459
|
}): Promise<void>;
|