Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make foal generate script generate a script with a default Mongoose connection in MongoDB projects #362

Closed
LoicPoullain opened this issue Feb 20, 2019 · 1 comment

Comments

@LoicPoullain
Copy link
Member

Issue

Currently, when we generate a MongoDB project with foal createapp <name> --mongodb and then run foal generate script <name>, the CLI generates a script with a default TypeORM connection.

// 3p
import { createConnection } from 'typeorm';

[...]

export async function main(args) {
  await createConnection();

  // Do something.
}

Solution

Detect that the project is a Mongoose project and generate this file:

// 3p
import { Config } from '@foal/core';
import { connect, disconnect } from 'mongoose';

[...]

export async function main(args) {
  const uri = Config.get<string>('mongodb.uri');
  connect(uri, { useNewUrlParser: true, useCreateIndex: true });

  // Do something.

  disconnect();
}
@LoicPoullain
Copy link
Member Author

Fixed in v1.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

1 participant