Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.