dynoquery 0.1.10 → 0.1.11

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 CHANGED
@@ -33,7 +33,8 @@ const db = new DynoQuery({
33
33
  },
34
34
  findBy: {
35
35
  // TENANT#A#CAT#
36
- Category: { indexName: 'GSI1', pkPrefix: 'CAT#' } // pkName defaults to GSI1PK, skName defaults to GSI1SK
36
+ Category: { indexName: 'GSI1', pkPrefix: 'CAT#' }, // pkName defaults to GSI1PK, skName defaults to GSI1SK
37
+ Date: { indexName: 'GSI2', pkPrefix: 'DATE#' }
37
38
  }
38
39
  });
39
40
 
@@ -69,13 +70,12 @@ async function example() {
69
70
 
70
71
  // Resulting GSI1PK: TENANT#A#CAT#USER
71
72
  const cat = db.findByCategory('USER', '1');
73
+ const date = db.findByDate('2026-10-11', '2');
72
74
  console.log(cat.getSkValue()); // '1'
73
75
  await john.create('PROFILE', {
74
76
  name: 'John Doe',
75
77
  email: 'john@example.com',
76
- GSI1PK: cat.getPkValue(),
77
- GSI1SK: cat.getSkValue()
78
- });
78
+ }, [cat, date]);
79
79
 
80
80
  // Update the item (updates both DB and partition cache)
81
81
  await john.update('PROFILE', { theme: 'dark' });
@@ -112,7 +112,7 @@ A way to manage data within a specific partition.
112
112
  - `getPkValue()`: Returns the generated partition key value.
113
113
  - `get(sk)`: Fetches data for a specific sort key (returns a Promise).
114
114
  - `getAll()`: Fetches all items in the partition and caches them. Returns the items.
115
- - `create(sk, data)`: Creates an item in the partition.
115
+ - `create(sk, data, indices?)`: Creates an item in the partition. If `indices` (array of `IndexQuery`) are provided, it automatically adds the index PK and SK to the item.
116
116
  - `update(sk, data)`: Updates an existing item (partial update).
117
117
  - `delete(sk)`: Deletes an item.
118
118
  - `deleteAll()`: Deletes all items in the partition.
@@ -24,6 +24,8 @@ export declare class IndexQuery {
24
24
  }): Promise<T[]>;
25
25
  getAll<T = any>(): Promise<T[]>;
26
26
  getPkValue(): string;
27
+ getPkName(): string;
28
+ getSkName(): string;
27
29
  getSkValue(): string | undefined;
28
30
  private mapItemToModel;
29
31
  }
@@ -75,6 +75,12 @@ class IndexQuery {
75
75
  getPkValue() {
76
76
  return this.pkValue;
77
77
  }
78
+ getPkName() {
79
+ return this.pkName;
80
+ }
81
+ getSkName() {
82
+ return this.skName;
83
+ }
78
84
  getSkValue() {
79
85
  return this.skValue;
80
86
  }
@@ -1,4 +1,5 @@
1
1
  import { DynoQuery } from "./index";
2
+ import { IndexQuery } from "./index-query";
2
3
  export interface PartitionConfig {
3
4
  tableName?: string;
4
5
  pk?: string;
@@ -21,7 +22,7 @@ export declare class Partition {
21
22
  /**
22
23
  * Create an item in this partition.
23
24
  */
24
- create<T = any>(sk: string, data: T): Promise<void>;
25
+ create<T = any>(sk: string, data: T, indices?: IndexQuery[]): Promise<void>;
25
26
  /**
26
27
  * Update an existing item in this partition.
27
28
  */
package/dist/partition.js CHANGED
@@ -79,9 +79,17 @@ class Partition {
79
79
  /**
80
80
  * Create an item in this partition.
81
81
  */
82
- create(sk, data) {
82
+ create(sk, data, indices) {
83
83
  return __awaiter(this, void 0, void 0, function* () {
84
84
  const item = Object.assign({ [this.pkName]: this.pkValue, [this.skName]: sk }, data);
85
+ if (indices) {
86
+ indices.forEach((index) => {
87
+ item[index.getPkName()] = index.getPkValue();
88
+ if (index.getSkValue() !== undefined) {
89
+ item[index.getSkName()] = index.getSkValue();
90
+ }
91
+ });
92
+ }
85
93
  yield this.db.create({
86
94
  TableName: this.tableName,
87
95
  Item: item,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynoquery",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/devspikejs/dynoquery.git"