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.

image

This outputs the right result, by the way :-)

Print | posted on Tuesday, March 02, 2010 12:00 PM

Feedback


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 12:32 PM addys

curious: are you using a library for parsing the linq string into an expression tree, or did you cook up your own parser?


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 12:33 PM Ayende Rahien

addys,
I am doing some funky things there.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 12:52 PM Bruce Boughton

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?


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 12:59 PM Ayende Rahien

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


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 2:35 PM configurator

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?


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 2:42 PM Ayende Rahien

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


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 2:48 PM Darius Damalakas

I am really supprised to see that a call to db.AddView accepts some kind of string, which is not validated at compile time.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 3:09 PM Ayende Rahien

Darius,
You shouldn't, this is a client/server thing, you can't pass live isntances along the wire.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 3:31 PM Roy

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.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 3:47 PM Andrew Stewart

@Roy,

I'm hoping we can do this, I'm going to be working on something like that shortly.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 4:10 PM Ayende Rahien

Roy,
That is likely to be _very_ hard.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 4:29 PM Roy

Maybe then the parameters could be passed in as lambdas? So, something like:

db.AddView(@"var pagesByTitle = [snip] select new {0}", doc => doc.Title);


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 4:38 PM Roy

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.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 5:18 PM Ayende Rahien

Roy,
This isn't a query, this is building an index.
Those are different things


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 5:23 PM Roy

True, and I guess introducing refactorability using expressions is nice, but not if it comes at the cost of adding a lot of complexity.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 6:05 PM Chris

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.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 6:23 PM Jeff Handley

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


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 7:48 PM Dan Finch

Expression.ToString() returns the actual expression (sort of), that may be helpful.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 8:11 PM Ayende Rahien

Not in a way that allow you to recompile it, though


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 8:30 PM Rafal

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?


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/2/2010 8:42 PM Ayende Rahien

Rafal,
It is compiled and run on the server.
The results are JSON docs


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/3/2010 1:55 PM o_o

Expression Tree Serialization: http://code.msdn.microsoft.com/exprserialization


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/3/2010 3:12 PM Khalid Abuhakmeh

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.


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/3/2010 3:28 PM Ayende Rahien

I am aware of that,and the name was changed


Gravatar

# re: Rhino DivanDB – A full coding sample – Embedded 3/12/2010 6:16 PM Ryan Roberts

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.

Comments have been closed on this topic.