wiki:DatabaseTier

Version 2 (modified by apoirier, 6 years ago) (diff)

--

Database tier

You can use SQLAlchemy or its declarative layer Elixir with Nagare. For each request received, Nagare creates a database transaction which is commited at the end of the request handling or rollbacked if an exception is raised.

The database connection is activated and configurated in the [database] section of the application configuration file as described in ApplicationConfiguration#database-section. One of the parameters in this section is the location of the __metadata__ object of SQLAlchemy:

  • which must be explicitly created:

    from elixir import *
    from sqlalchemy import MetaData
    
    __metadata__ = MetaData()
    
    # Database definitions
    ...
    
  • which Nagare automatically binds to the database engine when the application is launched

  • where your code must explicitly register the table definitions if you are using SQLAlchemy only

  • where Elixir automatically register the entities defined (see for example the Wiki entities definition at examples/nagare/examples/wiki/wikidata.py)