Skip to content
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

DOC-440 | Add interface examples for APIs and GUI (Concepts section) #648

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Simran-B
Copy link
Contributor

@Simran-B Simran-B commented Dec 4, 2024

Description

Add examples for all official drivers, cURL, and the web interface to the pages under Concepts > Data structure for common operations that were previously only described for arangosh.

The driver code examples must be reviewed and possibly adjusted to include some error handling.
Up for discussion: How much should the examples show? For example, should setting options like returnNew be covered or should the examples rather be kept as minimal as possible?

Preview: https://deploy-preview-648--docs-hugo.netlify.app/stable/concepts/data-structure/databases/#set-the-database-context ff.

  • Databases
  • Collections
  • Views
  • Documents
    • Computed Values
    • Schema Validation

Upstream PRs

  • 3.10:
  • 3.11:
  • 3.12: arangodb/enterprise:3.12.3
  • 3.13:

@Simran-B Simran-B self-assigned this Dec 4, 2024
Copy link
Contributor

Deploy Preview Available Via
https://deploy-preview-648--docs-hugo.netlify.app

@Simran-B
Copy link
Contributor Author

Simran-B commented Dec 4, 2024

/generate

@Simran-B
Copy link
Contributor Author

Simran-B commented Dec 9, 2024

/generate

@Simran-B Simran-B marked this pull request as ready for review December 17, 2024 21:12
Copy link
Member

@pluma4345 pluma4345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only checked the arangojs examples but they LGTM


{{< tab "Java" >}}
```java
ArangoCollection coll = db.collection("coll");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArangoCollection coll = db.collection("coll");
CollectionEntity coll = db.collection("coll").getInfo();

ArangoCollection coll = db.collection("coll");
```

