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

Adjusted documentation of dbList command (Java) #1289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/java/manipulating-databases/db_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ related_commands:
# Command syntax #

{% apibody %}
r.dbList() → array
r.dbList() → DbList
Copy link
Contributor

Choose a reason for hiding this comment

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

The return type should be array. The types in this section refer to ReQL types, not Java types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will revert that.

{% endapibody %}

# Description #
Expand All @@ -22,5 +22,9 @@ List all database names in the cluster. The result is a list of strings.
__Example:__ List all databases.

```java
r.dbList().run(conn);
List<?> dbList = r.dbList().run(connection, ArrayList.class).single();

if (dbList != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with the Java driver, but I think dbList will never be null. Unless RethinkDB returns a nil result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this example, my IDE (IntelliJ IDEA) complained that forEach could produce a NullPointerException and suggested adding this check.

In the end I did something more like this:

final Result<?> result = r.dbList().run(connection, List.class);

try (result) {
    List<?> databaseList = (List<?>) result.single();

    if (databaseList != null) {
        databaseList.forEach(System.out::println);
    }
}

So, maybe that should be the example code? People can still leave out anything they do not want or rewrite it according to their needs. My thought was just to provide a hint on how to use it. And maybe a more elaborated example could also lower the hurdle for new developers, to see how they could use it.

But of course the provided example should show a somewhat recommended way. For me r.dbList().run(conn); was not really that sufficient or telling and this is what I thought could have helped me in the first place to get to use it more quickly. This is code I use because it is robust, but any suggestions are welcome.. I am referring to the new code above.

dbList.forEach(System.out::println);
}
```