Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function initInMemoryDatabase(
schema: string
): Promise {
// initialize the knex db
const knex = Knex({
client: "sqlite3",
connection: { filename: ":memory:" }
});
// migrate the schema
const strategy = new DropCreateDatabaseAlways("sqlite3", knex);
await migrate(schema, strategy);
return new InMemoryDatabase(knex);
}
export async function createDatabaseMigration(schema: string, config: GenerateConfig) {
const db = knex({
client: config.db.database,
connection: config.db.dbConfig,
});
// FIXME move to UpdateDatabaseIfChanges after adding relationships support
const dbInitialization = new DropCreateDatabaseAlways(config.db.database, db);
await migrate(schema, dbInitialization);
return new Promise(resolve => db.destroy(resolve));
}
export async function handler() {
const configInstance = new ConfigBuilder();
const config = configInstance.config;
const db = await connect(config.db.database, config.db.dbConfig);
const initializationStrategy = new DropCreateDatabaseAlways(config.db.database, db);
await createDB(initializationStrategy)
postCommandMessage(`
Database resources created.
Run ${chalk.cyan(`npm run develop`)} to start the server.
`)
process.exit(0);
}