Testing Vapor 3 with different database provider

Viewed 121

Is this possible to use in-memory FluentSQLite provider for testing purpose and FluentPostgreSQL for app's models?

1 Answers

It depends....

In short for simple apps yeah you can. You basically need to make your models generic and then set up the generic models from your configuration all the way down. See how the benchmark models are set up here.

In reality - no you can't. As soon as you want to do anything that isn't standard (TEXT column type) etc, you need to make your models specific to the DB type.

The way to do it is to use the repository pattern and completely abstract away your database from your application logic. See the Vapor style guide for more details.

Related