Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code-gen: query where and update object key validation #466

Closed
tjonger opened this issue Nov 5, 2020 · 1 comment · Fixed by #477
Closed

code-gen: query where and update object key validation #466

tjonger opened this issue Nov 5, 2020 · 1 comment · Fixed by #477
Assignees
Labels
prio 1 Defines the highest prio issues

Comments

@tjonger
Copy link
Collaborator

tjonger commented Nov 5, 2020

Can we make the generated queries more verbose? In the way that when provided a property to the update of where param/object that is not part of the target subject (field on entity), we get some error/info? And if so, should we make it an hard fail of just a notice?

Example;

// example entity
const entity = {
  name: T.string(),
  birthDate: T.date().optional(),
};

await queries.entityUpdate(sql, { birthPlace: "No place like 127.0.0.1" }, { id });

// expected result:
INFO { type: "query", msg: "No field 'birthPlace' on 'entity', available fields: 'name', 'birthDate'" }

Additions; same for non fields, but where clause condition 'fields'. Like array fields, number fields. {field}In, {field}NotIn. For example; when providing the where object with keysIn instead of keyIn (for field name; key). It should let the user know.

@dirkdev98
Copy link
Member

There's two things:

  • We don't have a logger there, so we can only do a hard fail
  • We need to dump all possible keys, in the partials: entityWhere & entityUpdateSet, entityInsertvalues and then loop over the keys, checking if they exists in the known set.

If we use a Set for the last part, we can keep it O(n) where N is the amount of keys in the passed in objects.
We can easily reuse the generated Sets by generating them at the top of the query-partials file, so at least we don't allocate them every call.
For the error part, something like the following:

new AppError("query.{entity}.{where|update|insert}Fields", 500, { unknownKey: "xxx", knownKeys: xxxFieldSet });

@dirkdev98 dirkdev98 added the prio 1 Defines the highest prio issues label Nov 5, 2020
dirkdev98 added a commit that referenced this issue Nov 5, 2020
This works by dumping the possible keys, and looping over the input objects. It is guarded by an `isStaging()` check, so shouldn't be too much of a performance hit.

Closes #466
dirkdev98 added a commit that referenced this issue Nov 5, 2020
This works by dumping the possible keys, and looping over the input objects. It is guarded by an `isStaging()` check, so shouldn't be too much of a performance hit.

Closes #466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio 1 Defines the highest prio issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants