Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Add support for blob types in primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendura committed Sep 20, 2019
1 parent ef231ca commit 90179e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## v2.0.2 - 2019-06-28

### Fixed
- Fix blob types in primary keys not being comparable

## v2.0.1 - 2019-06-28

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gocassa

Gocassa is a high-level library on top of [gocql](https://github.com/gocql/gocql).

Current version: v2.0.0
Current version: v2.0.2

Compared to gocql it provides query building, adds data binding, and provides easy-to-use "recipe" tables for common query use-cases. Unlike [cqlc](https://github.com/relops/cqlc), it does not use code generation.

Expand Down
10 changes: 10 additions & 0 deletions relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ func convertToPrimitive(i interface{}) interface{} {
return v.UnixNano()
case time.Duration:
return v.Nanoseconds()
case []byte:
// This case works as strings in Go are simply defined as the following:
// "A string value is a (possibly empty) sequence of bytes" (from the go lang spec)
// and
// "Converting a slice of bytes to a string type yields a string whose successive bytes are the elements of the slice."
// Finally:
// "String values are comparable and ordered, lexically byte-wise."
// We mostly want this to allow comparisons of blob types in the primary key of a table,
// since []byte are not `==` comparable in go, but strings are
return string(v)
default:
return i
}
Expand Down
1 change: 1 addition & 0 deletions relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestAnyEquals(t *testing.T) {
{time.Minute * 2, makeInterfaceArray(time.Second * 120)},
{testTime1, makeInterfaceArray(testTime2)},
{1950, makeInterfaceArray(1950)},
{[]byte{0x00, 0xFF, 0x01, 0x99, 0xEA}, makeInterfaceArray("\x00\xFF\x01\x99\xEA")},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 90179e0

Please sign in to comment.