dynamo-bao 0.1.2 → 0.1.3
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 +53 -53
- package/bin/dynamo-bao-create-table.js +1 -1
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Adrian Graham
|
|
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
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# DynamoBao
|
|
2
2
|
|
|
3
|
+
[](https://github.com/aag1024/dynamo-bao)
|
|
4
|
+
[](https://badge.fury.io/js/dynamo-bao)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
3
7
|
DynamoBao is a simple lightweight library for building DynamoDB models in JavaScript. I've used
|
|
4
8
|
DynamoDB for years and generally love it, but find getting started difficult and repetitive.
|
|
5
9
|
DynamoBao is the tool I wish I had when I started.
|
|
@@ -155,7 +159,7 @@ npm install dynamo-bao
|
|
|
155
159
|
Create a new Dynamo table for your project. You should have one table per project.
|
|
156
160
|
|
|
157
161
|
```
|
|
158
|
-
npx bao-
|
|
162
|
+
npx bao-init
|
|
159
163
|
```
|
|
160
164
|
|
|
161
165
|
This creates a `config.js` which contains settings for your project like AWS region and the table name.
|
|
@@ -218,60 +222,56 @@ const { Post } = require("./models/post");
|
|
|
218
222
|
const userConfig = require("./config");
|
|
219
223
|
const dynamoBao = require("dynamo-bao");
|
|
220
224
|
async function testUserModel() {
|
|
221
|
-
|
|
222
|
-
dynamoBao.initModels(userConfig);
|
|
223
|
-
|
|
224
|
-
// Find user by email
|
|
225
|
-
const existingUser = await User.findByEmail("test@example.com");
|
|
226
|
-
console.log("Found user by email:", existingUser.exists());
|
|
227
|
-
if (existingUser.exists()) {
|
|
228
|
-
await User.delete(existingUser.getPrimaryId());
|
|
229
|
-
console.log("Deleted existing user");
|
|
230
|
-
await new Promise((resolve) => setTimeout(resolve, 100)); // 100ms
|
|
231
|
-
}
|
|
225
|
+
dynamoBao.initModels(userConfig);
|
|
232
226
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
await user.save();
|
|
242
|
-
console.log("Created user:", user.getPrimaryId());
|
|
243
|
-
|
|
244
|
-
// Find user by email
|
|
245
|
-
const foundUser = await User.findByEmail("test@example.com");
|
|
246
|
-
console.log("Found user by email:", foundUser.getPrimaryId());
|
|
247
|
-
|
|
248
|
-
// Create some test posts for the user
|
|
249
|
-
const post1 = new Post({
|
|
250
|
-
userId: user.userId,
|
|
251
|
-
title: "Test Post 1",
|
|
252
|
-
content: "This is a test post",
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
const post2 = new Post({
|
|
256
|
-
userId: user.userId,
|
|
257
|
-
title: "Test Post 2",
|
|
258
|
-
content: "This is another test post",
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
await Promise.all([post1.save(), post2.save()]);
|
|
262
|
-
|
|
263
|
-
// Query user posts
|
|
264
|
-
const userPosts = await user.queryPosts();
|
|
265
|
-
console.log("User posts:", userPosts.items.length);
|
|
266
|
-
|
|
267
|
-
// Or add a filter condition to the query
|
|
268
|
-
const filteredPosts = await user.queryPosts(null, {
|
|
269
|
-
filter: { content: { $contains: "another" } },
|
|
270
|
-
});
|
|
271
|
-
console.log("User posts matching filter:", filteredPosts.items.length);
|
|
272
|
-
} catch (error) {
|
|
273
|
-
console.error("Error:", error);
|
|
227
|
+
// Find user by email
|
|
228
|
+
const existingUser = await User.findByEmail("test@example.com");
|
|
229
|
+
console.log("Found user by email:", existingUser.exists());
|
|
230
|
+
if (existingUser.exists()) {
|
|
231
|
+
await User.delete(existingUser.getPrimaryId());
|
|
232
|
+
console.log("Deleted existing user");
|
|
233
|
+
await new Promise((resolve) => setTimeout(resolve, 100)); // 100ms
|
|
274
234
|
}
|
|
235
|
+
|
|
236
|
+
// Create a new user
|
|
237
|
+
const user = new User({
|
|
238
|
+
name: "Test User",
|
|
239
|
+
email: "test@example.com",
|
|
240
|
+
role: "user",
|
|
241
|
+
profilePictureUrl: "https://example.com/profile.jpg",
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
await user.save();
|
|
245
|
+
console.log("Created user:", user.getPrimaryId());
|
|
246
|
+
|
|
247
|
+
// Find user by email
|
|
248
|
+
const foundUser = await User.findByEmail("test@example.com");
|
|
249
|
+
console.log("Found user by email:", foundUser.getPrimaryId());
|
|
250
|
+
|
|
251
|
+
// Create some test posts for the user
|
|
252
|
+
const post1 = new Post({
|
|
253
|
+
userId: user.userId,
|
|
254
|
+
title: "Test Post 1",
|
|
255
|
+
content: "This is a test post",
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const post2 = new Post({
|
|
259
|
+
userId: user.userId,
|
|
260
|
+
title: "Test Post 2",
|
|
261
|
+
content: "This is another test post",
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
await Promise.all([post1.save(), post2.save()]);
|
|
265
|
+
|
|
266
|
+
// Query user posts
|
|
267
|
+
const userPosts = await user.queryPosts();
|
|
268
|
+
console.log("User posts:", userPosts.items.length);
|
|
269
|
+
|
|
270
|
+
// Or add a filter condition to the query
|
|
271
|
+
const filteredPosts = await user.queryPosts(null, {
|
|
272
|
+
filter: { content: { $contains: "another" } },
|
|
273
|
+
});
|
|
274
|
+
console.log("User posts matching filter:", filteredPosts.items.length);
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
// Run the test
|
|
@@ -172,7 +172,7 @@ async function createDirectoriesAndFiles() {
|
|
|
172
172
|
|
|
173
173
|
// Create models.yaml with default content
|
|
174
174
|
const modelsYamlPath = path.resolve(process.cwd(), "models.yaml");
|
|
175
|
-
const yamlContent = `# Edit this file to create your models. For more information see:
|
|
175
|
+
const yamlContent = `# Edit this file to create your models. For more information see: aag1024.github.io/dynamo-bao/
|
|
176
176
|
#
|
|
177
177
|
# Here's a simple example:
|
|
178
178
|
# models:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynamo-bao",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Simple powerful data modeling primitives for DynamoDB in JavaScript.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "
|
|
30
|
+
"url": "https://github.com/aag1024/dynamo-bao"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@aws-sdk/client-dynamodb": "^3.521.0",
|