-
Notifications
You must be signed in to change notification settings - Fork 7
Add Fluent #23
base: master
Are you sure you want to change the base?
Add Fluent #23
Conversation
|
Hi! I saw that you were busy adding a fluent dialect to CqlSharp. First of all, thanks for the interest en effort! Let me share a few thoughts: First, I'm not sure yet how to deal with these kind of pull requests. There are basically two options:
To be honest, I tend to go for the second option as it splits the core ADO.NET driver from higher level constructs. For example, what if someone adds an Rx layer? Or what about my own Linq efforts? Merging all these into the core repository seems not wise to me. Splitting it makes that each package will get its own release life-cycle. Furthermore it allows for more control on who contributes on what parts. For example we can set up a new repository CqlSharp.Fluent where we are both authors. I'll make the necessary adjustments in the core layer to accommodate the features you need (e.g. make ObjectAccessor public, and add the required properties). Second, I wasn't aware that Fakes are a VS Ultimate and Premium only feature. I think this is what prevents you from loading/running the test project. Replacing the Fakes with something else is regrettably not that easy, as I'm faking Time as well as the underlying connections. Changing this is substantial effort (probably requiring the introduction of some factory/dependency injection pattern to create the connection instances). I'll have a look into it. Note that I'm not in favor of using multiple unit-test frameworks in the same solution/repository... Third, and finally more on content level is that I do not completely understand your thoughts on the API you provide. Why do you need methods like: Define.CreateTable("blog_comment")
.WithComment("This is a test");
.AddPartitionKey("blog_id", CqlType.Uuid)
.AddClusteringKey("comment_id", CqlType.Timeuuid, Order.Descending)
.AddColumn("name", CqlType.Varchar)
.AddColumn("comment", CqlType.Varchar)
.AddIndexForColumn("name")
.Execute();Note the changes:
Again, I'm not sure why you would need the Finished* methods. Is there something I'm missing? All-in-all a very good start, and thanks for putting your effort into this! |
|
Thanks for the comments. The primary reason I put it as a core part was because of accessibility of ObjectAccessor and properties. If that's changed then it makes sense to keep it separate (and gets around the unit test issue). The point of the Finished* is to provide logical segmentation so that there are not overwhelming choices. For instance, in the create table, there would be probably 30 different actions that could be taken if they were all implemented in one class, so it has been segmented to have so adding partitions, clustering and columns are separate. The Finished part is the way to say that segment is complete. I have seen a few Fluent APIs do a similar thing so that's where I got the idea. Thoughts? It looks like UUID and string are the only types that have options on storage? Perhaps I will add a special AddColumnAscii and AddColumnTimeGuid then because I'd like to keep it in CLR types as much as possible. I haven't looked at the serialization/deserialization too much; does CqlSharp automatically handle Ascii and TimeGuid conversions? How would the execution work? Right now the fluent is only to build up a prepared statement so the arguments still need to be set and attached to a command. |
|
Oh, instead of .Finished it could be something like .AddPartitionKeys( or such |
|
Hi, The second option you mentioned seems a lot more logical (and Fluent) to me. I will create a new repository today or tomorrow, and add you as contributor/manager or whatever role Github provides... Will let you know when it's there. In addition, I'll incorporate the required changes in CqlSharp to enable the Fluent library. In the mean time I'll have to figure out how to work with unpublished/unstable/development NuGet packages... Perhaps you have an idea? Or must I publish the changes first before the Fluent development can continue? |
|
Hey, I am ready to work on this again. did you figure out what to do re: the changes? |
|
I've created a new CqlSharp.Fluent repository and made you one of the members. Currently working on the changes. Hope to finish that in the coming day(s). The challenge is to make it generic for all kinds of extensions, such as your Fluent as well as my own Linq extension. As a result, I'm rewriting the ObjectAccessor to expose all column information in a uniform way. This will make it different than what you propose, but will have all the information you need. |
|
Just pushed the latest version to NuGet (0.31.0). This should contain the changes you need... |
|
Sweet, I'll have a look On Mon, Jan 20, 2014 at 1:54 PM, reuzel notifications@github.com wrote:
|
Hello, I've created a fluent API for CqlSharp for a few reasons.
I really like the prepare functionality and object binding, but found the actual commands to be "magic strings" that were too complicated for error free behavior.
I wanted to marry the attribute tags defined on a class (column name, partition key, etc) with a command, so that there was as seamless binding as possible; similar to mongo db drivers, etc.
Cql has some quirks that I felt could be made clearer through a fluent syntax. For example, the primary key is the partition key(s) + clustering key(s) but the syntax for compound partition keys is not particularly obvious.
I'm not totally sure that this is ready to merge but thought it was good enough for you to take a look and give comments.
Also I couldn't get the test project to load (don't have a good enough Visual Studio) so made a separate test library using xunit.
Let me know if you have any thoughts! Thanks.
An example query that I've tested is:
Alternatively you could have the following class definition and then generate the fluent automatically with
using the existing prepare with object code.