import process from 'node:process';
import config from 'config';
import knex from 'knex';

export const knexOwner = knex({
	client: 'pg',
	connection: config.database.owner,
	pool: config.database.pool,
	// performance overhead, don't use asyncStackTraces in production
	asyncStackTraces: process.env.NODE_ENV === 'development',
	// debug: process.env.NODE_ENV === 'development',
});

export const knexQuery = knexOwner; // legacy

export const knexManticore = knex({
	client: 'mysql',
	connection: {
		host: config.database.manticore.host,
		port: config.database.manticore.sqlPort,
		database: 'Manticore',
	},
	asyncStackTraces: process.env.NODE_ENV === 'development',
	wrapIdentifier(value, _original, _queryContext) {
		return value;
	},
});

export default knexQuery;
