Feat: add read Logic (Going for a function-based API instead of relying heavily on structs) - #23
Merged
Conversation
2-define a new model_predicate template that handles uniques and first level logical operators (and, or, not), and define fields of models on the generic field or the string helper to allow chaining other logical operators (EQ, NEQ, GT, LT...etc) 3- define builders_read, same generic modular design as the create ops, returns a builder with client, array of predicates and an exec function, define executeFindOne/FindMany() as helper to use them in executeSingle/ManyWithRelations() that does transaction in case of relations present 4- define sub-packages to house type aliases and make the api less verbose, for model fields, logical operators,select, create and omit,which is more natural and less verbose than having to import from the client.model each time 5- define FindFirst, many and unique funcs on the predicate, returning a builder with the exec function, that simply compiles predicates and builds raw SQL 6- Define generic query building blocks in the client package (StandardPredicate, Field[T], UniqueField[T], and specialized string fields) that implement the Predicate and UniquePredicate interfaces, expose logical operators (&, ||, !) as global functions to compose queries, and implement type-safe comparison operators (EQ, NEQ, GT, LT,...etc) as methods on the field structs,allowinh all generated models to reuse these building blocks, preventing duplicate, per-model query handlers 7- add read_test to the suite trying to cover edge cases as much as i can think of
… of doing it inline 1- add validate function to the predicate interface 2- implement a detached validateValue() helper that checks for valid UTF-8 strings and null bytes, used by PredicateData's validate and called via StandardPredicate to support validation on queries nested inside logical operators, validate read queries in FindFirst/Many, and FindUnique(the where clause validation for required)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Going for a function-based API instead of relying heavily on structs
1- add conditional imports on the client header template
2-define a new model_predicate template that handles uniques and first level logical operators (and, or, not), and define fields of models on the generic field or the string helper to allow chaining other logical operators (EQ, NEQ, GT, LT...etc)
3- define builders_read, same generic modular design as the create ops, returns a builder with client, array of predicates and an exec function, define executeFindOne/FindMany() as helper to use them in executeSingle/ManyWithRelations() that does transaction in case of relations present
4- define sub-packages to house type aliases and make the api less verbose, for model fields, logical operators,select, create and omit,which is more natural and less verbose than having to import from the client.model each time
5- define FindFirst, many and unique funcs on the predicate, returning a builder with the exec function, that simply compiles predicates and builds raw SQL
6- Define generic query building blocks in the client package (StandardPredicate, Field[T], UniqueField[T], and specialized string fields) that implement the Predicate and UniquePredicate interfaces, expose logical operators (&, ||, !) as global functions to compose queries, and implement type-safe comparison operators (EQ, NEQ, GT, LT,...etc) as methods on the field structs,allowinh all generated models to reuse these building blocks, preventing duplicate, per-model query handlers
7- add read_test to the suite trying to cover edge cases as much as i can think of