diff --git a/docs/source/index.rst b/docs/source/index.rst index 49b18b6..be5ea87 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -10,6 +10,7 @@ SQLAlchemy Postgresql Audit example alembic-integration naming-conventions + session-settings contributing roadmap contributors diff --git a/docs/source/session-settings.rst b/docs/source/session-settings.rst new file mode 100644 index 0000000..65a529a --- /dev/null +++ b/docs/source/session-settings.rst @@ -0,0 +1,42 @@ +Session Settings +---------------- + +In order to enrich the audit tables with information, we can set session settings that live for the duration of a transaction. + + +**SQLAlchemy Session** + +.. code-block:: python + + from sqlalchemy_postgresql_audit import set_session_vars + from sqlalchemy.orm import sessionmaker + + Session = sessionmaker(bind=engine) + session = Session() + + set_session_vars(session, username='huntcsg') + session.execute(insert_stmt, { ... values ... }) + session.commit() + + + +**SQLAlchemy Connection** + +.. code-block:: python + + from sqlalchemy_postgresql_audit import set_session_vars + + with engine.connect() as conn: + with conn.begin() as trans: + set_session_vars(conn, username='huntcsg') + conn.execute(insert_stmt, { ... values ... }) + + +**SQLAlchemy Engine** + +.. code-block:: python + + from sqlalchemy_postgresql_audit import set_session_vars + with engine.begin() as conn: + set_session_vars(conn, username='huntcsg') + conn.execute(insert_stmt, { ... values ... }) diff --git a/examples/alembic/README.md b/examples/alembic/README.md new file mode 100644 index 0000000..1c53b7f --- /dev/null +++ b/examples/alembic/README.md @@ -0,0 +1,20 @@ +# Instructions + +1. Install package and dependencies + ```bash + $ pip install sqlalchemy-postgresql-audit + $ pip install psycopg2 + $ pip install alembic + $ pip install -e test-app + +2. Run + + ```bash + $ docker-compose up -d + +3. Run + + ```bash + $ alembic upgrade head + +4. Database now has tables, audit tables, and triggers. diff --git a/examples/plugin/README.md b/examples/plugin/README.md new file mode 100644 index 0000000..c32ee16 --- /dev/null +++ b/examples/plugin/README.md @@ -0,0 +1,19 @@ +# Instructions + +1. Install package and dependencies + ```bash + $ pip install sqlalchemy-postgresql-audit + $ pip install psycopg2 + +2. Run + + ```bash + $ docker-compose up -d + +3. Run + + ```bash + $ python plugin.py + +4. Database now has tables, audit tables, and triggers. + diff --git a/examples/simple/README.md b/examples/simple/README.md new file mode 100644 index 0000000..825aa1d --- /dev/null +++ b/examples/simple/README.md @@ -0,0 +1,18 @@ +# Instructions + +1. Install package and dependencies + ```bash + $ pip install sqlalchemy-postgresql-audit + $ pip install psycopg2 + +2. Run + + ```bash + $ docker-compose up -d + +3. Run + + ```bash + $ python simple.py + +4. Database now has tables, audit tables, and triggers.