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

Connection config onConnect #303

Merged
merged 2 commits into from
Sep 17, 2018
Merged

Connection config onConnect #303

merged 2 commits into from
Sep 17, 2018

Conversation

milo
Copy link
Collaborator

@milo milo commented Jul 30, 2018

  • new feature
  • BC break? no

onConnect option is an array of SQL queries run by Connection::query() right after a database connection is established.

It is "hard" to run SQL queries once when a connection is established, especially in non-lazy configuration. Such queries are usually part of the connection setup phase, like:

  • ['ALTER SESSION SET NLS_DATE_FORMAT = %s', 'YYYY-MM-DD'] (by Oracle)
  • PRAGMA foreign_keys=true by Foreign keys and SQLite #301 (by SQLite)
  • SET application_name = 'MyApp'; (by PostgreSQL)

In lazy mode, the Dibi\Event can be used, but such event is invoked by every next SQL query which is not necessary. Moreover, when used with Nette DI, it requires some stuff/boilerplate code to achive that. This solution seems clear to me, setup queries are kept near configuration.

For onConnect option, I was thinking about callbacks instead of SQL queries. It would be more universal, but harder to write by configuration, NEON for example. IMHO, callbacks can by added later without BC break.

jan-oliva and others added 2 commits July 14, 2018 16:39
onConnect option is an array of SQL queries run by Connection::query() right after a database connection is established.
@dg
Copy link
Owner

dg commented Sep 17, 2018

Thanks

@dg dg merged commit 5b60820 into dg:master Sep 17, 2018
dg pushed a commit that referenced this pull request Sep 17, 2018
onConnect option is an array of SQL queries run by Connection::query() right after a database connection is established.
dg pushed a commit that referenced this pull request Sep 17, 2018
onConnect option is an array of SQL queries run by Connection::query() right after a database connection is established.
@milo
Copy link
Collaborator Author

milo commented Sep 17, 2018

Thank you!

@milo milo deleted the config-on-connect branch May 23, 2022 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants