增加了aggregate接口
This commit is contained in:
parent
8d6fdb0185
commit
90f72210e3
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDict, OperateOption, SelectOption, OperationResult } from "oak-domain/lib/types";
|
||||
import { EntityDict, OperateOption, SelectOption, OperationResult, AggregationResult } from "oak-domain/lib/types";
|
||||
import { AmapInstance } from "oak-external-sdk";
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
|
||||
|
|
@ -17,6 +17,11 @@ export declare type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt
|
|||
data: Partial<ED[T]['Schema']>[];
|
||||
count?: number;
|
||||
}>;
|
||||
aggregate: <T extends keyof ED, OP extends SelectOption>(params: {
|
||||
entity: T;
|
||||
aggregation: ED[T]['Aggregation'];
|
||||
option?: OP;
|
||||
}, context: Cxt) => Promise<AggregationResult<ED[T]['Schema']>>;
|
||||
count: <T extends keyof ED, OP extends SelectOption>(params: {
|
||||
entity: T;
|
||||
selection: Pick<ED[T]['Selection'], 'filter'>;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ export declare function select<ED extends EntityDict, T extends keyof ED, Cxt ex
|
|||
data: Partial<ED[T]['Schema']>[];
|
||||
count?: number | undefined;
|
||||
}>;
|
||||
export declare function aggregate<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, OP extends SelectOption>(params: {
|
||||
entity: T;
|
||||
aggregation: ED[T]['Aggregation'];
|
||||
option?: OP;
|
||||
}, context: Cxt): Promise<import("oak-domain/lib/types").AggregationResult<ED[T]["Schema"]>>;
|
||||
export declare function fetchRows<ED extends EntityDict & BaseEntityDict, OP extends SelectOption, Cxt extends AsyncContext<ED>>(params: Array<{
|
||||
entity: keyof ED;
|
||||
selection: ED[keyof ED]['Selection'];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.count = exports.fetchRows = exports.select = exports.operate = void 0;
|
||||
exports.count = exports.fetchRows = exports.aggregate = exports.select = exports.operate = void 0;
|
||||
const types_1 = require("oak-domain/lib/types");
|
||||
async function operate(params, context) {
|
||||
const { entity, operation, option } = params;
|
||||
|
|
@ -39,6 +39,11 @@ async function select(params, context) {
|
|||
return result;
|
||||
}
|
||||
exports.select = select;
|
||||
async function aggregate(params, context) {
|
||||
const { entity, aggregation, option } = params;
|
||||
return context.aggregate(entity, aggregation, option || {});
|
||||
}
|
||||
exports.aggregate = aggregate;
|
||||
async function fetchRows(params, context) {
|
||||
await Promise.all(params.map((ele) => context.select(ele.entity, ele.selection, ele.option || {})));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { operate, select, fetchRows, count } from './crud';
|
||||
import { operate, select, fetchRows, count, aggregate } from './crud';
|
||||
import { amap } from './amap';
|
||||
import { getTranslations } from './locales';
|
||||
declare const aspectDict: {
|
||||
operate: typeof operate;
|
||||
select: typeof select;
|
||||
count: typeof count;
|
||||
aggregate: typeof aggregate;
|
||||
fetchRows: typeof fetchRows;
|
||||
amap: typeof amap;
|
||||
getTranslations: typeof getTranslations;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const aspectDict = {
|
|||
operate: crud_1.operate,
|
||||
select: crud_1.select,
|
||||
count: crud_1.count,
|
||||
aggregate: crud_1.aggregate,
|
||||
fetchRows: crud_1.fetchRows,
|
||||
amap: amap_1.amap,
|
||||
getTranslations: locales_1.getTranslations,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDict, OperateOption, SelectOption, OperationResult } from "oak-domain/lib/types";
|
||||
import { EntityDict, OperateOption, SelectOption, OperationResult, AggregationResult } from "oak-domain/lib/types";
|
||||
import { AmapInstance } from "oak-external-sdk";
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { AsyncContext } from "oak-domain/lib/store/AsyncRowStore";
|
||||
|
|
@ -23,6 +23,14 @@ export type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|||
data: Partial<ED[T]['Schema']>[];
|
||||
count?: number;
|
||||
}>;
|
||||
aggregate: <T extends keyof ED, OP extends SelectOption>(
|
||||
params: {
|
||||
entity: T;
|
||||
aggregation: ED[T]['Aggregation'];
|
||||
option?: OP;
|
||||
},
|
||||
context: Cxt
|
||||
) => Promise<AggregationResult<ED[T]['Schema']>>;
|
||||
count: <
|
||||
T extends keyof ED,
|
||||
OP extends SelectOption
|
||||
|
|
|
|||
14
src/crud.ts
14
src/crud.ts
|
|
@ -91,6 +91,20 @@ export async function select<
|
|||
return result;
|
||||
}
|
||||
|
||||
export async function aggregate<
|
||||
ED extends EntityDict,
|
||||
T extends keyof ED,
|
||||
Cxt extends AsyncContext<ED>,
|
||||
OP extends SelectOption
|
||||
>(params: {
|
||||
entity: T,
|
||||
aggregation: ED[T]['Aggregation'],
|
||||
option?: OP,
|
||||
}, context: Cxt) {
|
||||
const { entity, aggregation, option } = params;
|
||||
return context.aggregate(entity, aggregation, option || {});
|
||||
}
|
||||
|
||||
export async function fetchRows<
|
||||
ED extends EntityDict & BaseEntityDict,
|
||||
OP extends SelectOption,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { operate, select, fetchRows, count } from './crud';
|
||||
import { operate, select, fetchRows, count, aggregate } from './crud';
|
||||
import { amap } from './amap';
|
||||
import { getTranslations } from './locales';
|
||||
const aspectDict = {
|
||||
operate,
|
||||
select,
|
||||
count,
|
||||
aggregate,
|
||||
fetchRows,
|
||||
amap,
|
||||
getTranslations,
|
||||
|
|
|
|||
Loading…
Reference in New Issue