Updates
This commit is contained in:
@@ -986,7 +986,8 @@ export const ServerQueryEqualities = [
|
||||
] as const;
|
||||
|
||||
export type ServerQueryParam<
|
||||
T extends { [k: string]: any } = { [k: string]: any }
|
||||
T extends { [k: string]: any } = { [k: string]: any },
|
||||
K extends string = string
|
||||
> = {
|
||||
selectFields?: (keyof T)[];
|
||||
omitFields?: (keyof T)[];
|
||||
@@ -1003,27 +1004,32 @@ export type ServerQueryParam<
|
||||
addUserId?: {
|
||||
fieldName: keyof T;
|
||||
};
|
||||
join?: ServerQueryParamsJoin[];
|
||||
join?: ServerQueryParamsJoin<K>[];
|
||||
group?: (keyof T)[];
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type ServerQueryObject<T extends object = { [key: string]: any }> = {
|
||||
export type ServerQueryObject<
|
||||
T extends object = { [key: string]: any },
|
||||
K extends string = string
|
||||
> = {
|
||||
value?: string | string[];
|
||||
nullValue?: boolean;
|
||||
notNullValue?: boolean;
|
||||
operator?: (typeof ServerQueryOperators)[number];
|
||||
equality?: (typeof ServerQueryEqualities)[number];
|
||||
tableName?: string;
|
||||
tableName?: K;
|
||||
__query?: {
|
||||
[key in keyof T]: Omit<ServerQueryObject<T>, "__query">;
|
||||
};
|
||||
};
|
||||
|
||||
export type ServerQueryQueryObject<T extends object = { [key: string]: any }> =
|
||||
{
|
||||
[key in keyof T]: ServerQueryObject<T>;
|
||||
};
|
||||
export type ServerQueryQueryObject<
|
||||
T extends object = { [key: string]: any },
|
||||
K extends string = string
|
||||
> = {
|
||||
[key in keyof T]: ServerQueryObject<T, K>;
|
||||
};
|
||||
|
||||
export type FetchDataParams = {
|
||||
path: string;
|
||||
@@ -1432,9 +1438,10 @@ export type DsqlCrudTransformQueryFunction<
|
||||
export const DsqlCrudActions = ["insert", "update", "delete", "get"] as const;
|
||||
|
||||
export type DsqlCrudQueryObject<
|
||||
T extends { [key: string]: any } = { [key: string]: any }
|
||||
> = ServerQueryParam<T> & {
|
||||
query?: ServerQueryQueryObject<T>;
|
||||
T extends { [key: string]: any } = { [key: string]: any },
|
||||
K extends string = string
|
||||
> = ServerQueryParam<T, K> & {
|
||||
query?: ServerQueryQueryObject<T, K>;
|
||||
};
|
||||
|
||||
export type SQLDeleteGeneratorParams<
|
||||
@@ -1469,7 +1476,7 @@ export type DsqlCrudParam<
|
||||
targetId?: string | number;
|
||||
targetValue?: string | number;
|
||||
targetField?: keyof T;
|
||||
query?: DsqlCrudQueryObject<T>;
|
||||
query?: DsqlCrudQueryObject<T, K>;
|
||||
sanitize?: ({ data, batchData }: { data?: T; batchData?: T[] }) => T | T[];
|
||||
debug?: boolean;
|
||||
count?: boolean;
|
||||
|
||||
@@ -5,7 +5,8 @@ import checkArrayDepth from "../check-array-depth";
|
||||
import parseDbResults from "../../functions/backend/parseDbResults";
|
||||
|
||||
export default async function <
|
||||
T extends { [key: string]: any } = { [key: string]: any }
|
||||
T extends { [key: string]: any } = { [key: string]: any },
|
||||
K extends string = string
|
||||
>({
|
||||
table,
|
||||
query,
|
||||
@@ -15,7 +16,7 @@ export default async function <
|
||||
tableSchema,
|
||||
dbConfig,
|
||||
}: Omit<
|
||||
DsqlCrudParam<T>,
|
||||
DsqlCrudParam<T, K>,
|
||||
"action" | "data" | "sanitize"
|
||||
>): Promise<APIResponseObject> {
|
||||
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;
|
||||
|
||||
@@ -38,7 +38,7 @@ export default async function dsqlCrud<
|
||||
|
||||
switch (action) {
|
||||
case "get":
|
||||
return await dsqlCrudGet(params);
|
||||
return await dsqlCrudGet<T, K>(params);
|
||||
|
||||
// case "batch-get":
|
||||
// return await dsqlCrudBatchGet(params);
|
||||
|
||||
Reference in New Issue
Block a user