Permalink
Browse files

fix Reader.Columns, update docs

  • Loading branch information...
1 parent 8e90a2f commit 30fcf86f8d81f6e7550e72a6c980dcb3c40e0c7c @carloscm committed May 15, 2012
Showing with 18 additions and 3 deletions.
  1. +2 −3 README.md
  2. +1 −0 src/gossie/reader.go
  3. +15 −0 src/gossie/readerwriter_test.go
View
@@ -109,13 +109,13 @@ The tags `mapping`, `cf`, `key`, `cols` and `value` can be used in any field in
### Query and Result
-Query allows to look up mapped structs over Cassandra rows. Pass to `Query.Get` the row key, followed by zero or more composite keys, to get a Result. `Result.Next` reads a single struct from the Cassandra row, and returns `Done` when no more structs can be read.
+Query allows to look up mapped structs over Cassandra rows. Pass to `Query.Components` one or more component values that all the result objects must have in common. You can also leave out the last component and use `Query.Between` to slice a range of values for it. Call `Query.Get` with the row key to get a Result. `Result.Next` reads a single struct from the Cassandra row, and returns `Done` when no more structs can be read.
```Go
query := pool.Query(TweetMapping)
// a single tweet, since we pass the row key and all possible composite values
-result, err := query.Get("username", 10000000000004)
+result, err := query.Components(10000000000004).Get("username")
// all tweets for a given user
result, err := query.Get("username")
@@ -135,7 +135,6 @@ for {
- Error passing overhaul, to be based on typing
- Query: secondary index read with buffering
-- Query: multiget reads with buffering
- A higher level abstraction for writes (Batch interface)
- High level mapping for Go slices
- High level mapping for Go maps
View
@@ -162,6 +162,7 @@ func (r *reader) Slice(s *Slice) Reader {
}
func (r *reader) Columns(c [][]byte) Reader {
+ r.columns = make([][]byte, len(c))
copy(r.columns, c)
r.setColumns = true
return r
@@ -64,6 +64,15 @@ func buildAllTypesTestRow(key string) *testRow {
}
}
+func buildAllTypesTestRowPartial(key string) *testRow {
+ return &testRow{
+ key: key, keyType: BytesType, columns: []testColumn{
+ testColumn{"colBooleanType", AsciiType, true, BooleanType},
+ testColumn{"colUTF8Type", AsciiType, "leña al fuego", UTF8Type},
+ },
+ }
+}
+
func buildAllTypesAfterDeletesTestRow(key string) *testRow {
u, _ := ParseUUID("00112233-4455-6677-8899-aabbccddeeff")
return &testRow{
@@ -228,6 +237,12 @@ func TestWriterAndReader(t *testing.T) {
}
checkRow(t, buildAllTypesTestRow("row2"), row)
+ row, err = cp.Reader().Cf("AllTypes").Columns([][]byte{[]byte("colBooleanType"), []byte("colUTF8Type")}).Get([]byte("row2"))
+ if err != nil {
+ t.Error("Error running query: ", err)
+ }
+ checkRow(t, buildAllTypesTestRowPartial("row2"), row)
+
count, err = cp.Reader().Cf("AllTypes").Count([]byte("row2"))
if err != nil {
t.Error("Error running query: ", err)

0 comments on commit 30fcf86

Please sign in to comment.