Why create the database explicitly?

In your examples you’re creating a database config and then doing this:

  let database = PostgreSQLDatabase(config: databaseConfig)
  databases.add(database: database, as: .psql)
  services.register(databases)

I realized that in my project I wasn’t creating the database, and I’m just calling services.register right against the databaseConfig itself and it seems to work fine.

Is there an advantage to one or the other?

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

@gargoyle apologies been away!

So if you are only specifying a config and not the database I’d be surprised if it works since it won’t know how to map the .psql DB used by models to a specific database.

The main reason for specifying it explicitly is because Fluent can work with multiple databases so you need to set them up correctly to work with the different models.

@0xtim It works flawlessly…at least as far as I’ve seen so far.

1 Like