Documentation
¶
Index ¶
- Constants
- type QField
- func (f *QField) ApplyFilter(qvalue string, out *QResult)
- func (f *QField) ParseAsBool() *QField
- func (f *QField) ParseAsDateTime() *QField
- func (f *QField) ParseAsFloat() *QField
- func (f *QField) ParseAsInt() *QField
- func (f *QField) ParseAsMeta() *QField
- func (f *QField) ParseAsObjectID() *QField
- func (f *QField) ParseAsString() *QField
- func (f *QField) Projectable() *QField
- func (f *QField) Sortable() *QField
- func (f *QField) UseAliases(alias ...string) *QField
- func (f *QField) UseDefault(fn func() string) *QField
- type QResult
- type QType
- type QueryProcessorFn
Constants ¶
const Version = "v0.8.0"
Version is the current mongoqs version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type QField ¶
type QField struct { Type QType // The data type expected when parsing the values of query parameter values Key string // The target parameter in the request query string - supports dot notation for nested fields Default func() string // Function to run if this field is missing/is invalid - the result should be a string that the processor will parse into it's appropriate type for non-Meta fields Aliases []string // List of aliases that can be used as alternatives to this QField.Key IsProjectable bool // If true, this QField may be used for projections IsSortable bool // If true, this QField can be used for sorting IsMeta bool // If true, this QFieeld will be used as a meta field HasDefaultFunc bool // If true, the Default function will be used if a the field is missing/is invalid }
QField - Query field definition. Key and Aliases cannot be empty or use any of the following reserved values: 'qlmt', 'qskp', 'qsrt', 'qprj'. If provided, the Default method should return a valid MongoDB filter parameter.
func (*QField) ApplyFilter ¶
ApplyFilter - Processes the qvalue as the specified Type and applies the result to the provided out QResult.
func (*QField) ParseAsBool ¶ added in v0.5.0
ParseAsBool - Indicates that this field represents a database document field that contains a boolean value
func (*QField) ParseAsDateTime ¶ added in v0.5.0
ParseAsDateTime - Indicates that this field represents a database document field that contains a datetime value
func (*QField) ParseAsFloat ¶ added in v0.5.0
ParseAsFloat - Indicates that this field represents a database document field that contains a floating point number value
func (*QField) ParseAsInt ¶ added in v0.5.0
ParseAsInt - Indicates that this field represents a database document field that contains an integer value
func (*QField) ParseAsMeta ¶ added in v0.5.0
ParseAsMeta - Indicates that this field will not appear in the QResult Filter and will be parsed/interpreted outside of MongoQS
func (*QField) ParseAsObjectID ¶ added in v0.5.0
ParseAsObjectID - Indicates that this field represents a database document field that contains a string value
func (*QField) ParseAsString ¶ added in v0.5.0
ParseAsString - Indicates that this field represents a database document field that contains a string value
func (*QField) Projectable ¶
Projectable - Allows field to be used in projections. Returns caller for chaining.
func (*QField) UseAliases ¶ added in v0.3.0
UseAliases - Adds one or more aliases to this field. Returns caller for chaining.
func (*QField) UseDefault ¶
UseDefault - Sets the Default method to the provided function. Returns caller for chaining.
type QResult ¶
type QResult struct { Filter bson.M // MongoDB filter Projection bson.M // MongoDB projection Limit int64 // MongoDB document limit Skip int64 // MongoDB ocument skip count Sort bson.M // MongoDB sort Meta map[string]string // Map of keys to raw qstring value }
QResult - Query result containing Filter, Limit, Skip, Sort, and Projection parameters compatible with MongoDB.
func NewQResult ¶
func NewQResult() QResult
NewQResult - Returns a new empty QResult. Should be passed as the *out parameter when calling the processor function returned from NewRequestQueryProcessor.
type QType ¶
type QType int
const QBool QType = 3
QBool - Allows query values to be processed as booleans. Does not apply to QResult if parsing fails.
const QDateTime QType = 4
QDateTime - Allows query values to be processed as datetimes using formats added with the UseTimeLayout method. If one or more formats are not provided then time.RFC3339 is used. Does not apply to QResult if the date is invalid.
const QFloat QType = 2
QFloat - Allows query values to be processed as floating point numbers. Does not apply to QResult if parsing fails.
const QInt QType = 1
QInt - Allows query values to be processed as integers. Does not apply to QResult if parsing fails.
const QObjectID QType = 5
QObjectID - Allows query values to be processed as MongoDB ObjectIDs. Does not apply to QResult if the value is not a valid ObjectID.
const QString QType = 0 // QField created without setting Type will default to string
QString - Allows query values to be processed as strings. Does not apply to QResult if the value is empty after removing leading and trailing white space.
type QueryProcessorFn ¶ added in v0.6.0
QueryProcessorFn - function signature for a query processor
func NewQProcessor ¶
func NewQProcessor(fields ...QField) QueryProcessorFn
NewQProcessor - Validates the provided QFields and returns a function that converts a URL query to a QResult.