tempestphp / tempest-framework

The PHP framework that gets out of your way 🌊
https://tempest.stitcher.io
MIT License
659 stars 44 forks source link

Multiple database connections #339

Open brendt opened 4 weeks ago

brendt commented 4 weeks ago

How about we change our database config like so?

return new DatabaseConfig(
    connections: [
        'main' => new SQLiteConnection(
            path: 'database.sqlite'
        ),
        'backup' => new MysqlConnection(
            // …
        ),
        // …
    ]
);

We'd change the name of the interface Driver to Connection, I think that makes more sense anyway.

By default, the first registered connection is used. However, users can manually switch their connection:

(new Query($sql))->connection('backup')->execute();

We'd need to consider whether we want the DatabaseModel trait to allow for connection switching on per-model basis. That's up for debate, although I lean more towards no.

brendt commented 4 weeks ago

@aidan-casey feel free to share your thoughts