0.0.3 • Published 8 years ago
dt-server v0.0.3
dt-server -
A wrapper around a datatable server side processing
Installation
npm install dt-serverDependencies
None
Example Usage (Express)
There are four main objects in this project.
DtRequest
- Wraps the raw query from a datatable with added helper functionality
DtResponse
- Wraps an adapter - a SQLite adapter is provided - and generates a valid response
DtServer
- Handles creation of the above objects and returns the response
Adapter
- A class that implements the interface seen below in the DtSql3 Object
var DtServer = require('dt-server')
var db = require('MockSql3DB').Database
router.get('/dtsql3', function(req, res, next) {
var dtServer = DtServer('sql3', db, {
response: {
format: 'object-array'
}
})
dtServer.get(req.query,'USERS')
.then(function(results) {
res.status(200).json(results)
})
.catch(function(err) {
res.status(400).json(err)
})
})API
DtServer([adapter], [options])[adapter]Adapter for a database I.E. DtSql3 wraps the SQLite database[options]Custom options
DtServer.get([request], [model], (optional)[params])[request]Datatable JSON request object[model]Model to get from the database[params]Optional database parametersreturns{Promise}
DtSql3([Database])[Database]Database object`
DtSql3.get([dtRequest], [model], (optional)[params])[dtRequest]DtRequest object`[model]Model to get from the database`[params]Optional database parameters`returns{Promise}`
Extending
Implementing the interface seen in DtSql3 will allow you to pass that adapter as you would the DtSql3 object
Available Options
Defaults
{
request: {
excludeRegex: 'true' //'true'|'false'
filter: function(str, regex) {
return str
},
validate: 'true' //'true'|'false'
},
response: {
format: 'object-array', //object-array, value-array,
formatData: undefined, //Array function(data, format) { }
validate: 'false', 'true'|'false'
}
}Pass an object with one, or more of these options to override the defaults
request.exlcudeRegexremoves search columns using regexrequest.filterA function that augments incoming search stringsrequest.validateFlag to validate the datatable JSON request objectresponse.formatFormat of the response data from an adapterExample Formatsobject-array => [{name: 'a', address: 'b'}, ...]value-array => [['a', 'b'], ...]
request.formatDataCustom data formatting function used in-place of the default format functionrequest.validateFlag to validate JSON response object
License
MIT