SQL Template Engine
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({
});
TypeScript
import sqlTemplateEngine from '@mitmaro/sql-template-engine';
const serviceManager = sqlTemplateEngine({
});
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.
Type aliases
ExpressionNode
StatementNode
StringDelimiter
StringDelimiter: null | "'" | """
TemplateLoader
TemplateLoader: function
Value
Value: boolean | string | number
ValueNode
Variables
Const generalDelimiters
generalDelimiters: string[] = [' ', '\t', '\n']
Const readFile
readFile: __promisify__ = promisify(fs.readFile)
Functions
createMemoryCache
-
A cache instance
floatEqual
- floatEqual(a: number, b: number, epsilon: number): boolean
Object literals
Const binaryOperatorTypeLookup
binaryOperatorTypeLookup: object
&&
&&
: And = BinaryOperator.And
==
==
: Equals = BinaryOperator.Equals
||
||
: Or = BinaryOperator.Or
Const boundaryTypeLookup
boundaryTypeLookup: object
{{
{{
: TagStart = TokenBoundaryType.TagStart
}}
}}
: TagEnd = TokenBoundaryType.TagEnd
Const delimiters
delimiters: object
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
Create an instance of the sql template engine