tspace-mysql 1.4.7 → 1.4.8
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 +24 -7
- package/dist/lib/{tspace/Interface.d.ts → Interface.d.ts} +2 -1
- package/dist/lib/connection/index.d.ts +1 -1
- package/dist/lib/constants/index.js +3 -3
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.d.ts +2 -2
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractBuilder.js +2 -2
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.d.ts +8 -2
- package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.d.ts +4 -2
- package/dist/lib/tspace/Blueprint.d.ts +11 -1
- package/dist/lib/tspace/Blueprint.js +11 -1
- package/dist/lib/tspace/Builder.d.ts +22 -7
- package/dist/lib/tspace/Builder.js +384 -310
- package/dist/lib/tspace/DB.d.ts +42 -2
- package/dist/lib/tspace/DB.js +61 -5
- package/dist/lib/tspace/{ProxyHandler.js → Handlers/Proxy.js} +1 -1
- package/dist/lib/tspace/{RelationHandler.d.ts → Handlers/Relation.d.ts} +4 -4
- package/dist/lib/tspace/{RelationHandler.js → Handlers/Relation.js} +95 -19
- package/dist/lib/tspace/Model.d.ts +71 -10
- package/dist/lib/tspace/Model.js +228 -64
- package/dist/lib/tspace/Schema.js +4 -5
- package/dist/lib/tspace/index.d.ts +2 -0
- package/dist/lib/tspace/index.js +3 -1
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/index.js +8 -0
- package/package.json +1 -1
- /package/dist/lib/{tspace/Interface.js → Interface.js} +0 -0
- /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractDB.js +0 -0
- /package/dist/lib/tspace/{Abstract → Abstracts}/AbstractModel.js +0 -0
- /package/dist/lib/tspace/{ProxyHandler.d.ts → Handlers/Proxy.d.ts} +0 -0
- /package/dist/lib/tspace/{StateHandler.d.ts → Handlers/State.d.ts} +0 -0
- /package/dist/lib/tspace/{StateHandler.js → Handlers/State.js} +0 -0
package/README.md
CHANGED
|
@@ -260,7 +260,17 @@ const user = await new DB('users')
|
|
|
260
260
|
email : 'tspace1@gmail.com'
|
|
261
261
|
})
|
|
262
262
|
.save()
|
|
263
|
-
//
|
|
263
|
+
// UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
|
|
264
|
+
|
|
265
|
+
const user = await new DB('users')
|
|
266
|
+
.where('id',1)
|
|
267
|
+
.update({
|
|
268
|
+
name : 'tspace1**',
|
|
269
|
+
email : 'tspace1@gmail.com'
|
|
270
|
+
},['name'])
|
|
271
|
+
.save()
|
|
272
|
+
// UPDATE `users` SET `name` = CASE WHEN (`name` = "" OR `name` IS NULL) THEN "tspace1**" ELSE `name` END,`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
|
|
273
|
+
|
|
264
274
|
|
|
265
275
|
+--------------------------------------------------------------------------+
|
|
266
276
|
|
|
@@ -269,26 +279,28 @@ reposity.name = 'tspace1++'
|
|
|
269
279
|
reposity.email = 'tspace1++@gmail.com'
|
|
270
280
|
|
|
271
281
|
await reposity.save()
|
|
272
|
-
|
|
282
|
+
// UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
|
|
273
283
|
const { result } = reposity
|
|
274
284
|
// result => { id : 1 , username : 'tspace1++', email : 'tspace1++@gmail.com'}
|
|
275
285
|
|
|
276
286
|
```
|
|
277
|
-
Running A
|
|
287
|
+
Running A Update Or Created Query
|
|
278
288
|
```js
|
|
279
289
|
const user = await new DB('users')
|
|
280
290
|
.where('id',1)
|
|
281
291
|
.updateOrCreate({
|
|
282
|
-
|
|
283
|
-
|
|
292
|
+
name : 'tspace1**',
|
|
293
|
+
email : 'tspace1@gmail.com'
|
|
284
294
|
}).save()
|
|
285
|
-
//
|
|
295
|
+
// INSERT INTO `users` (`name`,`email`) VALUES ('tspace1**','tspace1@gmail.com');
|
|
296
|
+
|
|
297
|
+
// UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
|
|
286
298
|
```
|
|
287
299
|
|
|
288
300
|
Running A Delete Query
|
|
289
301
|
```js
|
|
290
302
|
const deleted = await new DB('users').where('id',1).delete()
|
|
291
|
-
//
|
|
303
|
+
// DELETE FROM `users` WHERE `users`.`id` = '1' LIMIT 1;
|
|
292
304
|
```
|
|
293
305
|
## Database Transactions
|
|
294
306
|
|
|
@@ -1074,6 +1086,11 @@ max(column)
|
|
|
1074
1086
|
min(column)
|
|
1075
1087
|
pagination({ limit , page })
|
|
1076
1088
|
save() /* for actions statements insert or update */
|
|
1089
|
+
makeSelectStatement()
|
|
1090
|
+
makeInsertStatement()
|
|
1091
|
+
makeUpdateStatement()
|
|
1092
|
+
makeDeleteStatement()
|
|
1093
|
+
makeCreateStatement()
|
|
1077
1094
|
```
|
|
1078
1095
|
|
|
1079
1096
|
## Cli
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Model from "./Model";
|
|
1
|
+
import Model from "./tspace/Model";
|
|
2
2
|
export interface Relation {
|
|
3
3
|
name: string;
|
|
4
4
|
model: new () => Model;
|
|
@@ -12,6 +12,7 @@ export interface Relation {
|
|
|
12
12
|
exists?: boolean | undefined;
|
|
13
13
|
all?: boolean | undefined;
|
|
14
14
|
trashed?: boolean | undefined;
|
|
15
|
+
count?: boolean | undefined;
|
|
15
16
|
oldVersion?: boolean | undefined;
|
|
16
17
|
modelPivot?: new () => Model | undefined;
|
|
17
18
|
}
|
|
@@ -65,7 +65,7 @@ const CONSTANTS = Object.freeze({
|
|
|
65
65
|
CREATE_DATABASE_NOT_EXISTS: 'CREATE DATABASE IF NOT EXISTS',
|
|
66
66
|
CREATE_TABLE: 'CREATE TABLE',
|
|
67
67
|
CREATE_TABLE_NOT_EXISTS: 'CREATE TABLE IF NOT EXISTS',
|
|
68
|
-
ENGINE: 'ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=
|
|
68
|
+
ENGINE: 'ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4',
|
|
69
69
|
RAND: 'RAND()',
|
|
70
70
|
ALTER_TABLE: 'ALTER TABLE',
|
|
71
71
|
ADD: 'ADD',
|
|
@@ -101,7 +101,7 @@ const CONSTANTS = Object.freeze({
|
|
|
101
101
|
COUNT: '',
|
|
102
102
|
FROM: 'FROM',
|
|
103
103
|
JOIN: [],
|
|
104
|
-
WHERE:
|
|
104
|
+
WHERE: [],
|
|
105
105
|
GROUP_BY: '',
|
|
106
106
|
ORDER_BY: '',
|
|
107
107
|
LIMIT: '',
|
|
@@ -129,7 +129,7 @@ const CONSTANTS = Object.freeze({
|
|
|
129
129
|
COUNT: '',
|
|
130
130
|
FROM: 'FROM',
|
|
131
131
|
JOIN: [],
|
|
132
|
-
WHERE:
|
|
132
|
+
WHERE: [],
|
|
133
133
|
GROUP_BY: '',
|
|
134
134
|
ORDER_BY: '',
|
|
135
135
|
LIMIT: '',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Pagination } from '
|
|
2
|
-
import { StateHandler } from '../
|
|
1
|
+
import { Pagination } from '../../Interface';
|
|
2
|
+
import { StateHandler } from '../Handlers/State';
|
|
3
3
|
declare abstract class AbstractBuilder {
|
|
4
4
|
protected $setters: string[];
|
|
5
5
|
protected $utils: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractBuilder = void 0;
|
|
4
|
-
const
|
|
4
|
+
const State_1 = require("../Handlers/State");
|
|
5
5
|
class AbstractBuilder {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.$setters = [
|
|
@@ -15,7 +15,7 @@ class AbstractBuilder {
|
|
|
15
15
|
];
|
|
16
16
|
this.$utils = {};
|
|
17
17
|
this.$constants = (name) => { };
|
|
18
|
-
this.$state = new
|
|
18
|
+
this.$state = new State_1.StateHandler({
|
|
19
19
|
state: {},
|
|
20
20
|
constants: {}
|
|
21
21
|
});
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import Builder from '../Builder';
|
|
2
|
-
import { Connection, ConnectionOptions } from '
|
|
2
|
+
import { Connection, ConnectionOptions } from '../../Interface';
|
|
3
3
|
declare abstract class AbstractDB extends Builder {
|
|
4
|
-
abstract table(name: string):
|
|
4
|
+
abstract table(name: string): this;
|
|
5
5
|
abstract beginTransaction(): Promise<any>;
|
|
6
6
|
abstract generateUUID(): string;
|
|
7
7
|
abstract raw(sql: string): string;
|
|
8
|
+
abstract escape(sql: string): string;
|
|
9
|
+
abstract escapeXSS(sql: string): string;
|
|
10
|
+
abstract snakeCase(sql: string): string;
|
|
11
|
+
abstract camelCase(sql: string): string;
|
|
12
|
+
abstract JSONObject(object: Record<string, string>, alias: string): string;
|
|
13
|
+
abstract jsonObject(object: Record<string, string>, alias: string): string;
|
|
8
14
|
abstract constants(constants?: string): string | Record<string, any>;
|
|
9
15
|
abstract caseUpdate(cases: {
|
|
10
16
|
when: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Relation, RelationQuery } from '
|
|
1
|
+
import { Relation, RelationQuery } from '../../Interface';
|
|
2
2
|
import { Builder } from '../Builder';
|
|
3
|
-
import { RelationHandler } from '../
|
|
3
|
+
import { RelationHandler } from '../Handlers/Relation';
|
|
4
4
|
declare abstract class AbstractModel extends Builder {
|
|
5
5
|
protected $relation: RelationHandler | undefined;
|
|
6
6
|
protected abstract useUUID(): this;
|
|
@@ -14,6 +14,8 @@ declare abstract class AbstractModel extends Builder {
|
|
|
14
14
|
protected abstract useSoftDelete(): this;
|
|
15
15
|
protected abstract useHooks(functions: Function[]): this;
|
|
16
16
|
protected abstract usePattern(pattern: string): this;
|
|
17
|
+
protected abstract useCamelCase(pattern: string): this;
|
|
18
|
+
protected abstract useSnakeCase(pattern: string): this;
|
|
17
19
|
protected abstract useLoadRelationsInRegistry(): this;
|
|
18
20
|
protected abstract useBuiltInRelationFunctions(): this;
|
|
19
21
|
protected abstract define(): void;
|
|
@@ -3,7 +3,7 @@ import { Model } from "./Model";
|
|
|
3
3
|
* Make schema for table with Blueprint
|
|
4
4
|
* @example
|
|
5
5
|
* import { Schema , Blueprint } from 'tspace-mysql'
|
|
6
|
-
* await new Schema().table('
|
|
6
|
+
* await new Schema().table('users',{
|
|
7
7
|
* id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
8
8
|
* name : new Blueprint().varchar(255).default('my name'),
|
|
9
9
|
* email : new Blueprint().varchar(255).unique(),
|
|
@@ -194,6 +194,16 @@ declare class Blueprint {
|
|
|
194
194
|
* @return {this} this
|
|
195
195
|
*/
|
|
196
196
|
autoincrement(): this;
|
|
197
|
+
/**
|
|
198
|
+
* Assign attributes 'foreign' in table
|
|
199
|
+
* Reference bettwen Column Main to Column Child
|
|
200
|
+
* @param {object} property object { key , value , operator }
|
|
201
|
+
* @property {string?} property.reference
|
|
202
|
+
* @property {Model | string} property.on
|
|
203
|
+
* @property {string?} property.onDelete
|
|
204
|
+
* @property {string?} property.onUpdate
|
|
205
|
+
* @return {this} this
|
|
206
|
+
*/
|
|
197
207
|
foreign({ references, on, onDelete, onUpdate }: {
|
|
198
208
|
references?: string;
|
|
199
209
|
on: (new () => Model) | string;
|
|
@@ -5,7 +5,7 @@ exports.Blueprint = void 0;
|
|
|
5
5
|
* Make schema for table with Blueprint
|
|
6
6
|
* @example
|
|
7
7
|
* import { Schema , Blueprint } from 'tspace-mysql'
|
|
8
|
-
* await new Schema().table('
|
|
8
|
+
* await new Schema().table('users',{
|
|
9
9
|
* id : new Blueprint().int().notNull().primary().autoIncrement(),
|
|
10
10
|
* name : new Blueprint().varchar(255).default('my name'),
|
|
11
11
|
* email : new Blueprint().varchar(255).unique(),
|
|
@@ -315,6 +315,16 @@ class Blueprint {
|
|
|
315
315
|
this._addAssignAttribute(`AUTO_INCREMENT`);
|
|
316
316
|
return this;
|
|
317
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Assign attributes 'foreign' in table
|
|
320
|
+
* Reference bettwen Column Main to Column Child
|
|
321
|
+
* @param {object} property object { key , value , operator }
|
|
322
|
+
* @property {string?} property.reference
|
|
323
|
+
* @property {Model | string} property.on
|
|
324
|
+
* @property {string?} property.onDelete
|
|
325
|
+
* @property {string?} property.onUpdate
|
|
326
|
+
* @return {this} this
|
|
327
|
+
*/
|
|
318
328
|
foreign({ references, on, onDelete, onUpdate }) {
|
|
319
329
|
this.foreignKey = {
|
|
320
330
|
references: references == null ? 'id' : references,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractBuilder } from './
|
|
2
|
-
import { Pagination, Backup, ConnectionOptions, BackupToFile, Connection, ConnectionTransaction, BackupTableToFile } from '
|
|
1
|
+
import { AbstractBuilder } from './Abstracts/AbstractBuilder';
|
|
2
|
+
import { Pagination, Backup, ConnectionOptions, BackupToFile, Connection, ConnectionTransaction, BackupTableToFile } from '../Interface';
|
|
3
3
|
declare class Builder extends AbstractBuilder {
|
|
4
4
|
constructor();
|
|
5
5
|
/**
|
|
@@ -94,7 +94,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
94
94
|
* @param {any?} value
|
|
95
95
|
* @return {this}
|
|
96
96
|
*/
|
|
97
|
-
where(column: string |
|
|
97
|
+
where(column: string | Record<string, any>, operator?: any, value?: any): this;
|
|
98
98
|
/**
|
|
99
99
|
* The 'orWhere' method is used to add conditions to a database query.
|
|
100
100
|
*
|
|
@@ -403,6 +403,14 @@ declare class Builder extends AbstractBuilder {
|
|
|
403
403
|
* @return {this}
|
|
404
404
|
*/
|
|
405
405
|
orWhereQuery(callback: Function): this;
|
|
406
|
+
/**
|
|
407
|
+
* The 'orWhereGroup' method is used to add conditions to a database query to create a grouped condition.
|
|
408
|
+
*
|
|
409
|
+
* It allows you to specify conditions that records in the database must meet in order to be included in the result set.
|
|
410
|
+
* @param {function} callback callback query
|
|
411
|
+
* @return {this}
|
|
412
|
+
*/
|
|
413
|
+
orWhereGroup(callback: Function): this;
|
|
406
414
|
/**
|
|
407
415
|
* The 'whereCases' method is used to add conditions with cases to a database query.
|
|
408
416
|
*
|
|
@@ -829,12 +837,18 @@ declare class Builder extends AbstractBuilder {
|
|
|
829
837
|
*/
|
|
830
838
|
toRawSQL(): string;
|
|
831
839
|
/**
|
|
832
|
-
*
|
|
840
|
+
* The 'getTableName' method is used to get table name
|
|
833
841
|
* @return {string} return table name
|
|
834
842
|
*/
|
|
835
843
|
getTableName(): string;
|
|
836
844
|
/**
|
|
837
|
-
*
|
|
845
|
+
* The 'getSchema' method is used to get schema information
|
|
846
|
+
* @return {this} this this
|
|
847
|
+
*/
|
|
848
|
+
getSchema(): Promise<any[]>;
|
|
849
|
+
/**
|
|
850
|
+
* The 'bindColumn' method is used to concat table and column -> `users`.`id`
|
|
851
|
+
* @param {string} column
|
|
838
852
|
* @return {string} return table.column
|
|
839
853
|
*/
|
|
840
854
|
bindColumn(column: string): string;
|
|
@@ -1264,7 +1278,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1264
1278
|
* @return {promise<boolean>}
|
|
1265
1279
|
*/
|
|
1266
1280
|
drop(): Promise<boolean>;
|
|
1267
|
-
protected
|
|
1281
|
+
protected exceptColumns(): Promise<string[]>;
|
|
1268
1282
|
protected _updateHandler(column: string, value?: string | number | null | boolean): string;
|
|
1269
1283
|
protected copyBuilder(instance: Builder, options?: {
|
|
1270
1284
|
update?: boolean;
|
|
@@ -1282,6 +1296,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1282
1296
|
insert: () => string;
|
|
1283
1297
|
update: () => string;
|
|
1284
1298
|
delete: () => string;
|
|
1299
|
+
where: () => string | null;
|
|
1285
1300
|
any: () => string;
|
|
1286
1301
|
};
|
|
1287
1302
|
protected _buildQueryStatement(): {
|
|
@@ -1289,6 +1304,7 @@ declare class Builder extends AbstractBuilder {
|
|
|
1289
1304
|
insert: () => string;
|
|
1290
1305
|
update: () => string;
|
|
1291
1306
|
delete: () => string;
|
|
1307
|
+
where: () => string | null;
|
|
1292
1308
|
any: () => string;
|
|
1293
1309
|
};
|
|
1294
1310
|
protected _getState(key: string): any;
|
|
@@ -1300,7 +1316,6 @@ declare class Builder extends AbstractBuilder {
|
|
|
1300
1316
|
sql: string;
|
|
1301
1317
|
returnId?: boolean;
|
|
1302
1318
|
}): Promise<any>;
|
|
1303
|
-
private _queryWhereIsExists;
|
|
1304
1319
|
private _insertNotExists;
|
|
1305
1320
|
private _insert;
|
|
1306
1321
|
private _checkValueHasRaw;
|