mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
added useApi and useApiQuery to work seamlessly with SWR (tbc)
This commit is contained in:
@@ -15,7 +15,7 @@ export class DataApi extends ModuleApi<DataApiOptions> {
|
||||
};
|
||||
}
|
||||
|
||||
async readOne(
|
||||
readOne(
|
||||
entity: string,
|
||||
id: PrimaryFieldType,
|
||||
query: Partial<Omit<RepoQuery, "where" | "limit" | "offset">> = {}
|
||||
@@ -23,14 +23,14 @@ export class DataApi extends ModuleApi<DataApiOptions> {
|
||||
return this.get<RepositoryResponse<EntityData>>([entity, id], query);
|
||||
}
|
||||
|
||||
async readMany(entity: string, query: Partial<RepoQuery> = {}) {
|
||||
readMany(entity: string, query: Partial<RepoQuery> = {}) {
|
||||
return this.get<Pick<RepositoryResponse, "meta" | "data">>(
|
||||
[entity],
|
||||
query ?? this.options.defaultQuery
|
||||
);
|
||||
}
|
||||
|
||||
async readManyByReference(
|
||||
readManyByReference(
|
||||
entity: string,
|
||||
id: PrimaryFieldType,
|
||||
reference: string,
|
||||
@@ -42,19 +42,19 @@ export class DataApi extends ModuleApi<DataApiOptions> {
|
||||
);
|
||||
}
|
||||
|
||||
async createOne(entity: string, input: EntityData) {
|
||||
createOne(entity: string, input: EntityData) {
|
||||
return this.post<RepositoryResponse<EntityData>>([entity], input);
|
||||
}
|
||||
|
||||
async updateOne(entity: string, id: PrimaryFieldType, input: EntityData) {
|
||||
updateOne(entity: string, id: PrimaryFieldType, input: EntityData) {
|
||||
return this.patch<RepositoryResponse<EntityData>>([entity, id], input);
|
||||
}
|
||||
|
||||
async deleteOne(entity: string, id: PrimaryFieldType) {
|
||||
deleteOne(entity: string, id: PrimaryFieldType) {
|
||||
return this.delete<RepositoryResponse<EntityData>>([entity, id]);
|
||||
}
|
||||
|
||||
async count(entity: string, where: RepoQuery["where"] = {}) {
|
||||
count(entity: string, where: RepoQuery["where"] = {}) {
|
||||
return this.post<RepositoryResponse<{ entity: string; count: number }>>(
|
||||
[entity, "fn", "count"],
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user