Skip to content

Commit

Permalink
[Fix] Allow filtering optional db model fields (#1)
Browse files Browse the repository at this point in the history
* fix: allow filtering on optional fields

* docs: add gif for demo on readme, bumped to 1.0.1
  • Loading branch information
Mingyang-Li authored Dec 17, 2024
1 parent 66ecfa2 commit 20f24e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ This package is for you if you're building data-driven applications and you're u

If you're tired of writing raw SQL for querying Azure CosmosDB NoSQL database with complex filters, then this package is for you, too.

<p align="center">
<img src="docs/demo.gif" />
The code above gives you query auto-completion based on the data model you specified for each container in Azure CosmosDB
</p>

## 🤔 Use cases:

- Data analytics dashboard
Expand Down Expand Up @@ -199,4 +204,4 @@ const result = orm.user.delete({
- ~~Core Query builder~~
- Bulk create / update operations
- Observability - query logging
- Filtering complex data types such as string arrays & number arrays
- Filtering on more complex data types such as enums, enum arrays, string arrays & number arrays
Binary file added docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmox",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [
"cosmosdb",
"prisma",
Expand Down
12 changes: 7 additions & 5 deletions src/services/cosmos-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ const defaultFields: AutoFields = {

/** Utility type to define where clause filters */
export type Where<T extends Base> = {
[K in keyof T]?: T[K] extends string
[K in keyof T]?: T[K] extends string | undefined
? StringFilter
: T[K] extends number
: T[K] extends number | undefined
? NumberFilter
: T[K] extends boolean
: T[K] extends boolean | undefined
? BooleanFilter
: T[K] extends Date
: T[K] extends Date | undefined
? DateFilter
: never;
};
Expand Down Expand Up @@ -340,7 +340,9 @@ export class BaseModel<T extends Base = typeof initial> {
}

/** Find many items with pagination and type-safe filters */
public async findMany(args: FindManyArgs<T>): Promise<FindManyResponse<T>> {
public async findMany(
args: FindManyArgs<Required<T>>,
): Promise<FindManyResponse<T>> {
const { take, nextCursor } = args;

// validate "take" if provided by user
Expand Down

0 comments on commit 20f24e8

Please sign in to comment.