cycle / database

Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
MIT License
54 stars 22 forks source link

💡 Feature request: __set_state for driver configs #78

Closed wakebit closed 1 year ago

wakebit commented 1 year ago

I have an idea!

There is some config:

new DatabaseConfig([
        'default' => 'default',

        'databases' => [
            'default' => [
                'connection' => 'mysql',
            ],
        ],

        'connections' => [
            'sqlite' => new \Cycle\Database\Config\SQLiteDriverConfig(
                connection: new \Cycle\Database\Config\SQLite\MemoryConnectionConfig(),
                driver: \Cycle\Database\Driver\SQLite\SQLiteDriver::class,
                queryCache: true,
            ),

            'mysql' => new \Cycle\Database\Config\MySQLDriverConfig(
                connection: new \Cycle\Database\Config\MySQL\TcpConnectionConfig(
                    database: 'project_name',
                    host: '127.0.0.1',
                    port: 3306,
                    user: 'test',
                    password: 'secret',
                ),
                queryCache: true,
            ),
        ],
    ]),

It would be good if these settings will be cached. It works well with var_export. But it cannot be recovered because driver configs don't have __set_state methods.

I have a suggestion to add default method __set_state to \Cycle\Database\Config\DriverConfig and override in another configs when it's required. I can create pull request if this idea will be accepted.

roxblnfk commented 1 year ago

Feel free to make a PR. Thank you.

roxblnfk commented 1 year ago

Thank you! We will release the new database version soon.