tspace-mysql 1.9.3 → 1.9.4-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 +139 -21
- package/dist/lib/constants/index.d.ts +1 -1
- package/dist/lib/constants/index.js +8 -1
- package/dist/lib/constants/index.js.map +1 -1
- package/dist/lib/core/Abstracts/AbstractBuilder.d.ts +1 -1
- package/dist/lib/core/Abstracts/AbstractBuilder.js +1 -0
- package/dist/lib/core/Abstracts/AbstractBuilder.js.map +1 -1
- package/dist/lib/core/Blueprint.d.ts +45 -12
- package/dist/lib/core/Blueprint.js +43 -2
- package/dist/lib/core/Blueprint.js.map +1 -1
- package/dist/lib/core/Builder.d.ts +6 -6
- package/dist/lib/core/Builder.js +29 -35
- package/dist/lib/core/Builder.js.map +1 -1
- package/dist/lib/core/Contracts/Audit.d.ts +2 -2
- package/dist/lib/core/Contracts/Logger.d.ts +2 -2
- package/dist/lib/core/DB.d.ts +137 -6
- package/dist/lib/core/DB.js +153 -30
- package/dist/lib/core/DB.js.map +1 -1
- package/dist/lib/core/Driver/index.d.ts +2 -1
- package/dist/lib/core/Driver/index.js +11 -0
- package/dist/lib/core/Driver/index.js.map +1 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.d.ts +4 -1
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js +21 -7
- package/dist/lib/core/Driver/mariadb/MariadbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mongodb/MongodbDriver.d.ts +4 -1
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js +8 -6
- package/dist/lib/core/Driver/mongodb/MongodbDriver.js.map +1 -1
- package/dist/lib/core/Driver/mysql/MysqlDriver.d.ts +4 -1
- package/dist/lib/core/Driver/mysql/MysqlDriver.js +35 -7
- package/dist/lib/core/Driver/mysql/MysqlDriver.js.map +1 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.d.ts +4 -1
- package/dist/lib/core/Driver/postgres/PostgresDriver.js +24 -8
- package/dist/lib/core/Driver/postgres/PostgresDriver.js.map +1 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.d.ts +4 -1
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js +14 -6
- package/dist/lib/core/Driver/sqlite/SqliteDriver.js.map +1 -1
- package/dist/lib/core/Model.d.ts +332 -29
- package/dist/lib/core/Model.js +329 -19
- package/dist/lib/core/Model.js.map +1 -1
- package/dist/lib/core/Pool.d.ts +1 -1
- package/dist/lib/core/Pool.js +10 -4
- package/dist/lib/core/Pool.js.map +1 -1
- package/dist/lib/core/{Queue.d.ts → Queue/index.d.ts} +115 -111
- package/dist/lib/core/Queue/index.js +283 -0
- package/dist/lib/core/Queue/index.js.map +1 -0
- package/dist/lib/core/Queue/types.d.ts +40 -0
- package/dist/lib/core/Queue/types.js +3 -0
- package/dist/lib/core/Queue/types.js.map +1 -0
- package/dist/lib/core/Queue/worker.d.ts +103 -0
- package/dist/lib/core/{Queue.js → Queue/worker.js} +261 -311
- package/dist/lib/core/Queue/worker.js.map +1 -0
- package/dist/lib/core/Repository.d.ts +40 -20
- package/dist/lib/core/Repository.js +35 -14
- package/dist/lib/core/Repository.js.map +1 -1
- package/dist/lib/core/Schema.d.ts +4 -4
- package/dist/lib/core/Schema.js +40 -14
- package/dist/lib/core/Schema.js.map +1 -1
- package/dist/lib/core/UtilityTypes.d.ts +7 -3
- package/dist/lib/core/UtilityTypes.js.map +1 -1
- package/dist/lib/types/decorator/index.d.ts +3 -0
- package/dist/lib/types/index.d.ts +19 -18
- package/dist/lib/types/repository/index.d.ts +3 -3
- package/dist/lib/utils/index.d.ts +10 -5
- package/dist/lib/utils/index.js +42 -9
- package/dist/lib/utils/index.js.map +1 -1
- package/package.json +3 -5
- package/dist/lib/core/Queue.js.map +0 -1
package/dist/lib/core/Builder.js
CHANGED
|
@@ -2036,10 +2036,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
2036
2036
|
columns[key] = `( ${updateColumns[key].join(" ")} )`;
|
|
2037
2037
|
}
|
|
2038
2038
|
const keyValue = Object.entries(columns).map(([column, value]) => {
|
|
2039
|
-
|
|
2040
|
-
!value.includes(this.$constants("RAW"))) {
|
|
2041
|
-
value = this.$utils.escapeActions(value);
|
|
2042
|
-
}
|
|
2039
|
+
value = this.$utils.escapePayload(value);
|
|
2043
2040
|
return `${this.bindColumn(column)} = ${value == null || value === this.$constants("NULL")
|
|
2044
2041
|
? this.$constants("NULL")
|
|
2045
2042
|
: typeof value === "string" && value.includes(this.$constants("RAW"))
|
|
@@ -3127,18 +3124,20 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3127
3124
|
* @returns {promise<any[]>}
|
|
3128
3125
|
*/
|
|
3129
3126
|
async get(cb) {
|
|
3130
|
-
if (this.$state.get("
|
|
3127
|
+
if (this.$state.get("VOID"))
|
|
3128
|
+
return [];
|
|
3129
|
+
if (this.$state.get("EXCEPTS")?.length) {
|
|
3131
3130
|
this.select(...(await this.exceptColumns()));
|
|
3131
|
+
}
|
|
3132
3132
|
let sql = this._queryBuilder().select();
|
|
3133
3133
|
if (cb) {
|
|
3134
3134
|
const callbackSql = cb(sql);
|
|
3135
|
-
if (callbackSql == null || callbackSql === "")
|
|
3135
|
+
if (callbackSql == null || callbackSql === "") {
|
|
3136
3136
|
throw new Error("Please provide a callback for execution");
|
|
3137
|
+
}
|
|
3137
3138
|
sql = callbackSql;
|
|
3138
3139
|
}
|
|
3139
3140
|
const result = await this._queryStatement(sql);
|
|
3140
|
-
if (this.$state.get("VOID"))
|
|
3141
|
-
return [];
|
|
3142
3141
|
await this.$utils.hookHandle(this.$state.get("HOOKS"), result || []);
|
|
3143
3142
|
return this._resultHandler(result || []);
|
|
3144
3143
|
}
|
|
@@ -3153,18 +3152,19 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
3153
3152
|
return await this.get(cb);
|
|
3154
3153
|
}
|
|
3155
3154
|
/**
|
|
3156
|
-
*
|
|
3157
|
-
* The 'toJSON' method is used to execute a database query and retrieve the result set that matches the query conditions.
|
|
3155
|
+
* The 'toAsyncIterable' method is used to execute a database query and return the result set as an asynchronous iterable.
|
|
3158
3156
|
*
|
|
3159
3157
|
* It retrieves multiple records from a database table based on the criteria specified in the query.
|
|
3158
|
+
* The optional callback function can be used to modify the generated SQL query before execution.
|
|
3160
3159
|
*
|
|
3161
|
-
*
|
|
3162
|
-
* @returns {
|
|
3160
|
+
* @param {Function?} cb callback function return query sql
|
|
3161
|
+
* @returns {AsyncIterable<any>}
|
|
3163
3162
|
*/
|
|
3164
|
-
async
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3163
|
+
async *toAsyncIterable(cb) {
|
|
3164
|
+
if (this.$state.get("VOID"))
|
|
3165
|
+
return yield* [];
|
|
3166
|
+
const results = await this.get(cb);
|
|
3167
|
+
return yield* results;
|
|
3168
3168
|
}
|
|
3169
3169
|
/**
|
|
3170
3170
|
* The 'toArray' method is used to execute a database query and retrieve the result set that matches the query conditions.
|
|
@@ -4043,10 +4043,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4043
4043
|
_queryUpdate(data) {
|
|
4044
4044
|
this.$utils.transfromDateToDateString(data);
|
|
4045
4045
|
const values = Object.entries(data).map(([column, value]) => {
|
|
4046
|
-
|
|
4047
|
-
!value.includes(this.$constants("RAW"))) {
|
|
4048
|
-
value = this.$utils.escapeActions(value);
|
|
4049
|
-
}
|
|
4046
|
+
value = this.$utils.escapePayload(value);
|
|
4050
4047
|
return `${this.bindColumn(column)} = ${value == null || value === this.$constants("NULL")
|
|
4051
4048
|
? this.$constants("NULL")
|
|
4052
4049
|
: this.$utils.transfromValueHasRaw(value)}`;
|
|
@@ -4058,10 +4055,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4058
4055
|
data = this.$utils.transfromDateToDateString(data);
|
|
4059
4056
|
const columns = Object.keys(data).map((c) => `\`${c.replace(/\`/g, "")}\``);
|
|
4060
4057
|
const values = Object.values(data).map((value) => {
|
|
4061
|
-
|
|
4062
|
-
!value.includes(this.$constants("RAW"))) {
|
|
4063
|
-
value = this.$utils.escapeActions(value);
|
|
4064
|
-
}
|
|
4058
|
+
value = this.$utils.escapePayload(value);
|
|
4065
4059
|
if (this.$utils.typeOf(value) === "object" ||
|
|
4066
4060
|
this.$utils.typeOf(value) === "array") {
|
|
4067
4061
|
value = JSON.stringify(value);
|
|
@@ -4081,10 +4075,7 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4081
4075
|
for (let objects of data) {
|
|
4082
4076
|
this.$utils.transfromDateToDateString(objects);
|
|
4083
4077
|
const vals = Object.values(objects).map((value) => {
|
|
4084
|
-
|
|
4085
|
-
!value.includes(this.$constants("RAW"))) {
|
|
4086
|
-
value = this.$utils.escapeActions(value);
|
|
4087
|
-
}
|
|
4078
|
+
value = this.$utils.escapePayload(value);
|
|
4088
4079
|
if (this.$utils.typeOf(value) === "object" ||
|
|
4089
4080
|
this.$utils.typeOf(value) === "array") {
|
|
4090
4081
|
value = JSON.stringify(value);
|
|
@@ -4150,17 +4141,14 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4150
4141
|
return {
|
|
4151
4142
|
query: async (sql) => {
|
|
4152
4143
|
const first = sql.trim().split(/\s+/)[0].toUpperCase();
|
|
4144
|
+
const isRowLock = Object.values(this.$constants("ROW_LEVEL_LOCK")).some(lock => sql.toUpperCase().includes(lock));
|
|
4145
|
+
// Row-level locked SELECTs (e.g. FOR UPDATE, FOR SHARE) acquire database locks,
|
|
4146
|
+
// so they are not considered read-only queries and should be handled as write/locking operations.
|
|
4153
4147
|
const isReaded = [
|
|
4154
4148
|
this.$constants("SELECT"),
|
|
4155
4149
|
this.$constants("SHOW"),
|
|
4156
4150
|
this.$constants("DESCRIBE")
|
|
4157
|
-
].includes(first) &&
|
|
4158
|
-
(!sql
|
|
4159
|
-
.toUpperCase()
|
|
4160
|
-
.includes(this.$constants("ROW_LEVEL_LOCK").update) ||
|
|
4161
|
-
!sql
|
|
4162
|
-
.toUpperCase()
|
|
4163
|
-
.includes(this.$constants("ROW_LEVEL_LOCK").share));
|
|
4151
|
+
].includes(first) && !isRowLock;
|
|
4164
4152
|
if (isReaded) {
|
|
4165
4153
|
const length = poolCluster?.slaves?.length ?? 0;
|
|
4166
4154
|
const random = Math.floor(Math.random() * length);
|
|
@@ -4194,10 +4182,16 @@ class Builder extends AbstractBuilder_1.AbstractBuilder {
|
|
|
4194
4182
|
transaction: async () => {
|
|
4195
4183
|
return await poolCluster.masters[0].connection();
|
|
4196
4184
|
},
|
|
4185
|
+
stream: async (sql) => {
|
|
4186
|
+
return await poolCluster.masters[0].stream(sql);
|
|
4187
|
+
},
|
|
4197
4188
|
};
|
|
4198
4189
|
}
|
|
4199
4190
|
let pool = Pool_1.Pool.connect();
|
|
4200
4191
|
return {
|
|
4192
|
+
stream: async (sql) => {
|
|
4193
|
+
return await pool.stream(sql);
|
|
4194
|
+
},
|
|
4201
4195
|
transaction: async () => {
|
|
4202
4196
|
return await pool.connection();
|
|
4203
4197
|
},
|