Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { init } from 'midway-web';
import { Sequelize } from 'sequelize';
import { Options as SequelizeOptions, Sequelize as SequelizeInstance } from 'sequelize';
export class BaseDataSource {
protected instance: SequelizeInstance;
protected config;
protected logger;
protected name: string;
@init()
async connection() {
const password = await this.getPassword();
const options: SequelizeOptions = this.getOptions();
const database: string = this.config.database;
const username: string = this.config.username;
this.instance = new Sequelize(database, username, password, options);
try {
await this.instance.authenticate();
await this.prepare();
} catch (error) {
error.message = `[DataSource-${this.name}] connection error:${error.message}`;
throw error;
}
}
@provide('traceNodeManager')
export class TraceNodeManager {
@inject()
protected dw;
@logger()
protected logger;
@inject()
protected traceNodeModel;
protected instance;
@init()
initialize() {
this.instance = this.dw.instance;
}
escape(query: object, fields: string[]): void {
fields.forEach((field) => {
if (query[field] !== undefined) {
query[field] = this.instance.escape(query[field]);
}
});
}
public async list(condition: FindOptions): Promise> {
return this.traceNodeModel.findAndCount(condition);
}
@logger()
public logger;
defaultQueryOpts = {
ms: 'true',
};
defaultPOSTOpts = {
msResolution: true,
showQuery: false,
};
protected host: string;
protected port: string;
protected prefix: string;
@init()
init() {
this.host = this.config.host;
this.port = this.config.port;
this.prefix = 'http://' + this.host + ':' + this.port;
}
async suggest(suggestOptions: SuggestOptions) {
const resp = await this.request('/api/suggest', suggestOptions, {
method: 'GET',
});
return resp.data;
}
async query(queryOptions: QueryOptions): Promise {
const resp = await this.requestPost('/api/query', {
data: {
import {sqlPartTimestampConvertToTs} from '../util/util';
@provide('traceManager')
export class TraceManager {
@logger()
protected logger;
@inject()
protected dw;
@inject()
protected traceModel;
protected instance;
@init()
initialize() {
this.instance = this.dw.instance;
}
escape(query: object, fields: string[]): void {
fields.forEach((field) => {
if (query[field] !== undefined) {
query[field] = this.instance.escape(query[field]);
}
});
}
async list(condition: FindOptions): Promise> {
return this.traceModel.findAndCount(condition);
}