Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use item id as default partition key #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ export class CosmosDataSource<TData extends { id: string }, TContext>
this.options?.logger?.info(
`CosmosDataSource/deleteOne: deleting id: '${id}'`
);
const response = await this.container.item(id, partitionKey).delete<TData>();
const response = await this.container.item(id, partitionKey ?? id).delete<TData>();
await this.deleteFromCacheById(id);
return response;
}

async updateOne(updDoc: TData, partitionKey?: string) {
const response = await this.container
.item(updDoc.id, partitionKey)
.item(updDoc.id, partitionKey ?? updDoc.id)
.replace(updDoc);
if (response.resource) {
this.primeLoader(response.resource);
Expand All @@ -99,7 +99,7 @@ export class CosmosDataSource<TData extends { id: string }, TContext>
this.options?.logger?.debug(
`Updating doc id ${id} contents: ${JSON.stringify(contents, null, "")}`
);
const item = this.container.item(id, partitionKey);
const item = this.container.item(id, partitionKey ?? id);
const docItem = await item.read<TData>();
const { resource } = docItem;
const newResource = { ...resource, ...contents, id } as TData; // don't change the ID ever
Expand Down
Loading