mfenniak / rethinkdb-net

A C# / .NET client driver for RethinkDB.
Other
247 stars 37 forks source link

Implemented Compound Indexes #235

Closed mfenniak closed 8 years ago

mfenniak commented 8 years ago

Updated @nkreipke's PR #229 to include integration tests.

mfenniak commented 8 years ago

@nkreipke, just want to let you know that I made an API change in this PR while writing tests for it. I liked the direction you took it, but I didn't like the disconnect between the index definition and then accessing any data via the index; it was possible to be type-safe on either side, but the types weren't related. So, I changed the API to use the IndexDefine method, like so:

var index = testTable.IndexDefine("Compound", a => a.Name, a => a.SomeNumber);
// index is now an object that knows it is a compound index of type <String, Double>
connection.Run(index.IndexCreate());

// index.Key() method is a type-safe method to create a compound index key object
var key = index.Key("Jim Bob", 100);

// index.GetAll() is an existing index extension method that ensures the key being
// accessed matches the type of the index; in this case it must be a
// CompoundKey<String, Double>; similar extension methods exist
// for Between, and other operations that can use secondary indexes
connection.Run(index.GetAll(key))
nkreipke commented 8 years ago

I like this, it looks far better than what I've come up with. Thanks!