tspace-mysql 1.4.7 → 1.4.9
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 +128 -49
- package/dist/lib/{tspace/Interface.d.ts → Interface.d.ts} +18 -2
- 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 +3 -3
- 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 +22 -2
- package/dist/lib/tspace/Blueprint.d.ts +19 -5
- package/dist/lib/tspace/Blueprint.js +41 -19
- package/dist/lib/tspace/Builder.d.ts +26 -11
- package/dist/lib/tspace/Builder.js +378 -330
- package/dist/lib/tspace/DB.d.ts +42 -2
- package/dist/lib/tspace/DB.js +61 -5
- package/dist/lib/tspace/Decorator.d.ts +20 -0
- package/dist/lib/tspace/Decorator.js +166 -0
- 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} +103 -28
- package/dist/lib/tspace/{StateHandler.js → Handlers/State.js} +3 -2
- package/dist/lib/tspace/Model.d.ts +275 -11
- package/dist/lib/tspace/Model.js +989 -99
- package/dist/lib/tspace/Schema.js +5 -8
- package/dist/lib/tspace/index.d.ts +4 -0
- package/dist/lib/tspace/index.js +20 -2
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/index.js +9 -0
- package/dist/tests/01-Pool.test.d.ts +1 -0
- package/dist/tests/01-Pool.test.js +45 -0
- package/dist/tests/02-DB.test.d.ts +1 -0
- package/dist/tests/02-DB.test.js +109 -0
- package/dist/tests/03-Model.test.d.ts +1 -0
- package/dist/tests/03-Model.test.js +73 -0
- package/package.json +14 -3
- /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/README.md
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com)
|
|
4
4
|
[](https://www.npmjs.com)
|
|
5
5
|
|
|
6
|
-
tspace-mysql is an ORM
|
|
7
|
-
Its always support the latest TypeScript and JavaScript features and provide additional features that help you to develop.
|
|
6
|
+
tspace-mysql is an Object-Relational Mapping (ORM) tool designed to run seamlessly in Node.js and is fully compatible with TypeScript. It consistently supports the latest features in both TypeScript and JavaScript, providing additional functionalities to enhance your development experience.
|
|
8
7
|
|
|
9
8
|
## Install
|
|
10
9
|
|
|
@@ -29,6 +28,7 @@ npm install tspace-mysql --save
|
|
|
29
28
|
- [Deeply Nested Relations](#deeply-nested-relations)
|
|
30
29
|
- [Relation Exists](#relation-exists)
|
|
31
30
|
- [Built in Relation Functions](#built-in-relation-functions)
|
|
31
|
+
- [Decorator](#decorator)
|
|
32
32
|
- [Schema Model](#schema-model)
|
|
33
33
|
- [Validation](#validation)
|
|
34
34
|
- [Sync](#sync)
|
|
@@ -43,7 +43,7 @@ npm install tspace-mysql --save
|
|
|
43
43
|
- [Blueprint](#blueprint)
|
|
44
44
|
|
|
45
45
|
## Configuration
|
|
46
|
-
|
|
46
|
+
To establish a connection, the recommended method for creating your environment variables is by using a '.env' file. using the following:
|
|
47
47
|
```js
|
|
48
48
|
DB_HOST = localhost
|
|
49
49
|
DB_PORT = 3306
|
|
@@ -59,7 +59,7 @@ DB_DATABASE = database
|
|
|
59
59
|
* DB_DATE_STRINGS = true
|
|
60
60
|
*/
|
|
61
61
|
```
|
|
62
|
-
|
|
62
|
+
You can also create a file named 'db.tspace' to configure the connection. using the following:
|
|
63
63
|
```js
|
|
64
64
|
source db {
|
|
65
65
|
host = localhost
|
|
@@ -77,7 +77,7 @@ source db {
|
|
|
77
77
|
|
|
78
78
|
```
|
|
79
79
|
## Running Queries
|
|
80
|
-
Once you have configured your database connection, you
|
|
80
|
+
Once you have configured your database connection, you can execute queries using the following:
|
|
81
81
|
```js
|
|
82
82
|
+-------------+--------------+----------------------------+
|
|
83
83
|
| table users |
|
|
@@ -192,6 +192,19 @@ const hookResult = (result) => console.log('hook!! result => ',result)
|
|
|
192
192
|
const user = await new DB('users').where('id',1).hook(hookResult).findOne()
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
+
Running A Faker
|
|
196
|
+
```js
|
|
197
|
+
|
|
198
|
+
await new DB('users').faker(5)
|
|
199
|
+
// custom some columns
|
|
200
|
+
await new DB('users').faker(5 , (row , index) => {
|
|
201
|
+
return {
|
|
202
|
+
...row,
|
|
203
|
+
custom : 'custom' + index
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
```
|
|
207
|
+
|
|
195
208
|
Running A Insert Query
|
|
196
209
|
```js
|
|
197
210
|
const user = await new DB('users')
|
|
@@ -203,16 +216,6 @@ const user = await new DB('users')
|
|
|
203
216
|
// user => { id : 3 , username : 'tspace3', email : 'tspace3@gmail.com'}
|
|
204
217
|
|
|
205
218
|
+--------------------------------------------------------------------------+
|
|
206
|
-
|
|
207
|
-
const reposity = new DB('users')
|
|
208
|
-
reposity.name = 'tspace4'
|
|
209
|
-
reposity.email = 'tspace4@gmail.com'
|
|
210
|
-
|
|
211
|
-
await reposity.save()
|
|
212
|
-
|
|
213
|
-
const { result } = reposity
|
|
214
|
-
// result => { id : 4 , username : 'tspace4', email : 'tspace4@gmail.com'}
|
|
215
|
-
|
|
216
219
|
const users = await new DB('users')
|
|
217
220
|
.createMultiple([
|
|
218
221
|
{
|
|
@@ -260,39 +263,39 @@ const user = await new DB('users')
|
|
|
260
263
|
email : 'tspace1@gmail.com'
|
|
261
264
|
})
|
|
262
265
|
.save()
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
+--------------------------------------------------------------------------+
|
|
266
|
-
|
|
267
|
-
const reposity = new DB('users').where('id',1)
|
|
268
|
-
reposity.name = 'tspace1++'
|
|
269
|
-
reposity.email = 'tspace1++@gmail.com'
|
|
266
|
+
// UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
|
|
270
267
|
|
|
271
|
-
await
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
268
|
+
const user = await new DB('users')
|
|
269
|
+
.where('id',1)
|
|
270
|
+
.update({
|
|
271
|
+
name : 'tspace1**',
|
|
272
|
+
email : 'tspace1@gmail.com'
|
|
273
|
+
},['name'])
|
|
274
|
+
.save()
|
|
275
|
+
// 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;
|
|
275
276
|
|
|
276
277
|
```
|
|
277
|
-
Running A
|
|
278
|
+
Running A Update Or Created Query
|
|
278
279
|
```js
|
|
279
280
|
const user = await new DB('users')
|
|
280
281
|
.where('id',1)
|
|
281
282
|
.updateOrCreate({
|
|
282
|
-
|
|
283
|
-
|
|
283
|
+
name : 'tspace1**',
|
|
284
|
+
email : 'tspace1@gmail.com'
|
|
284
285
|
}).save()
|
|
285
|
-
//
|
|
286
|
+
// INSERT INTO `users` (`name`,`email`) VALUES ('tspace1**','tspace1@gmail.com');
|
|
287
|
+
|
|
288
|
+
// UPDATE `users` SET `name` = 'tspace1**',`email` = 'tspace1@gmail.com' WHERE `users`.`id` = '1' LIMIT 1;
|
|
286
289
|
```
|
|
287
290
|
|
|
288
291
|
Running A Delete Query
|
|
289
292
|
```js
|
|
290
293
|
const deleted = await new DB('users').where('id',1).delete()
|
|
291
|
-
//
|
|
294
|
+
// DELETE FROM `users` WHERE `users`.`id` = '1' LIMIT 1;
|
|
292
295
|
```
|
|
293
296
|
## Database Transactions
|
|
294
297
|
|
|
295
|
-
Within a
|
|
298
|
+
Within a database transaction, you can utilize the following:
|
|
296
299
|
|
|
297
300
|
```js
|
|
298
301
|
const connection = await new DB().beginTransaction()
|
|
@@ -352,7 +355,7 @@ try {
|
|
|
352
355
|
|
|
353
356
|
```
|
|
354
357
|
## Connection
|
|
355
|
-
When establishing a connection, you
|
|
358
|
+
When establishing a connection, you can specify options as follows:
|
|
356
359
|
```js
|
|
357
360
|
const connection = await new DB().getConnection({
|
|
358
361
|
host: 'localhost',
|
|
@@ -369,7 +372,7 @@ const users = await new DB('users')
|
|
|
369
372
|
```
|
|
370
373
|
|
|
371
374
|
## Backup
|
|
372
|
-
|
|
375
|
+
To backup a database, you can perform the following steps:
|
|
373
376
|
```js
|
|
374
377
|
/**
|
|
375
378
|
*
|
|
@@ -406,8 +409,7 @@ const backupToFile = await new DB().backupToFile({
|
|
|
406
409
|
```
|
|
407
410
|
|
|
408
411
|
## Generating Model Classes
|
|
409
|
-
To get started,
|
|
410
|
-
you may use the make:model command to generate a new model:
|
|
412
|
+
To get started, install the 'tspace-mysql' package globally using the following npm command:
|
|
411
413
|
|
|
412
414
|
```js
|
|
413
415
|
/**
|
|
@@ -500,8 +502,8 @@ export { User }
|
|
|
500
502
|
export default User
|
|
501
503
|
```
|
|
502
504
|
## Relationships
|
|
503
|
-
Relationships are defined as methods on your Model classes
|
|
504
|
-
Let's
|
|
505
|
+
Relationships are defined as methods on your Model classes.
|
|
506
|
+
Let's example a basic relationship:
|
|
505
507
|
|
|
506
508
|
## One To One
|
|
507
509
|
A one-to-one relationship is used to define relationships where a single model is the parent to one child models
|
|
@@ -647,8 +649,8 @@ const userUsingFunction = await new User().roles().findOne()
|
|
|
647
649
|
```
|
|
648
650
|
|
|
649
651
|
## Deeply Nested Relations
|
|
650
|
-
Relationships can
|
|
651
|
-
|
|
652
|
+
Relationships can involve deep connections.
|
|
653
|
+
Let's example of a deep relationship:
|
|
652
654
|
```js
|
|
653
655
|
import { Model } from 'tspace-mysql'
|
|
654
656
|
|
|
@@ -723,8 +725,8 @@ await new User()
|
|
|
723
725
|
|
|
724
726
|
```
|
|
725
727
|
## Relation Exists
|
|
726
|
-
Relationships can return only
|
|
727
|
-
|
|
728
|
+
Relationships can return results only if they are not empty in relations, considering soft deletes.
|
|
729
|
+
Let's illustrate this with an example of an existence check in relations:
|
|
728
730
|
```js
|
|
729
731
|
+-------------+--------------+----------------------------+--------------------+
|
|
730
732
|
| table users | |
|
|
@@ -820,8 +822,7 @@ await new User().relationsExists('posts').findMany()
|
|
|
820
822
|
|
|
821
823
|
```
|
|
822
824
|
## Built in Relation Functions
|
|
823
|
-
|
|
824
|
-
let's example a built in function :
|
|
825
|
+
Certainly, let's illustrate the use of a built-in function in the results of relationships:
|
|
825
826
|
```js
|
|
826
827
|
import { Model } from 'tspace-mysql'
|
|
827
828
|
|
|
@@ -859,16 +860,89 @@ for (const post of posts) {
|
|
|
859
860
|
const comments = await post.$comments()
|
|
860
861
|
}
|
|
861
862
|
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
## Decorator
|
|
866
|
+
Decorators can be used in a Model.
|
|
867
|
+
Let's illustrate this with an example of a decorator:
|
|
868
|
+
```js
|
|
869
|
+
|
|
870
|
+
import {
|
|
871
|
+
Blueprint,
|
|
872
|
+
Model ,
|
|
873
|
+
Table ,TableSingular, TablePlural,
|
|
874
|
+
UUID, SoftDelete, Timestamp,
|
|
875
|
+
Column, Pattern, Validate,
|
|
876
|
+
HasMany, HasOne, BelongsTo, BelongsToMany
|
|
877
|
+
|
|
878
|
+
} from 'tspace-mysql'
|
|
879
|
+
import { Post } from './Post'
|
|
880
|
+
import { PostUser } from './PostUser'
|
|
881
|
+
|
|
882
|
+
@Pattern('camelCase')
|
|
883
|
+
@UUID()
|
|
884
|
+
@SoftDelete()
|
|
885
|
+
@Timestamp()
|
|
886
|
+
@Table('users')
|
|
887
|
+
class User extends Model {
|
|
888
|
+
|
|
889
|
+
@Column(() => new Blueprint().int().notNull().primary().autoIncrement())
|
|
890
|
+
public id!: number
|
|
891
|
+
|
|
892
|
+
@Column(() => new Blueprint().varchar(50).null())
|
|
893
|
+
public uuid!: string
|
|
894
|
+
|
|
895
|
+
@Column(() => new Blueprint().varchar(50).null())
|
|
896
|
+
@Validate({
|
|
897
|
+
type : String,
|
|
898
|
+
require : true,
|
|
899
|
+
length : 50,
|
|
900
|
+
match: /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
901
|
+
unique : true,
|
|
902
|
+
fn : (email : string) => /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)
|
|
903
|
+
})
|
|
904
|
+
public email!: string
|
|
905
|
+
|
|
906
|
+
@Column(() => new Blueprint().varchar(50).null())
|
|
907
|
+
public name !: string
|
|
908
|
+
|
|
909
|
+
@Column(() => new Blueprint().varchar(50).null())
|
|
910
|
+
public username !: string
|
|
911
|
+
|
|
912
|
+
@Column(() => new Blueprint().varchar(50).null())
|
|
913
|
+
public password !: string
|
|
914
|
+
|
|
915
|
+
@Column(() => new Blueprint().timestamp().null())
|
|
916
|
+
public createdAt!: Date
|
|
917
|
+
|
|
918
|
+
@Column(() => new Blueprint().timestamp().null())
|
|
919
|
+
public updatedAt!: Date
|
|
920
|
+
|
|
921
|
+
@Column(() => new Blueprint().timestamp().null())
|
|
922
|
+
public deletedAt!: Date
|
|
923
|
+
|
|
924
|
+
@HasMany({ model : Post })
|
|
925
|
+
public posts!: Post[]
|
|
926
|
+
|
|
927
|
+
@HasOne({ model : Post })
|
|
928
|
+
public post!: Post
|
|
929
|
+
|
|
930
|
+
@BelongsToMany({ model : Post , modelPivot : PostUser })
|
|
931
|
+
public users!: PostUser[]
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
export { User }
|
|
935
|
+
export default User
|
|
936
|
+
|
|
862
937
|
```
|
|
863
938
|
## Schema Model
|
|
864
|
-
Define the schema of Model
|
|
865
|
-
let's example a validator model:
|
|
939
|
+
Define the schema of a Model
|
|
866
940
|
|
|
867
941
|
## Validation
|
|
868
942
|
Validate the schema of Model
|
|
869
943
|
let's example a validator model:
|
|
870
944
|
```js
|
|
871
|
-
|
|
945
|
+
import { Model , Blueprint , Column } from 'tspace-mysql'
|
|
872
946
|
class User extends Model {
|
|
873
947
|
constructor(){
|
|
874
948
|
super()
|
|
@@ -888,7 +962,7 @@ class User extends Model {
|
|
|
888
962
|
uuid : Number,
|
|
889
963
|
name : {
|
|
890
964
|
type : String,
|
|
891
|
-
length : 191
|
|
965
|
+
length : 191,
|
|
892
966
|
require : true,
|
|
893
967
|
json : true
|
|
894
968
|
},
|
|
@@ -898,7 +972,7 @@ class User extends Model {
|
|
|
898
972
|
length : 191,
|
|
899
973
|
match: /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
900
974
|
unique : true,
|
|
901
|
-
fn : (email : string) =>
|
|
975
|
+
fn : (email : string) => /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)
|
|
902
976
|
},
|
|
903
977
|
createdAt : Date,
|
|
904
978
|
updatedAt : Date,
|
|
@@ -1074,6 +1148,11 @@ max(column)
|
|
|
1074
1148
|
min(column)
|
|
1075
1149
|
pagination({ limit , page })
|
|
1076
1150
|
save() /* for actions statements insert or update */
|
|
1151
|
+
makeSelectStatement()
|
|
1152
|
+
makeInsertStatement()
|
|
1153
|
+
makeUpdateStatement()
|
|
1154
|
+
makeDeleteStatement()
|
|
1155
|
+
makeCreateStatement()
|
|
1077
1156
|
```
|
|
1078
1157
|
|
|
1079
1158
|
## 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,13 +12,14 @@ 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
|
}
|
|
18
19
|
export interface RelationQuery {
|
|
19
20
|
name?: string;
|
|
20
21
|
model: new () => Model;
|
|
21
|
-
as?: string;
|
|
22
|
+
as?: string | undefined;
|
|
22
23
|
localKey?: string | undefined;
|
|
23
24
|
foreignKey?: string | undefined;
|
|
24
25
|
freezeTable?: string | undefined;
|
|
@@ -28,6 +29,7 @@ export interface RelationQuery {
|
|
|
28
29
|
exists?: boolean | undefined;
|
|
29
30
|
all?: boolean | undefined;
|
|
30
31
|
trashed?: boolean | undefined;
|
|
32
|
+
count?: boolean | undefined;
|
|
31
33
|
oldVersion?: boolean | undefined;
|
|
32
34
|
modelPivot?: new () => Model | undefined;
|
|
33
35
|
}
|
|
@@ -141,3 +143,17 @@ export type ValidateSchema = null | Record<string, NumberConstructor | StringCon
|
|
|
141
143
|
json?: boolean;
|
|
142
144
|
fn?: Function;
|
|
143
145
|
}>;
|
|
146
|
+
export type ValidateSchemaDecorator = NumberConstructor | StringConstructor | DateConstructor | BooleanConstructor | {
|
|
147
|
+
type: NumberConstructor | StringConstructor | DateConstructor | BooleanConstructor;
|
|
148
|
+
require?: boolean;
|
|
149
|
+
match?: RegExp;
|
|
150
|
+
length?: number;
|
|
151
|
+
minLength?: number;
|
|
152
|
+
maxLength?: number;
|
|
153
|
+
min?: number;
|
|
154
|
+
max?: number;
|
|
155
|
+
enum?: string[] | number[] | boolean[];
|
|
156
|
+
unique?: boolean;
|
|
157
|
+
json?: boolean;
|
|
158
|
+
fn?: Function;
|
|
159
|
+
};
|
|
@@ -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: {
|
|
@@ -117,7 +117,7 @@ declare abstract class AbstractBuilder {
|
|
|
117
117
|
abstract save(): Promise<Record<string, any> | any[] | null | undefined>;
|
|
118
118
|
abstract increment(column: string, value: number): Promise<number>;
|
|
119
119
|
abstract decrement(column: string, value: number): Promise<number>;
|
|
120
|
-
abstract faker(round: number): Promise<
|
|
120
|
+
abstract faker(round: number, cb?: Function): Promise<Record<string, any>[]>;
|
|
121
121
|
}
|
|
122
122
|
export { AbstractBuilder };
|
|
123
123
|
export default AbstractBuilder;
|
|
@@ -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,8 +1,26 @@
|
|
|
1
|
-
import { Relation, RelationQuery } from '
|
|
1
|
+
import { Pattern, Relation, RelationQuery, ValidateSchema } from '../../Interface';
|
|
2
|
+
import { Blueprint } from '../Blueprint';
|
|
2
3
|
import { Builder } from '../Builder';
|
|
3
|
-
import { RelationHandler } from '../
|
|
4
|
+
import { RelationHandler } from '../Handlers/Relation';
|
|
4
5
|
declare abstract class AbstractModel extends Builder {
|
|
5
6
|
protected $relation: RelationHandler | undefined;
|
|
7
|
+
protected $schema: Record<string, Blueprint> | undefined;
|
|
8
|
+
protected $validateSchema: ValidateSchema | undefined;
|
|
9
|
+
protected $table: string | undefined;
|
|
10
|
+
protected $pattern: Pattern | undefined;
|
|
11
|
+
protected $hasMany: RelationQuery[] | undefined;
|
|
12
|
+
protected $hasOne: RelationQuery[] | undefined;
|
|
13
|
+
protected $belongsTo: RelationQuery[] | undefined;
|
|
14
|
+
protected $belongsToMany: RelationQuery[] | undefined;
|
|
15
|
+
protected $uuid: boolean | undefined;
|
|
16
|
+
protected $timestamp: boolean | undefined;
|
|
17
|
+
protected $softDelete: boolean | undefined;
|
|
18
|
+
protected $uuidColumn: string | undefined;
|
|
19
|
+
protected $timestampColumns: {
|
|
20
|
+
createdAt: string;
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
protected $softDeleteColumn: string | undefined;
|
|
6
24
|
protected abstract useUUID(): this;
|
|
7
25
|
protected abstract usePrimaryKey(primaryKey: string): this;
|
|
8
26
|
protected abstract useRegistry(): this;
|
|
@@ -14,6 +32,8 @@ declare abstract class AbstractModel extends Builder {
|
|
|
14
32
|
protected abstract useSoftDelete(): this;
|
|
15
33
|
protected abstract useHooks(functions: Function[]): this;
|
|
16
34
|
protected abstract usePattern(pattern: string): this;
|
|
35
|
+
protected abstract useCamelCase(pattern: string): this;
|
|
36
|
+
protected abstract useSnakeCase(pattern: string): this;
|
|
17
37
|
protected abstract useLoadRelationsInRegistry(): this;
|
|
18
38
|
protected abstract useBuiltInRelationFunctions(): this;
|
|
19
39
|
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(),
|
|
@@ -15,10 +15,10 @@ import { Model } from "./Model";
|
|
|
15
15
|
* })
|
|
16
16
|
*/
|
|
17
17
|
declare class Blueprint {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
private _type;
|
|
19
|
+
private _attributes;
|
|
20
|
+
private _foreignKey;
|
|
21
|
+
private _valueType;
|
|
22
22
|
/**
|
|
23
23
|
* Assign type 'int' in table
|
|
24
24
|
* @return {this} this
|
|
@@ -194,12 +194,26 @@ 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;
|
|
200
210
|
onDelete?: 'CASCADE' | 'NO ACTION' | 'RESTRICT' | 'SET NULL';
|
|
201
211
|
onUpdate?: 'CASCADE' | 'NO ACTION' | 'RESTRICT' | 'SET NULL';
|
|
202
212
|
}): this;
|
|
213
|
+
get type(): string;
|
|
214
|
+
get attributes(): string[];
|
|
215
|
+
get foreignKey(): Record<string, any> | null;
|
|
216
|
+
get valueType(): NumberConstructor | StringConstructor | DateConstructor;
|
|
203
217
|
private _addAssignType;
|
|
204
218
|
private _addAssignAttribute;
|
|
205
219
|
}
|