Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify API, add new MysqlClient and remove Factory and ConnectionInterface #186

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

clue
Copy link
Contributor

@clue clue commented Nov 17, 2023

This changeset simplifies the API by adding a new MysqlClient and removing the existing Factory and ConnectionInterface:

// old
$factory = new React\MySQL\Factory();
$mysql = $factory->createLazyClient('user:pass@localhost/bookstore');
assert($mysql instanceof React\MySQL\ConnectionInterface);

// new
$mysql = new React\MySQL\MysqlClient('user:pass@localhost/bookstore');

The resulting API is somewhat more straight-forward and easier to use. On top of this, this is also one of the prerequisites for introducing the connection pool as discussed in #175.

Internally, the MysqlClient works similar to what was previously called a "lazy" client, but we're getting rid of this wording altogether. This means it automatically creates the underlying connection to MySQL only when it's actually needed and will close this connection after a short while when it is not in use anymore. The changeset introduced in #182 already reduces the default itle time to 1ms (0.001s). A follow-up PR will adjust the open and close event handling as discussed in #147.

For the reference: I realize the changeset looks pretty big, but if you take a look at the individual commits, you will see that most of this comes from rearranging existing code. I've tried hard to keep the existing logic in place otherwise to not introduce any side effects.

Builds on top of #87, #182 and #185
Refs #147 and clue/reactphp-redis#129

Copy link
Contributor

@SimonFrings SimonFrings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

@WyriHaximus WyriHaximus merged commit 9e01898 into friends-of-reactphp:0.7.x Nov 21, 2023
13 checks passed
@clue clue deleted the mysqlclient branch November 22, 2023 08:43
@legionth
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants