Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Knex from "knex";
const knex = Knex({});
// $ExpectError - invalid Client
Knex({
client: "foo"
});
knex
.clearSelect()
.clearWhere()
.select("foo")
.withSchema("a")
.from("bar")
.where("foo", 2)
.where({ mixed: "hi" })
.orWhere("bar", "foo")
.whereNot("asd", 1)
.whereIn("batz", [1, 2]);
async function execute() {
try {
// Dynamically load app or config from the path provided package.json script
const [,, command, importPath, ...args] = process.argv
const execute = command && getCommand(commands, command.split(':'))
if (!isFunction(execute)) {
throw new Error(`Unknown command: ${command}`)
}
let arg = (await import(path.resolve(importPath))).default
if (isFunction(arg)) {
arg = await arg()
} else if (isPlainObject(arg) && arg.knex) {
arg = Knex(arg.knex)
}
const res = await execute(arg, ...args)
process.exit(res === true ? 0 : 1)
} catch (err) {
if (err instanceof Error) {
console.error(
chalk.red(`${err.detail ? `${err.detail}\n` : ''}${err.stack}`)
)
} else {
console.error(chalk.red(err))
}
process.exit(1)
}
}
async function task(args, options) {
logger.task('Seeding database');
const rootDir = appRoot.get();
const knexConfig = {
client: 'pg',
connection: options.dburl || config.get('db.url'),
migrations: {
tableName: 'migrations',
directory: path.resolve(rootDir, '.boldr/db/migrations'),
},
seeds: {
directory: path.resolve(rootDir, '.boldr/db/seeds'),
},
};
const db = knex(knexConfig);
try {
await db.seed.run(knexConfig);
logger.info('Database populated.');
process.exit(0);
} catch (err) {
logger.error(err);
process.exit(1);
}
}
const runCode = async () => {
const knex = Knex({
client: SQLJSClient,
debug: true,
pool: { min: 1, max: 1 },
acquireConnectionTimeout: 500,
});
knex.initialize();
const run = new AsyncFunction("Knex", "knex", "greldal", "graphql", code);
try {
const schema = await run(Knex, knex, greldal, graphql);
setResult("");
setError("");
setSchema(schema);
} catch (e) {
console.error(e);
setError(`${e.message}\n${e.stack && e.stack.join("\n")}`);
}
constructor (
config: Config,
schemaName: string,
tablePrefix: string,
columnPrefix: string,
) {
this.config = config
this.schemaName = schemaName
this.tablePrefix = tablePrefix
this.columnPrefix = columnPrefix
this.knex = Knex(config)
this.database = {
tables: [],
tableMap: new Map(),
}
}
import express from 'express';
import { development as devconfig } from '../../knexfile';
import knexModule from 'knex';
import bookshelfModule from 'bookshelf';
import bookshelfBcrypt from 'bookshelf-bcrypt';
import User from '../db/controllers/users';
import Model from '../db/models/users';
const knex = knexModule(devconfig);
const knexdb = bookshelfModule(knex).plugin(bookshelfBcrypt);
const usersModel = Model(knexdb);
const router = express.Router();
router.post('/', (req, res) => {
const userParams = req.body;
User.saveNewUser(userParams, usersModel)
.then((user) => {
if (user) {
res.status(201).json({ message: 'Registration Successful' });
}
})
.catch((err) => {
private _setupWriteConnection () {
this.client = knex(this._getWriteConfig())
patchKnex(this.client, this._writeConfigResolver.bind(this))
}
export async function connect() {
return knex({
client: config.db.database,
connection: config.db.dbConfig
})
}
level: process.env.LOG_LEVEL || 'info',
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.align(),
formatter
),
defaultMeta: { service: 'rafiki' },
transports: [
new winston.transports.Console()
]
})
const config = new Config()
config.loadFromEnv()
knex = Knex(config.databaseConnectionString)
const authService = config.authProviderUrl !== '' ? new RemoteAuthService(knex, config.authProviderUrl) : new AuthService(knex)
const app = new App(config, authService.getPeerIdByToken.bind(authService), knex)
const adminApi = new AdminApi({ host: config.adminApiHost, port: config.adminApiPort, useAuthentication: config.adminApiAuth }, { app, authService })
const settlementAdminApi = new SettlementAdminApi({ host: config.settlementAdminApiHost, port: config.settlementAdminApiPort }, { getAccountBalance: app.getBalance.bind(app), updateAccountBalance: app.updateBalance.bind(app), sendMessage: app.forwardSettlementMessage.bind(app) })
export const gracefulShutdown = async () => {
winston.debug('shutting down.')
await app.shutdown()
adminApi.shutdown()
settlementAdminApi.shutdown()
winston.debug('completed graceful shutdown.')
}
export const start = async () => {
let shuttingDown = false
process.on('SIGINT', async () => {