dyna-record 0.0.14 → 0.0.16
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 +56 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,11 +48,19 @@ Entities in Dyna-Record represent your DynamoDB table structures and relationshi
|
|
|
48
48
|
|
|
49
49
|
[Docs](https://dyna-record.com/functions/Table.html)
|
|
50
50
|
|
|
51
|
-
Create a table class that extends [DynaRecord base class](https://dyna-record.com/classes/default.html) and
|
|
51
|
+
Create a table class that extends [DynaRecord base class](https://dyna-record.com/classes/default.html) and is decorated with the [Table decorator](https://dyna-record.com/functions/Table.html). At a minimum, the table class must define the [PartitionKeyAttribute](https://dyna-record.com/functions/PartitionKeyAttribute.html) and [SortKeyAttribute](https://dyna-record.com/functions/SortKeyAttribute.html).
|
|
52
52
|
|
|
53
53
|
#### Basic usage
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
|
+
import DynaRecord, {
|
|
57
|
+
Table,
|
|
58
|
+
PartitionKeyAttribute,
|
|
59
|
+
SortKeyAttribute,
|
|
60
|
+
PartitionKey,
|
|
61
|
+
SortKey
|
|
62
|
+
} from "dyna-record";
|
|
63
|
+
|
|
56
64
|
@Table({ name: "my-table", delimiter: "#" })
|
|
57
65
|
abstract class MyTable extends DynaRecord {
|
|
58
66
|
@PartitionKeyAttribute({ alias: "PK" })
|
|
@@ -66,6 +74,14 @@ abstract class MyTable extends DynaRecord {
|
|
|
66
74
|
#### Customizing the default field table aliases
|
|
67
75
|
|
|
68
76
|
```typescript
|
|
77
|
+
import DynaRecord, {
|
|
78
|
+
Table,
|
|
79
|
+
PartitionKeyAttribute,
|
|
80
|
+
SortKeyAttribute,
|
|
81
|
+
PartitionKey,
|
|
82
|
+
SortKey
|
|
83
|
+
} from "dyna-record";
|
|
84
|
+
|
|
69
85
|
@Table({
|
|
70
86
|
name: "mock-table",
|
|
71
87
|
delimiter: "#",
|
|
@@ -103,6 +119,8 @@ By default, each entity will have [default attributes](https://dyna-record.com/t
|
|
|
103
119
|
- [updatedAt](https://dyna-record.com/classes/default.html#updatedAt) - Timestamp of when the entity was updated last
|
|
104
120
|
|
|
105
121
|
```typescript
|
|
122
|
+
import { Entity } from "dyna-record";
|
|
123
|
+
|
|
106
124
|
@Entity
|
|
107
125
|
class Student extends MyTable {
|
|
108
126
|
// ...
|
|
@@ -124,6 +142,8 @@ For [natively supported data types](https://docs.aws.amazon.com/amazondynamodb/l
|
|
|
124
142
|
- Attempting to remove a non-nullable attribute will result in a [NullConstrainViolationError](https://dyna-record.com/classes/NullConstraintViolationError.html)
|
|
125
143
|
|
|
126
144
|
```typescript
|
|
145
|
+
import { Entity, Attribute, NullableAttribute } from "dyna-record";
|
|
146
|
+
|
|
127
147
|
@Entity
|
|
128
148
|
class Student extends MyTable {
|
|
129
149
|
@Attribute({ alias: "Username" }) // Sets alias if field in Dynamo is different then on the model
|
|
@@ -146,6 +166,8 @@ Dates are not natively supported in Dynamo. To define a date attribute use [@Dat
|
|
|
146
166
|
- Attempting to remove a non-nullable attribute will result in a [NullConstrainViolationError](https://dyna-record.com/classes/NullConstraintViolationError.html)
|
|
147
167
|
|
|
148
168
|
```typescript
|
|
169
|
+
import { Entity, DateAttribute, NullableDateAttribute } from "dyna-record";
|
|
170
|
+
|
|
149
171
|
@Entity
|
|
150
172
|
class Student extends MyTable {
|
|
151
173
|
@DateAttribute()
|
|
@@ -165,6 +187,15 @@ Define foreign keys in order to support [@BelongsTo](https://dyna-record.com/fun
|
|
|
165
187
|
- Attempting to remove an entity from a non-nullable foreign key will result in a [NullConstrainViolationError](https://dyna-record.com/classes/NullConstraintViolationError.html)
|
|
166
188
|
|
|
167
189
|
```typescript
|
|
190
|
+
import {
|
|
191
|
+
Entity,
|
|
192
|
+
ForeignKeyAttribute,
|
|
193
|
+
ForeignKey,
|
|
194
|
+
NullableForeignKeyAttribute,
|
|
195
|
+
NullableForeignKey,
|
|
196
|
+
BelongsTo
|
|
197
|
+
} from "dyna-record";
|
|
198
|
+
|
|
168
199
|
@Entity
|
|
169
200
|
class Assignment extends MyTable {
|
|
170
201
|
@ForeignKeyAttribute()
|
|
@@ -199,6 +230,14 @@ A relationship can be defined as nullable or non-nullable. Non-nullable relation
|
|
|
199
230
|
[Docs](https://dyna-record.com/functions/HasOne.html)
|
|
200
231
|
|
|
201
232
|
```typescript
|
|
233
|
+
import {
|
|
234
|
+
Entity,
|
|
235
|
+
ForeignKeyAttribute,
|
|
236
|
+
ForeignKey,
|
|
237
|
+
BelongsTo,
|
|
238
|
+
HasOne
|
|
239
|
+
} from "dyna-record";
|
|
240
|
+
|
|
202
241
|
@Entity
|
|
203
242
|
class Assignment extends MyTable {
|
|
204
243
|
// 'assignmentId' must be defined on associated model
|
|
@@ -222,6 +261,14 @@ class Grade extends MyTable {
|
|
|
222
261
|
[Docs](https://dyna-record.com/functions/HasMany.html)
|
|
223
262
|
|
|
224
263
|
```typescript
|
|
264
|
+
import {
|
|
265
|
+
Entity,
|
|
266
|
+
NullableForeignKeyAttribute,
|
|
267
|
+
NullableForeignKey,
|
|
268
|
+
BelongsTo,
|
|
269
|
+
HasMany
|
|
270
|
+
} from "dyna-record";
|
|
271
|
+
|
|
225
272
|
@Entity
|
|
226
273
|
class Teacher extends MyTable {
|
|
227
274
|
// 'teacherId' must be defined on associated model
|
|
@@ -247,6 +294,13 @@ class Course extends MyTable {
|
|
|
247
294
|
HasAndBelongsToMany relationships require a [JoinTable](https://dyna-record.com/classes/JoinTable.html) class. This represents a virtual table to support the relationship
|
|
248
295
|
|
|
249
296
|
```typescript
|
|
297
|
+
import {
|
|
298
|
+
Entity,
|
|
299
|
+
JoinTable,
|
|
300
|
+
ForeignKey,
|
|
301
|
+
HasAndBelongsToMany
|
|
302
|
+
} from "dyna-record";
|
|
303
|
+
|
|
250
304
|
class StudentCourse extends JoinTable<Student, Course> {
|
|
251
305
|
public readonly studentId: ForeignKey;
|
|
252
306
|
public readonly courseId: ForeignKey;
|
|
@@ -303,7 +357,7 @@ const grade: Grade = await Grade.create({
|
|
|
303
357
|
|
|
304
358
|
#### Error handling
|
|
305
359
|
|
|
306
|
-
The method is designed to throw errors under various conditions, such as transaction cancellation due to failed conditional checks. For instance, if you attempt to create a `Grade` for an `Assignment` that already has one, the method throws a
|
|
360
|
+
The method is designed to throw errors under various conditions, such as transaction cancellation due to failed conditional checks. For instance, if you attempt to create a `Grade` for an `Assignment` that already has one, the method throws a [TransactionWriteFailedError](https://dyna-record.com/classes/TransactionWriteFailedError.html).
|
|
307
361
|
|
|
308
362
|
#### Notes
|
|
309
363
|
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
package/dist/src/index.js
CHANGED