diff --git a/src/doc/getting_started/helloworld.md b/src/doc/getting_started/helloworld.md index f26caf9e2484dcc8423f4fbc95aefe84e0aa0861..723fb88d08047350d9f4bc3d3d2bd84ec9b27efb 100644 --- a/src/doc/getting_started/helloworld.md +++ b/src/doc/getting_started/helloworld.md @@ -1,5 +1,7 @@ # Hello World +## Setting up the data model ## + For this example, we need a very simple data model. You can insert it into your CaosDB instance by saving the following to a file called `model.yml`: @@ -13,15 +15,22 @@ HelloWorld: ``` and insert the model using ```sh -python -m caosadvancedtools.models.parser model.yml --sync +python -m caosadvancedtools.models.parser model.yml --sync ``` Let's look first at how the CaosDB Crawler synchronizes Records that are created locally with those that might already exist on the CaosDB server. +For this you need a file called `identifiables.yml` with this content: +```yaml +HelloWorld: + - name +``` + +## Synchronizing data ## -You can do the following interactively in (I)Python. But we recommend that you -can copy the code into a script and execute it to spare yourself typing. +Then you can do the following interactively in (I)Python. But we recommend that you +copy the code into a script and execute it to spare yourself typing. ```python import caosdb as db @@ -50,12 +59,7 @@ print(f"Inserted {len(inserts)} Records") print(f"Updated {len(updates)} Records") ``` -You also need a file called `identifiables.yml` with the following content: -```yaml -HelloWorld: - - name -``` -Now, start by executing the code. What happens? The output suggests, that one +Now, start by executing the code. What happens? The output suggests that one entity was inserted. Please go to the web interface of your instance and have a look. You can use the query `FIND HelloWorld`. You should see a brand new Record with a current time stamp. @@ -67,23 +71,25 @@ use the name. The Crawler thus checked whether a "HelloWorld" Record with our name exists on the Server. It did not. Therefore the Record that we provided was inserted in the Server. +## Running the synchronization again ## + Now, run the script again. What happens? There is an update! This time, a -Record with the required name existed. Thus the "time" Property was updated. +Record with the required name existed. Thus the "time" Property of the existing Record was updated. The Crawler does not touch Properties that are not present in the local data. -Thus, if you add a "note" Property to the Record in the Server (e.g. with the +Thus, if you add a "note" Property to the Record in the server (e.g. with the edit mode in the web interface) and run the script again, this Property is -kept unchanged. This means that you can extend Records, that were created using +kept unchanged. This means that you can extend Records that were created using the Crawler. -Note, that if you change the name of the "HelloWorld" Record in the script and -run it again, a new Record is inserted by the Crawler. This is because we told -the Crawler that it should use the name to check whether a "HelloWorld" Record +Note that if you change the name of the "HelloWorld" Record in the script and +run it again, a new Record is inserted by the Crawler. This is because in the `identifiables.yml` we +told the Crawler that it should use the *name* to check whether a "HelloWorld" Record already exists in the Server. So far, you saw how the Crawler handles synchronization in a very simple -scenario in the following tutorials, you will learn how this looks like if -there are multiple connected Records involved which might not simply be +scenario. In the following tutorials, you will learn how this looks like if +there are multiple connected Records involved which may not simply be identified using the name. Also, we created the Record "manually" in this -example while the typical use case is to create it automatically from some file -or directory. How this is done will also be shown in the following chapters. +example while the typical use case is to create it automatically from some files +or directories. How this is done will also be shown in the following chapters.