-
Notifications
You must be signed in to change notification settings - Fork 1
Support named databases #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ def __init__( | |
url: str = None, | ||
username: str = None, | ||
password: str = None, | ||
database: str = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect this to live inside the driver configuration and not be visible inside the driver signature, as you have assumed. Maybe we can group the ENVS that are driver specific, there is a lot of configuration on that side, so we do not continue to expand this signature, and instead just unpack the ENVS in MCP and pass the dictionary. What do you think? |
||
driver_config: Optional[Dict] = None, | ||
): | ||
""" | ||
|
@@ -22,11 +23,13 @@ def __init__( | |
- MEMGRAPH_URL (default: "bolt://localhost:7687") | ||
- MEMGRAPH_USER (default: "") | ||
- MEMGRAPH_PASSWORD (default: "") | ||
- MEMGRAPH_DATABASE (default: "memgraph") | ||
|
||
Args: | ||
url: The Memgraph connection URL | ||
username: Username for authentication | ||
password: Password for authentication | ||
database: The database name to connect to (default: "memgraph") | ||
driver_config: Additional Neo4j driver configuration | ||
""" | ||
|
||
|
@@ -38,6 +41,9 @@ def __init__( | |
self.driver = GraphDatabase.driver( | ||
url, auth=(username, password), **(driver_config or {}) | ||
) | ||
|
||
self.database = database or os.environ.get("MEMGRAPH_DATABASE", "memgraph") | ||
|
||
try: | ||
import neo4j | ||
except ImportError: | ||
|
@@ -74,6 +80,7 @@ def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]: | |
data, _, _ = self.driver.execute_query( | ||
query, | ||
parameters_=params, | ||
database_=self.database, | ||
) | ||
json_data = [r.data() for r in data] | ||
return json_data | ||
|
@@ -106,7 +113,7 @@ def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]: | |
raise | ||
|
||
# fallback to allow implicit transactions | ||
with self.driver.session() as session: | ||
with self.driver.session(database=self.database) as session: | ||
data = session.run(query, params) | ||
json_data = [r.data() for r in data] | ||
return json_data | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we are adding them to the README, which we should have done previously, can you add them to a separate section called configuration, and then Envs as a subtitle, since these envs also work without Docker?