## Database


Database connection manager.


Usage

``` python
Database(
    path,
    *,
    echo=False,
)
```


## Attributes


`path`  
Path to SQLite database file.

`engine`  
SQLAlchemy engine instance.


## Methods

| Name | Description |
|----|----|
| [__enter__()](#__enter__) | Return this database, to be closed on exiting the context. |
| [__exit__()](#__exit__) | Close the database connection. |
| [__init__()](#__init__) | Initialize database connection manager. |
| [close()](#close) | Close the database connection. |
| [session()](#session) | Return a fresh session bound to this database's engine. |

------------------------------------------------------------------------


#### \_\_enter\_\_()


Return this database, to be closed on exiting the context.


Usage

``` python
__enter__()
```


------------------------------------------------------------------------


#### \_\_exit\_\_()


Close the database connection.


Usage

``` python
__exit__(exc_type, exc_value, traceback)
```


------------------------------------------------------------------------


#### \_\_init\_\_()


Initialize database connection manager.


Usage

``` python
__init__(path, *, echo=False)
```


##### Parameters


`path: str | Path`  
Path to the SQLite database file.

`echo: bool = ``False`  
If True, SQL statements will be logged to the standard output. If False, no logging is performed.


------------------------------------------------------------------------


#### close()


Close the database connection.


Usage

``` python
close()
```


------------------------------------------------------------------------


#### session()


Return a fresh session bound to this database's engine.


Usage

``` python
session()
```


##### Note

A new session is created per call; use it as a context manager (`with database.session() as session: ...`) to close it on exit. Nothing is committed automatically -- call `session.commit()` explicitly. Validation and automatic identities are only applied by sessions of type [AutostorageSession](AutostorageSession.md#autostorage.AutostorageSession), such as the ones returned here.
