rads-db 3.0.75 → 3.0.76

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.
@@ -114,18 +114,24 @@ var _default = options => (schema, entity) => {
114
114
  };
115
115
  },
116
116
  async putMany(items, ctx) {
117
+ const itemsToPut = [];
117
118
  for (const item of items) {
118
119
  const id = item?.id;
119
120
  if (!id) throw new Error(`You must provide an id`);
120
- const itemToPut = {
121
+ itemsToPut.push({
121
122
  _partition: entity,
122
123
  id,
123
124
  ...item
124
- };
125
- const response = await client.items.upsert(itemToPut);
125
+ });
126
+ }
127
+ for (const chunk of _lodash.default.chunk(itemsToPut, 200)) {
128
+ const response = await client.items.bulk(chunk.map(x => ({
129
+ operationType: "Upsert",
130
+ resourceBody: x
131
+ })));
126
132
  ctx?.log?.({
127
- charge: response.requestCharge,
128
- request: `put#${itemToPut._partition}|${itemToPut.id}`
133
+ charge: _lodash.default.sumBy(response, r => r.requestCharge),
134
+ request: `put#${itemsToPut[0]._partition}[${chunk.length}]`
129
135
  });
130
136
  }
131
137
  }
@@ -73,13 +73,24 @@ export default (options) => (schema, entity) => {
73
73
  return { nodes, cursor };
74
74
  },
75
75
  async putMany(items, ctx) {
76
+ const itemsToPut = [];
76
77
  for (const item of items) {
77
78
  const id = item?.id;
78
79
  if (!id)
79
80
  throw new Error(`You must provide an id`);
80
- const itemToPut = { _partition: entity, id, ...item };
81
- const response = await client.items.upsert(itemToPut);
82
- ctx?.log?.({ charge: response.requestCharge, request: `put#${itemToPut._partition}|${itemToPut.id}` });
81
+ itemsToPut.push({ _partition: entity, id, ...item });
82
+ }
83
+ for (const chunk of _.chunk(itemsToPut, 200)) {
84
+ const response = await client.items.bulk(
85
+ chunk.map((x) => ({
86
+ operationType: "Upsert",
87
+ resourceBody: x
88
+ }))
89
+ );
90
+ ctx?.log?.({
91
+ charge: _.sumBy(response, (r) => r.requestCharge),
92
+ request: `put#${itemsToPut[0]._partition}[${chunk.length}]`
93
+ });
83
94
  }
84
95
  }
85
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.75",
3
+ "version": "3.0.76",
4
4
  "packageManager": "pnpm@8.6.1",
5
5
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
6
6
  "author": "",