This library is to facilate using Spraxa's DFramework related applications via NodeJS
import Framework from 'dframework-node';
const framework = new Framework({
logger
});
const loggedIn = await framework.login({
username: process.env.APP_USER,
password: process.env.APP_PASSWORD,
});
if (!loggedIn) {
logger.error('Login failed');
}
// create 2 controllers User and Item framework.createControllers('User', 'Item');
const result = await framework.controllers.User.list({
controller: 'User',
listParameters: new portal.ListParameters({
comboTypes: ['Role']
})
});
const result = await framework.controllers.User.get({
id: 1
});
or
const result = await framework.controllers.User.get(1);
const result = await framework.controllers.User.save({
id: 1
firstName: 'John',
lastName: 'Doe'
});
const sqlConfig = {
user: env.SQL_USER || env.USER,
password: env.SQL_PASSWORD || env.PASSWORD,
server: env.SQL_SERVER || env.SERVER,
database: env.SQL_DATABASE || env.DATABASE,
options: {
trustServerCertificate: true,
}
};
await DFramework.setSql(sqlConfig);
const fileName = 'queries/activeClients.sql';
const activeUsers = await framework.sql.query(fileName);
where fileName is the name of a file containing actual SQL query.
import { mssql } from 'dframework-node';
const request = framework.sql.createRequest();
request.input('IsActive', mssql.VarChar, 'Y');
const { recordset: activeUsers } = await framework.sql.query(`
SELECT * FROM dbo.Users WHERE IsActive = @IsActive
`);
// TODO
-
Create a file demo.esenv in environments folder with host information: { "host": "http://0.0.0.0:9000", "name": "Demo" }
-
Initialize code
const elasticConfig = {
environment: env.ELASTIC_ENVIRONMENT || 'Demo'
};
await framework.setElastic(elasticConfig);
const elasticResults = await framework.elastic.aggregate({
query: 'myQuery',
customize: this.customizeElasticQuery, // function to customize elastic query
mappings: {
"Items": {
root: "items",
map: {
"Transactions": "doc_count"
}
}
}
});
// TODO: Explain parameters
- Need to create config.json file on root of the project, which can be override with all config with local file like config.local.json
- Configuration in the JSON file which has all default values which can change accordingly
{
"logging": {
"otherConfig": {
"stdout": true,
"httpConfig": {
"url": "http://xyz.com/error_post",
"headers": {}
},
postLevel: "error",
stdout: true,
logLevel: 'debug',
logFolder: './logs',
mixin: null,
},
"prettyPrint": {
translateTime: 'SYS:yyyy-mm-dd h:MM:ss',
ignore: '',
colorize: true,
singleLine: false,
levelFirst: false,
},
"file": {
frequency: 'daily',
verbose: false,
max_logs: '10d',
date_format: 'YYYY-MM-DD',
size: '1m',
extension: ".log"
},
"customLevels" : { custom: 35 }
}
}
import { logger } from '@durlabh/dframework';
logger.info("info");
logger.debug("debug");
logger.error("error");
logger.trace("trace");