Skip to content

Commit 913e8f3

Browse files
committed
batter cosmos batch query format
1 parent fb4e715 commit 913e8f3

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export const createCachingMethods = <DType extends { id: string }>({
6868
// const response = await container.items.bulk(operations);
6969
const idList = ids.map((id) => `'${id}'`).join(",");
7070
const querySpec = {
71-
query: `select * from c where c.id in (${idList})`,
72-
// query: "select * from c where c.id in (@ids)",
73-
// parameters: [{ name: "@ids", value: ids }],
71+
// query: `select * from c where c.id in (${idList})`,
72+
query: "select * from c where ARRAY_CONTAINS(@ids, c.id)",
73+
parameters: [{ name: "@ids", value: ids }],
7474
};
7575
const response = await container.items.query(querySpec).fetchAll();
7676

src/datasource.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ export class CosmosDataSource<TData extends { id: string }, TContext = any>
3030
dataLoader: CachedMethods<TData>["dataLoader"];
3131
primeCache: CachedMethods<TData>["primeCache"] = placeholderHandler;
3232

33-
// base SQL operations aren't cached so directly declared here
34-
async findManyByQuery(query: SqlQuerySpec | string, { ttl }: FindArgs) {
33+
async findManyByQuery(query: SqlQuerySpec | string, { ttl }: FindArgs = {}) {
3534
const results = await this.container.items.query<TData>(query).fetchAll();
3635
// prime these into the dataloader and maybe the cache
3736
if (this.dataLoader && results.resources) {

0 commit comments

Comments
 (0)