Options
All
  • Public
  • Public/Protected
  • All
Menu

SQL Template Engine

Service Status Build Status Coverage Status NPM version GitHub license Known Vulnerabilities

Install

npm install --save @mitmaro/sql-template-engine

Documentation

Usage

Creating an instance

Creating a SQL Template Engine instance is very straight forward.

JavaScript

const sqlTemplateEngine = require('@mitmaro/sql-template-engine');
const serviceManager = sqlTemplateEngine({
    // options
});

TypeScript

import sqlTemplateEngine from '@mitmaro/sql-template-engine';
const serviceManager = sqlTemplateEngine({
    // options
});

Options

Name Type Description Default
cache AbstractSyntaxTreeCache A custom abstract syntax tree cache Memory
epsilon number The allowed error due to rounding in floating point comparisons Number.EPSILON
fileEncoding string The file encoding for template files UTF-8
rootPath string The root directory for looking for template files Current working directory
maximumCallDepth number The maximum depth of nested includes 64

Invoking a template file

const result = await serviceManager.invokeTemplateFile('template.tpl', {foo: 'bar'});

Development

Development is done using Node 8 and NPM 5, and tested against both Node 8 and Node 10. To get started

  • Install Node 8 from NodeJS.org or using nvm
  • Clone the repository using git clone git@github.com:MitMaro/node-sql-template-engine.git
  • cd node-sql-template-engine
  • Install the dependencies npm install
  • Make changes, add tests, etc.
  • Run linting and test suite using npm run test
  • Build using npm run build

License

This project is released under the ISC license. See LICENSE.

Index

Type aliases

ExpressionNode

StatementNode

StringDelimiter

StringDelimiter: null | "'" | """

TemplateLoader

TemplateLoader: function

Type declaration

Token

TokenSubType

Value

Value: boolean | string | number

ValueNode

Variables

Const generalDelimiters

generalDelimiters: string[] = [' ', '\t', '\n']

Const readFile

readFile: __promisify__ = promisify(fs.readFile)

Functions

create

  • Create an instance of the sql template engine

    Parameters

    • Default value options: SqlTemplateOptions = {}

      The configuration options for creating an instance of the sql template engine

    Returns SqlTemplateEngine

    An instance of the sql template engine

createMemoryCache

  • Create an in-memory cache for the compiled templates

    Returns AbstractSyntaxTreeCache

    A cache instance

floatEqual

  • floatEqual(a: number, b: number, epsilon: number): boolean
  • Safely compare two floating point numbers

    Parameters

    • a: number

      The first number

    • b: number

      The second number

    • epsilon: number

      The allowed difference between the values

    Returns boolean

    True if values match, else false

isInputData

  • Guard for InputData

    Parameters

    Returns boolean

    True if the value provided is InputData

Object literals

Const binaryOperatorTypeLookup

binaryOperatorTypeLookup: object

!=

!=: NotEquals = BinaryOperator.NotEquals

!==

!==: StrictNotEquals = BinaryOperator.StrictNotEquals

&&

&&: And = BinaryOperator.And

<

<: LessThan = BinaryOperator.LessThan

<=

<=: LessEqualThan = BinaryOperator.LessEqualThan

==

==: Equals = BinaryOperator.Equals

===

===: StrictEquals = BinaryOperator.StrictEquals

>

>: GreaterThan = BinaryOperator.GreaterThan

>=

>=: GreaterEqualThan = BinaryOperator.GreaterEqualThan

||

||: Or = BinaryOperator.Or

Const boundaryTypeLookup

boundaryTypeLookup: object

"

": StringDouble = TokenBoundaryType.StringDouble

'

': StringSingle = TokenBoundaryType.StringSingle

(

(: BracketOpen = TokenBoundaryType.BracketOpen

)

): BracketClose = TokenBoundaryType.BracketClose

{{

{{: TagStart = TokenBoundaryType.TagStart

}}

}}: TagEnd = TokenBoundaryType.TagEnd

Const delimiters

delimiters: object

1

1: never[] = []

2

2: never[] = []

3

3: never[] = []

Const precedenceTable

precedenceTable: object

__computed

__computed: object

association

association: Right = Associativity.Right

precedence

precedence: number = 5

Const statementTypeLookup

statementTypeLookup: object

elif

elif: ElseIf = TokenStatementType.ElseIf

else

else: Else = TokenStatementType.Else

fi

fi: EndIf = TokenStatementType.EndIf

if

if: If = TokenStatementType.If

include

include: Include = TokenStatementType.Include

Const unaryOperatorTypeLookup

unaryOperatorTypeLookup: object

!

!: Not = UnaryOperator.Not

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc