-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
24 lines (18 loc) · 765 Bytes
/
Copy pathmain.py
File metadata and controls
24 lines (18 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Demo: laziness, denial, and metering over one connection."""
from __future__ import annotations
from patterns.structural.proxy.examples.db_gateway.gateway import (
WarehouseConnection,
build_gateway,
)
def main() -> None:
analyst = build_gateway("warehouse://prod", role="analyst")
print(f"connections before any query: {WarehouseConnection.instances_connected}")
rows = analyst.query("SELECT sku, qty FROM stock")
print(f"first query connected lazily: {WarehouseConnection.instances_connected} -> {rows}")
try:
analyst.drop_table("stock")
except PermissionError as exc:
print(f"analyst denied: {exc}")
print(f"metered access counts: {dict(analyst.access_counts)}")
if __name__ == "__main__":
main()