rethinkdb / rethinkdb-java

Official RethinkDB Java client
https://rethinkdb.com/api/java/
Apache License 2.0
21 stars 10 forks source link

Updated Documentation? #57

Closed moloch-- closed 3 years ago

moloch-- commented 3 years ago

Is your feature request related to a problem? Please describe.

The documentation on https://rethinkdb.com/api/java/ seems to be out of date with v2.4.1? None of the return types seem to be correct.

For example, https://rethinkdb.com/api/java/db_list says .dbList() returns an array but in practice seems to return a Result<Object>? The Result class also seems undocumented:

Result<Object> dbList = r.dbList().run(dbConn);

The documentation also says that .toJson should return a String https://rethinkdb.com/api/java/to_json_string/#wrapper --In practice this method also returns a seems to return a Result<Object>?

There doesn't seem to be any examples or documentation on how to handle a Result<Object> or covert it to the types the documentation says should be returned. I can tell the class does contain the data I'm looking for using %s but there doesn't seem to be any documented way to access that data.

srh commented 3 years ago

ReQL API documentation describes what data types are returned in the ReQL language.

https://rethinkdb.com/docs/data-types/

Every client driver has its own way of reading in/out ReQL queries, and Java's run command, I presume, has a return type of Result<Object> no matter what the ReQL expression is.

NotJustAnna commented 3 years ago

Result is one of your ways to handle data. It exposes all the bells and whistles for you to handle stuff such as sequences of objects.

Since the driver can't predict the return type of a given function, you gotta pass to it a optional class or a type reference for it to cast your objects.

You can use r.dbList().run(dbConn, Types.listOf(String.class)) to get a Result with a single List<String> inside. Or use runAtom(dbConn, Types.listOf(String.class)) utility class, which would be somewhat equivalent to the previous syntax.

moloch-- commented 3 years ago

Thanks guys I was able to figure it out by reading the Java driver source code, with some trial and error. However, it would be nice to have some of this information in the official documentation!