dsquery

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2017 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Package dsquery provides mechanisms for managing templated queries to be executed against a data source.

The types in this package are agnostic to the type of data source being used (e.g. RDBMS, NoSQL, cache). Instead, these types are concerned with reading templated queries from files and populating those templates with variables a runtime. The actual execution of queries is the responsibility of clients that understand the type of data source in use (see the rdbms package).

Most Granitic applications requiring access to a data source will enable the QueryManager facility which provides access to an instance of the TemplatedQueryManager type defined in this package. Instructions on configuring and using the QueryManager facility can be found at http://granitic.io/1.0/ref/query-manager also see the package documentation for the facility/querymanager package for some basic examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewQueryTemplateToken

func NewQueryTemplateToken(tokenType queryTokenType) *queryTemplateToken

Types

type QueryManager

type QueryManager interface {
	// BuildQueryFromID finds a template with the supplied query ID and uses the supplied named parameters to populate
	// that template. Returns the populated query or an error if the template could not be found or there was a problem
	// populating the query.
	BuildQueryFromID(qid string, params map[string]interface{}) (string, error)

	// FragmentFromID is used to recover a template which does not have any parameters to populate (a fragment). This is most commonly
	// used when code needs to dynamically construct a query from several fragments and templates. Returns the fragment
	// or an error if the fragment could not be found.
	FragmentFromID(qid string) (string, error)
}

A QueryManager is a type that is able to populate a pre-defined template query given a set of named parameters and return a complete query ready for execution against some data source.

type TemplatedQueryManager

type TemplatedQueryManager struct {
	// The path to a folder where template files are stored.
	TemplateLocation string

	// A regular expression that allows variable names to be recognised in queries.
	VarMatchRegEx string

	// Logger used by Granitic framework components. Automatically injected.
	FrameworkLogger logging.Logger

	// Lines in a template file starting with this string are considered to indicate the start of a new query template. The remainder
	// of the line will be used as the ID of that query template.
	QueryIdPrefix string

	// Whether or not query IDs should have leading and trailing whitespace removed.
	TrimIdWhiteSpace bool

	// Whether string parameters should have their contents wrapped with the string defined in StringWrapWith before
	// being injected into the query. For example, SQL RDBMSs usually require strings to be wrapped with ' or "
	WrapStrings bool

	// A string that will be used as a prefix and suffix to a string parameter if WrapStrings is true.
	StringWrapWith string

	// The character sequence that indicates a new line in a template file (e.g. \n)
	NewLine string
	// contains filtered or unexported fields
}

An implementation of QueryManager that reads files containing template queries, tokenizes them and populates them on demand with maps of named parameters. This is the implementation provided by the QueryManager facility. See http://granitic.io/1.0/ref/query-manager for details.

func NewTemplatedQueryManager

func NewTemplatedQueryManager() *TemplatedQueryManager

NewTemplatedQueryManager creates a new, empty TemplatedQueryManager.

func (*TemplatedQueryManager) BuildQueryFromID

func (qm *TemplatedQueryManager) BuildQueryFromID(qid string, params map[string]interface{}) (string, error)

See QueryManager.BuildQueryFromID

func (*TemplatedQueryManager) FragmentFromID

func (qm *TemplatedQueryManager) FragmentFromID(qid string) (string, error)

See QueryManager.FragmentFromID

func (*TemplatedQueryManager) StartComponent

func (qm *TemplatedQueryManager) StartComponent() error

StartComponent is called by the IoC container. Loads, parses and tokenizes query templates. Returns an error if there was a problem loading, parsing or tokenizing.

Jump to

Keyboard shortcuts

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