How millenniumdb/millenniumdb-driver-python works
Project Type and Purpose
• This is an open-source Python client library (driver) for MillenniumDB. It wraps network connection, message encoding/decoding, session management, and query result handling into a cohesive API. There’s no frontend or database code here—only client‐side logic interacting with an external server.
File Structure Analysis
• Top-level folders:
• docs/ – Sphinx documentation config
• src/millenniumdb_driver/ – core driver implementation
• Key modules under src:
• driver.py – entry point, factory for Driver instances
• session.py – manages sessions over a Driver (pool, lifecycle)
• socket_connection.py – raw TCP connection abstraction
• protocol.py, request_builder.py, message_encoder/decoder, receiver, response_handler – layered protocol stack
• catalog.py, graph_objects.py, record.py, result.py – domain object definitions
README Insights
• Describes usage: instantiate Driver → open Session → run queries → consume Result
• Emphasizes single connection per Driver, explicit close, and result‐consumption methods.
Components & Interactions
a. Application Layer
• Your client code imports millenniumdb_driver and calls driver()
b. Driver Component
• Driver Factory → holds Connection config
• Session Manager → issues Session instances
c. Connection & Protocol Stack
• SocketConnection → low-level TCP
• RequestBuilder → builds query messages
• MessageEncoder → serializes messages
• MessageReceiver → reads frames
• MessageDecoder → parses frames
• ResponseHandler → transforms into Result
d. Domain Objects
• Catalog, GraphObjects, Record, Result
• Data flows: ResponseHandler → Result → your code
e. External Service
• MillenniumDB Server (running elsewhere)
Architectural Patterns & Principles
• Layered protocol stack (builder → encode → send → receive → decode → handler)
• Factory (Driver → Session)
• Separation of concerns: transport, protocol, domain objects