@jspreddy/torq 0.1.31
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/LICENSE +21 -0
- package/README.md +146 -0
- package/dist/module.js +1149 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +113 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +60 -0
- package/src/core/Query.ts +574 -0
- package/src/core/Structure.ts +57 -0
- package/src/core/dynamo_reserved_words.ts +583 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sai Phaninder Reddy Jonnala
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# torq
|
|
2
|
+
|
|
3
|
+
SQL Like query builder for dynamodb.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
SQL Like Query interface for better code readability.
|
|
9
|
+
|
|
10
|
+
- Supports `select`, `scan` and `count` operations
|
|
11
|
+
- Supports **select**ing specific columns
|
|
12
|
+
- Supports **Hash Keys** and **Range Keys**
|
|
13
|
+
- Supports **Filters**
|
|
14
|
+
- Supports various operations for **Range Keys** and **Filters**
|
|
15
|
+
- Supports **Pagination** and **limit**ing results.
|
|
16
|
+
- Automatically handles reserved and special character attribute names by using `ExpressionAttributeNames`
|
|
17
|
+
- Supports querying on **Indexes**, with optional scan direction
|
|
18
|
+
- Well Tested: Unit tests + Integration Tests (using `jest-dynamodb`).
|
|
19
|
+
- Supports returning **Consumed Capacity** from dynamodb
|
|
20
|
+
|
|
21
|
+
> See tests for all the features that are supported, and examples on how to use them.
|
|
22
|
+
> - [Unit Tests](https://github.com/jspreddy/torq/blob/main/tests/unit-tests/index.test.js)
|
|
23
|
+
> - [Integration tests: Files Table](https://github.com/jspreddy/torq/blob/main/tests/integration-tests/00-files-table.test.js#L45)
|
|
24
|
+
> - [Integration tests: Users Table](https://github.com/jspreddy/torq/blob/main/tests/integration-tests/01-users-table.test.js#L33)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### Example 1: Basic query
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const myTable = new Table('some-table-name', 'pk', 'sk');
|
|
33
|
+
const x = new Query(myTable);
|
|
34
|
+
|
|
35
|
+
x.select(['asdf', 'pqrs'])
|
|
36
|
+
.where.hash.eq('aasdf')
|
|
37
|
+
.where.range.eq('1235:238h9084')
|
|
38
|
+
.filter.eq('flower', 'rose')
|
|
39
|
+
.filter.eq('isPolinated', true)
|
|
40
|
+
.limit(10);
|
|
41
|
+
|
|
42
|
+
// Convert to object that can be used with dynamodb client.
|
|
43
|
+
console.log(x.toDynamo());
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This is what `x.toDynamo()` returns.
|
|
48
|
+
```js
|
|
49
|
+
{
|
|
50
|
+
TableName: 'some-table-name',
|
|
51
|
+
Limit: 10,
|
|
52
|
+
ProjectionExpression: "asdf, pqrs",
|
|
53
|
+
KeyConditionExpression: "pk = :pk and sk = :sk",
|
|
54
|
+
FilterExpression: "flower = :flower and isPolinated = :isPolinated",
|
|
55
|
+
ExpressionAttributeValues: {
|
|
56
|
+
":pk": 'aasdf',
|
|
57
|
+
':sk': '1235:238h9084',
|
|
58
|
+
':flower': 'rose',
|
|
59
|
+
':isPolinated': true,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Example 2: Automatic handling of reserved attribute names.
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
const table = new Table('some-table-name', '_friend', '_best');
|
|
69
|
+
const x = new Query(table);
|
|
70
|
+
|
|
71
|
+
// query builder
|
|
72
|
+
x.select(['asdf', 'pqrs'])
|
|
73
|
+
.where.hash.eq('ramana')
|
|
74
|
+
.where.range.eq('bestie')
|
|
75
|
+
.filter.eq('_test', true)
|
|
76
|
+
.filter.eq('__test', 'stop!');
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// log the result
|
|
80
|
+
console.log(x.toDynamo());
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This is the resulting dynamo query.
|
|
84
|
+
```js
|
|
85
|
+
{
|
|
86
|
+
TableName: 'some-table-name',
|
|
87
|
+
Limit: 25,
|
|
88
|
+
ProjectionExpression: "asdf, pqrs",
|
|
89
|
+
KeyConditionExpression: "#_friend = :_friend and #_best = :_best",
|
|
90
|
+
FilterExpression: "#_test = :_test and #__test = :__test",
|
|
91
|
+
ExpressionAttributeNames: {
|
|
92
|
+
'#_friend': '_friend',
|
|
93
|
+
'#_best': '_best',
|
|
94
|
+
'#_test': '_test',
|
|
95
|
+
'#__test': '__test',
|
|
96
|
+
},
|
|
97
|
+
ExpressionAttributeValues: {
|
|
98
|
+
':_friend': 'ramana',
|
|
99
|
+
':_best': 'bestie',
|
|
100
|
+
':_test': true,
|
|
101
|
+
':__test': 'stop!',
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
> See the section on `"Reserved & Special Char Names"` in [unit tests](https://github.com/jspreddy/torq/blob/main/tests/unit-tests/index.test.js#L876) for more examples.
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### More Examples
|
|
111
|
+
|
|
112
|
+
See tests for all the features that are supported, and examples on how to use them.
|
|
113
|
+
- [Unit Tests](https://github.com/jspreddy/torq/blob/main/tests/unit-tests/index.test.js)
|
|
114
|
+
- [Integration tests: Files Table](https://github.com/jspreddy/torq/blob/main/tests/integration-tests/00-files-table.test.js#L45)
|
|
115
|
+
- [Integration tests: Users Table](https://github.com/jspreddy/torq/blob/main/tests/integration-tests/01-users-table.test.js#L33)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
-----------------------------
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# For Maintainer
|
|
124
|
+
|
|
125
|
+
## Reference Docs
|
|
126
|
+
|
|
127
|
+
Docs for referencing while building this library.
|
|
128
|
+
|
|
129
|
+
- [AWS Dynamodb](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html)
|
|
130
|
+
- [Dynamo Reserved Words](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html)
|
|
131
|
+
- [Dynamo Scan](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html)
|
|
132
|
+
- [Dynamo Parallel Scan](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.ParallelScan)
|
|
133
|
+
- [Dynamo TTL](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## TODO
|
|
137
|
+
|
|
138
|
+
- TODO: Provide an interface to run the dynamodb operations (Query, Scan).
|
|
139
|
+
|
|
140
|
+
- TODO: Add recursive ddb query/scan to fill the requested limit.
|
|
141
|
+
|
|
142
|
+
- TODO: Add support for parallel scans.
|
|
143
|
+
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.ParallelScan
|
|
144
|
+
|
|
145
|
+
- TODO: Add support for easy ttl operations.
|
|
146
|
+
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
|