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