diff options
author | Victor Sergeyev <vsergeyev@mirantis.com> | 2014-04-22 18:11:55 +0300 |
---|---|---|
committer | Victor Sergeyev <vsergeyev@mirantis.com> | 2014-04-22 18:37:08 +0300 |
commit | b50609bc0e63704947c0e9d66e503155e885bc0d (patch) | |
tree | 5fa28143f5600d32b8bed1e8e4daee8138162810 /doc | |
parent | 276f7570d7af4a7a62d0e1ffb4edf904cfbf0600 (diff) | |
download | oslo-db-b50609bc0e63704947c0e9d66e503155e885bc0d.tar.gz |
Fix dhellmann's notes from April 18
removed the python 3 classifier. See note
https://github.com/malor/oslo.db/commit/e4cfa6d39d2aa53af64ab34de97183f98fbeb667#commitcomment-6058177
added W292 pep8 check. See note
https://github.com/malor/oslo.db/commit/276f7570d7af4a7a62d0e1ffb4edf904cfbf0600#commitcomment-6058296
added usage examples. See note
https://github.com/malor/oslo.db/commit/e4cfa6d39d2aa53af64ab34de97183f98fbeb667#commitcomment-6058130
Diffstat (limited to 'doc')
-rw-r--r-- | doc/source/usage.rst | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 81c25cf..be9ff69 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -2,6 +2,66 @@ Usage ======== -To use in a project:: +To use oslo.db in a project:: + +* Session Handling + + .. code:: python + + from oslo.db.sqlalchemy import session as db_session + + _FACADE = None + + def _create_facade_lazily(): + global _FACADE + if _FACADE is None: + _FACADE = db_session.EngineFacade.from_config( + CONF.database.connection, CONF) + return _FACADE + + def get_engine(): + facade = _create_facade_lazily() + return facade.get_engine() + + def get_session(**kwargs): + facade = _create_facade_lazily() + return facade.get_session(**kwargs) + + +* Base class for models usage + + .. code:: python + + from oslo.db import models + + + class ProjectSomething(models.TimestampMixin, + models.ModelBase): + id = Column(Integer, primary_key=True) + ... + + +* DB API backend support + + .. code:: python + + from oslo.config import cfg + from oslo.db import api as db_api + + CONF = cfg.CONF + CONF.import_opt('backend', 'oslo.db.options', group='database') + + _BACKEND_MAPPING = {'sqlalchemy': 'project.db.sqlalchemy.api'} + + IMPL = db_api.DBAPI(CONF.database.backend, backend_mapping=_BACKEND_MAPPING) + + def get_engine(): + return IMPL.get_engine() + + def get_session(): + return IMPL.get_session() + + # DB-API method + def do_something(somethind_id): + return IMPL.do_something(somethind_id) - import db
\ No newline at end of file |