myorm_pg 2.0.0 → 2.1.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.
- package/README.md +356 -170
- package/lib/core/decorators/SchemasDecorators.d.ts +3 -0
- package/lib/core/decorators/SchemasDecorators.d.ts.map +1 -1
- package/lib/core/decorators/SchemasDecorators.js +14 -0
- package/lib/core/decorators/SchemasDecorators.js.map +1 -1
- package/lib/core/exceptions/ConstraintFailException.d.ts +5 -0
- package/lib/core/exceptions/ConstraintFailException.d.ts.map +1 -0
- package/lib/core/exceptions/ConstraintFailException.js +13 -0
- package/lib/core/exceptions/ConstraintFailException.js.map +1 -0
- package/lib/core/objects/interfaces/IDBConnection.d.ts +1 -0
- package/lib/core/objects/interfaces/IDBConnection.d.ts.map +1 -1
- package/lib/core/objects/interfaces/IDBContext.d.ts +2 -0
- package/lib/core/objects/interfaces/IDBContext.d.ts.map +1 -1
- package/lib/core/objects/interfaces/IDBManager.d.ts +1 -0
- package/lib/core/objects/interfaces/IDBManager.d.ts.map +1 -1
- package/lib/core/objects/interfaces/IDBSet.d.ts +19 -0
- package/lib/core/objects/interfaces/IDBSet.d.ts.map +1 -1
- package/lib/implementations/PGDBConnection.d.ts +1 -0
- package/lib/implementations/PGDBConnection.d.ts.map +1 -1
- package/lib/implementations/PGDBConnection.js +5 -0
- package/lib/implementations/PGDBConnection.js.map +1 -1
- package/lib/implementations/PGDBContext.d.ts +2 -0
- package/lib/implementations/PGDBContext.d.ts.map +1 -1
- package/lib/implementations/PGDBContext.js +10 -0
- package/lib/implementations/PGDBContext.js.map +1 -1
- package/lib/implementations/PGDBManager.d.ts +2 -0
- package/lib/implementations/PGDBManager.d.ts.map +1 -1
- package/lib/implementations/PGDBManager.js +37 -0
- package/lib/implementations/PGDBManager.js.map +1 -1
- package/lib/implementations/PGDBSet.d.ts +10 -2
- package/lib/implementations/PGDBSet.d.ts.map +1 -1
- package/lib/implementations/PGDBSet.js +117 -13
- package/lib/implementations/PGDBSet.js.map +1 -1
- package/lib/implementations/PGFluentField.d.ts +18 -0
- package/lib/implementations/PGFluentField.d.ts.map +1 -0
- package/lib/implementations/PGFluentField.js +154 -0
- package/lib/implementations/PGFluentField.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,121 +11,15 @@ npm install myorm_pg
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# Usage
|
|
15
15
|
This ORM is based on https://www.nuget.org/packages/Adr.MyORMForPostgreSQL for .NET. The usage is similar.
|
|
16
16
|
|
|
17
|
-
### ./entities/Person.ts
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { Table, Column, PrimaryKey, DataType, OneToMany, OneToOne, ManyToMany, DBTypes} from 'myorm_pg';
|
|
21
|
-
import { Message } from './Message';
|
|
22
|
-
|
|
23
|
-
@Table("person_tb")
|
|
24
|
-
export class Person
|
|
25
|
-
{
|
|
26
|
-
@PrimaryKey()
|
|
27
|
-
@Column()
|
|
28
|
-
@DataType(DBTypes.SERIAL)
|
|
29
|
-
public Id : number;
|
|
30
|
-
|
|
31
|
-
@Column()
|
|
32
|
-
public Name : string;
|
|
33
|
-
|
|
34
|
-
@Column("email_address")
|
|
35
|
-
public Email : string;
|
|
36
|
-
|
|
37
|
-
@Column()
|
|
38
|
-
public Age : number;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
@Column()
|
|
42
|
-
@DataType(DBTypes.INTEGER)
|
|
43
|
-
public CEP : number;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@Column()
|
|
47
|
-
@DataType(DBTypes.TEXTARRAY)
|
|
48
|
-
public PhoneNumbers : string[];
|
|
49
|
-
|
|
50
|
-
@Column()
|
|
51
|
-
@DataType(DBTypes.INTEGERARRAY)
|
|
52
|
-
public Documents : number[];
|
|
53
|
-
|
|
54
|
-
@Column()
|
|
55
|
-
@DataType(DBTypes.DATE)
|
|
56
|
-
public Birth : Date;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
@Column()
|
|
60
|
-
@OneToMany(()=> Message, "From")
|
|
61
|
-
public MessagesWriten? : Message[];
|
|
62
|
-
|
|
63
|
-
@Column()
|
|
64
|
-
@OneToMany(()=> Message, "To")
|
|
65
|
-
public MessagesReceived? : Message[];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
constructor(name : string = "", email : string = "", age : number = 1)
|
|
69
|
-
{
|
|
70
|
-
this.Id = -1;
|
|
71
|
-
this.Name = name;
|
|
72
|
-
this.Email = email;
|
|
73
|
-
this.Age = age;
|
|
74
|
-
this.CEP = -1;
|
|
75
|
-
this.PhoneNumbers = [];
|
|
76
|
-
this.Birth = new Date(1992,4,23);
|
|
77
|
-
this.Documents = [];
|
|
78
|
-
this.MessagesReceived = [];
|
|
79
|
-
this.MessagesWriten = [];
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### ./entities/Message.ts
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
import { Table, Column, PrimaryKey, DataType, ManyToOne, ManyToMany, DBTypes} from 'myorm_pg';
|
|
91
|
-
import { Person } from './Person';
|
|
92
|
-
|
|
93
|
-
@Table("message_tb")
|
|
94
|
-
export class Message
|
|
95
|
-
{
|
|
96
|
-
@PrimaryKey()
|
|
97
|
-
@Column()
|
|
98
|
-
@DataType(DBTypes.SERIAL)
|
|
99
|
-
public Id : number = -1;
|
|
100
|
-
|
|
101
|
-
@Column()
|
|
102
|
-
public Message : string;
|
|
103
|
-
|
|
104
|
-
@Column()
|
|
105
|
-
@ManyToOne(()=> Person, "MessagesWriten")
|
|
106
|
-
public From? : Person;
|
|
107
|
-
|
|
108
|
-
@Column()
|
|
109
|
-
@ManyToMany(()=> Person, "MessagesReceived")
|
|
110
|
-
public To? : Person[];
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
constructor(message : string, from? : Person, to? : Person[])
|
|
114
|
-
{
|
|
115
|
-
this.Message = message;
|
|
116
|
-
this.From = from;
|
|
117
|
-
this.To = to;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
17
|
|
|
124
18
|
### Context.ts
|
|
125
19
|
|
|
126
20
|
```typescript
|
|
127
21
|
import { PGDBManager, PGDBContext, PGDBSet} from 'myorm_pg';
|
|
128
|
-
import { Message } from './entities/Message';
|
|
22
|
+
import { Message } from './entities/Message';
|
|
129
23
|
import { Person } from './entities/Person';
|
|
130
24
|
|
|
131
25
|
|
|
@@ -143,18 +37,35 @@ export default class Context extends PGDBContext
|
|
|
143
37
|
}
|
|
144
38
|
```
|
|
145
39
|
|
|
146
|
-
|
|
147
|
-
|
|
40
|
+
# Create a instance of context and update or creare database
|
|
41
|
+
### Create with explicts parameters
|
|
42
|
+
|
|
148
43
|
```typescript
|
|
149
44
|
|
|
150
45
|
var context = new Context(PGDBManager.Build("localhost", 5432, "test_db", "username", "password"));
|
|
151
46
|
|
|
152
47
|
await context.UpdateDatabaseAsync();
|
|
153
48
|
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Create with enviroment variables
|
|
52
|
+
|
|
53
|
+
this method will try get values from __process.env__ keys. The ORM will search for __DB_HOST__, __DB_PORT__, __DB_NAME__, __DB_USER__ and __DB_PASS__
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
|
|
59
|
+
var context = new Context(PGDBManager.BuildFromEnviroment());
|
|
60
|
+
|
|
61
|
+
await context.UpdateDatabaseAsync();
|
|
62
|
+
|
|
154
63
|
|
|
155
64
|
```
|
|
156
65
|
|
|
157
|
-
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Insert entities
|
|
158
69
|
|
|
159
70
|
```typescript
|
|
160
71
|
|
|
@@ -170,68 +81,187 @@ await context.Persons.AddAsync(person);
|
|
|
170
81
|
```
|
|
171
82
|
|
|
172
83
|
|
|
173
|
-
|
|
84
|
+
## Insert entities with relation
|
|
174
85
|
In this case, all persons will be saved automatically. All persons of __Message.To__ property will have a reference to this message on property
|
|
175
86
|
__Person.MessagesReceived__ and the person of __Message.From__ will have a reference to this message on __Person.MessagesWriten__ property
|
|
176
87
|
|
|
177
88
|
```typescript
|
|
178
|
-
let msg = new Message(
|
|
179
|
-
"some message to my friends",
|
|
89
|
+
let msg = new Message("some message to my friends",
|
|
180
90
|
new Person("Adriano", "adriano@test.com"),
|
|
181
91
|
[
|
|
182
92
|
new Person("Camila", "camila@test.com"),
|
|
183
93
|
new Person("Juliana", "juliana@test.com"),
|
|
184
94
|
new Person("Andre", "andre@test.com")
|
|
185
|
-
|
|
186
|
-
]
|
|
187
|
-
);
|
|
95
|
+
]);
|
|
188
96
|
|
|
189
97
|
await context.Messages.AddAsync(msg);
|
|
190
98
|
|
|
191
99
|
```
|
|
192
100
|
|
|
101
|
+
# where
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
|
|
106
|
+
let persons = await context.Persons.Where({
|
|
107
|
+
Field : 'Name',
|
|
108
|
+
Value : 'Adriano'
|
|
109
|
+
})
|
|
110
|
+
.ToListAsync();
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
# And
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
|
|
119
|
+
let persons = await context.Persons.Where({
|
|
120
|
+
Field : 'Name',
|
|
121
|
+
Value : 'Adriano'
|
|
122
|
+
})
|
|
123
|
+
.And({
|
|
124
|
+
Field : 'Email',
|
|
125
|
+
Value : 'adriano@test.com'
|
|
126
|
+
})
|
|
127
|
+
.ToListAsync();
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# Or
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
|
|
137
|
+
let persons = await context.Persons.Where({
|
|
138
|
+
Field : 'Name',
|
|
139
|
+
Value : 'Adriano'
|
|
140
|
+
})
|
|
141
|
+
.Or({
|
|
142
|
+
Field : 'Email',
|
|
143
|
+
Value : 'adriano@test.com'
|
|
144
|
+
})
|
|
145
|
+
.ToListAsync();
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
|
|
193
149
|
|
|
194
|
-
|
|
150
|
+
# Operations
|
|
151
|
+
|
|
152
|
+
### Equals
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
|
|
156
|
+
let persons = await context.Persons.Where({
|
|
157
|
+
Field : 'Name',
|
|
158
|
+
Value : 'Adriano'
|
|
159
|
+
})
|
|
160
|
+
.ToListAsync();
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### Not equals
|
|
195
166
|
|
|
196
167
|
```typescript
|
|
197
168
|
|
|
198
|
-
let persons = await context.Persons
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
169
|
+
let persons = await context.Persons.Where({
|
|
170
|
+
Field : 'Name',
|
|
171
|
+
Kind : Operation.NOTEQUALS,
|
|
172
|
+
Value : 'Adriano'
|
|
173
|
+
})
|
|
174
|
+
.ToListAsync();
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Contains
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
205
181
|
|
|
182
|
+
let persons = await context.Persons.Where({
|
|
183
|
+
Field : 'Email',
|
|
184
|
+
Kind : Operation.CONTAINS,
|
|
185
|
+
Value : 'test@.com'
|
|
186
|
+
})
|
|
187
|
+
.ToListAsync();
|
|
206
188
|
```
|
|
207
189
|
|
|
208
190
|
|
|
209
|
-
###
|
|
191
|
+
### Starts with
|
|
210
192
|
|
|
211
193
|
```typescript
|
|
212
194
|
|
|
213
|
-
let persons = await context.Persons
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
195
|
+
let persons = await context.Persons.Where({
|
|
196
|
+
Field : 'Name',
|
|
197
|
+
Kind : Operation.STARTWITH,
|
|
198
|
+
Value : 'Adriano'
|
|
199
|
+
})
|
|
200
|
+
.ToListAsync();
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
### Ends with
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
|
|
208
|
+
let persons = await context.Persons.Where({
|
|
209
|
+
Field : 'Name',
|
|
210
|
+
Kind : Operation.ENDWITH,
|
|
211
|
+
Value : 'Adriano'
|
|
212
|
+
})
|
|
213
|
+
.ToListAsync();
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Greater
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
|
|
220
|
+
let persons = await context.Persons.Where({
|
|
221
|
+
Field : 'Age',
|
|
222
|
+
Kind : Operation.GREATER,
|
|
223
|
+
Value : 30
|
|
224
|
+
})
|
|
225
|
+
.ToListAsync();
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Smaller
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
|
|
232
|
+
let persons = await context.Persons.Where({
|
|
233
|
+
Field : 'Name',
|
|
234
|
+
Kind : Operation.SMALLER,
|
|
235
|
+
Value : 'Adriano'
|
|
236
|
+
})
|
|
237
|
+
.ToListAsync();
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
# Join
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
|
|
245
|
+
let persons = await context.Persons.Where({
|
|
246
|
+
Field : 'Name',
|
|
247
|
+
Value : 'Adriano'
|
|
248
|
+
})
|
|
249
|
+
.Join("MessagesReceived")
|
|
250
|
+
.ToListAsync();
|
|
221
251
|
|
|
222
252
|
```
|
|
223
253
|
This query will retrieve from database all persons with name "Adriano" and load all mensagens that this persons are in "To" list.
|
|
224
254
|
|
|
225
255
|
|
|
226
|
-
|
|
256
|
+
## Order by
|
|
227
257
|
|
|
228
258
|
```typescript
|
|
229
259
|
let all = await context.Persons
|
|
230
|
-
|
|
231
|
-
|
|
260
|
+
.OrderBy('Name')
|
|
261
|
+
.ToListAsync();
|
|
232
262
|
```
|
|
233
263
|
|
|
234
|
-
|
|
264
|
+
## Order by descending
|
|
235
265
|
|
|
236
266
|
```typescript
|
|
237
267
|
let all = await context.Persons
|
|
@@ -240,7 +270,7 @@ let all = await context.Persons
|
|
|
240
270
|
```
|
|
241
271
|
|
|
242
272
|
|
|
243
|
-
|
|
273
|
+
## Limit
|
|
244
274
|
|
|
245
275
|
```typescript
|
|
246
276
|
let all = await context.Persons
|
|
@@ -249,59 +279,215 @@ let all = await context.Persons
|
|
|
249
279
|
.ToListAsync();
|
|
250
280
|
```
|
|
251
281
|
|
|
252
|
-
|
|
282
|
+
## Get first or default
|
|
253
283
|
|
|
254
284
|
```typescript
|
|
255
|
-
let person
|
|
256
|
-
.Where(
|
|
257
|
-
{
|
|
285
|
+
let person = await context.Persons.Where({
|
|
258
286
|
Field : 'Name',
|
|
259
287
|
Value : 'Adriano'
|
|
260
|
-
|
|
261
|
-
|
|
288
|
+
})
|
|
289
|
+
.FirstOrDefaultAsync();
|
|
262
290
|
```
|
|
263
291
|
|
|
264
292
|
|
|
265
|
-
|
|
293
|
+
## Update person
|
|
266
294
|
|
|
267
295
|
```typescript
|
|
268
|
-
let person
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
.FirstOrDefaultAsync();
|
|
296
|
+
let person = await context.Persons.Where({
|
|
297
|
+
Field : 'Name',
|
|
298
|
+
Value : 'Adriano'
|
|
299
|
+
})
|
|
300
|
+
.FirstOrDefaultAsync();
|
|
276
301
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
person.Name = "Adriano Marino";
|
|
302
|
+
person.Name = "Adriano Marino";
|
|
303
|
+
await context.Persons.UpdateAsync(person);
|
|
280
304
|
|
|
281
|
-
await context.Persons.UpdateAsync(person);
|
|
282
|
-
}
|
|
283
305
|
```
|
|
284
306
|
|
|
285
307
|
|
|
286
308
|
|
|
287
309
|
|
|
288
|
-
|
|
310
|
+
## Delete
|
|
289
311
|
|
|
290
312
|
```typescript
|
|
291
|
-
let person
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
313
|
+
let person = await context.Persons.Where({
|
|
314
|
+
Field : 'Name',
|
|
315
|
+
Value : 'Adriano'
|
|
316
|
+
}).FirstOrDefaultAsync();
|
|
317
|
+
|
|
318
|
+
await context.Persons.DeleteAsync(person);
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
# Fluent query methods
|
|
323
|
+
|
|
324
|
+
## Where
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
let persons= await context.Persons.WhereField("Name").Constains("Adriano")
|
|
328
|
+
.AndLoadAll("MessagesReceived")
|
|
329
|
+
.ToListAsync();
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## And and Or
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
let persons = await context.Persons.WhereField("Name").Constains("Adriano")
|
|
336
|
+
.AndField("Age").IsGreaterThan(30)
|
|
337
|
+
.OrField("Email").Constains("@test.com")
|
|
338
|
+
.AndLoadAll("MessagesReceived")
|
|
339
|
+
.ToListAsync();
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## IsInsideIn
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
let persons = await context.Persons.WhereField("Age").IsInsideIn([1,30, 12, 40, 120]).ToListAsync();
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### This is equilalent to :
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
let persons = await context.Persons.Where({Field : 'Age', Value : 1})
|
|
352
|
+
.Or({Field : 'Age', Value : 30})
|
|
353
|
+
.Or({Field : "Age" , Value : 12})
|
|
354
|
+
.Or({Field : "Age" , Value : 40})
|
|
355
|
+
.Or({Field : "Age" , Value : 120})
|
|
356
|
+
.ToListAsync();
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Get null
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
let persons = await context.Persons.WhereField("MessagesReceived").IsNull().ToListAsync();
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
# Free hand query
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
let persons = await context.Persons.WhereAsString(`age > 30 or name ilike '%adriano%'`).ToListAsync();
|
|
369
|
+
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
# Method to run queries with connection manager system
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
let pg_result = await context.ExecuteQuery("select now()");
|
|
377
|
+
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
# Entities used in this example
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
### ./entities/Person.ts
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
import { Table, Column, PrimaryKey, DataType, OneToMany, OneToOne, ManyToMany, DBTypes} from 'myorm_pg';
|
|
388
|
+
import { Message } from './Message';
|
|
389
|
+
|
|
390
|
+
@Table("person_tb")
|
|
391
|
+
export class Person
|
|
392
|
+
{
|
|
393
|
+
@PrimaryKey()
|
|
394
|
+
@Column()
|
|
395
|
+
@DataType(DBTypes.SERIAL)
|
|
396
|
+
public Id : number;
|
|
397
|
+
|
|
398
|
+
@Column()
|
|
399
|
+
public Name : string;
|
|
400
|
+
|
|
401
|
+
@Column("email_address")
|
|
402
|
+
public Email : string;
|
|
403
|
+
|
|
404
|
+
@Column()
|
|
405
|
+
public Age : number;
|
|
406
|
+
|
|
299
407
|
|
|
300
|
-
|
|
408
|
+
@Column()
|
|
409
|
+
@DataType(DBTypes.INTEGER)
|
|
410
|
+
public CEP : number;
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
@Column()
|
|
414
|
+
@DataType(DBTypes.TEXTARRAY)
|
|
415
|
+
public PhoneNumbers : string[];
|
|
416
|
+
|
|
417
|
+
@Column()
|
|
418
|
+
@DataType(DBTypes.INTEGERARRAY)
|
|
419
|
+
public Documents : number[];
|
|
420
|
+
|
|
421
|
+
@Column()
|
|
422
|
+
@DataType(DBTypes.DATE)
|
|
423
|
+
public Birth : Date;
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
@Column()
|
|
427
|
+
@OneToMany(()=> Message, "From")
|
|
428
|
+
public MessagesWriten? : Message[];
|
|
429
|
+
|
|
430
|
+
@Column()
|
|
431
|
+
@OneToMany(()=> Message, "To")
|
|
432
|
+
public MessagesReceived? : Message[];
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
constructor(name : string = "", email : string = "", age : number = 1)
|
|
436
|
+
{
|
|
437
|
+
this.Id = -1;
|
|
438
|
+
this.Name = name;
|
|
439
|
+
this.Email = email;
|
|
440
|
+
this.Age = age;
|
|
441
|
+
this.CEP = -1;
|
|
442
|
+
this.PhoneNumbers = [];
|
|
443
|
+
this.Birth = new Date(1992,4,23);
|
|
444
|
+
this.Documents = [];
|
|
445
|
+
this.MessagesReceived = [];
|
|
446
|
+
this.MessagesWriten = [];
|
|
447
|
+
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### ./entities/Message.ts
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
import { Table, Column, PrimaryKey, DataType, ManyToOne, ManyToMany, DBTypes} from 'myorm_pg';
|
|
458
|
+
import { Person } from './Person';
|
|
459
|
+
|
|
460
|
+
@Table("message_tb")
|
|
461
|
+
export class Message
|
|
301
462
|
{
|
|
302
|
-
|
|
463
|
+
@PrimaryKey()
|
|
464
|
+
@Column()
|
|
465
|
+
@DataType(DBTypes.SERIAL)
|
|
466
|
+
public Id : number = -1;
|
|
467
|
+
|
|
468
|
+
@Column()
|
|
469
|
+
public Message : string;
|
|
470
|
+
|
|
471
|
+
@Column()
|
|
472
|
+
@ManyToOne(()=> Person, "MessagesWriten")
|
|
473
|
+
public From? : Person;
|
|
474
|
+
|
|
475
|
+
@Column()
|
|
476
|
+
@ManyToMany(()=> Person, "MessagesReceived")
|
|
477
|
+
public To? : Person[];
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
constructor(message : string, from? : Person, to? : Person[])
|
|
481
|
+
{
|
|
482
|
+
this.Message = message;
|
|
483
|
+
this.From = from;
|
|
484
|
+
this.To = to;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
|
|
303
488
|
}
|
|
304
489
|
```
|
|
490
|
+
|
|
305
491
|
## Contributing
|
|
306
492
|
|
|
307
493
|
Pull requests are welcome. For major changes, please open an issue first
|
|
@@ -7,10 +7,13 @@ export default class SchemasDecorators {
|
|
|
7
7
|
private static _dataTypeAttribute;
|
|
8
8
|
private static _primaryKeyAttribute;
|
|
9
9
|
private static _relationAttribute;
|
|
10
|
+
private static _notNullAttribute;
|
|
10
11
|
static Table(name?: string): (target: Object) => void;
|
|
11
12
|
static GetTableAttribute(target: Object): string | undefined;
|
|
12
13
|
static Column(name?: string): (target: Object, propertyName: string) => void;
|
|
13
14
|
static GetColumnAttribute(cTor: Function, propertyName: string): string | undefined;
|
|
15
|
+
static NotNull(): (target: Object, propertyName: string) => void;
|
|
16
|
+
static AllowNullValue(cTor: Function, propertyName: string): boolean;
|
|
14
17
|
static OneToOne<T>(lazyBuilder: () => {
|
|
15
18
|
new (...args: any[]): T;
|
|
16
19
|
}, property?: keyof T & string): (target: Object, propertyName: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemasDecorators.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/SchemasDecorators.ts"],"names":[],"mappings":"AACA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,E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AS;WAY/E,QAAQ,CAAC,IAAI,EAAG,OAAO,YAEP,MAAM,gBAAiB,MAAM;WAO7C,oBAAoB,CAAC,IAAI,EAAG,QAAQ,EAAE,YAAY,EAAG,MAAM,GAAI,OAAO,GAAG,SAAS;CAcnG"}
|
|
@@ -33,6 +33,19 @@ class SchemasDecorators {
|
|
|
33
33
|
meta = (_a = OwnMetaDataContainer.Get(cTor, SchemasDecorators._columnAttribute, propertyName)) === null || _a === void 0 ? void 0 : _a.Value;
|
|
34
34
|
return meta;
|
|
35
35
|
}
|
|
36
|
+
static NotNull() {
|
|
37
|
+
return function (target, propertyName) {
|
|
38
|
+
OwnMetaDataContainer.Set(target.constructor, SchemasDecorators._notNullAttribute, propertyName, true);
|
|
39
|
+
Reflect.defineMetadata(SchemasDecorators._notNullAttribute, true, target.constructor, propertyName);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
static AllowNullValue(cTor, propertyName) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
let meta = Reflect.getMetadata(SchemasDecorators._notNullAttribute, cTor, propertyName);
|
|
45
|
+
if (meta == undefined)
|
|
46
|
+
meta = (_b = (_a = OwnMetaDataContainer.Get(cTor, SchemasDecorators._notNullAttribute, propertyName)) === null || _a === void 0 ? void 0 : _a.Value) !== null && _b !== void 0 ? _b : false;
|
|
47
|
+
return !meta;
|
|
48
|
+
}
|
|
36
49
|
static OneToOne(lazyBuilder, property) {
|
|
37
50
|
return SchemasDecorators.Relation(lazyBuilder, RelationType_1.RelationType.ONE_TO_ONE, property);
|
|
38
51
|
}
|
|
@@ -105,6 +118,7 @@ SchemasDecorators._columnAttribute = "compile:schema-column";
|
|
|
105
118
|
SchemasDecorators._dataTypeAttribute = "compile:schema-dataType";
|
|
106
119
|
SchemasDecorators._primaryKeyAttribute = "compile:schema-primarykey";
|
|
107
120
|
SchemasDecorators._relationAttribute = "compile:schema-relationWith";
|
|
121
|
+
SchemasDecorators._notNullAttribute = "compile:schema-notNull";
|
|
108
122
|
class OwnMetaDataContainer {
|
|
109
123
|
static Get(target, key, member) {
|
|
110
124
|
let meta = this._metadas.filter(s => s.Key == key && (s.CTor == target || s.CTor == target.prototype) && s.Member == member);
|