Generic 'Where' type #10409
Replies: 3 comments 1 reply
-
|
It's a primitive solution, for example it doesn't support nested keys (for arrays / relations etc), richtext / json querying and the |
Beta Was this translation helpful? Give feedback.
-
|
Ok, a little update. The documentation doesn't have many examples of how to use some operators (e.g. As for arrays, I'll think about how to approach this in the next few days. import { FieldPath, FieldPathValue } from 'react-hook-form';
export type AnyWhereField<TValue> = {
exists?: boolean;
equals?: TValue;
not_equals?: TValue;
};
export type ComparableWhereField<TValue extends number | string> = {
greater_than?: TValue;
greater_than_equal?: TValue;
less_than?: TValue;
less_than_equal?: TValue;
};
export type SearchableWhereField<TValue extends string> = {
like?: TValue;
contains?: TValue;
};
export type Point = [number, number];
export type PointValue = { type: 'Polygon'; coordinates: Point[] }; // TODO
export type SpatialableWhereField<TValue extends Point> = {
near?: [number, number, number | null, number | null]; // TODO
within?: PointValue;
intersect?: PointValue;
};
export type WhereField<TValue> = AnyWhereField<TValue> &
(TValue extends number | string ? ComparableWhereField<TValue> : {}) &
(TValue extends string ? SearchableWhereField<TValue> : {}) &
(TValue extends Point ? SpatialableWhereField<TValue> : {});
export type Where<T extends object> = {
[TPath in FieldPath<T>]?: WhereField<FieldPathValue<T, TPath>>;
} & { and?: Where<T>[]; or?: Where<T>[] }; |
Beta Was this translation helpful? Give feedback.
-
|
I'm in the process of implementing Payload on an existing, fairly complex Next js app and in the process migrating from Prisma to use Payload's local api client. I'm shocked that these calls are so loosely typed (e.g. where, select, etc), this is one of the main advantages of using a typed ORM like drizzle. Payload has access to everything it needs at compile-time to strongly type these calls, and there has been no movement on this discussion in a year. Are there any plans to improve this? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal: Generic: 'Where' type
Currently, the
Wheretype in Payload relies on a loosely typed structure (e.g.,JsonValue), which results in limited editor autocompletion and a higher risk of runtime errors. I'd like to propose a generic version ofWherethat leverages TypeScript's type system, providing stronger type safety and better DX.Example
Beta Was this translation helpful? Give feedback.
All reactions