Configuring Database

Overview of configuration options for the Nette Database.

If you are not using the whole framework, but only this library, read how to load the configuration.

Single Connection

Configure a single database connection:

	# DSN, only mandatory key
	dsn: "sqlite:%appDir%/Model/demo.db"
	user: ...
	password: ...

It creates services of type Nette\Database\Connection and also Nette\Database\Explorer for the Database Explorer layer. The database connection is usually passed by autowiring, if this is not possible, use the service names @database.default.connection resp. @database.default.context.

Other settings:

	# shows database panel in Tracy Bar?
	debugger: ...     # (bool) defaults to true

	# shows query EXPLAIN in Tracy Bar?
	explain: ...      # (bool) defaults to true

	# to enable autowiring for this connection?
	autowired: ...    # (bool) defaults to true for first connection

	# table conventions: discovered, static, or class name
	conventions: discovered  # (string) defaults to 'discovered'

		# to connect to the database only when needed?
		lazy: ...     # (bool) defaults to false

		# PHP database driver class
		driverClass:  # (string)

		# you can list the options found in the PDO driver documentation

		# only MySQL: sets sql_mode
		sqlmode:      # (string)

		# only MySQL: sets SET NAMES
		charset:      # (string) defaults to 'utf8mb4' ('utf8' before v5.5.3)

		# only Oracle and SQLite: date format
		formatDateTime: # (string) defaults to 'U'

Multiple Connections

In the configuration we can define more database connections by dividing them into named sections:

		dsn: 'mysql:host=;dbname=test'
		user: root
		password: password

		dsn: 'sqlite::memory:'

Each defined connection creates services that includes section name in their name, ie @database.main.connection & @database.main.context and further @database.another.connection & @database.another.context.

Autowiring is enabled only for services from the first section. This can be changed with autowired: false or autowired: true. Non-autowired services are passed by name:

	- UserFacade(@database.another.connection)