rads-db 0.1.68 → 0.1.69

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.
@@ -36,22 +36,72 @@ var _default = options => (schema, entity) => {
36
36
  });
37
37
  return r.resources;
38
38
  }
39
+ async function getMany(args, ctx) {
40
+ args = args || {};
41
+ const where = args.where || {};
42
+ const whereKeys = _lodash.default.keys(where);
43
+ if (whereKeys.length === 1) {
44
+ if (whereKeys[0] === "id" && where.id != null) {
45
+ const items = await getItemByIds([where.id], ctx);
46
+ return {
47
+ nodes: [items[0]].filter(x => x),
48
+ cursor: null
49
+ };
50
+ }
51
+ if (whereKeys[0] === "id_in" && where.id_in != null) {
52
+ const items = await getItemByIds(where.id_in, ctx);
53
+ return {
54
+ nodes: items.filter(x => x),
55
+ cursor: null
56
+ };
57
+ }
58
+ }
59
+ const {
60
+ query,
61
+ parameters
62
+ } = getCosmosQuery(schema, entity, args);
63
+ const response = client.items.query({
64
+ query,
65
+ parameters: Object.keys(parameters).map(k => ({
66
+ name: `@${k}`,
67
+ value: parameters[k]
68
+ }))
69
+ }, {
70
+ continuationToken: args.cursor || void 0,
71
+ continuationTokenLimitInKB: 4,
72
+ maxItemCount: args.maxItemCount
73
+ });
74
+ const page = await response.fetchNext();
75
+ ctx?.log?.({
76
+ charge: page.requestCharge,
77
+ request: query
78
+ });
79
+ return {
80
+ nodes: page.resources,
81
+ cursor: page.continuationToken || null
82
+ };
83
+ }
39
84
  const instance = {
40
85
  driverName: "azureCosmos",
86
+ getMany,
41
87
  async clear(ctx) {
42
- const responseIter = client.items.readAll();
43
- const items = await responseIter.fetchAll();
44
- ctx?.log?.({
45
- charge: items.requestCharge,
46
- request: "readAll"
47
- });
48
- for (const r of items.resources) {
49
- await client.item(r.id, r._partition).delete();
50
- ctx?.log?.({
51
- charge: items.requestCharge,
52
- request: `delete#${r._partition}|${r.id}`
88
+ let currentCursor = null;
89
+ do {
90
+ const {
91
+ nodes,
92
+ cursor
93
+ } = await getMany({
94
+ cursor: currentCursor
53
95
  });
54
- }
96
+ for (const r of nodes) {
97
+ const resp = await client.item(r.id, r._partition).delete();
98
+ ctx?.log?.({
99
+ charge: resp.requestCharge,
100
+ request: `delete#${r._partition}|${r.id}`
101
+ });
102
+ }
103
+ currentCursor = cursor;
104
+ } while (currentCursor);
55
105
  },
56
106
  async putMany(items, ctx) {
57
107
  for (const item of items) {
@@ -68,51 +118,6 @@ var _default = options => (schema, entity) => {
68
118
  request: `put#${itemToPut._partition}|${itemToPut.id}`
69
119
  });
70
120
  }
71
- },
72
- async getMany(args, ctx) {
73
- args = args || {};
74
- const where = args.where || {};
75
- const whereKeys = _lodash.default.keys(where);
76
- if (whereKeys.length === 1) {
77
- if (whereKeys[0] === "id" && where.id != null) {
78
- const items = await getItemByIds([where.id], ctx);
79
- return {
80
- nodes: [items[0]].filter(x => x),
81
- cursor: null
82
- };
83
- }
84
- if (whereKeys[0] === "id_in" && where.id_in != null) {
85
- const items = await getItemByIds(where.id_in, ctx);
86
- return {
87
- nodes: items.filter(x => x),
88
- cursor: null
89
- };
90
- }
91
- }
92
- const {
93
- query,
94
- parameters
95
- } = getCosmosQuery(schema, entity, args);
96
- const response = client.items.query({
97
- query,
98
- parameters: Object.keys(parameters).map(k => ({
99
- name: `@${k}`,
100
- value: parameters[k]
101
- }))
102
- }, {
103
- continuationToken: args.cursor || void 0,
104
- continuationTokenLimitInKB: 4,
105
- maxItemCount: args.maxItemCount
106
- });
107
- const page = await response.fetchNext();
108
- ctx?.log?.({
109
- charge: page.requestCharge,
110
- request: query
111
- });
112
- return {
113
- nodes: page.resources,
114
- cursor: page.continuationToken || null
115
- };
116
121
  }
117
122
  };
118
123
  return instance;
@@ -16,16 +16,52 @@ export default (options) => (schema, entity) => {
16
16
  ctx?.log?.({ charge: r.requestCharge, request: query });
17
17
  return r.resources;
18
18
  }
19
+ async function getMany(args, ctx) {
20
+ args = args || {};
21
+ const where = args.where || {};
22
+ const whereKeys = _.keys(where);
23
+ if (whereKeys.length === 1) {
24
+ if (whereKeys[0] === "id" && where.id != null) {
25
+ const items = await getItemByIds([where.id], ctx);
26
+ return { nodes: [items[0]].filter((x) => x), cursor: null };
27
+ }
28
+ if (whereKeys[0] === "id_in" && where.id_in != null) {
29
+ const items = await getItemByIds(where.id_in, ctx);
30
+ return { nodes: items.filter((x) => x), cursor: null };
31
+ }
32
+ }
33
+ const { query, parameters } = getCosmosQuery(schema, entity, args);
34
+ const response = client.items.query(
35
+ {
36
+ query,
37
+ parameters: Object.keys(parameters).map((k) => ({ name: `@${k}`, value: parameters[k] }))
38
+ },
39
+ {
40
+ continuationToken: args.cursor || void 0,
41
+ continuationTokenLimitInKB: 4,
42
+ maxItemCount: args.maxItemCount
43
+ }
44
+ );
45
+ const page = await response.fetchNext();
46
+ ctx?.log?.({ charge: page.requestCharge, request: query });
47
+ return {
48
+ nodes: page.resources,
49
+ cursor: page.continuationToken || null
50
+ };
51
+ }
19
52
  const instance = {
20
53
  driverName: "azureCosmos",
54
+ getMany,
21
55
  async clear(ctx) {
22
- const responseIter = client.items.readAll();
23
- const items = await responseIter.fetchAll();
24
- ctx?.log?.({ charge: items.requestCharge, request: "readAll" });
25
- for (const r of items.resources) {
26
- await client.item(r.id, r._partition).delete();
27
- ctx?.log?.({ charge: items.requestCharge, request: `delete#${r._partition}|${r.id}` });
28
- }
56
+ let currentCursor = null;
57
+ do {
58
+ const { nodes, cursor } = await getMany({ cursor: currentCursor });
59
+ for (const r of nodes) {
60
+ const resp = await client.item(r.id, r._partition).delete();
61
+ ctx?.log?.({ charge: resp.requestCharge, request: `delete#${r._partition}|${r.id}` });
62
+ }
63
+ currentCursor = cursor;
64
+ } while (currentCursor);
29
65
  },
30
66
  async putMany(items, ctx) {
31
67
  for (const item of items) {
@@ -36,39 +72,6 @@ export default (options) => (schema, entity) => {
36
72
  const response = await client.items.upsert(itemToPut);
37
73
  ctx?.log?.({ charge: response.requestCharge, request: `put#${itemToPut._partition}|${itemToPut.id}` });
38
74
  }
39
- },
40
- async getMany(args, ctx) {
41
- args = args || {};
42
- const where = args.where || {};
43
- const whereKeys = _.keys(where);
44
- if (whereKeys.length === 1) {
45
- if (whereKeys[0] === "id" && where.id != null) {
46
- const items = await getItemByIds([where.id], ctx);
47
- return { nodes: [items[0]].filter((x) => x), cursor: null };
48
- }
49
- if (whereKeys[0] === "id_in" && where.id_in != null) {
50
- const items = await getItemByIds(where.id_in, ctx);
51
- return { nodes: items.filter((x) => x), cursor: null };
52
- }
53
- }
54
- const { query, parameters } = getCosmosQuery(schema, entity, args);
55
- const response = client.items.query(
56
- {
57
- query,
58
- parameters: Object.keys(parameters).map((k) => ({ name: `@${k}`, value: parameters[k] }))
59
- },
60
- {
61
- continuationToken: args.cursor || void 0,
62
- continuationTokenLimitInKB: 4,
63
- maxItemCount: args.maxItemCount
64
- }
65
- );
66
- const page = await response.fetchNext();
67
- ctx?.log?.({ charge: page.requestCharge, request: query });
68
- return {
69
- nodes: page.resources,
70
- cursor: page.continuationToken || null
71
- };
72
75
  }
73
76
  };
74
77
  return instance;
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  "require": "./integrations/*.cjs"
35
35
  }
36
36
  },
37
- "version": "0.1.68",
37
+ "version": "0.1.69",
38
38
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
39
39
  "keywords": [],
40
40
  "author": "",