Rhino DivanDB – A full coding sample – Embedded
Rhino Divan DB is going to come in at least two forms, embedded, and remote. The following is a full example of starting DivanDB, defining a view, adding some documents and then querying the database.
Note that here we want to ensure that we get the most up to date result, so we refuse to accept a potentially stale query.
This outputs the right result, by the way :-)
Comments
curious: are you using a library for parsing the linq string into an expression tree, or did you cook up your own parser?
addys,
I am doing some funky things there.
Out of interest: why do you pass the views as strings instead of expression trees? Also, why not provide an overload to Query that does the do... while for you to ensure non stale results? Is this just an early preview of the API?
Bruce,
Try passing expression tree on the wire, and making sense of them on the other side.
And Query doesn't know how long to wait.
Busy waiting is NOT something that I want to do, talk about DoS yourself
So why did you busy wait here, on your first full example?
Do you have an idea how to actually wait for queries to be not-stale without busy waiting?
Configurator,
This is a unit test, and I know that I'll wait for ~ms or so, because I know the entire context.
As for waiting with scaling, you put waits, or if you accept potentially stale results
I am really supprised to see that a call to db.AddView accepts some kind of string, which is not validated at compile time.
Darius,
You shouldn't, this is a client/server thing, you can't pass live isntances along the wire.
But wouldn't it still be possible to create the expression on the client side, and before it goes on the wire have it converted to something serializable? That way, the client code still has the benefit of compile-time checking.
@Roy,
I'm hoping we can do this, I'm going to be working on something like that shortly.
Roy,
That is likely to be very hard.
Maybe then the parameters could be passed in as lambdas? So, something like:
db.AddView <doc(@"var pagesByTitle = [snip] select new {0}", doc => doc.Title);
Oh, some tags got clipped, but AddView should be a generic of type "Doc". But that's assuming you even want to have domain objects defined in that way.
Meh, that seems like a fiddly solution anyway.
Roy,
This isn't a query, this is building an index.
Those are different things
True, and I guess introducing refactorability using expressions is nice, but not if it comes at the cost of adding a lot of complexity.
Looks good - can't wait to play with it. Now I see the programming interface, I can almost see how it works.
Regarding all the moaning about stale results and blocking; It is NICE that consistency is OPTIONALLY enforceable (by waiting). For the stuff I do, it is useful to make that distinction.
Ayende,
You might want to look at DynamicQueryable. Scott Hanselman and Marcin Dobosz have blogged about it recently. I have used a flavor of DynamicQuerable to serialize and deserialize LINQ expressions very well.
Here's Hanselman's recent post:
www.hanselman.com/.../...INQExpressionsEasier.aspx
And Marcin's:
blogs.msdn.com/.../...-DynamicQueryable_2E00_.aspx
And ScottGu's post from long ago:
weblogs.asp.net/.../...-dynamic-query-library.aspx
At the very least, DynamicQueryable could give you a good starting point for the (de)serialization of the expression - that's what it did for me.
-Jeff
Expression.ToString() returns the actual expression (sort of), that may be helpful.
Not in a way that allow you to recompile it, though
But why use LINQ syntax if you put it in a string anyway? Is it C# that is compiled and executed server side, or some expression language that only mimics C#? And what happens to projection objects produced by the query - are they persisted somehow, or just used to stuff Lucene Document with data fields?
One more question: what are the results returned by query? Full documents or just the 'title' column? How are they returned - as strings?
Rafal,
It is compiled and run on the server.
The results are JSON docs
Expression Tree Serialization: http://code.msdn.microsoft.com/exprserialization
I was actually curious as to why you called it DivanDB and then I did a google search on Divan. That's pretty funny, it's a play off of CouchDB. There is a library that allows you to do linq queries over WCF http://interlinq.codeplex.com/ check it out it might give you some ideas.
I am aware of that,and the name was changed
Wasn't there talk on the remotion / relinq project of using javascript as an intermediate format for sending linq expressions over the wire?
Can't see anything in the codebase though and the oloh page has changed since I last remember it. It's a shame as I would kill puppies for a linq expression to js translator.
Comment preview