rql icon indicating copy to clipboard operation
rql copied to clipboard

support custom ops

Open ashtonian opened this issue 2 years ago • 2 comments

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 avatar Aug 07 '23 21:08 ashtonian