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

support custom ops #51

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

ashtonian
Copy link
Contributor

@ashtonian ashtonian commented Aug 7, 2023

I've added basic test coverage, but I wanted to see if there was any feedback before continuing. The current refactor gets a little weird with the time layout function. I was thinking of adding, a map[string]string{} of 'Options' from the struct tag to the function signatures to fix support and any other weird edge cases like that.

Refactored the main loop to separate out some of the concerns a bit and allow the user to override some of the core behavior for custom types and db operations. Its a little excessive but enables the user to handle custom types and ops. The user can also use the existing functionality and only override special cases.

	type Validator func(Op, *FieldMeta, interface{}) error
	type Converter func(Op, *FieldMeta, interface{}) interface{}
	// Lets the user define how a rql op is translated to a db op.
	GetDBOp func(Op, *FieldMeta) string
	// Lets the user define how a rql dir ('+','-') is translated to a db direction.
	GetDBDir func(Direction) string
	// Sets the validator function based on the type
	GetValidator func(f *FieldMeta) Validator
	// Sets the convertor function based on the type
	GetConverter func(f *FieldMeta) Converter
	// Sets the supported operations for that type
	GetSupportedOps func(f *FieldMeta) []Op

Alternatively I was thinking about doing something like:

GetFieldOps(f FieldMeta,  map[string]string, ...) ([]Op, Validator, Converter)

What are your thoughts?

@ashtonian
Copy link
Contributor Author

ashtonian commented Aug 11, 2023

Updated the function signatures to add additional context in order to support reusing rql ops with different db ops, with test coverage. The test case adds support for IN,NIN for regular types and field support for slices and maps. The custom implementation assumes postgres array and jsonb column types and uses their respective operators.

@ashtonian
Copy link
Contributor Author

Sorry for all the notifications, this is working and ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant