basenine

package module
v0.0.0-...-3b28eea Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
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.

View Source
const (
	CloseConnection = "%quit%"
)

Closing indicators

View Source
const LATEST = "latest"
View Source
const REDACTED = "[REDACTED]"
View Source
const VERSION string = "0.8.3"

Version of the software.

Variables

This section is empty.

Functions

func AddMacro

func AddMacro(macros map[string]string, macro string, expanded string) map[string]string

addMacro takes macros map, macro and its corresponding expanded version as arguments. It stores the macro in a global map.

func Check

func Check(e error)

check panics if the given error is not nil.

func ConnCheck

func ConnCheck(conn net.Conn) error

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

func ExpandMacros(macros map[string]string, query string) (string, error)

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.

func IndexToID

func IndexToID(index int) string

func ReverseSlice

func ReverseSlice(arr []int64) (newArr []int64)

Reverses an int64 slice.

func SendClose

func SendClose(conn net.Conn)

func SendErr

func SendErr(conn net.Conn, err error)

func SendMsg

func SendMsg(conn net.Conn, msg string)

func SendOK

func SendOK(conn net.Conn)

Types

type CallExpression

type CallExpression struct {
	Identifier       *string           `@Ident ( @("." "*" | ".") @Ident? )*`
	Parameters       []*Parameter      `[ "(" (@@ ("," @@)*)? ")" ]`
	SelectExpression *SelectExpression `[ @@ ]`
}

type Commands

type Commands int

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 Logical

type Logical struct {
	Equality *Equality `@@`
	Op       string    `[ @( "and" | "or" )`
	Next     *Logical  `  @@ ]`
}

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 Parameter

type Parameter struct {
	Tag        *string     `[ @Ident ":" ]`
	Expression *Expression `@@`
	JsonPath   *jp.Expr
	TimeSet    bool
	Time       time.Time
}

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

type Propagate struct {
	Path  string
	Limit uint64
}

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.

type Unary

type Unary struct {
	Op      string   `  ( @( "!" | "-" )`
	Unary   *Unary   `    @@ )`
	Primary *Primary `| @@`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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