Gathering detailed insights and metrics for iesupdate-lb4-connector-dynamodb
Gathering detailed insights and metrics for iesupdate-lb4-connector-dynamodb
Gathering detailed insights and metrics for iesupdate-lb4-connector-dynamodb
Gathering detailed insights and metrics for iesupdate-lb4-connector-dynamodb
npm install iesupdate-lb4-connector-dynamodb
Typescript
Module System
Node Version
NPM Version
75.2
Supply Chain
98.6
Quality
75.1
Maintenance
100
Vulnerability
99.6
License
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
300%
4
Compared to previous week
Last month
200%
12
Compared to previous month
Last year
-30.5%
57
Compared to previous year
Refer to original https://github.com/tmpaul/jugglingdb-dynamodb
Forked from ggcasuso's loopback-connector-dynamodb
DynamoDB Connector for loopback (compatible with datasource-juggler) forked from this repository
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar [options]
-port
: port_number (8000 by default)--inMemory
: Run in memory--shared
: Shared DB1 var dynSettings = { 2 host: "localhost", 3 port:"8000", 4 accessKeyId: "mykey", 5 secretAccessKey:"secret" 6 };
host
: Address of the dynamodb server. Defaults to "localhost".port
: Port number of the dynamodb server. Defaults to "8000".region
: DynamoDB server region. Defaults to "ap-southeast-1".accessKeyId
: Your access key id. Defaults to "fake".secretAccessKey
: Your secret access key. Defaults to "fake".maxRetries
: Number of connection retries. Defaults to 0.logLevel
: Log level. Defaults to "debug".1 var Schema = require('jugglingdb').Schema; 2 var schemaDynamo = new Schema('dynamodb', dynSettings); 3 4 var User = schemaDynamo.define('User', { 5 id: { type: String, keyType: "hash", uuid: true}, 6 name: { type: String }, 7 age: { type: Number}, 8 isDead: { type: Boolean}, 9 DOB: { type: Date, keyType: "range"}, 10 tasks: { type: String, sharding: true, splitter: "60kb"} 11 }, { 12 table: "User" 13 });
credentials.json
in the root folder of your app. For example,1 { 2 "accessKeyId": "xxxxxxxxxxxxxx", 3 "secretAccessKey": "xxxxxxxxxxxxxxxxxx", 4 "region": "us-east-1" 5 }
If this file is missing, the adapter will try to read host, port , IDs and key from the values you pass in the schema/model file. See below for an example.
AWS_ACCESS_KEY_ID
& AWS_SECRET_ACCESS_KEY
. If these values are found, extra settings like region, maxRetries are loaded from dynSettings
. Example:1 var dynSettings = { region: "us-east-1", logLevel: "info" }
credentials.json
. Any extra settings like log level can still be passed with dynSettings
.1 var dynSettings = { logLevel: 'info' } 2 var Schema = require('jugglingdb').Schema; 3 var schemaDynamo = new Schema('dynamodb', dynSettings); 4 5 var User = schemaDynamo.define('User', { 6 id: { type: String, keyType: "hash", uuid: true}, 7 name: { type: String }, 8 age: { type: Number}, 9 isDead: { type: Boolean}, 10 DOB: { type: Date, keyType: "range"}, 11 tasks: { type: String, sharding: true, splitter: "60kb"} 12 }, { 13 table: "User", 14 ReadCapacityUnits: 15, 15 WriteCapacityUnits: 20, 16 });
CREATING
. The table will be ready for read or writes only when the table status changes to ACTIVE
. To make sure that tables are ready for your read/write operations, the adapter continuously checks for the table status. This behavior can be adjusted as follows:1 { 2 table : "User", 3 ReadCapacityUnits : 15, 4 WriteCapacityUnits: 20, 5 tableStatus : { waitTillActive: true, timeInterval : 2000 } 6 });
According to the above example, the table status is checked every 2000 ms.
If tableStatus property is not specified, the adapter automatically checks table status every 5000 ms. To turn this off, specify waitTillActive
as false.
Unlike other adapters, dynamodb adapter creates table when schema.define is called. Since the schema.define function does not accept a callback, listen to the created
event to check for table creation. The adapter also fires off a secondary created-modelName
event right after created
where modelName
is the model's name in LOWERCASE. The secondary event can be used to resolve ambiguities as to which model was created.
Additionally, if checking for table status is enabled, the created
event is emitted after the table status is ACTIVE
.
1 schemaDynamo.adapter.emitter.on("created", function() { 2 // Do stuff with user... 3 });
created-modelName
event. Example:1 schemaDynamo.adapter.emitter.on("created-user", function() { 2 // Do stuff with user... 3 });
1 // Assume there are 4 models. Check test/relations.test.js for an example. 2 var modelCount = 0; 3 schemaDynamo.adapter.emitter.on("created", function() { 4 modelCount++; 5 if (modelCount == 4) { 6 // ... Do stuff ... 7 } 8 });
1 During model definition, all errors are thrown because `schema.define` does not accept a callback.
DynamoDB primary key is a composite key consisting of a hash key and a range key. For a given item in the table, the key schema can specify one hash key or one hash key and a range key.
To specify a given attribute as hash key, use keyType: "hash"
along with its definition as shown in the above example.
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.
Similarly, attribute becomes a range key if keyType is set to "range".
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
must be id
. This restriction comes from JugglingDB.
If you forget to include a hash key for the model, automatically an attribute called id
is generated with uuid
set to true
.
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
.
1 var User = schemaDynamo.define('User', { 2 someId: { 3 type: String, 4 keyType: "hash", 5 uuid: true 6 }, ... 7 //Not allowed 8 9 var User = schemaDynamo.define('User', { 10 someId: { 11 type: String, 12 keyType: "hash" 13 }, ... 14 // Allowed
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. Unlike the above given case, id
attribute does not get created for the object.
The primary key must be defined as follows:
1 var User = schemaDynamo.define('User', { 2 id: { 3 type: String, 4 keyType: "pk", 5 separator: "--oo--" 6 }, 7 companyId: { 8 type: Number, 9 keyType: "hash" 10 }, 11 name: { 12 type: String 13 }, 14 age: { 15 type: Number, 16 keyType: "range" 17 }, 18 ... 19 });
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--
.
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.
true
or false
.set
property function of Jugglingdb. In the above example, the
read and write capacity units are set for User
.sharding
is set to true
in the model property.1 tasks: { 2 type: String, 3 sharding: true, 4 splitter: "63kb" 5 }
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:1 { 2 user#id: { "S" : "xxxxyyyyy" }, 3 tasks#ID: { "N" : "1" }, 4 tasks: { "S" : "This attribute has been broken" } 5 } 6 7 { 8 user#id: { "S" : "xxxxyyyyy" }, 9 tasks#ID: { "N" : "2" }, 10 tasks: { "S" : "down into two different pieces" } 11 }
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.
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.
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:
1 tasks: { 2 type: String, 3 sharding: true, 4 splitter: "63kb", 5 read: 15, 6 write: 20 7 }
If read and write are not specified, the read / write capacities of the parent table is used.
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.
1 // Only hash key 2 3 User = db.define('User', { 4 email: { type: String, keyType: "hash"}, 5 name: { type: String } 6 }); 7 8 // Both hash and range keys 9 10 Book = db.define('Book', { 11 id : { type: String, keyType: "pk"}, 12 title : { type: String, keyType: "hash"}, 13 subject : { type: String, keyType: "range"}, 14 }); 15 16 var user = new User(); 17 var book = new Book(); 18 19 user.email = "john@doe.com"; 20 user.name = "John Doe"; 21 22 /* Note that book's `id` is not specified. `id` being 23 a primary key is automatically created from the hash and range keys: 24 title and subject 25 */ 26 27 book.title = "A Lost Cause"; 28 book.subject = "Fiction"; 29 30 User.create(user, function(err, _user) { 31 ... 32 console.log(_user); 33 /* 34 { 35 id : "john@doe.com", 36 // Note that id is set to the same value as hashKey. This ensures that views don't break 37 email: "john@doe.com", 38 name: "John Doe", 39 } 40 */ 41 }); 42 43 Book.create(book, function(err, _book) { 44 ... 45 console.log(_book); 46 /* 47 { 48 id : "A Lost Cause--x--Fiction", // Value is simply returned by create. It does not exist in database. 49 title: "A Lost Cause", 50 subject: "Fiction" 51 } 52 */ 53 });
1 var id = "0e203f96-8edc-437a-b1f0-625a584a49bd"; 2 User.find(id, function (err, user) { 3 ... 4 });
query
operation if hash , hash/range keys are provided. Otherwise it will use scan
operation. Both operations are limited to a result set size of 1 mb by DynamoDB.1 User.all({ 2 where : { 3 age : { gt : 20 } 4 /* 5 or age : { between : [10,20] } - Between 6 or age : { eq : 20 } - Equal to 7 or age : [10,20] - In range 10 to 20 8 or age : { le : 35} - Less than or equal to 9 */ 10 } 11 }, function(err, users){ 12 ... 13 });
1 2 // Model instance.updateAttributes(...) 3 4 user.updateAttributes({name : "No Name"}, function(err, updatedUser){ 5 ... 6 });
create
method first.1 user.save(function(err, savedUser){ 2 ... 3 });
1 user.destroy(function(err){ 2 ... 3 });
npm test
command.mocha
and should
are required for the tests to run.logLevel
is debug
. You can suppress output of the test by changing the logLevel in test/init.js
to error
.No vulnerabilities found.
No security vulnerabilities found.