mongoqp

package module
v0.0.0-...-9b59f04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2019 License: BSD-2-Clause Imports: 4 Imported by: 0

README

mongoqp

A MongoDB Query Filter Documents parser for Go.

The expression, please see MongoDB's document: https://docs.mongodb.com/manual/tutorial/query-documents

An example expression is like:

{ status: "A", age: { $lt: 30 } }

Usage

package main

import (
	"fmt"

	"github.com/clia/mongoqp"
)

func main() {
	parser := mongoqp.Parser{}

	exp, err := parser.Parse(`{ R_STAT: 10 }`)
	if err != nil {
		fmt.Printf("%s\n", err.Error())
	} else {
		fmt.Printf("%#v\n", exp)
		fmt.Printf("%#v\n", exp.Properties[0])
		fmt.Printf("%#v\n", exp.Properties[0].Value)
	}

	exp2, err := parser.Parse(`{ ERR_S: { $gte: 1 } }`)
	if err != nil {
		fmt.Printf("%s\n", err.Error())
	} else {
		fmt.Printf("%#v\n", exp2)
		fmt.Printf("%#v\n", exp2.Properties[0].Value)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exp

type Exp struct {
	Properties []*Property `"{" @@ { "," @@ } "}"`
}

Exp the expression top element

type Parser

type Parser struct{}

Parser the parser type

func (*Parser) Parse

func (p *Parser) Parse(expression string) (*Exp, error)

Parse parse the expression string

type Property

type Property struct {
	Key   string `@Ident ":"`
	Value *Value `@@`
}

Property a property element

type Value

type Value struct {
	String   *string   `  @String`
	Number   *float64  `| @Number`
	Property *Property `| "{" @@ "}"`
}

Value some type of value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL