Skip to content

Multiple database connections #339

@brendt

Description

@brendt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions