dynoquery 0.1.8 → 0.1.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 +5 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,9 +31,9 @@ const db = new DynoQuery({
|
|
|
31
31
|
models: {
|
|
32
32
|
User: { pkPrefix: 'USER#' }, // TENANT#A#USER#
|
|
33
33
|
},
|
|
34
|
-
|
|
34
|
+
findBy: {
|
|
35
35
|
// TENANT#A#CAT#
|
|
36
|
-
|
|
36
|
+
Category: { indexName: 'GSI1', pkPrefix: 'CAT#' } // pkName defaults to GSI1PK, skName defaults to GSI1SK
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ async function example() {
|
|
|
44
44
|
|
|
45
45
|
// Use registered index
|
|
46
46
|
// Resulting GSI1PK: TENANT#A#CAT#1
|
|
47
|
-
const categories = db.
|
|
47
|
+
const categories = db.findByCategory('1');
|
|
48
48
|
const items = await categories.get('100');
|
|
49
49
|
const allItems = await categories.getAll();
|
|
50
50
|
|
|
@@ -67,9 +67,8 @@ async function example() {
|
|
|
67
67
|
// Create an item through partition
|
|
68
68
|
await john.create('PROFILE', { name: 'John Doe', email: 'john@example.com' });
|
|
69
69
|
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
const cat = db.ByCategory('USER');
|
|
70
|
+
// Resulting GSI1PK: TENANT#A#CAT#USER
|
|
71
|
+
const cat = db.findByCategory('USER');
|
|
73
72
|
await john.create('PROFILE', {
|
|
74
73
|
name: 'John Doe',
|
|
75
74
|
email: 'john@example.com',
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -41,7 +41,7 @@ const partition_1 = require("./partition");
|
|
|
41
41
|
class DynoQuery {
|
|
42
42
|
constructor(config = {}) {
|
|
43
43
|
this.registeredModels = {};
|
|
44
|
-
const { tableName, pkName, skName, pkPrefix, models,
|
|
44
|
+
const { tableName, pkName, skName, pkPrefix, models, findBy } = config, clientConfig = __rest(config, ["tableName", "pkName", "skName", "pkPrefix", "models", "findBy"]);
|
|
45
45
|
this.client = new client_dynamodb_1.DynamoDBClient(clientConfig);
|
|
46
46
|
this.docClient = lib_dynamodb_1.DynamoDBDocumentClient.from(this.client, {
|
|
47
47
|
marshallOptions: {
|
|
@@ -60,10 +60,11 @@ class DynoQuery {
|
|
|
60
60
|
};
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
if (
|
|
63
|
+
if (findBy) {
|
|
64
64
|
const { IndexQuery } = require("./index-query");
|
|
65
|
-
Object.entries(
|
|
66
|
-
|
|
65
|
+
Object.entries(findBy).forEach(([name, def]) => {
|
|
66
|
+
const methodName = `findBy${name}`;
|
|
67
|
+
this[methodName] = (id) => {
|
|
67
68
|
return new IndexQuery(this, {
|
|
68
69
|
indexName: def.indexName,
|
|
69
70
|
pkName: def.pkName,
|