See [`ArangoDB.collection()`](https://www.javadoc.io/doc/com.arangodb/arangodb-java-driver/latest/com/arangodb/ArangoDB.html#db%28java.lang.String%29)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See [`ArangoDB.collection()`](https://www.javadoc.io/doc/com.arangodb/arangodb-java-driver/latest/com/arangodb/ArangoDB.html#db%28java.lang.String%29)
See [`ArangoCollection.getInfo()`](https://www.javadoc.io/static/com.arangodb/arangodb-java-driver/latest/com/arangodb/ArangoCollection.html#getInfo())

{{< tab "Java" >}}
```java
CollectionPropertiesOptions options = new CollectionPropertiesOptions()
.waitForSync(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.waitForSync(true);
.waitForSync(true)
.replicationFactor(ReplicationFactor.of(3));

ArangoCollection coll = db.collection("coll");
CollectionPropertiesEntity props = coll.changeProperties(options);
```
{{< comment >}}TODO: setReplicationFactor not yet supported by Java driver{{< /comment >}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{< comment >}}TODO: setReplicationFactor not yet supported by Java driver{{< /comment >}}

Comment on lines +379 to +398
CollectionEntity coll = db.collection("coll");

// Single document
coll.insertDocument(new BaseDocument("the-document-key")
.addAttribute("name", "ArangoDB")
.addAttribute("tags", [ "graph", "database", "NoSQL" ])
.addAttribute("scalable", true)
.addAttribute("company", new Map<String, Object>()
.put("name", "ArangoDB Inc.")
.put("founded", 2015)
)
.addAttribute("name", "ArangoDB")
);

// Multiple documents
coll.insertDocuments([
new BaseDocument("one"),
new BaseDocument("two"),
new BaseDocument("three")
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CollectionEntity coll = db.collection("coll");
// Single document
coll.insertDocument(new BaseDocument("the-document-key")
.addAttribute("name", "ArangoDB")
.addAttribute("tags", [ "graph", "database", "NoSQL" ])
.addAttribute("scalable", true)
.addAttribute("company", new Map<String, Object>()
.put("name", "ArangoDB Inc.")
.put("founded", 2015)
)
.addAttribute("name", "ArangoDB")
);
// Multiple documents
coll.insertDocuments([
new BaseDocument("one"),
new BaseDocument("two"),
new BaseDocument("three")
]);
ArangoCollection coll = db.collection("coll");
// Single document
BaseDocument doc = new BaseDocument("the-document-key");
doc.addAttribute("name", "ArangoDB");
doc.addAttribute("tags", List.of("graph", "database", "NoSQL"));
doc.addAttribute("scalable", true);
doc.addAttribute("company", Map.of(
"name", "ArangoDB Inc.",
"founded", 2015
));
doc.addAttribute("name", "ArangoDB");
coll.insertDocument(doc);
// Multiple documents
coll.insertDocuments(List.of(
new BaseDocument("one"),
new BaseDocument("two"),
new BaseDocument("three")
));

Comment on lines +991 to +997
// Single document
DocumentDeleteEntity<Void> result = coll.deleteDocument("the-document-key");

// Multiple documents
for (MultiDocumentEntity<DocumentDeleteEntity<Void>> result : coll.deleteDocuments(["one", "two", "three"])) {
// ...
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Single document
DocumentDeleteEntity<Void> result = coll.deleteDocument("the-document-key");
// Multiple documents
for (MultiDocumentEntity<DocumentDeleteEntity<Void>> result : coll.deleteDocuments(["one", "two", "three"])) {
// ...
}
// Single document
DocumentDeleteEntity<Void> result = coll.deleteDocument("the-document-key");
// Multiple documents
MultiDocumentEntity<DocumentDeleteEntity<Void>> multipleResult =
coll.deleteDocuments(List.of("one", "two", "three"));

Comment on lines +184 to +208
String schemaRule = (
"{" +
" \"type\": \"object\"," +
" \"properties\": {" +
" \"nums\": {" +
" \"type\": \"array\"," +
" \"items\": {" +
" \"type\": \"number\"," +
" \"minimum\": 6" +
" }" +
" }" +
" }," +
" \"additionalProperties\": { \"type\": \"string\" }," +
" \"required\": [\"nums\"]" +
"}");

CollectionPropertiesOptions props = new CollectionPropertiesOptions()
.schema(new CollectionSchema()
.setRule(schemaRule)
.setLevel(CollectionSchema.Level.MODERATE)
.setMessage("The document does not contain an array of numbers in attribute \"nums\", one of the numbers is greater than 6, or another top-level attribute is not a string.")
);

ArangoCollection coll = db.collection("coll");
CollectionPropertiesEntity = coll.changeProperties(props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String schemaRule = (
"{" +
" \"type\": \"object\"," +
" \"properties\": {" +
" \"nums\": {" +
" \"type\": \"array\"," +
" \"items\": {" +
" \"type\": \"number\"," +
" \"minimum\": 6" +
" }" +
" }" +
" }," +
" \"additionalProperties\": { \"type\": \"string\" }," +
" \"required\": [\"nums\"]" +
"}");
CollectionPropertiesOptions props = new CollectionPropertiesOptions()
.schema(new CollectionSchema()
.setRule(schemaRule)
.setLevel(CollectionSchema.Level.MODERATE)
.setMessage("The document does not contain an array of numbers in attribute \"nums\", one of the numbers is greater than 6, or another top-level attribute is not a string.")
);
ArangoCollection coll = db.collection("coll");
CollectionPropertiesEntity = coll.changeProperties(props);
String schemaRule = (
"{" +
" \"type\": \"object\"," +
" \"properties\": {" +
" \"nums\": {" +
" \"type\": \"array\"," +
" \"items\": {" +
" \"type\": \"number\"," +
" \"minimum\": 6" +
" }" +
" }" +
" }," +
" \"additionalProperties\": { \"type\": \"string\" }," +
" \"required\": [\"nums\"]" +
"}");
CollectionPropertiesOptions props = new CollectionPropertiesOptions()
.schema(new CollectionSchema()
.setRule(schemaRule)
.setLevel(CollectionSchema.Level.MODERATE)
.setMessage("The document does not contain an array of numbers in attribute \"nums\", one of the numbers is greater than 6, or another top-level attribute is not a string.")
);
ArangoCollection coll = db.collection("coll");
CollectionPropertiesEntity changedProperties = coll.changeProperties(props);

Comment on lines +284 to +287
ArangoView view = db.view("myView");

ArangoSearch viewSearch = db.arangoSearch("myArangoSearchView");
SearchAlias viewAlias = db.searchAlias("mySearchAliasView");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArangoView view = db.view("myView");
ArangoSearch viewSearch = db.arangoSearch("myArangoSearchView");
SearchAlias viewAlias = db.searchAlias("mySearchAliasView");
ViewEntity view = db.view("myView").getInfo();
ViewEntity viewSearch = db.arangoSearch("myArangoSearchView").getInfo();
ViewEntity viewAlias = db.searchAlias("mySearchAliasView").getInfo();

Comment on lines +381 to +385
ArangoSearch viewSearch = db.view("myArangoSearchView");
ArangoSearchPropertiesEntity viewSearch.getProperties();

SearchAlias viewAlias = db.view("mySearchAliasView");
SearchAliasPropertiesEntity viewAlias.getProperties();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArangoSearch viewSearch = db.view("myArangoSearchView");
ArangoSearchPropertiesEntity viewSearch.getProperties();
SearchAlias viewAlias = db.view("mySearchAliasView");
SearchAliasPropertiesEntity viewAlias.getProperties();
ArangoSearch viewSearch = db.arangoSearch("myArangoSearchView");
ArangoSearchPropertiesEntity viewSearchProperties = viewSearch.getProperties();
SearchAlias viewAlias = db.searchAlias("mySearchAliasView");
SearchAliasPropertiesEntity viewAliasProperties = viewAlias.getProperties();

Comment on lines +513 to +526
ArangoSearchPropertiesOptions options = new ArangoSearchPropertiesOptions();
options.cleanupIntervalStep(12L);
options.link(CollectionLink.on("coll")
.includeAllFields(true)
);

ArangoSearch viewSearch = db.view("myArangoSearchView");
ArangoSearchPropertiesEntity viewSearch.updateProperties(options);

SearchAlias viewAlias = db.view("mySearchAliasView");
SearchAliasPropertiesEntity viewAlias.updateProperties(
new SearchAliasPropertiesOptions()
.indexes(new SearchAliasIndex("coll", "idx"))
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArangoSearchPropertiesOptions options = new ArangoSearchPropertiesOptions();
options.cleanupIntervalStep(12L);
options.link(CollectionLink.on("coll")
.includeAllFields(true)
);
ArangoSearch viewSearch = db.view("myArangoSearchView");
ArangoSearchPropertiesEntity viewSearch.updateProperties(options);
SearchAlias viewAlias = db.view("mySearchAliasView");
SearchAliasPropertiesEntity viewAlias.updateProperties(
new SearchAliasPropertiesOptions()
.indexes(new SearchAliasIndex("coll", "idx"))
);
ArangoSearch viewSearch = db.arangoSearch("myArangoSearchView");
ArangoSearchPropertiesEntity viewSearchProperties = viewSearch.updateProperties(
new ArangoSearchPropertiesOptions()
.cleanupIntervalStep(12L)
.link(CollectionLink.on("coll")
.includeAllFields(true)
)
);
SearchAlias viewAlias = db.searchAlias("mySearchAliasView");
SearchAliasPropertiesEntity viewAliasProperties = viewAlias.updateProperties(
new SearchAliasPropertiesOptions()
.indexes(new SearchAliasIndex("coll", "idx"))
);

@Simran-B Simran-B changed the title DOC-440 | Add interface examples for APIs and GUI DOC-440 | Add interface examples for APIs and GUI (Concepts section) Jan 20, 2025
.name("title")
.expression("RETURN \"TBA\"")
.overwrite(false)
.computeOn(ComputeOn.insert, ComputeOn.update, ComputeOn.replace)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rashtao I added the examples for Computed Values now too.
Is it necessary to use ComputedValue.ComputeOn.* here to refer to the elements of the enum?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.computeOn(ComputeOn.insert, ComputeOn.update, ComputeOn.replace)
.computeOn(ComputedValue.ComputeOn.insert, ComputedValue.ComputeOn.update, ComputedValue.ComputeOn.replace)

Copy link
Member

@aMahanna aMahanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python examples look good,2 small adjustments:

```py
coll = db.collection("coll")
props = coll.configure(
computed_values: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
computed_values: [
computed_values=[


{{< tab "Python" >}}
```py
coll = db.get_collection("coll")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
coll = db.get_collection("coll")
coll = db.collection("coll")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants