Database
Source code in src/cocalc_api/hub.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
query(query)
Do a user query. The input is of one of the following forms, where the tables are defined at https://github.com/sagemathinc/cocalc/tree/master/src/packages/util/db-schema
{"table-name":{"key":"value", ...}}with no None values sets one record in the database{"table-name":[{"key":"value", "key2":None...}]}gets an array of all matching records in the database, filling in None's with the actual values.{"table-name:{"key":"value", "key2":None}}gets one record, filling in None's with actual values.
This is used for most configuration, e.g., user names, project descriptions, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
dict[str, Any]
|
Object that defines the query, as explained above. |
required |
Examples:
Get and also change your first name:
>>> import cocalc_api; hub = cocalc_api.Hub(api_key="sk...")
>>> hub.db.query({"accounts":{"first_name":None}})
{'accounts': {'first_name': 'William'}}
>>> hub.db.query({"accounts":{"first_name":"W"}})
{}
>>> hub.db.query({"accounts":{"first_name":None}})
{'accounts': {'first_name': 'W'}}
Source code in src/cocalc_api/hub.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |