You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -81,7 +81,7 @@ If this file is missing, the adapter will try to read host, port , IDs and key f
81
81
});
82
82
```
83
83
84
-
####Explanation
84
+
###Explanation
85
85
- DynamoDB stores information in the form of tables. Each table has a collection of items. Think of items as a row in a table. Each
86
86
item in turn is a collection of attributes. Each attribute is stored in the database as a key:value pair.
87
87
@@ -91,50 +91,57 @@ one hash key or one hash key and a range key.
91
91
- To specify a given attribute as hash key, use `keyType: "hash"` along with its definition as shown in the above example.
92
92
- DynamoDB expects a hash key for every item that is created. If this value is not available at the time of creation, there is an option to use a UUID generator to generate the hash key. To use this option, specify `uuid: true` in the model definition.
93
93
- Similarly, attribute becomes a range key if keyType is set to "range".
94
-
- Make sure that the hash key and range keys are specified during CRUD operations. For most of these operations, hash key is a must and range key is optional, or conditional. Delete operation requires both hash and range keys. JugglingDB `destroy` method by default only
95
-
sends in the id of the model. To support destroy operation for items with range keys, add the following method in `lib/model.js` of JugglingDB
94
+
95
+
96
+
###USAGE
97
+
98
+
#####HASH KEY ONLY
99
+
- If a model only has a hash key, any attribute can be specified as the hash key. However, if `uuid` is set to `true`, then the attribute name
100
+
must be `id`. This restriction comes from JugglingDB.
101
+
- If no unique ID generation is present, the value of the hash key must be provided at the time of creating an item in the table. In this case, the attribute name can be anything; not just `id`.
96
102
```javascript
97
-
AbstractClass.prototype.remove=function (cb) {
98
-
if (stillConnecting(this.constructor.schema, this, arguments)) return;
99
-
100
-
var hashKey =this.schema.adapter._models[this.constructor.modelName].hashKey;
101
-
var rangeKey =this.schema.adapter._models[this.constructor.modelName].rangeKey;
102
-
103
-
this.trigger('destroy', function (destroyed) {
104
-
this._adapter().remove(this.constructor.modelName, this[hashKey], this[rangeKey], function (err) {
- To destroy an object with both hash and range key, use the following:
111
+
#####HASH & RANGE KEYS
112
+
- If a model has both hash & range keys, a primary key attribute called `id` must be present in the table. The attribute name cannot be anything else other than `id`, or the adapter will throw an error.
113
+
114
+
- The primary key must be defined as follows:
117
115
```javascript
118
-
user.remove(function(err){
119
-
if (err) {
116
+
var User =schemaDynamo.define('User', {
117
+
id : { type:String, keyType:"pk", separator :"--oo--"},
118
+
companyId : { type:Number, keyType:"hash"},
119
+
name: { type:String },
120
+
age: { type:Number , keyType:"range"},....
120
121
....
121
-
}
122
-
});
123
122
```
124
-
#####Data Types
123
+
- The separator is used to define the primary key based on the hash and range keys. If the hash key is `1` and the range key is `xyz`, then according to the above example, the primary key `id` will be `1--oo--xyz`. Any random separator can be used to store the primary key, but make sure that you do not include separators like `###` or `?`. These separators might cause problems in the view pages of the model, wherein they will be interpreted as part of the url. The default separator is `--x--`.
124
+
125
+
- The important thing to note is that the primary key is purely a virtual attribute to identify a particular item. It does not get persisted in the database.
126
+
127
+
#####DATATYPES
125
128
- DynamoDB supports only String, Binary, and Number datatypes along with their corresponding Sets.
126
129
- The adapter currently supports String, Number, Date and Boolean datatypes.
127
130
- Null, undefined and empty strings are handled by the adapter. However, invalid date or missing numbers might cause
128
131
DynamoDB to throw an error.
129
132
- Date is stored internally as a number, and boolean is stored as a string => `true` or `false`.
130
133
131
-
#####Read Write / Capacity Units
134
+
#####READ/ WRITE CAPCACITY UNITS
132
135
- Provisioned Throughput for each table can be specified by using the `set` property function of Jugglingdb. In the above example, the
133
136
read and write capacity units are set for `User`.
134
137
- The defaults for read and write capacity units are 5 and 10 respectively.
135
138
136
-
#####Database Limitations
137
-
- DynamoDB has an item size limit of 64 kb. Typically data is stored in the form of big strings in NoSQL tables (e.g objects with complex data structures). Eventually these strings might exceed 64 kb in size. To overcome this limitation, the adapter uses a sharding technique.
139
+
#####DATABASE LIMITATIONS
140
+
- DynamoDB has an item size limit of 64 kb. Typically data is stored in the form of big strings in NoSQL tables (e.g objects with complex data structures). Eventually these strings might exceed 64 kb in size. To overcome this limitation, the adapter uses a sharding technique. Sharding is done if `sharding` is set to `true` in the model property.
- When an attribute is being sharded, the attribute is separated from the parent table, and is stored in a different (child) table. According to the example above, tasks attribute will be stored in a new table called `User_tasks`. The primary key of User table `id`, is stored in the new table as `user#id`, and a new range key is assigned for every chunk that exceeds a given size. So if `splitter` is set to 60 kb, and the tasks string exceeds 60 kb, the structure of child table will be as shown below:
140
147
@@ -151,15 +158,104 @@ read and write capacity units are set for `User`.
151
158
tasks: { "S":"down into two different pieces" }
152
159
}
153
160
```
161
+
- The value of `splitter` can be anywhere from 1 to 63 kb. This is to make sure that there is enough room to store the primary key of parent table and the range key in the child table.
154
162
155
163
- The attribute value (String) is broken down based on the size specified by the `splitter` attribute. For example, in the above given model definition, the tasks string is broken down into 60 kb chunks. Each chunk is stored as a new item with a range key and the primary key of parent item.
156
164
157
165
- Due to the large size of items being retrieved/written to the child tables, these tables require more read and write capacity compared to the original table. Read and write capacities for the child table can be specified as follows:
- If read and write are not specified, the read / write capacities of the parent table is used.
170
+
161
171
- When the main item is being retrieved from the database, the adapter queries each child table, and builds back the string. As a result, the data structure is still intact after retrieval.
0 commit comments