Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func ParseStruct ¶
ParseStruct parses the given data and returns an Options struct and an error. It iterates over the fields of the data structure and populates the Options struct accordingly. The "query" tag is used to specify the behavior for each field. The "limit" tag is used to set the limit value for the Options struct. The "offset" tag is used to set the offset value for the Options struct. For other fields, the parseQuery function is used to parse the field value and add it to the Options struct. If any parsing or validation error occurs, an error is returned.
func (*Options) AddField ¶
AddField adds a field to the Options struct. It takes the name, value, and operator of the field as parameters. The operator is validated, and if it is invalid, an error is returned. If the operator is "like" and the value does not contain "%", the value is modified to include "%" at the beginning and end. If the operator is "range", the value is split into two parts using " to " as the delimiter. If the value does not contain exactly two parts, an error is returned. The field is then appended to the fields slice in the Options struct. Returns nil if successful, otherwise returns an error.
func (*Options) Apply ¶
Apply applies the options to the given GORM transaction. It iterates through each option and applies the corresponding condition to the transaction. If the option's operator is "range", it splits the option value by space and applies a range condition. Otherwise, it applies a regular condition using the option's name, operator, and value. It also sets the offset and limit of the transaction based on the options. Finally, it returns the modified transaction.