Documentation ¶
Index ¶
- Constants
- func AddMacro(macros map[string]string, macro string, expanded string) map[string]string
- func Check(e error)
- func ConnCheck(conn net.Conn) error
- func Eval(expr *Expression, json string) (truth bool, newJson string, err error)
- func ExpandMacros(macros map[string]string, query string) (string, error)
- func IndexToID(index int) string
- func ReverseSlice(arr []int64) (newArr []int64)
- func SendClose(conn net.Conn)
- func SendErr(conn net.Conn, err error)
- func SendMsg(conn net.Conn, msg string)
- func SendOK(conn net.Conn)
- type CallExpression
- type Commands
- type Comparison
- type ConnectionMode
- type Equality
- type Expression
- type Logical
- type Metadata
- type Parameter
- type Primary
- type Propagate
- type SelectExpression
- type Storage
- type Unary
Constants ¶
const ( CMD_INSERT string = "/insert" CMD_INSERTION_FILTER string = "/insert-filter" CMD_QUERY string = "/query" CMD_SINGLE string = "/single" CMD_FETCH string = "/fetch" CMD_VALIDATE string = "/validate" CMD_MACRO string = "/macro" CMD_LIMIT string = "/limit" CMD_METADATA string = "/metadata" CMD_FLUSH string = "/flush" CMD_RESET string = "/reset" )
Commands refers to TCP connection modes.
const (
CloseConnection = "%quit%"
)
Closing indicators
const LATEST = "latest"
const REDACTED = "[REDACTED]"
const VERSION string = "0.8.3"
Version of the software.
Variables ¶
This section is empty.
Functions ¶
func AddMacro ¶
addMacro takes macros map, macro and its corresponding expanded version as arguments. It stores the macro in a global map.
func ConnCheck ¶
POSIX compliant method for checking whether connection was closed by the peer or not
func Eval ¶
func Eval(expr *Expression, json string) (truth bool, newJson string, err error)
Eval evaluatues boolean truthiness of given JSON against the query that's provided in the form of an AST (Expression). It's the method that implements the querying functionality in the database.
It's a lazy and a generic implementation to provide a medium for flexible filtering on an arbitrary JSON structure.
Calling Precompute() on Expression before calling Eval() improves performance.
func ExpandMacros ¶
expandMacro expands the macros in a given query, if there are any. It uses a lookahead regular expression to ignore the occurences of the macro inside the string literals.
Types ¶
type CallExpression ¶
type CallExpression struct { Identifier *string `@Ident ( @("." "*" | ".") @Ident? )*` Parameters []*Parameter `[ "(" (@@ ("," @@)*)? ")" ]` SelectExpression *SelectExpression `[ @@ ]` }
type Comparison ¶
type Comparison struct { Unary *Unary `@@` Op string `[ @( ">" "=" | ">" | "<" "=" | "<" )` Next *Comparison ` @@ ]` }
type ConnectionMode ¶
type ConnectionMode int
const ( NONE ConnectionMode = iota INSERT INSERTION_FILTER QUERY SINGLE FETCH VALIDATE MACRO LIMIT FLUSH RESET )
The modes of TCP connections that the clients can use.
INSERT is a long lasting TCP connection mode for inserting data into database.
INSERTION_FILTER is a short lasting TCP connection mode for setting the insertion filter.
QUERY is a long lasting TCP connection mode for retrieving data from the database based on a given filtering query.
SINGLE is a short lasting TCP connection mode for fetching a single record from the database.
FETCH is a short lasting TCP connection mode for fetching N number of records from the database, starting from a certain offset, supporting both directions.
VALIDATE is a short lasting TCP connection mode for validating a query against syntax errors.
MACRO is a short lasting TCP connection mode for setting a macro that will be expanded later on for each individual query.
LIMIT is a short lasting TCP connection mode for setting the maximum database size to limit the disk usage.
FLUSH is a short lasting TCP connection mode that removes all the records in the database.
RESET is a short lasting TCP connection mode that removes all the records in the database and resets the core into its initial state.
type Equality ¶
type Equality struct { Comparison *Comparison `@@` Op string `[ @( "!" "=" | "=" "=" )` Next *Equality ` @@ ]` }
type Expression ¶
type Expression struct {
Logical *Logical `@@`
}
func Parse ¶
func Parse(text string) (expr *Expression, err error)
Parse parses the query (filtering syntax) into tree stucture defined as Expression. Tags defines the grammar rules and tokens. Expression is the Abstract Syntax Tree (AST) of this query language.
type Metadata ¶
type Metadata struct { Current uint64 `json:"current"` Total uint64 `json:"total"` NumberOfWritten uint64 `json:"numberOfWritten"` LeftOff string `json:"leftOff"` TruncatedTimestamp int64 `json:"truncatedTimestamp"` NoMoreData bool `json:"noMoreData"` }
Metadata info that's streamed after each record
type Primary ¶
type Primary struct { Number *float64 ` @Float | @Int` String *string `| @(String|Char|RawString)` Regex *string `| "r" @(String|Char|RawString)` Bool *bool `| ( @"true" | "false" )` Nil bool `| @"nil"` CallExpression *CallExpression `| @@` SubExpression *Expression `| "(" @@ ")" ` JsonPath *jp.Expr Regexp *regexp.Regexp Helper *string }
type Propagate ¶
func Precompute ¶
func Precompute(expr *Expression) (prop Propagate, err error)
Precompute does compile-time evaluations on parsed query (AST/Expression) to prevent unnecessary computations in Eval() method. Modifies the fields of only the Primary struct.
type SelectExpression ¶
type SelectExpression struct { Index *int `[ "[" @Int "]" ]` Key *string `[ "[" @(String|Char|RawString|"*") "]" ]` RecursiveDescent *string `[ "." "." @Ident ]` Expression *Expression `[ "." @@ ]` }
type Storage ¶
type Storage interface { Init(persistent bool) (err error) DumpCore(silent bool, dontLock bool) (err error) RestoreCore() (err error) InsertData(data []byte) (insertedId interface{}, err error) ValidateQuery(conn net.Conn, query string) (err error) GetMacros() (macros map[string]string, err error) PrepareQuery(query string, macros map[string]string) (expr *Expression, prop Propagate, err error) StreamRecords(conn net.Conn, leftOff string, query string) (err error) RetrieveSingle(conn net.Conn, index string, query string) (err error) Fetch(conn net.Conn, leftOff string, direction string, query string, limit string) (err error) ApplyMacro(conn net.Conn, data []byte) (err error) SetLimit(conn net.Conn, data []byte) (err error) SetInsertionFilter(conn net.Conn, data []byte) (err error) Flush() (err error) Reset() (err error) HandleExit(sig syscall.Signal, persistent bool) (err error) }
The interface for all of the different storage solutions.