From f99da33cd6bb11763d595568f287013c009ed500 Mon Sep 17 00:00:00 2001 From: Daniel <daniel@harvey> Date: Wed, 11 Dec 2019 12:28:41 +0100 Subject: [PATCH] ENH: Example how to reconfigure a connection. --- examples/pycaosdb_example.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/pycaosdb_example.py b/examples/pycaosdb_example.py index d128e4e6..c7eab4a6 100755 --- a/examples/pycaosdb_example.py +++ b/examples/pycaosdb_example.py @@ -6,12 +6,19 @@ Make sure that a `pycaosdb.ini` is readable at one of the expected locations. import random -import caosdb +import caosdb as db + + +def reconfigure_connection(): + """Change the current connection configuration.""" + conf = db.configuration.get_config() + conf.set("Connection", "url", "https://demo.indiscale.com") + db.configure_connection() def main(): """Shows a few examples how to use the CaosDB library.""" - conf = dict(caosdb.configuration.get_config().items("Connection")) + conf = dict(db.configuration.get_config().items("Connection")) print("##### Config:\n{}\n".format(conf)) if conf["cacert"] == "/path/to/caosdb.ca.pem": @@ -19,12 +26,12 @@ def main(): "please fix it.") # Query the server, the result is a Container - result = caosdb.Query("FIND Record").execute() + result = db.Query("FIND Record").execute() print("##### First query result:\n{}\n".format(result[0])) # Retrieve a random Record rec_id = random.choice([rec.id for rec in result]) - rec = caosdb.Record(id=rec_id).retrieve() + rec = db.Record(id=rec_id).retrieve() print("##### Randomly retrieved Record:\n{}\n".format(rec)) -- GitLab