Skip to content

Commit

Permalink
add having to findone
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed May 9, 2024
1 parent 1f059b8 commit 7ad5813
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
12 changes: 5 additions & 7 deletions lib/DboBuilder/ViewHandler/ViewHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,15 @@ export class ViewHandler {
}
find = find.bind(this);

async findOne(filter?: Filter, selectParams?: SelectParams, param3_unused?: undefined, table_rules?: TableRule, localParams?: LocalParams): Promise<any> {
async findOne(filter?: Filter, selectParams?: SelectParams, _param3_unused?: undefined, table_rules?: TableRule, localParams?: LocalParams): Promise<any> {

try {
await this._log({ command: "find", localParams, data: { filter, selectParams } });
const { select = "*", orderBy, offset = 0 } = selectParams || {};
if (selectParams) {
const good_params = ["select", "orderBy", "offset"];
const bad_params = Object.keys(selectParams).filter(k => !good_params.includes(k));
if (bad_params && bad_params.length) throw "Invalid params: " + bad_params.join(", ") + " \n Expecting: " + good_params.join(", ");
const { limit, ...params } = selectParams ?? {};
if (limit) {
throw "limit not allowed in findOne()";
}
return this.find(filter, { select, orderBy, limit: 1, offset, returnType: "row" }, undefined, table_rules, localParams);
return this.find(filter, { ...params, limit: 1, returnType: "row" }, undefined, table_rules, localParams);
} catch (e) {
if (localParams && localParams.testRule) throw e;
throw parseError(e, `Issue with dbo.${this.name}.findOne()`);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.57",
"version": "4.2.58",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
36 changes: 36 additions & 0 deletions tests/server/DBoGenerated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ export type DBSchemaGenerated = {
name?: null | string;
};
};
logs: {
is_view: false;
select: true;
insert: true;
update: true;
delete: true;
columns: {
created_at?: string;
id?: string;
request?: null | any;
};
};
lookup_col1: {
is_view: false;
select: true;
Expand Down Expand Up @@ -292,6 +304,19 @@ export type DBSchemaGenerated = {
y?: null | number;
};
};
plans: {
is_view: false;
select: true;
insert: true;
update: true;
delete: true;
columns: {
id: string;
info?: null | any;
name: string;
price?: null | string;
};
};
"prostgles_test.basic": {
is_view: false;
select: true;
Expand Down Expand Up @@ -388,6 +413,17 @@ export type DBSchemaGenerated = {
srtext?: null | string;
};
};
subscriptions: {
is_view: false;
select: true;
insert: true;
update: true;
delete: true;
columns: {
created_at?: string;
plan_id: string;
};
};
symbols: {
is_view: false;
select: true;
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7ad5813

Please sign in to comment.