-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Samples and documentation #4
Comments
Hey @fiLLLip , You're right... the driver right now a bit rough around the edges at the moment. Something like this would be a lot less hack-ish:
There is a PR that adds POJO in the Java driver (in our case POCO) support rethinkdb/rethinkdb#4889 for a less-hackish use case; but it hasn't been merged yet by Josh (the main author for the official Java driver). I'm kinda waiting to see what Josh does with this PR. Right now, Josh's efforts have been focused on getting 1000+ ReQL unit tests converted into Java to test the validity of the driver's operations. Give me a few hours and I'll see if I can make your use case a little less hackish based on PR rethinkdb/rethinkdb#4889. |
Hi @fiLLLip , I've added some support for inserting and retrieving POCOs without hackish dictionary MapObject style conventions.
Both, Brief Technical Details and Usage for POCOsThis driver will mount the POCO object into the AST as a All the standard Newtonsoft
Every time a POCO object needs to be converted, your custom converter function will be called. This is all still cutting edge, so the final implementation may change based on @deontologician 's review of rethinkdb/rethinkdb#4889 in the Java driver, but I'll document any breaking changes as they occur. RethinkDb.Driver 0.0.5-alpha2 with POCO support is now available on NuGet for DNX CoreCLR. I'll leave the this issue open until we have the final implementation for POJO support in the Java driver. I hope this helps and I apologize for the inconvenience; we're still developing the the drivers and getting the rough edges out. Rock on 🚀. |
Looks promising! I will give it a try 👍 And don't apologize for doing amazing work 😄 |
Thanks @fiLLLip let me know how it goes. Also, I was looking at I'll need a bit more time to experiment with the Java driver to determine if this is a bug that affects both drivers. |
I am coming back to work today, and I'm pretty close to having all the On Wed, Oct 21, 2015, 07:54 Brian Chavez [email protected] wrote:
|
@deontologician Yeah, I think the C#, we can run: A problem occurs when we try to use a
where the type parameter The driver reads the response from RethinkDB and detects a sequence is returned so
Problem is
The Java call to Even if we omit the explicit It almost seems like C# will need a Another alternative is to delay the item's type information after the Option A:
Option B:
Option C:
Not sure about all this. Need a bit more time to think about the issue and perform some experiments. 💭. |
How about a fourth option D:
Here getAll is of a new type called ReqlAstCursor (or something) and returns a I have not researched if this would break any other desired behavior, something I suspect it does, but it does not break the desire to be as close to the official lib as possible. A fifth option E, would be to always return as a Could any of this be useful? |
That would be very different from the api of the other drivers, generally it's nice to be able to get a response unwrapped if it doesn't need to be. Conceptually, all that needs to happen is the cursor has to store how to deserialize each element. In java that's using the |
Ah, very nice options D and E as well... Thanks @fiLLLip . Some thoughts on Option D... ReqlAst.cs
Also, we can't override Thanks for your suggestions. Keep them coming 👍 _Any and all_ ideas help explore this issue fully. |
Ah, @deontologician gave me another idea. If the Option F:
But I'm not sure this is good either since there is some useful information in Another Option G: |
Exploring Option G more in LinqPad yields a decent solution and allows us to still stay within the confines of the Java driver API regarding
If anyone doesn't have any objections, this might be the best way to go... thoughts? We'll just throw an exception if the RethinkDB response is a sequence and the user's return type something that was not a |
This won't work in Java since generic type arguments are not present at runtime. But I think you should do what's nice for C# rather than stick to restrictions on the Java driver |
@deontologician how would the Java driver work under this
Would the statement above be the correct usage with the Java driver (and when RethinkDB returns a sequence)? Option G here in the C# driver would maintain the same behavior. The quickest way out for us would be to have a dedicated |
I'm thinking something like Cursor<Foo> all = r.db(DbName).table(TableName).getAll("a").run(conn, Foo.class); Then we pass the extra param through to runQuery, and it hands it off to |
So, the meaning of |
I see. One last question: If the response type is atom from
It seems like the user would need to know if it's an atom or sequence response ahead of time in order to determine the correct Or would |
getAll always returns a cursor. Basically, yeah the shape of the returned results needs to be known by the user when writing the query. If you don't want a cursor you can modify the query like: // get an list of Foo instead of a cursor
List<Foo> x = ...getAll("a").coerceTo("ARRAY").run(conn, Foo.class);
// get just the first element
Foo x = ...getAll("a").nth(0).run(conn, Foo.class); |
AWSOME. Thanks! This info helps a lot! |
😢 it looks like the reflection tax of Option G isn't worth it.
I suppose if the Java driver expects the user to know the shape of the query results, I guess we could expect the user of the C# driver to call @deontologician , is there any way to know which terms always return sequences and which terms always return atoms? like |
Unfortunately, we can't do a good enough job. RethinkDB is designed around a dynamic type system, so it's hard to really get the type at compile time without seriously limiting the kinds of queries you can do. A (contrived) example would be something like: Object foo = r.table("foo").get("bar").coerceTo(r.table("baz").get("qux").getField("what_to_coerce_to")) The result type of this query depends on what data is actually in your database. The programmer will know the constraints on the system and know that it's going to work out, but we can't necessarily encode those constraints into the static types available in Java and C#. |
@bchavez To skip the need of reflection, but make the whole system a lot more complex, could we look into Option D? This means we have to map all functions that can return a |
Thanks @deontologician for your help and guidance. It's invaluable at this stage of development. I've spiked on Java's Erasure of Generic Types, it's very interesting and seems like it's a strong influence on the crux of the problem here in C# land. Feels like the C# compiler is imposing too much type safety to make this work nicely under one method Just now thought of a new option.... in following the spirit of RethinkDB's dynamic type system.... another option worth exploring would be to introduce the DLR into the C# driver and go fully Option H
With Option H, all bets are off... we'd be fully dynamic at this point and it would be up to the user to figure out how to use the return types. The driver may return whatever it finds from the response, Thoughts? Option H might upset the apple cart with C# devs, but it's truly following the rest of the RethinkDB driver ecosystem. |
Hey @fiLLLip , In thinking about Option D we'd need:
My gut feeling is also telling me Option D might limit (and add complexity) to the expressiveness of ReQL in some way... especially when queries get very complex with lambda Also, my fear with Option D is the more differences we accumulate between C# and Java, the harder updating this driver will be. @fiLLLip do you have any thoughts about going purely |
Interestingly ... with Option H it looks like we can get the best of both worlds. When we define the Anything
Expect atom
And last but not least... _magical_: Expect
💥 Compiles and WORKS! And, In fact, _performance wise_, we're all in the same order of magnitude:
Amazingly, explicitly declaring the return type up front is even faster than raw dynamic when we know up front the driver's return type. 2930ms! |
@bchavez That looks very promising 😄 Would it be possible to have both of the following in the API?
I know it would break following the official API, but for the performance thirsty it runs roughly in 1/3 of the time of the dynamic typed, and some may favor that. |
@fiLLLip absolutely! In fact, I think it's awesome we have a way to maintain behavior compatibility with Java's And for those that really want performance and know what they're doing, they can use the type-safe As long as we can be a strict super set of the Java driver's API and behavior I think we'll be in a really good position. Awesome. I'll take a stab at it tomorrow. Really tired 💤 , but happy we have a promising solution to this. |
👍 this is awesome. I'm envious of the dynamic options you guys have! |
Okay. We now have a new Since we're using
Nice. 👍 Additionally, we have the power of LINQ backing
Even more cool 👍 One word of warning though. I don't recommend using a Also, we now have a faster RethinkDb.Driver 0.0.5-alpha3 is now published for consumption. Let me know how it goes @fiLLLip :) |
I tested them now, with and without |
Freaking awesoooooooooooome! 👍 😃 Going to work more unit tests and catch up to the java driver unit tests. After a bit I'll revisit anonymous type |
Alrighty, we have some pretty good WIKI documentation going now. Also, I've documented all the extended C# language features that we offer beyond the Java driver to enhance ReQL syntax: I also pushed further with implicit override for native types:
Kind of. Amazing. 👍 |
Would love to see some documentation, maybe some samples on how to use the different endpoints.
I'm trying to use it like the official documentation states, but I get a lot of errors, and the way I manage to use some of it feels more like a hack than the right way to do it.
To get insert to work I had to do the following where
obj
is a custom class with properties:Putting the object directly resultet in an exception, same with the serialized string.
I have not yet managed to get
getAll
to function. If someone could lead me in the right direction, I could possibly write some documentation along the way while using it.The text was updated successfully, but these errors were encountered: