granitic: Index | Files

package querymanager

import ""

Package querymanager provides the QueryManager facility which allows database queries to be stored away from code and looked up by ID.

The facility adds a component of type dsquery.QueryManager to the IoC container that other components may use to lookup templated queries by an ID and have those queries populated with supplied parameters.

A full description of this facility and how to configure it can be found at . Also refer to the GoDoc for the GoDoc for the dsquery package.

Template locations and template formats

The QueryManager manager facility is configured with the QueryManager configuration element. For most applications, only the TemplateLocation might need changing from it's default. The default setting is:

	"TemplateLocation": "resource/queries"

On startup, any files in the the TemplateLocation will be treated as containing query templates. The name of each file is not significant. A typical file might look like:


	name = '${artistName}'


INSERT INTO artist (


INSERT INTO record (

This file defines three query templates. A new template is signified by a line starting


In this example, an application would use the query ID ARTIST_ID_SELECT to recover the first query.


A query template may optionally include parameters. Any string inside a ${} structure is considered a parameter name. In the example above, query ID RECORD_INSERT defines three parameters catRef, recordName, artistID. The query manager can be supplied with a map containing keys that match those parameter names and will populate the template with the values associated with those keys.

Required parameters

If you put a ! character before a parameter name in your template (e.g. ${!artistID}), an error will be returned if that parameter is not available when a query is built.

Parameter Values

Parameter values are injected into the query using a component called a ParamValueProcessor. Granitic includes two built-in implementations - ConfigurableProcessor and SQLProcessor. These components a) decide how to handle missing parameter values and b) perform any escaping/substitution/conversion of values before they are injected into the query.

To enable one of the default processors, set QueryManager.ProcessorName to Configurable or SQL (the default is Configurable). If you want to implement your own processor, set QueryManager.CreateDefaultValueProcessor to false and define a component that implements ParamValueProcessor


Package Files



const QueryManagerComponentName = instance.FrameworkPrefix + "QueryManager"

QueryManagerComponentName is the name of the query manager in the IoC container.

const QueryManagerFacilityName = "QueryManager"

QueryManagerFacilityName is the name of the facility

type FacilityBuilder Uses

type FacilityBuilder struct {

FacilityBuilder creates an instance of dsquery.QueryManager and stores it in the IoC container.

func (*FacilityBuilder) BuildAndRegister Uses

func (qmfb *FacilityBuilder) BuildAndRegister(lm *logging.ComponentLoggerManager, ca *config.Accessor, cn *ioc.ComponentContainer) error

BuildAndRegister implements FacilityBuilder.BuildAndRegister

func (*FacilityBuilder) DependsOnFacilities Uses

func (qmfb *FacilityBuilder) DependsOnFacilities() []string

DependsOnFacilities implements FacilityBuilder.DependsOnFacilities

func (*FacilityBuilder) FacilityName Uses

func (qmfb *FacilityBuilder) FacilityName() string

FacilityName implements FacilityBuilder.FacilityName

Package querymanager imports 8 packages (graph). Updated 2020-05-25. Refresh now. Tools for package owners.