Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const createContainer = (): Container => {
const container = new Container();
// Generics
container.bind(Symbols.generic.appConfig)
.toConstantValue(JSON.parse(JSON.stringify(require(`${__dirname}/../integration/config.json`))));
container.bind(Symbols.generic.genesisBlock)
.toConstantValue(JSON.parse(JSON.stringify(require(`${__dirname}/../integration/genesisBlock.json`))));
const genesis = container.get(Symbols.generic.genesisBlock)
genesis.generatorPublicKey = Buffer.from(genesis.generatorPublicKey, 'hex');
genesis.blockSignature = Buffer.from(genesis.blockSignature, 'hex');
container.bind(Symbols.generic.socketIO).to(SocketIOStub).inSingletonScope();
container.bind(Symbols.generic.zschema).to(ZSchemaStub).inSingletonScope();
container.bind(Symbols.generic.sequelize).toConstantValue(new Sequelize({
database: 'test',
//dialect: 'sqlite',
dialect : 'postgres',
username: 'root',
password: 'test',
//storage: ':memory',
logging : !('SEQ_SILENT' in process.env),
}));
container.bind(Symbols.helpers.constants).toConstantValue({ ...{}, ...constants });
container.bind(Symbols.helpers.bus).to(BusStub).inSingletonScope();
container.bind(Symbols.helpers.crypto).to(CryptoStub).inSingletonScope();
container.bind(Symbols.helpers.db).to(DbStub).inSingletonScope();
container.bind(Symbols.helpers.migrator).to(MigratorStub).inSingletonScope();
container.bind(Symbols.helpers.exceptionsManager).to(ExceptionsManagerStub).inSingletonScope();
container.bind(Symbols.helpers.jobsQueue).to(JobsQueueStub).inSingletonScope();
import {Sequelize} from 'sequelize-typescript';
import * as config from '../config/config.json';
// dynamic configuration depending on env
const env = process.env.NODE_ENV || 'development';
const sequelize = new Sequelize(config[env]);
sequelize.addModels([`${__dirname}/../models`]);
// Convert decimals from String to Number right away - mainly for PSS in number instead of string
Sequelize.postgres.DECIMAL.parse = value => parseFloat(value);
export default sequelize;
let config;
switch (process.env.NODE_ENV) {
case 'prod':
case 'production':
config = databaseConfig.production;
case 'dev':
case 'development':
config = databaseConfig.development;
case 'test':
config = databaseConfig.test;
default:
config = databaseConfig.development;
}
const sequelize = new Sequelize(config);
const umzug = new Umzug({
storage: 'sequelize',
storageOptions: { sequelize },
// see: https://github.com/sequelize/umzug/issues/17
migrations: {
params: [
sequelize,
sequelize.constructor, // DataTypes
function() {
throw new Error(
'Migration tried to use old style "done" callback. Please upgrade to "umzug" and return a promise instead.'
);
}
],
constructor(connectionString: string) {
this.sequelize = new Sequelize(connectionString);
this.connect = new Promise(async (resolve, reject) => {
try {
await this.sequelize.authenticate();
await this.sequelize.sync();
resolve();
}
catch(err) {
reject(err);
}
});
}
host: process.env.DB_HOST || '127.0.0.1',
port: Number(process.env.DB_PORT) || 5432,
dialect: 'postgres',
logging: true,
force: true,
timezone: '+02:00',
modelPaths: [
path.resolve(__dirname, '../models')
]
}
};
const config = !process.env.NODE_ENV || process.env.NODE_ENV === 'development' ?
databaseConfig.development :
databaseConfig.production;
export const sequelize: Sequelize = new Sequelize(config);
import { Sequelize } from 'sequelize-typescript'
import _ from 'lodash'
import { dbLogger, cache, session } from '../lib'
import config from '../config'
import * as models from './models'
Sequelize.useCLS(session)
const { createContext, EXPECTED_OPTIONS_KEY } = require('dataloader-sequelize')
const sequelize = new Sequelize({
...config.db,
define: {
timestamps: false,
underscored: true
},
logging (sql, timing) {
dbLogger.info(sql, _.isObject(timing) ? timing : { timing })
}
})
sequelize.addModels(Object.values(models))
const contextOption = {
get [EXPECTED_OPTIONS_KEY] () {
const key = 'SequelizeContext'
if (cache.get(key)) {
useFactory: async () => {
const sequelize = new Sequelize({
dialect: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'root',
database: 'test',
});
sequelize.addModels([Cat]);
await sequelize.sync();
return sequelize;
},
},
import { Sequelize } from 'sequelize-typescript';
let config = {} as any;
if (process.env.DATABASE_URL) {
config.url = process.env.DATABASE_URL;
} else {
config.database = 'prime-sq';
config.username = 'birkir';
config.password = '';
}
export const sequelize = new Sequelize({
dialect: 'postgres',
modelPaths: [`${__dirname}/models`],
logging: true,
...config,
});
private async open() {
this.sequelize = new Sequelize(this.option);
await this.sequelize.authenticate();
this.sequelize.addModels([CasbinRule]);
await this.createTable();
}