Skip to content
Snippets Groups Projects
Commit f99da33c authored by Daniel's avatar Daniel
Browse files

ENH: Example how to reconfigure a connection.

parent e128ecae
No related branches found
No related tags found
No related merge requests found
...@@ -6,12 +6,19 @@ Make sure that a `pycaosdb.ini` is readable at one of the expected locations. ...@@ -6,12 +6,19 @@ Make sure that a `pycaosdb.ini` is readable at one of the expected locations.
import random 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(): def main():
"""Shows a few examples how to use the CaosDB library.""" """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)) print("##### Config:\n{}\n".format(conf))
if conf["cacert"] == "/path/to/caosdb.ca.pem": if conf["cacert"] == "/path/to/caosdb.ca.pem":
...@@ -19,12 +26,12 @@ def main(): ...@@ -19,12 +26,12 @@ def main():
"please fix it.") "please fix it.")
# Query the server, the result is a Container # 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])) print("##### First query result:\n{}\n".format(result[0]))
# Retrieve a random Record # Retrieve a random Record
rec_id = random.choice([rec.id for rec in result]) 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)) print("##### Randomly retrieved Record:\n{}\n".format(rec))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment