From 14bc2eba3b2999f569070c66bbc838cd645179ee Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 19:19:51 -0700 Subject: [PATCH 01/39] [dep] Init glide https://github.com/pingginp/cqlc/issues/1 --- .gitignore | 3 +++ glide.lock | 34 ++++++++++++++++++++++++++++++++++ glide.yaml | 15 +++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 glide.lock create mode 100644 glide.yaml diff --git a/.gitignore b/.gitignore index 33d9741..8087edc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ output/ test/.fixtures/collections/input.go test/collections.cql + +.idea +vendor \ No newline at end of file diff --git a/glide.lock b/glide.lock new file mode 100644 index 0000000..db7e1be --- /dev/null +++ b/glide.lock @@ -0,0 +1,34 @@ +hash: 7068a4d17fe81a559838fd967b24bbe472d33bce86ca270c19176cd5ef2ade0f +updated: 2018-09-14T19:15:26.835783-07:00 +imports: +- name: github.com/cihub/seelog + version: d2c6e5aa9fbfdd1c624e140287063c7730654115 +- name: github.com/gocql/gocql + version: 045d8d6abc70b5bd02bb18b8fdb05ee54d8c87aa + subpackages: + - internal/lru + - internal/murmur + - internal/streams +- name: github.com/golang/snappy + version: 2e65f85255dbc3072edf28d6b5b8efc472979f5a +- name: github.com/hailocab/go-hostpool + version: e80d13ce29ede4452c43dea11e79b9bc8a15b478 +- name: github.com/jessevdk/go-flags + version: c6ca198ec95c841fdb89fc0de7496fed11ab854e +- name: gopkg.in/inf.v0 + version: d2d2541c53f18d2a059457998ce2876cc8e67cbf +testImports: +- name: github.com/davecgh/go-spew + version: d8f796af33cc11cb798c1aaeb27a4ebc5099927d + subpackages: + - spew +- name: github.com/pmezard/go-difflib + version: 792786c7400a136282c1664665ae0a8db921c6c2 + subpackages: + - difflib +- name: github.com/stretchr/testify + version: f35b8ab0b5a2cef36673838d662e249dd9c94686 + subpackages: + - assert + - require + - suite diff --git a/glide.yaml b/glide.yaml new file mode 100644 index 0000000..ac55af4 --- /dev/null +++ b/glide.yaml @@ -0,0 +1,15 @@ +package: github.com/relops/cqlc +import: +- package: github.com/cihub/seelog + version: ^2.6.0 +- package: github.com/gocql/gocql +- package: github.com/jessevdk/go-flags + version: ^1.4.0 +- package: gopkg.in/inf.v0 + version: ^0.9.1 +testImport: +- package: github.com/stretchr/testify + version: ^1.2.2 + subpackages: + - assert + - suite From 490ad342fde9b80d4303463ee70cc01e7ad1c245 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 19:29:48 -0700 Subject: [PATCH 02/39] [dep] Fix gocql ColumnClusterKey etc. - upstream https://github.com/relops/cqlc/issues/36 --- Makefile | 8 + README.md | 9 +- build/.gitignore | 1 + cqlc/columns.go | 825 ++++++-------------------------- generator/binding_tmpl.go | 7 +- generator/template.go | 12 +- test/.fixtures/sensor/sensor.go | 4 +- 7 files changed, 184 insertions(+), 682 deletions(-) create mode 100644 build/.gitignore diff --git a/Makefile b/Makefile index 0610092..81e24fd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,14 @@ CCM_NODE ?= node1 CQLSH_CMD ?= ccm $(CCM_NODE) cqlsh +.PHONY: build +build: + go build -o build/cqlc . + +.PHONY: install +install: + go install . + test/collections.cql: test/tmpl/schema.tmpl test/schema_generator.go cd test; go run schema_generator.go diff --git a/README.md b/README.md index e0e7e74..bb3b444 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -cqlc ----- +# cqlc [![Join the chat at https://gitter.im/relops/cqlc](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/relops/cqlc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -10,4 +9,10 @@ cqlc For more details please visit [http://relops.com/cqlc][cqlc] +## Usage + +````bash +make build +```` + [cqlc]: http://relops.com/cqlc diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..a581644 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1 @@ +cqlc \ No newline at end of file diff --git a/cqlc/columns.go b/cqlc/columns.go index d9092c1..f7a5f77 100755 --- a/cqlc/columns.go +++ b/cqlc/columns.go @@ -4,13 +4,11 @@ package cqlc import ( "github.com/gocql/gocql" - "time" - "math/big" "gopkg.in/inf.v0" + "math/big" + "time" ) - - type StringColumn interface { Column To(value *string) ColumnBinding @@ -45,8 +43,6 @@ type LastClusteredStringColumn interface { In(value ...string) Condition } - - type Int32Column interface { Column To(value *int32) ColumnBinding @@ -81,8 +77,6 @@ type LastClusteredInt32Column interface { In(value ...int32) Condition } - - type Int64Column interface { Column To(value *int64) ColumnBinding @@ -117,8 +111,6 @@ type LastClusteredInt64Column interface { In(value ...int64) Condition } - - type Float32Column interface { Column To(value *float32) ColumnBinding @@ -153,8 +145,6 @@ type LastClusteredFloat32Column interface { In(value ...float32) Condition } - - type Float64Column interface { Column To(value *float64) ColumnBinding @@ -189,8 +179,6 @@ type LastClusteredFloat64Column interface { In(value ...float64) Condition } - - type TimestampColumn interface { Column To(value *time.Time) ColumnBinding @@ -225,8 +213,6 @@ type LastClusteredTimestampColumn interface { In(value ...time.Time) Condition } - - type TimeUUIDColumn interface { Column To(value *gocql.UUID) ColumnBinding @@ -261,8 +247,6 @@ type LastClusteredTimeUUIDColumn interface { In(value ...gocql.UUID) Condition } - - type UUIDColumn interface { Column To(value *gocql.UUID) ColumnBinding @@ -297,8 +281,6 @@ type LastClusteredUUIDColumn interface { In(value ...gocql.UUID) Condition } - - type BooleanColumn interface { Column To(value *bool) ColumnBinding @@ -333,8 +315,6 @@ type LastClusteredBooleanColumn interface { In(value ...bool) Condition } - - type DecimalColumn interface { Column To(value **inf.Dec) ColumnBinding @@ -369,8 +349,6 @@ type LastClusteredDecimalColumn interface { In(value ...*inf.Dec) Condition } - - type VarintColumn interface { Column To(value **big.Int) ColumnBinding @@ -405,8 +383,6 @@ type LastClusteredVarintColumn interface { In(value ...*big.Int) Condition } - - type BytesColumn interface { Column To(value *[]byte) ColumnBinding @@ -441,9 +417,6 @@ type LastClusteredBytesColumn interface { In(value ...[]byte) Condition } - - - type StringSliceColumn interface { ListColumn To(value *[]string) ColumnBinding @@ -504,2032 +477,1549 @@ type BytesSliceColumn interface { To(value *[][]byte) ColumnBinding } - - - - - - - type StringStringMapColumn interface { Column } - type StringInt32MapColumn interface { Column } - type StringInt64MapColumn interface { Column } - type StringFloat32MapColumn interface { Column } - type StringFloat64MapColumn interface { Column } - type StringTimestampMapColumn interface { Column } - type StringTimeUUIDMapColumn interface { Column } - type StringUUIDMapColumn interface { Column } - type StringBooleanMapColumn interface { Column } - type StringDecimalMapColumn interface { Column } - type StringVarintMapColumn interface { Column } - type StringBytesMapColumn interface { Column } - - type Int32StringMapColumn interface { Column } - type Int32Int32MapColumn interface { Column } - type Int32Int64MapColumn interface { Column } - type Int32Float32MapColumn interface { Column } - type Int32Float64MapColumn interface { Column } - type Int32TimestampMapColumn interface { Column } - type Int32TimeUUIDMapColumn interface { Column } - type Int32UUIDMapColumn interface { Column } - type Int32BooleanMapColumn interface { Column } - type Int32DecimalMapColumn interface { Column } - type Int32VarintMapColumn interface { Column } - type Int32BytesMapColumn interface { Column } - - type Int64StringMapColumn interface { Column } - type Int64Int32MapColumn interface { Column } - type Int64Int64MapColumn interface { Column } - type Int64Float32MapColumn interface { Column } - type Int64Float64MapColumn interface { Column } - type Int64TimestampMapColumn interface { Column } - type Int64TimeUUIDMapColumn interface { Column } - type Int64UUIDMapColumn interface { Column } - type Int64BooleanMapColumn interface { Column } - type Int64DecimalMapColumn interface { Column } - type Int64VarintMapColumn interface { Column } - type Int64BytesMapColumn interface { Column } - - type Float32StringMapColumn interface { Column } - type Float32Int32MapColumn interface { Column } - type Float32Int64MapColumn interface { Column } - type Float32Float32MapColumn interface { Column } - type Float32Float64MapColumn interface { Column } - type Float32TimestampMapColumn interface { Column } - type Float32TimeUUIDMapColumn interface { Column } - type Float32UUIDMapColumn interface { Column } - type Float32BooleanMapColumn interface { Column } - type Float32DecimalMapColumn interface { Column } - type Float32VarintMapColumn interface { Column } - type Float32BytesMapColumn interface { Column } - - type Float64StringMapColumn interface { Column } - type Float64Int32MapColumn interface { Column } - type Float64Int64MapColumn interface { Column } - type Float64Float32MapColumn interface { Column } - type Float64Float64MapColumn interface { Column } - type Float64TimestampMapColumn interface { Column } - type Float64TimeUUIDMapColumn interface { Column } - type Float64UUIDMapColumn interface { Column } - type Float64BooleanMapColumn interface { Column } - type Float64DecimalMapColumn interface { Column } - type Float64VarintMapColumn interface { Column } - type Float64BytesMapColumn interface { Column } - - type TimestampStringMapColumn interface { Column } - type TimestampInt32MapColumn interface { Column } - type TimestampInt64MapColumn interface { Column } - type TimestampFloat32MapColumn interface { Column } - type TimestampFloat64MapColumn interface { Column } - type TimestampTimestampMapColumn interface { Column } - type TimestampTimeUUIDMapColumn interface { Column } - type TimestampUUIDMapColumn interface { Column } - type TimestampBooleanMapColumn interface { Column } - type TimestampDecimalMapColumn interface { Column } - type TimestampVarintMapColumn interface { Column } - type TimestampBytesMapColumn interface { Column } - - type TimeUUIDStringMapColumn interface { Column } - type TimeUUIDInt32MapColumn interface { Column } - type TimeUUIDInt64MapColumn interface { Column } - type TimeUUIDFloat32MapColumn interface { Column } - type TimeUUIDFloat64MapColumn interface { Column } - type TimeUUIDTimestampMapColumn interface { Column } - type TimeUUIDTimeUUIDMapColumn interface { Column } - type TimeUUIDUUIDMapColumn interface { Column } - type TimeUUIDBooleanMapColumn interface { Column } - type TimeUUIDDecimalMapColumn interface { Column } - type TimeUUIDVarintMapColumn interface { Column } - type TimeUUIDBytesMapColumn interface { Column } - - type UUIDStringMapColumn interface { Column } - type UUIDInt32MapColumn interface { Column } - type UUIDInt64MapColumn interface { Column } - type UUIDFloat32MapColumn interface { Column } - type UUIDFloat64MapColumn interface { Column } - type UUIDTimestampMapColumn interface { Column } - type UUIDTimeUUIDMapColumn interface { Column } - type UUIDUUIDMapColumn interface { Column } - type UUIDBooleanMapColumn interface { Column } - type UUIDDecimalMapColumn interface { Column } - type UUIDVarintMapColumn interface { Column } - type UUIDBytesMapColumn interface { Column } - - type BooleanStringMapColumn interface { Column } - type BooleanInt32MapColumn interface { Column } - type BooleanInt64MapColumn interface { Column } - type BooleanFloat32MapColumn interface { Column } - type BooleanFloat64MapColumn interface { Column } - type BooleanTimestampMapColumn interface { Column } - type BooleanTimeUUIDMapColumn interface { Column } - type BooleanUUIDMapColumn interface { Column } - type BooleanBooleanMapColumn interface { Column } - type BooleanDecimalMapColumn interface { Column } - type BooleanVarintMapColumn interface { Column } - type BooleanBytesMapColumn interface { Column } - - type DecimalStringMapColumn interface { Column } - type DecimalInt32MapColumn interface { Column } - type DecimalInt64MapColumn interface { Column } - type DecimalFloat32MapColumn interface { Column } - type DecimalFloat64MapColumn interface { Column } - type DecimalTimestampMapColumn interface { Column } - type DecimalTimeUUIDMapColumn interface { Column } - type DecimalUUIDMapColumn interface { Column } - type DecimalBooleanMapColumn interface { Column } - type DecimalDecimalMapColumn interface { Column } - type DecimalVarintMapColumn interface { Column } - type DecimalBytesMapColumn interface { Column } - - type VarintStringMapColumn interface { Column } - type VarintInt32MapColumn interface { Column } - type VarintInt64MapColumn interface { Column } - type VarintFloat32MapColumn interface { Column } - type VarintFloat64MapColumn interface { Column } - type VarintTimestampMapColumn interface { Column } - type VarintTimeUUIDMapColumn interface { Column } - type VarintUUIDMapColumn interface { Column } - type VarintBooleanMapColumn interface { Column } - type VarintDecimalMapColumn interface { Column } - type VarintVarintMapColumn interface { Column } - type VarintBytesMapColumn interface { Column } - - - - - - - - - - - - - - type SetValueStep interface { Executable SelectWhereStep Apply(cols ...ColumnBinding) SetValueStep IfExists(cols ...ColumnBinding) CompareAndSwap - SetString(col StringColumn, value string) SetValueStep - + SetInt32(col Int32Column, value int32) SetValueStep - + SetInt64(col Int64Column, value int64) SetValueStep - + SetFloat32(col Float32Column, value float32) SetValueStep - + SetFloat64(col Float64Column, value float64) SetValueStep - + SetTimestamp(col TimestampColumn, value time.Time) SetValueStep - + SetTimeUUID(col TimeUUIDColumn, value gocql.UUID) SetValueStep - + SetUUID(col UUIDColumn, value gocql.UUID) SetValueStep - + SetBoolean(col BooleanColumn, value bool) SetValueStep - + SetDecimal(col DecimalColumn, value *inf.Dec) SetValueStep - + SetVarint(col VarintColumn, value *big.Int) SetValueStep - + SetBytes(col BytesColumn, value []byte) SetValueStep - - - - SetStringStringMap(col StringStringMapColumn, value map[string]string) SetValueStep - - + SetStringInt32Map(col StringInt32MapColumn, value map[string]int32) SetValueStep - - + SetStringInt64Map(col StringInt64MapColumn, value map[string]int64) SetValueStep - - + SetStringFloat32Map(col StringFloat32MapColumn, value map[string]float32) SetValueStep - - + SetStringFloat64Map(col StringFloat64MapColumn, value map[string]float64) SetValueStep - - + SetStringTimestampMap(col StringTimestampMapColumn, value map[string]time.Time) SetValueStep - - + SetStringTimeUUIDMap(col StringTimeUUIDMapColumn, value map[string]gocql.UUID) SetValueStep - - + SetStringUUIDMap(col StringUUIDMapColumn, value map[string]gocql.UUID) SetValueStep - - + SetStringBooleanMap(col StringBooleanMapColumn, value map[string]bool) SetValueStep - - + SetStringDecimalMap(col StringDecimalMapColumn, value map[string]*inf.Dec) SetValueStep - - + SetStringVarintMap(col StringVarintMapColumn, value map[string]*big.Int) SetValueStep - - + SetStringBytesMap(col StringBytesMapColumn, value map[string][]byte) SetValueStep - - - + SetInt32StringMap(col Int32StringMapColumn, value map[int32]string) SetValueStep - - + SetInt32Int32Map(col Int32Int32MapColumn, value map[int32]int32) SetValueStep - - + SetInt32Int64Map(col Int32Int64MapColumn, value map[int32]int64) SetValueStep - - + SetInt32Float32Map(col Int32Float32MapColumn, value map[int32]float32) SetValueStep - - + SetInt32Float64Map(col Int32Float64MapColumn, value map[int32]float64) SetValueStep - - + SetInt32TimestampMap(col Int32TimestampMapColumn, value map[int32]time.Time) SetValueStep - - + SetInt32TimeUUIDMap(col Int32TimeUUIDMapColumn, value map[int32]gocql.UUID) SetValueStep - - + SetInt32UUIDMap(col Int32UUIDMapColumn, value map[int32]gocql.UUID) SetValueStep - - + SetInt32BooleanMap(col Int32BooleanMapColumn, value map[int32]bool) SetValueStep - - + SetInt32DecimalMap(col Int32DecimalMapColumn, value map[int32]*inf.Dec) SetValueStep - - + SetInt32VarintMap(col Int32VarintMapColumn, value map[int32]*big.Int) SetValueStep - - + SetInt32BytesMap(col Int32BytesMapColumn, value map[int32][]byte) SetValueStep - - - + SetInt64StringMap(col Int64StringMapColumn, value map[int64]string) SetValueStep - - + SetInt64Int32Map(col Int64Int32MapColumn, value map[int64]int32) SetValueStep - - + SetInt64Int64Map(col Int64Int64MapColumn, value map[int64]int64) SetValueStep - - + SetInt64Float32Map(col Int64Float32MapColumn, value map[int64]float32) SetValueStep - - + SetInt64Float64Map(col Int64Float64MapColumn, value map[int64]float64) SetValueStep - - + SetInt64TimestampMap(col Int64TimestampMapColumn, value map[int64]time.Time) SetValueStep - - + SetInt64TimeUUIDMap(col Int64TimeUUIDMapColumn, value map[int64]gocql.UUID) SetValueStep - - + SetInt64UUIDMap(col Int64UUIDMapColumn, value map[int64]gocql.UUID) SetValueStep - - + SetInt64BooleanMap(col Int64BooleanMapColumn, value map[int64]bool) SetValueStep - - + SetInt64DecimalMap(col Int64DecimalMapColumn, value map[int64]*inf.Dec) SetValueStep - - + SetInt64VarintMap(col Int64VarintMapColumn, value map[int64]*big.Int) SetValueStep - - + SetInt64BytesMap(col Int64BytesMapColumn, value map[int64][]byte) SetValueStep - - - + SetFloat32StringMap(col Float32StringMapColumn, value map[float32]string) SetValueStep - - + SetFloat32Int32Map(col Float32Int32MapColumn, value map[float32]int32) SetValueStep - - + SetFloat32Int64Map(col Float32Int64MapColumn, value map[float32]int64) SetValueStep - - + SetFloat32Float32Map(col Float32Float32MapColumn, value map[float32]float32) SetValueStep - - + SetFloat32Float64Map(col Float32Float64MapColumn, value map[float32]float64) SetValueStep - - + SetFloat32TimestampMap(col Float32TimestampMapColumn, value map[float32]time.Time) SetValueStep - - + SetFloat32TimeUUIDMap(col Float32TimeUUIDMapColumn, value map[float32]gocql.UUID) SetValueStep - - + SetFloat32UUIDMap(col Float32UUIDMapColumn, value map[float32]gocql.UUID) SetValueStep - - + SetFloat32BooleanMap(col Float32BooleanMapColumn, value map[float32]bool) SetValueStep - - + SetFloat32DecimalMap(col Float32DecimalMapColumn, value map[float32]*inf.Dec) SetValueStep - - + SetFloat32VarintMap(col Float32VarintMapColumn, value map[float32]*big.Int) SetValueStep - - + SetFloat32BytesMap(col Float32BytesMapColumn, value map[float32][]byte) SetValueStep - - - + SetFloat64StringMap(col Float64StringMapColumn, value map[float64]string) SetValueStep - - + SetFloat64Int32Map(col Float64Int32MapColumn, value map[float64]int32) SetValueStep - - + SetFloat64Int64Map(col Float64Int64MapColumn, value map[float64]int64) SetValueStep - - + SetFloat64Float32Map(col Float64Float32MapColumn, value map[float64]float32) SetValueStep - - + SetFloat64Float64Map(col Float64Float64MapColumn, value map[float64]float64) SetValueStep - - + SetFloat64TimestampMap(col Float64TimestampMapColumn, value map[float64]time.Time) SetValueStep - - + SetFloat64TimeUUIDMap(col Float64TimeUUIDMapColumn, value map[float64]gocql.UUID) SetValueStep - - + SetFloat64UUIDMap(col Float64UUIDMapColumn, value map[float64]gocql.UUID) SetValueStep - - + SetFloat64BooleanMap(col Float64BooleanMapColumn, value map[float64]bool) SetValueStep - - + SetFloat64DecimalMap(col Float64DecimalMapColumn, value map[float64]*inf.Dec) SetValueStep - - + SetFloat64VarintMap(col Float64VarintMapColumn, value map[float64]*big.Int) SetValueStep - - + SetFloat64BytesMap(col Float64BytesMapColumn, value map[float64][]byte) SetValueStep - - - + SetTimestampStringMap(col TimestampStringMapColumn, value map[time.Time]string) SetValueStep - - + SetTimestampInt32Map(col TimestampInt32MapColumn, value map[time.Time]int32) SetValueStep - - + SetTimestampInt64Map(col TimestampInt64MapColumn, value map[time.Time]int64) SetValueStep - - + SetTimestampFloat32Map(col TimestampFloat32MapColumn, value map[time.Time]float32) SetValueStep - - + SetTimestampFloat64Map(col TimestampFloat64MapColumn, value map[time.Time]float64) SetValueStep - - + SetTimestampTimestampMap(col TimestampTimestampMapColumn, value map[time.Time]time.Time) SetValueStep - - + SetTimestampTimeUUIDMap(col TimestampTimeUUIDMapColumn, value map[time.Time]gocql.UUID) SetValueStep - - + SetTimestampUUIDMap(col TimestampUUIDMapColumn, value map[time.Time]gocql.UUID) SetValueStep - - + SetTimestampBooleanMap(col TimestampBooleanMapColumn, value map[time.Time]bool) SetValueStep - - + SetTimestampDecimalMap(col TimestampDecimalMapColumn, value map[time.Time]*inf.Dec) SetValueStep - - + SetTimestampVarintMap(col TimestampVarintMapColumn, value map[time.Time]*big.Int) SetValueStep - - + SetTimestampBytesMap(col TimestampBytesMapColumn, value map[time.Time][]byte) SetValueStep - - - + SetTimeUUIDStringMap(col TimeUUIDStringMapColumn, value map[gocql.UUID]string) SetValueStep - - + SetTimeUUIDInt32Map(col TimeUUIDInt32MapColumn, value map[gocql.UUID]int32) SetValueStep - - + SetTimeUUIDInt64Map(col TimeUUIDInt64MapColumn, value map[gocql.UUID]int64) SetValueStep - - + SetTimeUUIDFloat32Map(col TimeUUIDFloat32MapColumn, value map[gocql.UUID]float32) SetValueStep - - + SetTimeUUIDFloat64Map(col TimeUUIDFloat64MapColumn, value map[gocql.UUID]float64) SetValueStep - - + SetTimeUUIDTimestampMap(col TimeUUIDTimestampMapColumn, value map[gocql.UUID]time.Time) SetValueStep - - + SetTimeUUIDTimeUUIDMap(col TimeUUIDTimeUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep - - + SetTimeUUIDUUIDMap(col TimeUUIDUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep - - + SetTimeUUIDBooleanMap(col TimeUUIDBooleanMapColumn, value map[gocql.UUID]bool) SetValueStep - - + SetTimeUUIDDecimalMap(col TimeUUIDDecimalMapColumn, value map[gocql.UUID]*inf.Dec) SetValueStep - - + SetTimeUUIDVarintMap(col TimeUUIDVarintMapColumn, value map[gocql.UUID]*big.Int) SetValueStep - - + SetTimeUUIDBytesMap(col TimeUUIDBytesMapColumn, value map[gocql.UUID][]byte) SetValueStep - - - + SetUUIDStringMap(col UUIDStringMapColumn, value map[gocql.UUID]string) SetValueStep - - + SetUUIDInt32Map(col UUIDInt32MapColumn, value map[gocql.UUID]int32) SetValueStep - - + SetUUIDInt64Map(col UUIDInt64MapColumn, value map[gocql.UUID]int64) SetValueStep - - + SetUUIDFloat32Map(col UUIDFloat32MapColumn, value map[gocql.UUID]float32) SetValueStep - - + SetUUIDFloat64Map(col UUIDFloat64MapColumn, value map[gocql.UUID]float64) SetValueStep - - + SetUUIDTimestampMap(col UUIDTimestampMapColumn, value map[gocql.UUID]time.Time) SetValueStep - - + SetUUIDTimeUUIDMap(col UUIDTimeUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep - - + SetUUIDUUIDMap(col UUIDUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep - - + SetUUIDBooleanMap(col UUIDBooleanMapColumn, value map[gocql.UUID]bool) SetValueStep - - + SetUUIDDecimalMap(col UUIDDecimalMapColumn, value map[gocql.UUID]*inf.Dec) SetValueStep - - + SetUUIDVarintMap(col UUIDVarintMapColumn, value map[gocql.UUID]*big.Int) SetValueStep - - + SetUUIDBytesMap(col UUIDBytesMapColumn, value map[gocql.UUID][]byte) SetValueStep - - - + SetBooleanStringMap(col BooleanStringMapColumn, value map[bool]string) SetValueStep - - + SetBooleanInt32Map(col BooleanInt32MapColumn, value map[bool]int32) SetValueStep - - + SetBooleanInt64Map(col BooleanInt64MapColumn, value map[bool]int64) SetValueStep - - + SetBooleanFloat32Map(col BooleanFloat32MapColumn, value map[bool]float32) SetValueStep - - + SetBooleanFloat64Map(col BooleanFloat64MapColumn, value map[bool]float64) SetValueStep - - + SetBooleanTimestampMap(col BooleanTimestampMapColumn, value map[bool]time.Time) SetValueStep - - + SetBooleanTimeUUIDMap(col BooleanTimeUUIDMapColumn, value map[bool]gocql.UUID) SetValueStep - - + SetBooleanUUIDMap(col BooleanUUIDMapColumn, value map[bool]gocql.UUID) SetValueStep - - + SetBooleanBooleanMap(col BooleanBooleanMapColumn, value map[bool]bool) SetValueStep - - + SetBooleanDecimalMap(col BooleanDecimalMapColumn, value map[bool]*inf.Dec) SetValueStep - - + SetBooleanVarintMap(col BooleanVarintMapColumn, value map[bool]*big.Int) SetValueStep - - + SetBooleanBytesMap(col BooleanBytesMapColumn, value map[bool][]byte) SetValueStep - - - + SetDecimalStringMap(col DecimalStringMapColumn, value map[*inf.Dec]string) SetValueStep - - + SetDecimalInt32Map(col DecimalInt32MapColumn, value map[*inf.Dec]int32) SetValueStep - - + SetDecimalInt64Map(col DecimalInt64MapColumn, value map[*inf.Dec]int64) SetValueStep - - + SetDecimalFloat32Map(col DecimalFloat32MapColumn, value map[*inf.Dec]float32) SetValueStep - - + SetDecimalFloat64Map(col DecimalFloat64MapColumn, value map[*inf.Dec]float64) SetValueStep - - + SetDecimalTimestampMap(col DecimalTimestampMapColumn, value map[*inf.Dec]time.Time) SetValueStep - - + SetDecimalTimeUUIDMap(col DecimalTimeUUIDMapColumn, value map[*inf.Dec]gocql.UUID) SetValueStep - - + SetDecimalUUIDMap(col DecimalUUIDMapColumn, value map[*inf.Dec]gocql.UUID) SetValueStep - - + SetDecimalBooleanMap(col DecimalBooleanMapColumn, value map[*inf.Dec]bool) SetValueStep - - + SetDecimalDecimalMap(col DecimalDecimalMapColumn, value map[*inf.Dec]*inf.Dec) SetValueStep - - + SetDecimalVarintMap(col DecimalVarintMapColumn, value map[*inf.Dec]*big.Int) SetValueStep - - + SetDecimalBytesMap(col DecimalBytesMapColumn, value map[*inf.Dec][]byte) SetValueStep - - - + SetVarintStringMap(col VarintStringMapColumn, value map[*big.Int]string) SetValueStep - - + SetVarintInt32Map(col VarintInt32MapColumn, value map[*big.Int]int32) SetValueStep - - + SetVarintInt64Map(col VarintInt64MapColumn, value map[*big.Int]int64) SetValueStep - - + SetVarintFloat32Map(col VarintFloat32MapColumn, value map[*big.Int]float32) SetValueStep - - + SetVarintFloat64Map(col VarintFloat64MapColumn, value map[*big.Int]float64) SetValueStep - - + SetVarintTimestampMap(col VarintTimestampMapColumn, value map[*big.Int]time.Time) SetValueStep - - + SetVarintTimeUUIDMap(col VarintTimeUUIDMapColumn, value map[*big.Int]gocql.UUID) SetValueStep - - + SetVarintUUIDMap(col VarintUUIDMapColumn, value map[*big.Int]gocql.UUID) SetValueStep - - + SetVarintBooleanMap(col VarintBooleanMapColumn, value map[*big.Int]bool) SetValueStep - - + SetVarintDecimalMap(col VarintDecimalMapColumn, value map[*big.Int]*inf.Dec) SetValueStep - - + SetVarintVarintMap(col VarintVarintMapColumn, value map[*big.Int]*big.Int) SetValueStep - - + SetVarintBytesMap(col VarintBytesMapColumn, value map[*big.Int][]byte) SetValueStep - - - - - - - - - - - - - - - - + SetStringSlice(col StringSliceColumn, value []string) SetValueStep AppendStringSlice(col StringSliceColumn, values ...string) SetValueStep PrependStringSlice(col StringSliceColumn, values ...string) SetValueStep RemoveStringSlice(col StringSliceColumn, values ...string) SetValueStep - + SetInt32Slice(col Int32SliceColumn, value []int32) SetValueStep AppendInt32Slice(col Int32SliceColumn, values ...int32) SetValueStep PrependInt32Slice(col Int32SliceColumn, values ...int32) SetValueStep RemoveInt32Slice(col Int32SliceColumn, values ...int32) SetValueStep - + SetInt64Slice(col Int64SliceColumn, value []int64) SetValueStep AppendInt64Slice(col Int64SliceColumn, values ...int64) SetValueStep PrependInt64Slice(col Int64SliceColumn, values ...int64) SetValueStep RemoveInt64Slice(col Int64SliceColumn, values ...int64) SetValueStep - + SetFloat32Slice(col Float32SliceColumn, value []float32) SetValueStep AppendFloat32Slice(col Float32SliceColumn, values ...float32) SetValueStep PrependFloat32Slice(col Float32SliceColumn, values ...float32) SetValueStep RemoveFloat32Slice(col Float32SliceColumn, values ...float32) SetValueStep - + SetFloat64Slice(col Float64SliceColumn, value []float64) SetValueStep AppendFloat64Slice(col Float64SliceColumn, values ...float64) SetValueStep PrependFloat64Slice(col Float64SliceColumn, values ...float64) SetValueStep RemoveFloat64Slice(col Float64SliceColumn, values ...float64) SetValueStep - + SetTimestampSlice(col TimestampSliceColumn, value []time.Time) SetValueStep AppendTimestampSlice(col TimestampSliceColumn, values ...time.Time) SetValueStep PrependTimestampSlice(col TimestampSliceColumn, values ...time.Time) SetValueStep RemoveTimestampSlice(col TimestampSliceColumn, values ...time.Time) SetValueStep - + SetTimeUUIDSlice(col TimeUUIDSliceColumn, value []gocql.UUID) SetValueStep AppendTimeUUIDSlice(col TimeUUIDSliceColumn, values ...gocql.UUID) SetValueStep PrependTimeUUIDSlice(col TimeUUIDSliceColumn, values ...gocql.UUID) SetValueStep RemoveTimeUUIDSlice(col TimeUUIDSliceColumn, values ...gocql.UUID) SetValueStep - + SetUUIDSlice(col UUIDSliceColumn, value []gocql.UUID) SetValueStep AppendUUIDSlice(col UUIDSliceColumn, values ...gocql.UUID) SetValueStep PrependUUIDSlice(col UUIDSliceColumn, values ...gocql.UUID) SetValueStep RemoveUUIDSlice(col UUIDSliceColumn, values ...gocql.UUID) SetValueStep - + SetBooleanSlice(col BooleanSliceColumn, value []bool) SetValueStep AppendBooleanSlice(col BooleanSliceColumn, values ...bool) SetValueStep PrependBooleanSlice(col BooleanSliceColumn, values ...bool) SetValueStep RemoveBooleanSlice(col BooleanSliceColumn, values ...bool) SetValueStep - + SetDecimalSlice(col DecimalSliceColumn, value []*inf.Dec) SetValueStep AppendDecimalSlice(col DecimalSliceColumn, values ...*inf.Dec) SetValueStep PrependDecimalSlice(col DecimalSliceColumn, values ...*inf.Dec) SetValueStep RemoveDecimalSlice(col DecimalSliceColumn, values ...*inf.Dec) SetValueStep - + SetVarintSlice(col VarintSliceColumn, value []*big.Int) SetValueStep AppendVarintSlice(col VarintSliceColumn, values ...*big.Int) SetValueStep PrependVarintSlice(col VarintSliceColumn, values ...*big.Int) SetValueStep RemoveVarintSlice(col VarintSliceColumn, values ...*big.Int) SetValueStep - + SetBytesSlice(col BytesSliceColumn, value [][]byte) SetValueStep AppendBytesSlice(col BytesSliceColumn, values ...[]byte) SetValueStep PrependBytesSlice(col BytesSliceColumn, values ...[]byte) SetValueStep RemoveBytesSlice(col BytesSliceColumn, values ...[]byte) SetValueStep - } - - - func (c *Context) SetStringStringMap(col StringStringMapColumn, value map[string]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringInt32Map(col StringInt32MapColumn, value map[string]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringInt64Map(col StringInt64MapColumn, value map[string]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringFloat32Map(col StringFloat32MapColumn, value map[string]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringFloat64Map(col StringFloat64MapColumn, value map[string]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringTimestampMap(col StringTimestampMapColumn, value map[string]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringTimeUUIDMap(col StringTimeUUIDMapColumn, value map[string]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringUUIDMap(col StringUUIDMapColumn, value map[string]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringBooleanMap(col StringBooleanMapColumn, value map[string]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringDecimalMap(col StringDecimalMapColumn, value map[string]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringVarintMap(col StringVarintMapColumn, value map[string]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetStringBytesMap(col StringBytesMapColumn, value map[string][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetInt32StringMap(col Int32StringMapColumn, value map[int32]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32Int32Map(col Int32Int32MapColumn, value map[int32]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32Int64Map(col Int32Int64MapColumn, value map[int32]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32Float32Map(col Int32Float32MapColumn, value map[int32]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32Float64Map(col Int32Float64MapColumn, value map[int32]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32TimestampMap(col Int32TimestampMapColumn, value map[int32]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32TimeUUIDMap(col Int32TimeUUIDMapColumn, value map[int32]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32UUIDMap(col Int32UUIDMapColumn, value map[int32]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32BooleanMap(col Int32BooleanMapColumn, value map[int32]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32DecimalMap(col Int32DecimalMapColumn, value map[int32]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32VarintMap(col Int32VarintMapColumn, value map[int32]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt32BytesMap(col Int32BytesMapColumn, value map[int32][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetInt64StringMap(col Int64StringMapColumn, value map[int64]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64Int32Map(col Int64Int32MapColumn, value map[int64]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64Int64Map(col Int64Int64MapColumn, value map[int64]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64Float32Map(col Int64Float32MapColumn, value map[int64]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64Float64Map(col Int64Float64MapColumn, value map[int64]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64TimestampMap(col Int64TimestampMapColumn, value map[int64]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64TimeUUIDMap(col Int64TimeUUIDMapColumn, value map[int64]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64UUIDMap(col Int64UUIDMapColumn, value map[int64]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64BooleanMap(col Int64BooleanMapColumn, value map[int64]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64DecimalMap(col Int64DecimalMapColumn, value map[int64]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64VarintMap(col Int64VarintMapColumn, value map[int64]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetInt64BytesMap(col Int64BytesMapColumn, value map[int64][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetFloat32StringMap(col Float32StringMapColumn, value map[float32]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32Int32Map(col Float32Int32MapColumn, value map[float32]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32Int64Map(col Float32Int64MapColumn, value map[float32]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32Float32Map(col Float32Float32MapColumn, value map[float32]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32Float64Map(col Float32Float64MapColumn, value map[float32]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32TimestampMap(col Float32TimestampMapColumn, value map[float32]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32TimeUUIDMap(col Float32TimeUUIDMapColumn, value map[float32]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32UUIDMap(col Float32UUIDMapColumn, value map[float32]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32BooleanMap(col Float32BooleanMapColumn, value map[float32]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32DecimalMap(col Float32DecimalMapColumn, value map[float32]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32VarintMap(col Float32VarintMapColumn, value map[float32]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat32BytesMap(col Float32BytesMapColumn, value map[float32][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetFloat64StringMap(col Float64StringMapColumn, value map[float64]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64Int32Map(col Float64Int32MapColumn, value map[float64]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64Int64Map(col Float64Int64MapColumn, value map[float64]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64Float32Map(col Float64Float32MapColumn, value map[float64]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64Float64Map(col Float64Float64MapColumn, value map[float64]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64TimestampMap(col Float64TimestampMapColumn, value map[float64]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64TimeUUIDMap(col Float64TimeUUIDMapColumn, value map[float64]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64UUIDMap(col Float64UUIDMapColumn, value map[float64]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64BooleanMap(col Float64BooleanMapColumn, value map[float64]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64DecimalMap(col Float64DecimalMapColumn, value map[float64]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64VarintMap(col Float64VarintMapColumn, value map[float64]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetFloat64BytesMap(col Float64BytesMapColumn, value map[float64][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetTimestampStringMap(col TimestampStringMapColumn, value map[time.Time]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampInt32Map(col TimestampInt32MapColumn, value map[time.Time]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampInt64Map(col TimestampInt64MapColumn, value map[time.Time]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampFloat32Map(col TimestampFloat32MapColumn, value map[time.Time]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampFloat64Map(col TimestampFloat64MapColumn, value map[time.Time]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampTimestampMap(col TimestampTimestampMapColumn, value map[time.Time]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampTimeUUIDMap(col TimestampTimeUUIDMapColumn, value map[time.Time]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampUUIDMap(col TimestampUUIDMapColumn, value map[time.Time]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampBooleanMap(col TimestampBooleanMapColumn, value map[time.Time]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampDecimalMap(col TimestampDecimalMapColumn, value map[time.Time]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampVarintMap(col TimestampVarintMapColumn, value map[time.Time]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimestampBytesMap(col TimestampBytesMapColumn, value map[time.Time][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetTimeUUIDStringMap(col TimeUUIDStringMapColumn, value map[gocql.UUID]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDInt32Map(col TimeUUIDInt32MapColumn, value map[gocql.UUID]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDInt64Map(col TimeUUIDInt64MapColumn, value map[gocql.UUID]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDFloat32Map(col TimeUUIDFloat32MapColumn, value map[gocql.UUID]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDFloat64Map(col TimeUUIDFloat64MapColumn, value map[gocql.UUID]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDTimestampMap(col TimeUUIDTimestampMapColumn, value map[gocql.UUID]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDTimeUUIDMap(col TimeUUIDTimeUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDUUIDMap(col TimeUUIDUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDBooleanMap(col TimeUUIDBooleanMapColumn, value map[gocql.UUID]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDDecimalMap(col TimeUUIDDecimalMapColumn, value map[gocql.UUID]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDVarintMap(col TimeUUIDVarintMapColumn, value map[gocql.UUID]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetTimeUUIDBytesMap(col TimeUUIDBytesMapColumn, value map[gocql.UUID][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetUUIDStringMap(col UUIDStringMapColumn, value map[gocql.UUID]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDInt32Map(col UUIDInt32MapColumn, value map[gocql.UUID]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDInt64Map(col UUIDInt64MapColumn, value map[gocql.UUID]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDFloat32Map(col UUIDFloat32MapColumn, value map[gocql.UUID]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDFloat64Map(col UUIDFloat64MapColumn, value map[gocql.UUID]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDTimestampMap(col UUIDTimestampMapColumn, value map[gocql.UUID]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDTimeUUIDMap(col UUIDTimeUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDUUIDMap(col UUIDUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDBooleanMap(col UUIDBooleanMapColumn, value map[gocql.UUID]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDDecimalMap(col UUIDDecimalMapColumn, value map[gocql.UUID]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDVarintMap(col UUIDVarintMapColumn, value map[gocql.UUID]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetUUIDBytesMap(col UUIDBytesMapColumn, value map[gocql.UUID][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetBooleanStringMap(col BooleanStringMapColumn, value map[bool]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanInt32Map(col BooleanInt32MapColumn, value map[bool]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanInt64Map(col BooleanInt64MapColumn, value map[bool]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanFloat32Map(col BooleanFloat32MapColumn, value map[bool]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanFloat64Map(col BooleanFloat64MapColumn, value map[bool]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanTimestampMap(col BooleanTimestampMapColumn, value map[bool]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanTimeUUIDMap(col BooleanTimeUUIDMapColumn, value map[bool]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanUUIDMap(col BooleanUUIDMapColumn, value map[bool]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanBooleanMap(col BooleanBooleanMapColumn, value map[bool]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanDecimalMap(col BooleanDecimalMapColumn, value map[bool]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanVarintMap(col BooleanVarintMapColumn, value map[bool]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetBooleanBytesMap(col BooleanBytesMapColumn, value map[bool][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetDecimalStringMap(col DecimalStringMapColumn, value map[*inf.Dec]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalInt32Map(col DecimalInt32MapColumn, value map[*inf.Dec]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalInt64Map(col DecimalInt64MapColumn, value map[*inf.Dec]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalFloat32Map(col DecimalFloat32MapColumn, value map[*inf.Dec]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalFloat64Map(col DecimalFloat64MapColumn, value map[*inf.Dec]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalTimestampMap(col DecimalTimestampMapColumn, value map[*inf.Dec]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalTimeUUIDMap(col DecimalTimeUUIDMapColumn, value map[*inf.Dec]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalUUIDMap(col DecimalUUIDMapColumn, value map[*inf.Dec]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalBooleanMap(col DecimalBooleanMapColumn, value map[*inf.Dec]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalDecimalMap(col DecimalDecimalMapColumn, value map[*inf.Dec]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalVarintMap(col DecimalVarintMapColumn, value map[*inf.Dec]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetDecimalBytesMap(col DecimalBytesMapColumn, value map[*inf.Dec][]byte) SetValueStep { set(c, col, value) return c } - - func (c *Context) SetVarintStringMap(col VarintStringMapColumn, value map[*big.Int]string) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintInt32Map(col VarintInt32MapColumn, value map[*big.Int]int32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintInt64Map(col VarintInt64MapColumn, value map[*big.Int]int64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintFloat32Map(col VarintFloat32MapColumn, value map[*big.Int]float32) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintFloat64Map(col VarintFloat64MapColumn, value map[*big.Int]float64) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintTimestampMap(col VarintTimestampMapColumn, value map[*big.Int]time.Time) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintTimeUUIDMap(col VarintTimeUUIDMapColumn, value map[*big.Int]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintUUIDMap(col VarintUUIDMapColumn, value map[*big.Int]gocql.UUID) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintBooleanMap(col VarintBooleanMapColumn, value map[*big.Int]bool) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintDecimalMap(col VarintDecimalMapColumn, value map[*big.Int]*inf.Dec) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintVarintMap(col VarintVarintMapColumn, value map[*big.Int]*big.Int) SetValueStep { set(c, col, value) return c } - func (c *Context) SetVarintBytesMap(col VarintBytesMapColumn, value map[*big.Int][]byte) SetValueStep { set(c, col, value) return c } - - - - - - - - - - - - - - - func (c *Context) SetString(col StringColumn, value string) SetValueStep { set(c, col, value) return c @@ -2590,8 +2080,6 @@ func (c *Context) SetBytes(col BytesColumn, value []byte) SetValueStep { return c } - - func (c *Context) SetStringSlice(col StringSliceColumn, value []string) SetValueStep { set(c, col, value) return c @@ -2795,4 +2283,3 @@ func (c *Context) RemoveBytesSlice(col BytesSliceColumn, values ...[]byte) SetVa removeList(c, col, values) return c } - diff --git a/generator/binding_tmpl.go b/generator/binding_tmpl.go index bfbfb5b..9384059 100644 --- a/generator/binding_tmpl.go +++ b/generator/binding_tmpl.go @@ -199,6 +199,7 @@ func AssetNames() []string { var _bindata = map[string]func() ([]byte, error){ "generator/tmpl/binding.tmpl": generator_tmpl_binding_tmpl, } + // AssetDir returns the file names below a certain // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the @@ -235,14 +236,14 @@ func AssetDir(name string) ([]string, error) { } type _bintree_t struct { - Func func() ([]byte, error) + Func func() ([]byte, error) Children map[string]*_bintree_t } + var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ "generator": &_bintree_t{nil, map[string]*_bintree_t{ "tmpl": &_bintree_t{nil, map[string]*_bintree_t{ - "binding.tmpl": &_bintree_t{generator_tmpl_binding_tmpl, map[string]*_bintree_t{ - }}, + "binding.tmpl": &_bintree_t{generator_tmpl_binding_tmpl, map[string]*_bintree_t{}}, }}, }}, }} diff --git a/generator/template.go b/generator/template.go index a98ee5e..ad40baa 100644 --- a/generator/template.go +++ b/generator/template.go @@ -47,19 +47,19 @@ func isCounterColumn(c gocql.ColumnMetadata) bool { } func supportsClustering(c gocql.ColumnMetadata) bool { - return c.Kind == gocql.CLUSTERING_KEY + return c.Kind == gocql.ColumnClusteringKey } func supportsPartitioning(c gocql.ColumnMetadata) bool { - return c.Kind == gocql.PARTITION_KEY + return c.Kind == gocql.ColumnPartitionKey } func isLastComponent(c gocql.ColumnMetadata, t *gocql.TableMetadata) bool { switch c.Kind { - case gocql.PARTITION_KEY: + case gocql.ColumnPartitionKey: lastPartitionKeyColumn := t.PartitionKey[len(t.PartitionKey)-1] return c.Name == lastPartitionKeyColumn.Name - case gocql.CLUSTERING_KEY: + case gocql.ColumnClusteringKey: lastClusteringColumn := t.ClusteringColumns[len(t.ClusteringColumns)-1] return c.Name == lastClusteringColumn.Name default: @@ -82,13 +82,13 @@ func columnType(c gocql.ColumnMetadata, table *gocql.TableMetadata) string { baseType := columnTypes[t.Type()] // TODO The Kind field should be an enum, not a string - if c.Kind == gocql.CLUSTERING_KEY { + if c.Kind == gocql.ColumnClusteringKey { replacement := ".Clustered" if isLastComponent(c, table) { replacement = ".LastClustered" } baseType = strings.Replace(baseType, ".", replacement, 1) - } else if c.Kind == gocql.PARTITION_KEY { + } else if c.Kind == gocql.ColumnPartitionKey { replacement := ".Partitioned" if isLastComponent(c, table) { replacement = ".LastPartitioned" diff --git a/test/.fixtures/sensor/sensor.go b/test/.fixtures/sensor/sensor.go index 3851c73..dc3fe99 100644 --- a/test/.fixtures/sensor/sensor.go +++ b/test/.fixtures/sensor/sensor.go @@ -29,8 +29,8 @@ func main() { iter, err := ctx.Select(). From(EVENTS). Where( - EVENTS.SENSOR.Eq(sensorId), - EVENTS.TIMESTAMP.Lt(gocql.TimeUUID())). + EVENTS.SENSOR.Eq(sensorId), + EVENTS.TIMESTAMP.Lt(gocql.TimeUUID())). Fetch(session) if err != nil { From c0a9108ec68da971e25f36ed38d769721149c80b Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 22:09:54 -0700 Subject: [PATCH 03/39] [gen] Format generated columns.go - the template would result in extra space --- README.md | 16 +++++++------- cqlc/column_generator.go | 46 +++++++++++++++------------------------- cqlc/columns.go | 7 +++--- cqlc/tmpl/columns.tmpl | 7 +++--- 4 files changed, 32 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index bb3b444..2c3dd57 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,8 @@ # cqlc -[![Join the chat at https://gitter.im/relops/cqlc](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/relops/cqlc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/pingginp/cqlc.svg?branch=master)](https://travis-ci.org/pingginp/cqlc) -[![Build Status](https://travis-ci.org/relops/cqlc.png?branch=master)](https://travis-ci.org/relops/cqlc) -[![GoDoc](http://godoc.org/_?status.png)](http://godoc.org/github.com/relops/cqlc/cqlc) - -`cqlc` generates Go code from your Cassandra schema so that you can write type safe CQL statements in Go with a natural query syntax. - -For more details please visit [http://relops.com/cqlc][cqlc] +This a fork of [relops/cqlc](https://github.com/relops/cqlc) which is no longer maintained ## Usage @@ -15,4 +10,9 @@ For more details please visit [http://relops.com/cqlc][cqlc] make build ```` -[cqlc]: http://relops.com/cqlc +## Dev + +````bash +# generate columns +make cqlc/columns.go +```` \ No newline at end of file diff --git a/cqlc/column_generator.go b/cqlc/column_generator.go index 4001ff8..27529a1 100644 --- a/cqlc/column_generator.go +++ b/cqlc/column_generator.go @@ -4,33 +4,12 @@ package main import ( "bytes" - "fmt" - log "github.com/cihub/seelog" + "go/format" "io/ioutil" + "log" "text/template" ) -var logConfig = ` - - - - - - - -` - -func init() { - logger, err := log.LoggerFromConfigAsString(logConfig) - - if err != nil { - fmt.Printf("Could not load seelog configuration: %s\n", err) - return - } - - log.ReplaceLogger(logger) -} - type TypeInfo struct { Prefix string Literal string @@ -57,17 +36,26 @@ func main() { t, err := template.New("columns.tmpl").ParseFiles("tmpl/columns.tmpl") if err != nil { - log.Errorf("Could not open template: %s", err) + log.Fatalf("Could not open template: %s", err) + return + } + + var buf bytes.Buffer + if err := t.Execute(&buf, params); err != nil { + log.Fatalf("Could not render template: %s", err) return } - var b bytes.Buffer - t.Execute(&b, params) + b, err := format.Source(buf.Bytes()) + if err != nil { + log.Fatalf("Could not format rendered template as go code: %s", err) + return + } - if err := ioutil.WriteFile("columns.go", b.Bytes(), 0644); err != nil { - log.Errorf("Could not write templated file: %s", err) + if err := ioutil.WriteFile("columns.go", b, 0644); err != nil { + log.Fatalf("Could not write templated file: %s", err) return } - log.Info("Regenerated columns") + log.Println("Regenerated columns") } diff --git a/cqlc/columns.go b/cqlc/columns.go index f7a5f77..efe16e7 100755 --- a/cqlc/columns.go +++ b/cqlc/columns.go @@ -1,12 +1,13 @@ -// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +// Code generated by column_generator.go from tmp/columns.tmpl DO NOT EDIT. package cqlc import ( - "github.com/gocql/gocql" - "gopkg.in/inf.v0" "math/big" "time" + + "github.com/gocql/gocql" + "gopkg.in/inf.v0" ) type StringColumn interface { diff --git a/cqlc/tmpl/columns.tmpl b/cqlc/tmpl/columns.tmpl index f042861..27a4c49 100644 --- a/cqlc/tmpl/columns.tmpl +++ b/cqlc/tmpl/columns.tmpl @@ -1,16 +1,16 @@ -// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +// Code generated by column_generator.go from tmp/columns.tmpl DO NOT EDIT. package cqlc import ( - "github.com/gocql/gocql" "time" "math/big" + "gopkg.in/inf.v0" + "github.com/gocql/gocql" ) {{ range $_, $t := .types }} - type {{ $t.Prefix }}Column interface { Column To(value *{{ $t.Literal }}) ColumnBinding @@ -44,7 +44,6 @@ type LastClustered{{ $t.Prefix }}Column interface { Clustered{{ $t.Prefix }}Column In(value ...{{ $t.Literal }}) Condition } - {{ end }} {{ range $_, $t := .types }} From 939cc7be4a0a6e7ef621970a6463ad3a99bd6151 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 22:18:19 -0700 Subject: [PATCH 04/39] [test] Bump go and cassandra version in Travis - https://github.com/pingginp/cqlc/issues/3 - not sure if I can run ccm locally --- .travis.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 675aff5..6e20e46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,18 +13,16 @@ env: global: - GOMAXPROCS=2 matrix: - - CASS=2.1.9 - - CASS=2.2.1 + - CASS=2.2.13 + - CASS=3.11 go: - - 1.4 - - 1.5 + - "1.10" + - "1.11" + - "tip" before_install: - - go get github.com/stretchr/testify/assert - - go get github.com/jteeuwen/go-bindata/... - - go get github.com/relops/csvb - - go get github.com/cihub/seelog + - curl -sSL https://github.com/Masterminds/glide/releases/download/$GLIDE_VERSION/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C /usr/local/bin --strip=1 - export PATH=$PATH:/home/travis/gopath/bin install: @@ -33,7 +31,8 @@ install: - pushd ccm - ./setup.py install --user - popd - - go get -v ./... + - glide install + - make install script: - set -e From 3c4103493b854418b70c6508e29df6dd34c643d8 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 22:33:30 -0700 Subject: [PATCH 05/39] [gen] Remove go-bindata and use template directly - https://github.com/pingginp/cqlc/issues/5 --- .travis.yml | 2 +- generator/binding_tmpl.go | 249 ----------------------- generator/template.go | 6 +- generator/{tmpl/binding.tmpl => tmpl.go} | 7 +- main.go | 12 +- 5 files changed, 15 insertions(+), 261 deletions(-) delete mode 100644 generator/binding_tmpl.go rename generator/{tmpl/binding.tmpl => tmpl.go} (98%) diff --git a/.travis.yml b/.travis.yml index 6e20e46..65abe55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ go: - "tip" before_install: - - curl -sSL https://github.com/Masterminds/glide/releases/download/$GLIDE_VERSION/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C /usr/local/bin --strip=1 + - curl -sSL https://github.com/Masterminds/glide/releases/download/v0.13.1/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C /usr/local/bin --strip=1 - export PATH=$PATH:/home/travis/gopath/bin install: diff --git a/generator/binding_tmpl.go b/generator/binding_tmpl.go deleted file mode 100644 index 9384059..0000000 --- a/generator/binding_tmpl.go +++ /dev/null @@ -1,249 +0,0 @@ -package generator - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "strings" -) - -func bindata_read(data []byte, name string) ([]byte, error) { - gz, err := gzip.NewReader(bytes.NewBuffer(data)) - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - - var buf bytes.Buffer - _, err = io.Copy(&buf, gz) - gz.Close() - - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - - return buf.Bytes(), nil -} - -func generator_tmpl_binding_tmpl() ([]byte, error) { - return bindata_read([]byte{ - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xec, 0x5a, - 0xdf, 0x6f, 0xda, 0xba, 0x17, 0x7f, 0xe7, 0xaf, 0xf0, 0xaa, 0xaa, 0x0a, - 0x1d, 0x5f, 0xb6, 0x67, 0xbe, 0xb7, 0x0f, 0x8c, 0x66, 0x6d, 0x34, 0x2e, - 0xb0, 0x26, 0x5d, 0x35, 0x4d, 0xd3, 0x64, 0x82, 0x69, 0xa3, 0x86, 0x84, - 0x25, 0xa6, 0x1b, 0x8a, 0xf8, 0xdf, 0xef, 0xb1, 0x63, 0x13, 0xc7, 0x71, - 0x28, 0x14, 0x2a, 0xdd, 0x5d, 0xe1, 0x97, 0x86, 0xe4, 0xf8, 0xfc, 0xf8, - 0x9c, 0x8f, 0x7f, 0x1d, 0xf7, 0xdd, 0x3b, 0xe4, 0x5d, 0x3b, 0x2e, 0xfa, - 0xe8, 0xf4, 0x6d, 0x74, 0xd7, 0x75, 0x51, 0xf7, 0xd6, 0x1b, 0x5e, 0xd9, - 0x03, 0xfb, 0xa6, 0xeb, 0xd9, 0x97, 0xe8, 0x7f, 0xa8, 0x3b, 0xf8, 0x8a, - 0xec, 0x4b, 0xc7, 0x73, 0x91, 0x37, 0xcc, 0x45, 0xef, 0x9c, 0x7e, 0x1f, - 0x7d, 0xb0, 0x51, 0x7f, 0xe8, 0x7a, 0xe8, 0xee, 0xda, 0x1e, 0x20, 0xc7, - 0x43, 0xf0, 0xfe, 0xc6, 0x5e, 0xf7, 0x6b, 0x80, 0xda, 0x42, 0xc9, 0xad, - 0xeb, 0x0c, 0xae, 0xd0, 0x27, 0xfb, 0xab, 0x3b, 0xea, 0xf6, 0x6c, 0x94, - 0x65, 0xa8, 0x3d, 0x4a, 0xe2, 0x27, 0x12, 0xe1, 0xc8, 0x27, 0xed, 0x4f, - 0x64, 0x99, 0xce, 0xb1, 0x4f, 0xd0, 0x6a, 0xc5, 0xba, 0x75, 0x3d, 0x5d, - 0xc0, 0x0b, 0x66, 0x24, 0xa5, 0x78, 0x36, 0x07, 0x09, 0xa1, 0xcb, 0xff, - 0x19, 0xfa, 0xe8, 0x8b, 0x7d, 0xe3, 0x3a, 0xc3, 0x81, 0x2e, 0xfe, 0x85, - 0x24, 0x69, 0x10, 0x47, 0x52, 0xdd, 0x55, 0xd7, 0x19, 0x80, 0x9f, 0xd7, - 0xcc, 0x59, 0xe7, 0x52, 0x17, 0xbe, 0x8e, 0x53, 0xea, 0x4c, 0x98, 0x62, - 0xcb, 0xb5, 0x6f, 0x40, 0x63, 0x9d, 0x56, 0x97, 0x24, 0x4f, 0x24, 0xb9, - 0x21, 0x21, 0xc1, 0x29, 0x73, 0xb5, 0xc9, 0x94, 0xf7, 0xfa, 0x8e, 0x3d, - 0xf0, 0xd0, 0xc0, 0xbe, 0x1a, 0x7a, 0x0e, 0x0f, 0xb5, 0xf7, 0xb9, 0x5f, - 0xa7, 0x61, 0x40, 0xee, 0x63, 0x1a, 0x60, 0x4a, 0x26, 0x4c, 0x48, 0xb1, - 0xe8, 0xde, 0x8e, 0x46, 0xc3, 0x1b, 0x00, 0xf8, 0x76, 0xc4, 0x30, 0x36, - 0x1a, 0xce, 0xbb, 0x34, 0x1b, 0x0d, 0xf8, 0x7a, 0x9a, 0x2e, 0x67, 0xe3, - 0x38, 0x4c, 0x51, 0xe7, 0x02, 0xb5, 0x87, 0x73, 0x0a, 0xc1, 0xa6, 0x6d, - 0x57, 0xbc, 0x83, 0xa8, 0x99, 0xc8, 0xa3, 0x04, 0x95, 0xc9, 0xd4, 0x80, - 0xdd, 0x80, 0x87, 0x47, 0x7c, 0x4f, 0xb8, 0x45, 0xa9, 0x67, 0x24, 0xde, - 0xb1, 0xef, 0xc1, 0x6c, 0x1e, 0x27, 0x14, 0x59, 0x0d, 0x04, 0x2d, 0xcb, - 0x12, 0x1c, 0xc1, 0x87, 0xd3, 0x1f, 0x2d, 0x74, 0x3a, 0xc7, 0xf4, 0x81, - 0xab, 0x76, 0xb8, 0x48, 0x0a, 0xd2, 0x48, 0xb4, 0x93, 0x2c, 0xe3, 0x9f, - 0x57, 0xab, 0x13, 0xd1, 0x8f, 0x44, 0x13, 0xf8, 0x0e, 0xbe, 0xfb, 0x60, - 0x40, 0xaa, 0x83, 0x80, 0x7a, 0x3f, 0x24, 0x52, 0x17, 0xac, 0x57, 0x4d, - 0x12, 0x4f, 0x1a, 0x3c, 0x6a, 0xc5, 0xb8, 0x3f, 0xe5, 0xa6, 0x3d, 0x3c, - 0x0e, 0x09, 0xb3, 0x2c, 0xcc, 0xa0, 0x53, 0x97, 0x26, 0x0b, 0x9f, 0x7a, - 0xcb, 0x39, 0x0f, 0x3b, 0x8d, 0xf0, 0x23, 0xf1, 0xe2, 0x1e, 0x9e, 0x91, - 0x90, 0x75, 0x6a, 0x0f, 0xe0, 0x09, 0x15, 0xf2, 0xaa, 0xc6, 0x38, 0x64, - 0x3d, 0x98, 0x50, 0x2f, 0x0e, 0x17, 0xb3, 0x48, 0x0d, 0x88, 0x69, 0x86, - 0xb7, 0x1b, 0x95, 0xc7, 0xe1, 0x5a, 0xbb, 0xda, 0xed, 0xf3, 0x02, 0x87, - 0xc1, 0x34, 0x80, 0x8c, 0x57, 0xfa, 0xcf, 0x93, 0x20, 0xa2, 0x25, 0x97, - 0x35, 0x23, 0x8a, 0x2a, 0xca, 0x7e, 0x03, 0xac, 0x66, 0x75, 0xab, 0x55, - 0xee, 0x33, 0x4a, 0xf9, 0xab, 0x6c, 0xdd, 0x4d, 0x78, 0x11, 0x4c, 0x51, - 0xba, 0x98, 0xf3, 0x34, 0xf5, 0xc2, 0x45, 0x4a, 0x09, 0x58, 0xbe, 0xcf, - 0x63, 0x56, 0x6c, 0xb0, 0x36, 0x21, 0xa9, 0x8f, 0xc6, 0x71, 0x1c, 0xea, - 0x2a, 0x20, 0x83, 0xaa, 0xac, 0x80, 0x90, 0xb5, 0xe9, 0x22, 0xf2, 0x91, - 0x35, 0x46, 0xe7, 0x5b, 0xf8, 0xd7, 0x44, 0xf9, 0x03, 0x43, 0xca, 0x6a, - 0x32, 0x77, 0x99, 0x23, 0x65, 0x7f, 0x13, 0x42, 0x17, 0x49, 0xc4, 0x49, - 0x24, 0x41, 0x95, 0x44, 0xd2, 0x2c, 0xe7, 0x91, 0x05, 0x69, 0x3f, 0x48, - 0x05, 0x7e, 0x22, 0xa2, 0x92, 0xbe, 0xdd, 0xfc, 0x93, 0xba, 0xc0, 0x3b, - 0x36, 0xc3, 0x08, 0x32, 0x68, 0x2e, 0x2a, 0x6e, 0x9e, 0x6d, 0x48, 0xb2, - 0x54, 0x9b, 0x95, 0x31, 0x2e, 0x47, 0x20, 0x80, 0x7d, 0x21, 0x9c, 0x5e, - 0x6c, 0x3d, 0xe1, 0x70, 0x41, 0xd0, 0x79, 0x96, 0xf1, 0x87, 0x35, 0x0e, - 0x30, 0x55, 0xa8, 0x11, 0x7c, 0x08, 0xa2, 0x49, 0x2d, 0xd6, 0x55, 0xb9, - 0x2c, 0xff, 0xd5, 0x41, 0xe3, 0x16, 0xfa, 0xc2, 0xf4, 0x76, 0x10, 0x57, - 0x6f, 0x64, 0x40, 0x9e, 0x87, 0x07, 0x9c, 0xba, 0x04, 0xc6, 0xf7, 0x04, - 0x27, 0x4b, 0x27, 0x9a, 0x90, 0xdf, 0x46, 0x82, 0xed, 0x16, 0x9e, 0xfd, - 0x53, 0x84, 0xb7, 0x21, 0x3a, 0xf0, 0x97, 0xcd, 0x5b, 0x86, 0x14, 0xf9, - 0xb9, 0x1a, 0x18, 0x6b, 0x67, 0xcf, 0x1a, 0xd3, 0x72, 0xc4, 0xda, 0x58, - 0x40, 0x06, 0xfd, 0x37, 0x00, 0x94, 0x1b, 0xa9, 0x43, 0xc9, 0x0c, 0xb4, - 0x70, 0x39, 0x13, 0xba, 0x3a, 0xd2, 0x54, 0x0b, 0x8d, 0x12, 0x32, 0x09, - 0x7c, 0x58, 0x21, 0x3a, 0xb9, 0xac, 0xfd, 0x73, 0xfd, 0x46, 0x27, 0xd1, - 0x06, 0x0e, 0xc9, 0x81, 0xd1, 0x8b, 0x17, 0x11, 0x0c, 0x76, 0x01, 0xe7, - 0xfe, 0xe9, 0xe8, 0xe1, 0xc8, 0x89, 0xfc, 0x84, 0xcc, 0x48, 0x44, 0x61, - 0x80, 0xb0, 0x79, 0xa2, 0x7e, 0x64, 0x80, 0x02, 0xb2, 0xc1, 0xe5, 0x30, - 0x25, 0xba, 0x33, 0xe5, 0x99, 0x6a, 0x84, 0x13, 0xca, 0x61, 0xaa, 0x9b, - 0xab, 0x8a, 0x2e, 0x51, 0x0c, 0x6b, 0x8a, 0x99, 0x7f, 0x4d, 0x53, 0xaf, - 0xdd, 0x23, 0xdf, 0x8f, 0x88, 0xb2, 0xed, 0x49, 0x48, 0xd9, 0x0e, 0x49, - 0x4c, 0x2d, 0x69, 0x87, 0x23, 0xa8, 0x6c, 0xc6, 0x9c, 0x69, 0xab, 0xc9, - 0xcb, 0x72, 0xb2, 0x26, 0xc8, 0x87, 0xe5, 0xb3, 0xb3, 0xb5, 0x12, 0xe2, - 0xb8, 0xf2, 0xb1, 0x8e, 0x56, 0xb0, 0xb2, 0xe0, 0x94, 0xf6, 0x62, 0xd8, - 0xe0, 0x44, 0x84, 0x2d, 0xd5, 0x8c, 0x84, 0x6c, 0xef, 0x71, 0x10, 0x4a, - 0x39, 0x91, 0xa0, 0x54, 0xbb, 0xdd, 0x3e, 0xb2, 0xaa, 0xcc, 0x2a, 0x27, - 0x3a, 0x10, 0xab, 0x6a, 0xdf, 0x6e, 0xde, 0x12, 0xed, 0xc9, 0x4c, 0xa1, - 0xf1, 0x2e, 0xa0, 0x0f, 0x75, 0xbb, 0x1c, 0x0d, 0xa1, 0x71, 0x5b, 0xdd, - 0x18, 0x19, 0x18, 0xba, 0xa7, 0x47, 0x97, 0xb0, 0xaf, 0x5b, 0x0f, 0x92, - 0xdc, 0x3b, 0x2e, 0xfc, 0xec, 0x68, 0xd9, 0x82, 0x52, 0x6c, 0xcf, 0xd8, - 0xe1, 0xd3, 0x7d, 0x35, 0x2b, 0x7b, 0x3b, 0xee, 0xa4, 0xcc, 0x75, 0xc2, - 0x79, 0x52, 0xbf, 0xe4, 0x94, 0x90, 0x64, 0xfe, 0x6c, 0xe3, 0xc8, 0x71, - 0xed, 0xf8, 0x93, 0xd7, 0x8e, 0xe3, 0x9c, 0x8d, 0xfe, 0x5d, 0xd9, 0x3c, - 0xd8, 0x9c, 0xbd, 0x7b, 0x5a, 0xae, 0xe8, 0xbe, 0x23, 0xec, 0x00, 0xf9, - 0x38, 0x74, 0x2e, 0x5e, 0x9a, 0x87, 0x2b, 0xba, 0x21, 0x0f, 0x7b, 0x23, - 0x4d, 0x8e, 0x48, 0x17, 0x48, 0x93, 0x57, 0x44, 0xba, 0x7f, 0xe4, 0x74, - 0x81, 0x74, 0xff, 0x35, 0x39, 0xdd, 0x3f, 0x72, 0x5a, 0x41, 0x7a, 0x7b, - 0x4e, 0x57, 0x67, 0x6f, 0x6d, 0x75, 0x96, 0x75, 0x5f, 0xfe, 0x43, 0x56, - 0x30, 0x55, 0x44, 0x44, 0xbd, 0x52, 0x41, 0x75, 0xfb, 0x9a, 0x6c, 0x2e, - 0x6d, 0x2e, 0xc2, 0x82, 0xe6, 0x6a, 0x2e, 0x15, 0x1b, 0xb9, 0x5b, 0x79, - 0x44, 0x3b, 0x96, 0x82, 0x73, 0x6a, 0xa5, 0x39, 0xb5, 0xd4, 0x58, 0x9a, - 0x1b, 0xbc, 0xe1, 0xe9, 0xb2, 0x9a, 0x06, 0xa7, 0xcc, 0xf5, 0xb8, 0xb4, - 0x5d, 0xaf, 0xab, 0x51, 0x4e, 0xc6, 0xb3, 0x18, 0x5f, 0x92, 0xe9, 0xfe, - 0x30, 0xd3, 0xf8, 0x76, 0x3e, 0x27, 0x89, 0x86, 0x70, 0xce, 0xc6, 0xa2, - 0xf2, 0xaa, 0x6d, 0xb3, 0x0c, 0x38, 0x73, 0xf4, 0x18, 0x09, 0x35, 0x27, - 0xad, 0x00, 0x0e, 0x24, 0xe8, 0xfc, 0x3e, 0x06, 0x0e, 0xb6, 0x1d, 0x78, - 0x6e, 0x22, 0xeb, 0xdb, 0x77, 0x4d, 0xa8, 0x85, 0x48, 0x92, 0xc4, 0xf0, - 0xa9, 0x88, 0x03, 0x27, 0x09, 0x5e, 0x32, 0xe7, 0x67, 0x00, 0x96, 0xa9, - 0xc7, 0xfb, 0xe2, 0x2c, 0x05, 0x9d, 0x99, 0xe4, 0xdf, 0x78, 0x6e, 0x32, - 0xde, 0xe2, 0xbe, 0x59, 0xb4, 0x9a, 0x56, 0x8b, 0x9d, 0x39, 0x0c, 0xb6, - 0x0b, 0xfb, 0x17, 0x08, 0x03, 0x3a, 0xd1, 0xc4, 0xe2, 0x3f, 0x5b, 0x88, - 0x36, 0x4d, 0x49, 0x65, 0x07, 0xa4, 0x16, 0x8a, 0x82, 0xa2, 0xb4, 0xbe, - 0x2a, 0xe4, 0x84, 0x8c, 0x50, 0x00, 0xb6, 0x2a, 0xa8, 0xd5, 0xf8, 0xad, - 0x82, 0xd6, 0x42, 0x3e, 0x0e, 0xc3, 0x31, 0xf6, 0x1f, 0xb7, 0x0b, 0xa6, - 0x99, 0xff, 0x55, 0x62, 0xca, 0x33, 0xca, 0xaf, 0x95, 0x98, 0x72, 0xc9, - 0x07, 0xe5, 0x44, 0x9a, 0xc4, 0xbf, 0x14, 0xbc, 0x03, 0x56, 0x5e, 0x9c, - 0x62, 0x9f, 0x64, 0x80, 0x75, 0x48, 0x22, 0x4b, 0x28, 0x68, 0x36, 0x95, - 0x82, 0x76, 0xc9, 0x02, 0xa7, 0x29, 0xd3, 0xa0, 0xb9, 0x96, 0xe9, 0x55, - 0x7b, 0xe8, 0x15, 0x30, 0xb9, 0xf7, 0xff, 0x87, 0xbf, 0x7f, 0x95, 0x94, - 0xc3, 0x9b, 0xb7, 0x6f, 0x0d, 0x53, 0x71, 0xfa, 0x2b, 0xa0, 0xfe, 0x83, - 0x0c, 0xe2, 0x5b, 0xf0, 0x3d, 0xbf, 0x91, 0xa9, 0x0a, 0xee, 0x46, 0xff, - 0x35, 0x38, 0xec, 0xda, 0x4f, 0xbb, 0x96, 0xe8, 0x30, 0x40, 0xc0, 0x12, - 0x70, 0xe0, 0x8c, 0x6e, 0x33, 0x6a, 0x0b, 0x17, 0x8a, 0xc1, 0xa1, 0xb6, - 0x09, 0x99, 0xe2, 0x45, 0x48, 0x3b, 0x46, 0x0f, 0xc2, 0xf8, 0xbe, 0xfd, - 0x11, 0x53, 0x1c, 0x5a, 0x27, 0x8b, 0xe8, 0x01, 0x47, 0x93, 0x90, 0x4c, - 0x44, 0xb8, 0x1d, 0x74, 0xd2, 0xd2, 0x23, 0x37, 0xd5, 0x11, 0xea, 0x7f, - 0xc1, 0xe1, 0xe9, 0x0d, 0x4f, 0xba, 0xeb, 0xe3, 0xc8, 0x82, 0xb0, 0xe0, - 0x8c, 0xa3, 0xf3, 0x9d, 0xb5, 0x71, 0x42, 0xf0, 0x63, 0xdd, 0x85, 0x06, - 0x6b, 0xf0, 0x7d, 0x32, 0x20, 0xbf, 0x69, 0x4b, 0x0e, 0x39, 0xc9, 0x4a, - 0x4b, 0x1b, 0x18, 0x60, 0x91, 0x49, 0xbc, 0xb9, 0x60, 0xa3, 0xa2, 0xbe, - 0x90, 0x2c, 0x47, 0x43, 0xbd, 0xdb, 0xd2, 0x62, 0xbd, 0x0e, 0x75, 0xd8, - 0x95, 0x75, 0x28, 0xce, 0x6b, 0xb2, 0xc5, 0xb5, 0x62, 0xb5, 0x98, 0xfe, - 0x11, 0xcf, 0x82, 0x70, 0xa9, 0xcf, 0x78, 0xb5, 0x8b, 0x03, 0x9b, 0x84, - 0x59, 0x2d, 0x43, 0xe8, 0xe0, 0xf7, 0x96, 0xe6, 0x6a, 0x86, 0xa9, 0x78, - 0x2e, 0x67, 0x7a, 0x5e, 0x34, 0xdf, 0xde, 0x9c, 0x2b, 0xea, 0x5b, 0xb7, - 0xf3, 0x94, 0x24, 0x35, 0xf5, 0xfa, 0xcd, 0xe6, 0x94, 0xb5, 0xfc, 0x19, - 0x5b, 0x3c, 0xa2, 0xba, 0x5b, 0x3d, 0xf5, 0x46, 0x6f, 0x5a, 0xba, 0xd0, - 0xdb, 0x4e, 0xb9, 0xbc, 0xb1, 0x7e, 0x46, 0xb7, 0xbc, 0xf0, 0xde, 0x4d, - 0x39, 0x5b, 0x8d, 0xac, 0xa7, 0xea, 0x4c, 0xc9, 0x77, 0x43, 0x3c, 0xac, - 0xea, 0xd5, 0x99, 0x2f, 0xae, 0xde, 0xbf, 0x7d, 0x37, 0xec, 0xd5, 0x5e, - 0xbc, 0xc8, 0xbe, 0xe8, 0x8e, 0x59, 0x76, 0x3d, 0xd0, 0x3d, 0x33, 0x8f, - 0xae, 0x7e, 0xff, 0xb9, 0xdd, 0x6d, 0x67, 0xb1, 0x3f, 0xdd, 0x30, 0x23, - 0xae, 0x5a, 0xc6, 0x8d, 0x42, 0x41, 0x40, 0x25, 0xbb, 0x95, 0x5c, 0x64, - 0xfc, 0x07, 0xf7, 0x47, 0x4f, 0x29, 0x33, 0x2f, 0x10, 0xe6, 0xfb, 0xe5, - 0xb4, 0xba, 0x01, 0xd9, 0x40, 0xe3, 0x18, 0xa8, 0x70, 0x7e, 0xe4, 0xc2, - 0x2b, 0x70, 0xe1, 0xec, 0x8f, 0x23, 0x43, 0xde, 0x11, 0x9e, 0x83, 0x88, - 0x9f, 0x9e, 0x60, 0x1b, 0x54, 0xce, 0x72, 0x75, 0x1a, 0x2a, 0x7d, 0xd6, - 0xff, 0x0d, 0x63, 0xd7, 0x3d, 0xc7, 0x1e, 0x2c, 0x78, 0x05, 0x26, 0xb0, - 0xb6, 0x65, 0xca, 0xb5, 0xb8, 0x4d, 0xf9, 0x54, 0x33, 0xa0, 0x81, 0xcf, - 0xb3, 0x09, 0xa8, 0x03, 0xda, 0xfa, 0x48, 0x64, 0x79, 0xa9, 0x60, 0x6e, - 0x4a, 0xfb, 0x7f, 0x0e, 0x79, 0xf3, 0x11, 0x6c, 0xeb, 0x41, 0xb8, 0x7d, - 0x46, 0xf2, 0xdd, 0xce, 0xfa, 0xff, 0xcb, 0x14, 0xb1, 0x27, 0x9c, 0x94, - 0xdc, 0x90, 0x2b, 0x39, 0xaa, 0xec, 0xe5, 0x8b, 0x0c, 0x9a, 0x76, 0x12, - 0x7f, 0xd2, 0xbf, 0x5d, 0xad, 0x67, 0x88, 0x2a, 0xc7, 0x9a, 0x06, 0xf7, - 0x24, 0xe2, 0xfc, 0xa8, 0x6f, 0x3e, 0x1d, 0x9b, 0xf7, 0x5f, 0x3b, 0xfe, - 0x17, 0x91, 0x76, 0xf4, 0x17, 0x0f, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, - 0x96, 0x1d, 0x87, 0x6d, 0xc8, 0x29, 0x00, 0x00, - }, - "generator/tmpl/binding.tmpl", - ) -} - -// Asset loads and returns the asset for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - return f() - } - return nil, fmt.Errorf("Asset %s not found", name) -} - -// AssetNames returns the names of the assets. -func AssetNames() []string { - names := make([]string, 0, len(_bindata)) - for name := range _bindata { - names = append(names, name) - } - return names -} - -// _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() ([]byte, error){ - "generator/tmpl/binding.tmpl": generator_tmpl_binding_tmpl, -} - -// AssetDir returns the file names below a certain -// directory embedded in the file by go-bindata. -// For example if you run go-bindata on data/... and data contains the -// following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error -// AssetDir("") will return []string{"data"}. -func AssetDir(name string) ([]string, error) { - node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - } - } - if node.Func != nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - rv := make([]string, 0, len(node.Children)) - for name := range node.Children { - rv = append(rv, name) - } - return rv, nil -} - -type _bintree_t struct { - Func func() ([]byte, error) - Children map[string]*_bintree_t -} - -var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ - "generator": &_bintree_t{nil, map[string]*_bintree_t{ - "tmpl": &_bintree_t{nil, map[string]*_bintree_t{ - "binding.tmpl": &_bintree_t{generator_tmpl_binding_tmpl, map[string]*_bintree_t{}}, - }}, - }}, -}} diff --git a/generator/template.go b/generator/template.go index ad40baa..ca09a16 100644 --- a/generator/template.go +++ b/generator/template.go @@ -3,10 +3,11 @@ package generator import ( "bytes" "fmt" - "github.com/gocql/gocql" "regexp" "strings" "text/template" + + "github.com/gocql/gocql" ) var bindingTemplate *template.Template @@ -27,8 +28,7 @@ func init() { "isLastComponent": isLastComponent, "isCounterColumnFamily": isCounterColumnFamily, } - temp, _ := generator_tmpl_binding_tmpl() - bindingTemplate = template.Must(template.New("binding.tmpl").Funcs(m).Parse(string(temp))) + bindingTemplate = template.Must(template.New("binding.tmpl").Funcs(m).Parse(Tmpl)) } // TODO This is metadata specific to the column family that should be cached at compilation diff --git a/generator/tmpl/binding.tmpl b/generator/tmpl.go similarity index 98% rename from generator/tmpl/binding.tmpl rename to generator/tmpl.go index 2666562..702e6db 100644 --- a/generator/tmpl/binding.tmpl +++ b/generator/tmpl.go @@ -1,4 +1,6 @@ -// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +package generator + +const Tmpl = `// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED // GENERATED USING KEYSPACE {{ .Provenance.Keyspace }} // AT {{ .Provenance.Timestamp }} USING cqlc VERSION {{ .Provenance.Version }} // AGAINST HOST ID {{ .Provenance.HostId }} (SERVER VERSION {{ .Provenance.ServerRelease }}) @@ -265,4 +267,5 @@ const ( } {{end}} -{{end}} \ No newline at end of file +{{end}} +` diff --git a/main.go b/main.go index 4e85b07..203d8c4 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,17 @@ package main import ( - "fmt" - "github.com/jessevdk/go-flags" - "github.com/relops/cqlc/generator" "log" "os" + + "github.com/jessevdk/go-flags" + "github.com/relops/cqlc/generator" ) var opts generator.Options var parser = flags.NewParser(&opts, flags.Default) -var VERSION string = "0.10.5" +var Version = "0.10.5" func init() { opts.Version = printVersionAndExit @@ -23,7 +23,7 @@ func main() { os.Exit(1) } - if err := generator.Generate(&opts, VERSION); err != nil { + if err := generator.Generate(&opts, Version); err != nil { if err == generator.ErrInvalidOptions { parser.WriteHelp(os.Stderr) os.Exit(1) @@ -34,6 +34,6 @@ func main() { } func printVersionAndExit() { - fmt.Fprintf(os.Stderr, "%s %s\n", "cqlc", VERSION) + os.Stdout.Write([]byte(Version + "\n")) os.Exit(0) } From d52409007bffc0cc7fe0463ba385ca7454cdb946 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 22:37:55 -0700 Subject: [PATCH 06/39] [test] Install glide to $GOPATH/bin - when use /usr/local/bin got permission denied ... --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 65abe55..be5c4a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,19 +11,19 @@ matrix: env: global: + # TODO: why need this? - GOMAXPROCS=2 matrix: - - CASS=2.2.13 +# - CASS=2.2.13 - CASS=3.11 go: - "1.10" - - "1.11" - - "tip" +# - "1.11" +# - "tip" before_install: - - curl -sSL https://github.com/Masterminds/glide/releases/download/v0.13.1/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C /usr/local/bin --strip=1 - - export PATH=$PATH:/home/travis/gopath/bin + - curl -sSL https://github.com/Masterminds/glide/releases/download/v0.13.1/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C ${GOPATH}/bin --strip=1 install: - pip install --user PyYAML six From 2a3fdb17d68c93bcf05d62088e52ab47bb28ee61 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 22:47:59 -0700 Subject: [PATCH 07/39] [test] Move project to right go path - it should be using relops/cqlc, but default travis will be using pingginp/cqlc, that's the problem of enable travis on fork --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index be5c4a8..e29c425 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,10 @@ go: before_install: - curl -sSL https://github.com/Masterminds/glide/releases/download/v0.13.1/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C ${GOPATH}/bin --strip=1 +# FIXME: workaround for gopath + - mkdir -p ${GOPATH}/src/github.com/relops/cqlc + - cp -r ./. ${GOPATH}/src/github.com/relops/cqlc + - cd ${GOPATH}/src/github.com/relops/cqlc install: - pip install --user PyYAML six From 38ead156a6c24c46776ad33ca3c020a55f3cd586 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 22:59:09 -0700 Subject: [PATCH 08/39] [test] Use C* 2.2.1 - it seems 3.11 is invalid for ccm --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e29c425..027f0d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,8 @@ env: # TODO: why need this? - GOMAXPROCS=2 matrix: -# - CASS=2.2.13 - - CASS=3.11 + - CASS=2.2.1 +# - CASS=3.11 go: - "1.10" From c65af037f9a0eac9662404f34c5bbc23a17881ce Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 23:10:31 -0700 Subject: [PATCH 09/39] [test] Remove bindata rule from test deps --- Makefile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 81e24fd..2a6c81d 100644 --- a/Makefile +++ b/Makefile @@ -27,14 +27,9 @@ cqlc/columns.go: cqlc/tmpl/columns.tmpl cqlc/column_generator.go columns: cqlc/columns.go -bindata: generator/binding_tmpl.go - input: test/.fixtures/collections/input.go test/collections.cql -generator/binding_tmpl.go: generator/tmpl/binding.tmpl - go-bindata -pkg=generator -o=generator/binding_tmpl.go generator/tmpl - -test: columns bindata schema test/.fixtures/collections/input.go +test: columns schema test/.fixtures/collections/input.go go test -v ./... format: From e10a96c068926d62bd10ccc6aab0bbf3304b6bfc Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 23:19:59 -0700 Subject: [PATCH 10/39] Fix Printf format error - see https://travis-ci.org/pingginp/cqlc/builds/428905343 --- cqlc/cqlc.go | 4 ++-- generator/generator.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index 055873d..a78aa93 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -382,7 +382,7 @@ func (c *Context) FetchOne(s *gocql.Session) (bool, error) { if !ok { row[i] = cols[i].TypeInfo.New() if c.Debug && row[i] == nil { - log.Printf("Could not map type info: %+v", cols[i].TypeInfo.Type) + log.Printf("Could not map type info: %+v", cols[i].TypeInfo.Type()) } } else { row[i] = binding.Value @@ -581,7 +581,7 @@ func (c *Context) RenderCQL() (string, error) { renderDelete(c, &buf) } default: - return "", fmt.Errorf("Unknown operation type: %s", c.Operation) + return "", fmt.Errorf("Unknown operation type: %v", c.Operation) } return buf.String(), nil diff --git a/generator/generator.go b/generator/generator.go index 0980189..8be7e2e 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -106,7 +106,7 @@ func generateBinding(opts *Options, version string, w io.Writer) error { s, err := cluster.CreateSession() if err != nil { - return fmt.Errorf("Connect error", err) + return fmt.Errorf("Connect error %s", err) } defer s.Close() @@ -116,12 +116,12 @@ func generateBinding(opts *Options, version string, w io.Writer) error { err = s.Query(`SELECT native_protocol_version, release_version, cql_version, host_id FROM system.local`).Scan(&protoString, &release, &cqlVersion, &hostId) if err != nil { - return fmt.Errorf("System metadata error", err) + return fmt.Errorf("System metadata error %s", err) } proto, err := strconv.Atoi(protoString) if err != nil { - return fmt.Errorf("Could not parse protocol version", err) + return fmt.Errorf("Could not parse protocol version %s", err) } if proto > 3 { @@ -130,7 +130,7 @@ func generateBinding(opts *Options, version string, w io.Writer) error { s, err = cluster.CreateSession() if err != nil { - return fmt.Errorf("Re-connect error", err) + return fmt.Errorf("Re-connect error %s", err) } } From 9d2aff5019b0e689563375946b19778e0a0a727d Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 23:33:06 -0700 Subject: [PATCH 11/39] [test] go get github.com/gocql/cql for generator - generator generates files in /tmp for testing, so need global gocql in $GOPATH to work ... --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 027f0d9..a7cda3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,8 @@ go: # - "tip" before_install: + # NOTE: needed for generator test, it generate file like /tmp/092804891/binding.go https://travis-ci.org/pingginp/cqlc/builds/428906675 + - go get github.com/gocql/gocql - curl -sSL https://github.com/Masterminds/glide/releases/download/v0.13.1/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C ${GOPATH}/bin --strip=1 # FIXME: workaround for gopath - mkdir -p ${GOPATH}/src/github.com/relops/cqlc From eca906ab8e150f1cca2476d686e60dd63fd40191 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Fri, 14 Sep 2018 23:47:20 -0700 Subject: [PATCH 12/39] [test] Only test cqlc, remove generator - generator was comparing type, and due to use vendor and global go path, there will be type mismatch https://travis-ci.org/pingginp/cqlc/builds/428908553 --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2a6c81d..56065df 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,9 @@ columns: cqlc/columns.go input: test/.fixtures/collections/input.go test/collections.cql +# FIXME: generator won't work due to go vendor ... inspect type does not equal test: columns schema test/.fixtures/collections/input.go - go test -v ./... + go test -v ./cqlc format: gofmt -w cqlc generator integration test From 69de726dbe7cdefc1ebb4dcb2626c7d246deb3ed Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 00:36:07 -0700 Subject: [PATCH 13/39] [gen] Add set map value by key #2 - only support `col[?] = ?`, value binding should work, because there was `WHERE foo in (?,?,?)` so in `Prepare` cqlc would flat the slice before passing to gocql - https://github.com/pingginp/cqlc/issues/2 - [ ] TODO: need to test against a real database to see if it works --- Makefile | 3 + README.md | 56 +++ cqlc/columns.go | 792 +++++++++++++++++++++++++++++++++++++++++ cqlc/cqlc.go | 8 +- cqlc/cqlc_test.go | 10 + cqlc/render.go | 14 + cqlc/tmpl/columns.tmpl | 10 + 7 files changed, 892 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 56065df..8a95d49 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,9 @@ input: test/.fixtures/collections/input.go test/collections.cql test: columns schema test/.fixtures/collections/input.go go test -v ./cqlc +test-unit: + go test -v ./cqlc + format: gofmt -w cqlc generator integration test diff --git a/README.md b/README.md index 2c3dd57..33fb142 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,60 @@ make build ````bash # generate columns make cqlc/columns.go +```` + +````go +func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) { + stmt, err := c.RenderCQL() +} + +// cqlc.go +func (c *Context) RenderCQL() (string, error) { + switch c.Operation { + case ReadOperation: + renderSelect(c, &buf) + case WriteOperation: + if c.hasConditions() { + renderUpdate(c, &buf, false) + } else { + renderInsert(c, &buf) + } + renderCAS(c, &buf) + case CounterOperation: + renderUpdate(c, &buf, true) + case DeleteOperation: + renderDelete(c, &buf) + default: + return "", fmt.Errorf("Unknown operation type: %v", c.Operation) + } +} + +// render.go +func renderUpdate(ctx *Context, buf *bytes.Buffer, counterTable bool) { + for i, binding := range ctx.Bindings { + col := binding.Column.ColumnName() + if counterTable { + setFragments[i] = fmt.Sprintf("%s = %s + ?", col, col) + } else { + switch binding.CollectionType { + case ListType: + switch binding.CollectionOperationType { + case Append: + setFragments[i] = fmt.Sprintf("%s = %s + ?", col, col) + case Prepend: + setFragments[i] = fmt.Sprintf("%s = ? + %s", col, col) + case RemoveByValue: + setFragments[i] = fmt.Sprintf("%s = %s - ?", col, col) + } + case MapType: + switch binding.CollectionOperationType { + case SetByKey: + setFragments[i] = fmt.Sprintf("%s[?] = ?", col) + } + default: + setFragments[i] = fmt.Sprintf("%s = ?", col) + } + } + } +} ```` \ No newline at end of file diff --git a/cqlc/columns.go b/cqlc/columns.go index efe16e7..8d0f260 100755 --- a/cqlc/columns.go +++ b/cqlc/columns.go @@ -1037,268 +1037,400 @@ type SetValueStep interface { SetBytes(col BytesColumn, value []byte) SetValueStep SetStringStringMap(col StringStringMapColumn, value map[string]string) SetValueStep + SetStringStringMapValue(col StringStringMapColumn, key string, value string) SetValueStep SetStringInt32Map(col StringInt32MapColumn, value map[string]int32) SetValueStep + SetStringInt32MapValue(col StringInt32MapColumn, key string, value int32) SetValueStep SetStringInt64Map(col StringInt64MapColumn, value map[string]int64) SetValueStep + SetStringInt64MapValue(col StringInt64MapColumn, key string, value int64) SetValueStep SetStringFloat32Map(col StringFloat32MapColumn, value map[string]float32) SetValueStep + SetStringFloat32MapValue(col StringFloat32MapColumn, key string, value float32) SetValueStep SetStringFloat64Map(col StringFloat64MapColumn, value map[string]float64) SetValueStep + SetStringFloat64MapValue(col StringFloat64MapColumn, key string, value float64) SetValueStep SetStringTimestampMap(col StringTimestampMapColumn, value map[string]time.Time) SetValueStep + SetStringTimestampMapValue(col StringTimestampMapColumn, key string, value time.Time) SetValueStep SetStringTimeUUIDMap(col StringTimeUUIDMapColumn, value map[string]gocql.UUID) SetValueStep + SetStringTimeUUIDMapValue(col StringTimeUUIDMapColumn, key string, value gocql.UUID) SetValueStep SetStringUUIDMap(col StringUUIDMapColumn, value map[string]gocql.UUID) SetValueStep + SetStringUUIDMapValue(col StringUUIDMapColumn, key string, value gocql.UUID) SetValueStep SetStringBooleanMap(col StringBooleanMapColumn, value map[string]bool) SetValueStep + SetStringBooleanMapValue(col StringBooleanMapColumn, key string, value bool) SetValueStep SetStringDecimalMap(col StringDecimalMapColumn, value map[string]*inf.Dec) SetValueStep + SetStringDecimalMapValue(col StringDecimalMapColumn, key string, value *inf.Dec) SetValueStep SetStringVarintMap(col StringVarintMapColumn, value map[string]*big.Int) SetValueStep + SetStringVarintMapValue(col StringVarintMapColumn, key string, value *big.Int) SetValueStep SetStringBytesMap(col StringBytesMapColumn, value map[string][]byte) SetValueStep + SetStringBytesMapValue(col StringBytesMapColumn, key string, value []byte) SetValueStep SetInt32StringMap(col Int32StringMapColumn, value map[int32]string) SetValueStep + SetInt32StringMapValue(col Int32StringMapColumn, key int32, value string) SetValueStep SetInt32Int32Map(col Int32Int32MapColumn, value map[int32]int32) SetValueStep + SetInt32Int32MapValue(col Int32Int32MapColumn, key int32, value int32) SetValueStep SetInt32Int64Map(col Int32Int64MapColumn, value map[int32]int64) SetValueStep + SetInt32Int64MapValue(col Int32Int64MapColumn, key int32, value int64) SetValueStep SetInt32Float32Map(col Int32Float32MapColumn, value map[int32]float32) SetValueStep + SetInt32Float32MapValue(col Int32Float32MapColumn, key int32, value float32) SetValueStep SetInt32Float64Map(col Int32Float64MapColumn, value map[int32]float64) SetValueStep + SetInt32Float64MapValue(col Int32Float64MapColumn, key int32, value float64) SetValueStep SetInt32TimestampMap(col Int32TimestampMapColumn, value map[int32]time.Time) SetValueStep + SetInt32TimestampMapValue(col Int32TimestampMapColumn, key int32, value time.Time) SetValueStep SetInt32TimeUUIDMap(col Int32TimeUUIDMapColumn, value map[int32]gocql.UUID) SetValueStep + SetInt32TimeUUIDMapValue(col Int32TimeUUIDMapColumn, key int32, value gocql.UUID) SetValueStep SetInt32UUIDMap(col Int32UUIDMapColumn, value map[int32]gocql.UUID) SetValueStep + SetInt32UUIDMapValue(col Int32UUIDMapColumn, key int32, value gocql.UUID) SetValueStep SetInt32BooleanMap(col Int32BooleanMapColumn, value map[int32]bool) SetValueStep + SetInt32BooleanMapValue(col Int32BooleanMapColumn, key int32, value bool) SetValueStep SetInt32DecimalMap(col Int32DecimalMapColumn, value map[int32]*inf.Dec) SetValueStep + SetInt32DecimalMapValue(col Int32DecimalMapColumn, key int32, value *inf.Dec) SetValueStep SetInt32VarintMap(col Int32VarintMapColumn, value map[int32]*big.Int) SetValueStep + SetInt32VarintMapValue(col Int32VarintMapColumn, key int32, value *big.Int) SetValueStep SetInt32BytesMap(col Int32BytesMapColumn, value map[int32][]byte) SetValueStep + SetInt32BytesMapValue(col Int32BytesMapColumn, key int32, value []byte) SetValueStep SetInt64StringMap(col Int64StringMapColumn, value map[int64]string) SetValueStep + SetInt64StringMapValue(col Int64StringMapColumn, key int64, value string) SetValueStep SetInt64Int32Map(col Int64Int32MapColumn, value map[int64]int32) SetValueStep + SetInt64Int32MapValue(col Int64Int32MapColumn, key int64, value int32) SetValueStep SetInt64Int64Map(col Int64Int64MapColumn, value map[int64]int64) SetValueStep + SetInt64Int64MapValue(col Int64Int64MapColumn, key int64, value int64) SetValueStep SetInt64Float32Map(col Int64Float32MapColumn, value map[int64]float32) SetValueStep + SetInt64Float32MapValue(col Int64Float32MapColumn, key int64, value float32) SetValueStep SetInt64Float64Map(col Int64Float64MapColumn, value map[int64]float64) SetValueStep + SetInt64Float64MapValue(col Int64Float64MapColumn, key int64, value float64) SetValueStep SetInt64TimestampMap(col Int64TimestampMapColumn, value map[int64]time.Time) SetValueStep + SetInt64TimestampMapValue(col Int64TimestampMapColumn, key int64, value time.Time) SetValueStep SetInt64TimeUUIDMap(col Int64TimeUUIDMapColumn, value map[int64]gocql.UUID) SetValueStep + SetInt64TimeUUIDMapValue(col Int64TimeUUIDMapColumn, key int64, value gocql.UUID) SetValueStep SetInt64UUIDMap(col Int64UUIDMapColumn, value map[int64]gocql.UUID) SetValueStep + SetInt64UUIDMapValue(col Int64UUIDMapColumn, key int64, value gocql.UUID) SetValueStep SetInt64BooleanMap(col Int64BooleanMapColumn, value map[int64]bool) SetValueStep + SetInt64BooleanMapValue(col Int64BooleanMapColumn, key int64, value bool) SetValueStep SetInt64DecimalMap(col Int64DecimalMapColumn, value map[int64]*inf.Dec) SetValueStep + SetInt64DecimalMapValue(col Int64DecimalMapColumn, key int64, value *inf.Dec) SetValueStep SetInt64VarintMap(col Int64VarintMapColumn, value map[int64]*big.Int) SetValueStep + SetInt64VarintMapValue(col Int64VarintMapColumn, key int64, value *big.Int) SetValueStep SetInt64BytesMap(col Int64BytesMapColumn, value map[int64][]byte) SetValueStep + SetInt64BytesMapValue(col Int64BytesMapColumn, key int64, value []byte) SetValueStep SetFloat32StringMap(col Float32StringMapColumn, value map[float32]string) SetValueStep + SetFloat32StringMapValue(col Float32StringMapColumn, key float32, value string) SetValueStep SetFloat32Int32Map(col Float32Int32MapColumn, value map[float32]int32) SetValueStep + SetFloat32Int32MapValue(col Float32Int32MapColumn, key float32, value int32) SetValueStep SetFloat32Int64Map(col Float32Int64MapColumn, value map[float32]int64) SetValueStep + SetFloat32Int64MapValue(col Float32Int64MapColumn, key float32, value int64) SetValueStep SetFloat32Float32Map(col Float32Float32MapColumn, value map[float32]float32) SetValueStep + SetFloat32Float32MapValue(col Float32Float32MapColumn, key float32, value float32) SetValueStep SetFloat32Float64Map(col Float32Float64MapColumn, value map[float32]float64) SetValueStep + SetFloat32Float64MapValue(col Float32Float64MapColumn, key float32, value float64) SetValueStep SetFloat32TimestampMap(col Float32TimestampMapColumn, value map[float32]time.Time) SetValueStep + SetFloat32TimestampMapValue(col Float32TimestampMapColumn, key float32, value time.Time) SetValueStep SetFloat32TimeUUIDMap(col Float32TimeUUIDMapColumn, value map[float32]gocql.UUID) SetValueStep + SetFloat32TimeUUIDMapValue(col Float32TimeUUIDMapColumn, key float32, value gocql.UUID) SetValueStep SetFloat32UUIDMap(col Float32UUIDMapColumn, value map[float32]gocql.UUID) SetValueStep + SetFloat32UUIDMapValue(col Float32UUIDMapColumn, key float32, value gocql.UUID) SetValueStep SetFloat32BooleanMap(col Float32BooleanMapColumn, value map[float32]bool) SetValueStep + SetFloat32BooleanMapValue(col Float32BooleanMapColumn, key float32, value bool) SetValueStep SetFloat32DecimalMap(col Float32DecimalMapColumn, value map[float32]*inf.Dec) SetValueStep + SetFloat32DecimalMapValue(col Float32DecimalMapColumn, key float32, value *inf.Dec) SetValueStep SetFloat32VarintMap(col Float32VarintMapColumn, value map[float32]*big.Int) SetValueStep + SetFloat32VarintMapValue(col Float32VarintMapColumn, key float32, value *big.Int) SetValueStep SetFloat32BytesMap(col Float32BytesMapColumn, value map[float32][]byte) SetValueStep + SetFloat32BytesMapValue(col Float32BytesMapColumn, key float32, value []byte) SetValueStep SetFloat64StringMap(col Float64StringMapColumn, value map[float64]string) SetValueStep + SetFloat64StringMapValue(col Float64StringMapColumn, key float64, value string) SetValueStep SetFloat64Int32Map(col Float64Int32MapColumn, value map[float64]int32) SetValueStep + SetFloat64Int32MapValue(col Float64Int32MapColumn, key float64, value int32) SetValueStep SetFloat64Int64Map(col Float64Int64MapColumn, value map[float64]int64) SetValueStep + SetFloat64Int64MapValue(col Float64Int64MapColumn, key float64, value int64) SetValueStep SetFloat64Float32Map(col Float64Float32MapColumn, value map[float64]float32) SetValueStep + SetFloat64Float32MapValue(col Float64Float32MapColumn, key float64, value float32) SetValueStep SetFloat64Float64Map(col Float64Float64MapColumn, value map[float64]float64) SetValueStep + SetFloat64Float64MapValue(col Float64Float64MapColumn, key float64, value float64) SetValueStep SetFloat64TimestampMap(col Float64TimestampMapColumn, value map[float64]time.Time) SetValueStep + SetFloat64TimestampMapValue(col Float64TimestampMapColumn, key float64, value time.Time) SetValueStep SetFloat64TimeUUIDMap(col Float64TimeUUIDMapColumn, value map[float64]gocql.UUID) SetValueStep + SetFloat64TimeUUIDMapValue(col Float64TimeUUIDMapColumn, key float64, value gocql.UUID) SetValueStep SetFloat64UUIDMap(col Float64UUIDMapColumn, value map[float64]gocql.UUID) SetValueStep + SetFloat64UUIDMapValue(col Float64UUIDMapColumn, key float64, value gocql.UUID) SetValueStep SetFloat64BooleanMap(col Float64BooleanMapColumn, value map[float64]bool) SetValueStep + SetFloat64BooleanMapValue(col Float64BooleanMapColumn, key float64, value bool) SetValueStep SetFloat64DecimalMap(col Float64DecimalMapColumn, value map[float64]*inf.Dec) SetValueStep + SetFloat64DecimalMapValue(col Float64DecimalMapColumn, key float64, value *inf.Dec) SetValueStep SetFloat64VarintMap(col Float64VarintMapColumn, value map[float64]*big.Int) SetValueStep + SetFloat64VarintMapValue(col Float64VarintMapColumn, key float64, value *big.Int) SetValueStep SetFloat64BytesMap(col Float64BytesMapColumn, value map[float64][]byte) SetValueStep + SetFloat64BytesMapValue(col Float64BytesMapColumn, key float64, value []byte) SetValueStep SetTimestampStringMap(col TimestampStringMapColumn, value map[time.Time]string) SetValueStep + SetTimestampStringMapValue(col TimestampStringMapColumn, key time.Time, value string) SetValueStep SetTimestampInt32Map(col TimestampInt32MapColumn, value map[time.Time]int32) SetValueStep + SetTimestampInt32MapValue(col TimestampInt32MapColumn, key time.Time, value int32) SetValueStep SetTimestampInt64Map(col TimestampInt64MapColumn, value map[time.Time]int64) SetValueStep + SetTimestampInt64MapValue(col TimestampInt64MapColumn, key time.Time, value int64) SetValueStep SetTimestampFloat32Map(col TimestampFloat32MapColumn, value map[time.Time]float32) SetValueStep + SetTimestampFloat32MapValue(col TimestampFloat32MapColumn, key time.Time, value float32) SetValueStep SetTimestampFloat64Map(col TimestampFloat64MapColumn, value map[time.Time]float64) SetValueStep + SetTimestampFloat64MapValue(col TimestampFloat64MapColumn, key time.Time, value float64) SetValueStep SetTimestampTimestampMap(col TimestampTimestampMapColumn, value map[time.Time]time.Time) SetValueStep + SetTimestampTimestampMapValue(col TimestampTimestampMapColumn, key time.Time, value time.Time) SetValueStep SetTimestampTimeUUIDMap(col TimestampTimeUUIDMapColumn, value map[time.Time]gocql.UUID) SetValueStep + SetTimestampTimeUUIDMapValue(col TimestampTimeUUIDMapColumn, key time.Time, value gocql.UUID) SetValueStep SetTimestampUUIDMap(col TimestampUUIDMapColumn, value map[time.Time]gocql.UUID) SetValueStep + SetTimestampUUIDMapValue(col TimestampUUIDMapColumn, key time.Time, value gocql.UUID) SetValueStep SetTimestampBooleanMap(col TimestampBooleanMapColumn, value map[time.Time]bool) SetValueStep + SetTimestampBooleanMapValue(col TimestampBooleanMapColumn, key time.Time, value bool) SetValueStep SetTimestampDecimalMap(col TimestampDecimalMapColumn, value map[time.Time]*inf.Dec) SetValueStep + SetTimestampDecimalMapValue(col TimestampDecimalMapColumn, key time.Time, value *inf.Dec) SetValueStep SetTimestampVarintMap(col TimestampVarintMapColumn, value map[time.Time]*big.Int) SetValueStep + SetTimestampVarintMapValue(col TimestampVarintMapColumn, key time.Time, value *big.Int) SetValueStep SetTimestampBytesMap(col TimestampBytesMapColumn, value map[time.Time][]byte) SetValueStep + SetTimestampBytesMapValue(col TimestampBytesMapColumn, key time.Time, value []byte) SetValueStep SetTimeUUIDStringMap(col TimeUUIDStringMapColumn, value map[gocql.UUID]string) SetValueStep + SetTimeUUIDStringMapValue(col TimeUUIDStringMapColumn, key gocql.UUID, value string) SetValueStep SetTimeUUIDInt32Map(col TimeUUIDInt32MapColumn, value map[gocql.UUID]int32) SetValueStep + SetTimeUUIDInt32MapValue(col TimeUUIDInt32MapColumn, key gocql.UUID, value int32) SetValueStep SetTimeUUIDInt64Map(col TimeUUIDInt64MapColumn, value map[gocql.UUID]int64) SetValueStep + SetTimeUUIDInt64MapValue(col TimeUUIDInt64MapColumn, key gocql.UUID, value int64) SetValueStep SetTimeUUIDFloat32Map(col TimeUUIDFloat32MapColumn, value map[gocql.UUID]float32) SetValueStep + SetTimeUUIDFloat32MapValue(col TimeUUIDFloat32MapColumn, key gocql.UUID, value float32) SetValueStep SetTimeUUIDFloat64Map(col TimeUUIDFloat64MapColumn, value map[gocql.UUID]float64) SetValueStep + SetTimeUUIDFloat64MapValue(col TimeUUIDFloat64MapColumn, key gocql.UUID, value float64) SetValueStep SetTimeUUIDTimestampMap(col TimeUUIDTimestampMapColumn, value map[gocql.UUID]time.Time) SetValueStep + SetTimeUUIDTimestampMapValue(col TimeUUIDTimestampMapColumn, key gocql.UUID, value time.Time) SetValueStep SetTimeUUIDTimeUUIDMap(col TimeUUIDTimeUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep + SetTimeUUIDTimeUUIDMapValue(col TimeUUIDTimeUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep SetTimeUUIDUUIDMap(col TimeUUIDUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep + SetTimeUUIDUUIDMapValue(col TimeUUIDUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep SetTimeUUIDBooleanMap(col TimeUUIDBooleanMapColumn, value map[gocql.UUID]bool) SetValueStep + SetTimeUUIDBooleanMapValue(col TimeUUIDBooleanMapColumn, key gocql.UUID, value bool) SetValueStep SetTimeUUIDDecimalMap(col TimeUUIDDecimalMapColumn, value map[gocql.UUID]*inf.Dec) SetValueStep + SetTimeUUIDDecimalMapValue(col TimeUUIDDecimalMapColumn, key gocql.UUID, value *inf.Dec) SetValueStep SetTimeUUIDVarintMap(col TimeUUIDVarintMapColumn, value map[gocql.UUID]*big.Int) SetValueStep + SetTimeUUIDVarintMapValue(col TimeUUIDVarintMapColumn, key gocql.UUID, value *big.Int) SetValueStep SetTimeUUIDBytesMap(col TimeUUIDBytesMapColumn, value map[gocql.UUID][]byte) SetValueStep + SetTimeUUIDBytesMapValue(col TimeUUIDBytesMapColumn, key gocql.UUID, value []byte) SetValueStep SetUUIDStringMap(col UUIDStringMapColumn, value map[gocql.UUID]string) SetValueStep + SetUUIDStringMapValue(col UUIDStringMapColumn, key gocql.UUID, value string) SetValueStep SetUUIDInt32Map(col UUIDInt32MapColumn, value map[gocql.UUID]int32) SetValueStep + SetUUIDInt32MapValue(col UUIDInt32MapColumn, key gocql.UUID, value int32) SetValueStep SetUUIDInt64Map(col UUIDInt64MapColumn, value map[gocql.UUID]int64) SetValueStep + SetUUIDInt64MapValue(col UUIDInt64MapColumn, key gocql.UUID, value int64) SetValueStep SetUUIDFloat32Map(col UUIDFloat32MapColumn, value map[gocql.UUID]float32) SetValueStep + SetUUIDFloat32MapValue(col UUIDFloat32MapColumn, key gocql.UUID, value float32) SetValueStep SetUUIDFloat64Map(col UUIDFloat64MapColumn, value map[gocql.UUID]float64) SetValueStep + SetUUIDFloat64MapValue(col UUIDFloat64MapColumn, key gocql.UUID, value float64) SetValueStep SetUUIDTimestampMap(col UUIDTimestampMapColumn, value map[gocql.UUID]time.Time) SetValueStep + SetUUIDTimestampMapValue(col UUIDTimestampMapColumn, key gocql.UUID, value time.Time) SetValueStep SetUUIDTimeUUIDMap(col UUIDTimeUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep + SetUUIDTimeUUIDMapValue(col UUIDTimeUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep SetUUIDUUIDMap(col UUIDUUIDMapColumn, value map[gocql.UUID]gocql.UUID) SetValueStep + SetUUIDUUIDMapValue(col UUIDUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep SetUUIDBooleanMap(col UUIDBooleanMapColumn, value map[gocql.UUID]bool) SetValueStep + SetUUIDBooleanMapValue(col UUIDBooleanMapColumn, key gocql.UUID, value bool) SetValueStep SetUUIDDecimalMap(col UUIDDecimalMapColumn, value map[gocql.UUID]*inf.Dec) SetValueStep + SetUUIDDecimalMapValue(col UUIDDecimalMapColumn, key gocql.UUID, value *inf.Dec) SetValueStep SetUUIDVarintMap(col UUIDVarintMapColumn, value map[gocql.UUID]*big.Int) SetValueStep + SetUUIDVarintMapValue(col UUIDVarintMapColumn, key gocql.UUID, value *big.Int) SetValueStep SetUUIDBytesMap(col UUIDBytesMapColumn, value map[gocql.UUID][]byte) SetValueStep + SetUUIDBytesMapValue(col UUIDBytesMapColumn, key gocql.UUID, value []byte) SetValueStep SetBooleanStringMap(col BooleanStringMapColumn, value map[bool]string) SetValueStep + SetBooleanStringMapValue(col BooleanStringMapColumn, key bool, value string) SetValueStep SetBooleanInt32Map(col BooleanInt32MapColumn, value map[bool]int32) SetValueStep + SetBooleanInt32MapValue(col BooleanInt32MapColumn, key bool, value int32) SetValueStep SetBooleanInt64Map(col BooleanInt64MapColumn, value map[bool]int64) SetValueStep + SetBooleanInt64MapValue(col BooleanInt64MapColumn, key bool, value int64) SetValueStep SetBooleanFloat32Map(col BooleanFloat32MapColumn, value map[bool]float32) SetValueStep + SetBooleanFloat32MapValue(col BooleanFloat32MapColumn, key bool, value float32) SetValueStep SetBooleanFloat64Map(col BooleanFloat64MapColumn, value map[bool]float64) SetValueStep + SetBooleanFloat64MapValue(col BooleanFloat64MapColumn, key bool, value float64) SetValueStep SetBooleanTimestampMap(col BooleanTimestampMapColumn, value map[bool]time.Time) SetValueStep + SetBooleanTimestampMapValue(col BooleanTimestampMapColumn, key bool, value time.Time) SetValueStep SetBooleanTimeUUIDMap(col BooleanTimeUUIDMapColumn, value map[bool]gocql.UUID) SetValueStep + SetBooleanTimeUUIDMapValue(col BooleanTimeUUIDMapColumn, key bool, value gocql.UUID) SetValueStep SetBooleanUUIDMap(col BooleanUUIDMapColumn, value map[bool]gocql.UUID) SetValueStep + SetBooleanUUIDMapValue(col BooleanUUIDMapColumn, key bool, value gocql.UUID) SetValueStep SetBooleanBooleanMap(col BooleanBooleanMapColumn, value map[bool]bool) SetValueStep + SetBooleanBooleanMapValue(col BooleanBooleanMapColumn, key bool, value bool) SetValueStep SetBooleanDecimalMap(col BooleanDecimalMapColumn, value map[bool]*inf.Dec) SetValueStep + SetBooleanDecimalMapValue(col BooleanDecimalMapColumn, key bool, value *inf.Dec) SetValueStep SetBooleanVarintMap(col BooleanVarintMapColumn, value map[bool]*big.Int) SetValueStep + SetBooleanVarintMapValue(col BooleanVarintMapColumn, key bool, value *big.Int) SetValueStep SetBooleanBytesMap(col BooleanBytesMapColumn, value map[bool][]byte) SetValueStep + SetBooleanBytesMapValue(col BooleanBytesMapColumn, key bool, value []byte) SetValueStep SetDecimalStringMap(col DecimalStringMapColumn, value map[*inf.Dec]string) SetValueStep + SetDecimalStringMapValue(col DecimalStringMapColumn, key *inf.Dec, value string) SetValueStep SetDecimalInt32Map(col DecimalInt32MapColumn, value map[*inf.Dec]int32) SetValueStep + SetDecimalInt32MapValue(col DecimalInt32MapColumn, key *inf.Dec, value int32) SetValueStep SetDecimalInt64Map(col DecimalInt64MapColumn, value map[*inf.Dec]int64) SetValueStep + SetDecimalInt64MapValue(col DecimalInt64MapColumn, key *inf.Dec, value int64) SetValueStep SetDecimalFloat32Map(col DecimalFloat32MapColumn, value map[*inf.Dec]float32) SetValueStep + SetDecimalFloat32MapValue(col DecimalFloat32MapColumn, key *inf.Dec, value float32) SetValueStep SetDecimalFloat64Map(col DecimalFloat64MapColumn, value map[*inf.Dec]float64) SetValueStep + SetDecimalFloat64MapValue(col DecimalFloat64MapColumn, key *inf.Dec, value float64) SetValueStep SetDecimalTimestampMap(col DecimalTimestampMapColumn, value map[*inf.Dec]time.Time) SetValueStep + SetDecimalTimestampMapValue(col DecimalTimestampMapColumn, key *inf.Dec, value time.Time) SetValueStep SetDecimalTimeUUIDMap(col DecimalTimeUUIDMapColumn, value map[*inf.Dec]gocql.UUID) SetValueStep + SetDecimalTimeUUIDMapValue(col DecimalTimeUUIDMapColumn, key *inf.Dec, value gocql.UUID) SetValueStep SetDecimalUUIDMap(col DecimalUUIDMapColumn, value map[*inf.Dec]gocql.UUID) SetValueStep + SetDecimalUUIDMapValue(col DecimalUUIDMapColumn, key *inf.Dec, value gocql.UUID) SetValueStep SetDecimalBooleanMap(col DecimalBooleanMapColumn, value map[*inf.Dec]bool) SetValueStep + SetDecimalBooleanMapValue(col DecimalBooleanMapColumn, key *inf.Dec, value bool) SetValueStep SetDecimalDecimalMap(col DecimalDecimalMapColumn, value map[*inf.Dec]*inf.Dec) SetValueStep + SetDecimalDecimalMapValue(col DecimalDecimalMapColumn, key *inf.Dec, value *inf.Dec) SetValueStep SetDecimalVarintMap(col DecimalVarintMapColumn, value map[*inf.Dec]*big.Int) SetValueStep + SetDecimalVarintMapValue(col DecimalVarintMapColumn, key *inf.Dec, value *big.Int) SetValueStep SetDecimalBytesMap(col DecimalBytesMapColumn, value map[*inf.Dec][]byte) SetValueStep + SetDecimalBytesMapValue(col DecimalBytesMapColumn, key *inf.Dec, value []byte) SetValueStep SetVarintStringMap(col VarintStringMapColumn, value map[*big.Int]string) SetValueStep + SetVarintStringMapValue(col VarintStringMapColumn, key *big.Int, value string) SetValueStep SetVarintInt32Map(col VarintInt32MapColumn, value map[*big.Int]int32) SetValueStep + SetVarintInt32MapValue(col VarintInt32MapColumn, key *big.Int, value int32) SetValueStep SetVarintInt64Map(col VarintInt64MapColumn, value map[*big.Int]int64) SetValueStep + SetVarintInt64MapValue(col VarintInt64MapColumn, key *big.Int, value int64) SetValueStep SetVarintFloat32Map(col VarintFloat32MapColumn, value map[*big.Int]float32) SetValueStep + SetVarintFloat32MapValue(col VarintFloat32MapColumn, key *big.Int, value float32) SetValueStep SetVarintFloat64Map(col VarintFloat64MapColumn, value map[*big.Int]float64) SetValueStep + SetVarintFloat64MapValue(col VarintFloat64MapColumn, key *big.Int, value float64) SetValueStep SetVarintTimestampMap(col VarintTimestampMapColumn, value map[*big.Int]time.Time) SetValueStep + SetVarintTimestampMapValue(col VarintTimestampMapColumn, key *big.Int, value time.Time) SetValueStep SetVarintTimeUUIDMap(col VarintTimeUUIDMapColumn, value map[*big.Int]gocql.UUID) SetValueStep + SetVarintTimeUUIDMapValue(col VarintTimeUUIDMapColumn, key *big.Int, value gocql.UUID) SetValueStep SetVarintUUIDMap(col VarintUUIDMapColumn, value map[*big.Int]gocql.UUID) SetValueStep + SetVarintUUIDMapValue(col VarintUUIDMapColumn, key *big.Int, value gocql.UUID) SetValueStep SetVarintBooleanMap(col VarintBooleanMapColumn, value map[*big.Int]bool) SetValueStep + SetVarintBooleanMapValue(col VarintBooleanMapColumn, key *big.Int, value bool) SetValueStep SetVarintDecimalMap(col VarintDecimalMapColumn, value map[*big.Int]*inf.Dec) SetValueStep + SetVarintDecimalMapValue(col VarintDecimalMapColumn, key *big.Int, value *inf.Dec) SetValueStep SetVarintVarintMap(col VarintVarintMapColumn, value map[*big.Int]*big.Int) SetValueStep + SetVarintVarintMapValue(col VarintVarintMapColumn, key *big.Int, value *big.Int) SetValueStep SetVarintBytesMap(col VarintBytesMapColumn, value map[*big.Int][]byte) SetValueStep + SetVarintBytesMapValue(col VarintBytesMapColumn, key *big.Int, value []byte) SetValueStep SetStringSlice(col StringSliceColumn, value []string) SetValueStep AppendStringSlice(col StringSliceColumn, values ...string) SetValueStep @@ -2021,6 +2153,666 @@ func (c *Context) SetVarintBytesMap(col VarintBytesMapColumn, value map[*big.Int return c } +func (c *Context) SetStringStringMapValue(col StringStringMapColumn, key string, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringInt32MapValue(col StringInt32MapColumn, key string, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringInt64MapValue(col StringInt64MapColumn, key string, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringFloat32MapValue(col StringFloat32MapColumn, key string, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringFloat64MapValue(col StringFloat64MapColumn, key string, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringTimestampMapValue(col StringTimestampMapColumn, key string, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringTimeUUIDMapValue(col StringTimeUUIDMapColumn, key string, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringUUIDMapValue(col StringUUIDMapColumn, key string, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringBooleanMapValue(col StringBooleanMapColumn, key string, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringDecimalMapValue(col StringDecimalMapColumn, key string, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringVarintMapValue(col StringVarintMapColumn, key string, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetStringBytesMapValue(col StringBytesMapColumn, key string, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32StringMapValue(col Int32StringMapColumn, key int32, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32Int32MapValue(col Int32Int32MapColumn, key int32, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32Int64MapValue(col Int32Int64MapColumn, key int32, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32Float32MapValue(col Int32Float32MapColumn, key int32, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32Float64MapValue(col Int32Float64MapColumn, key int32, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32TimestampMapValue(col Int32TimestampMapColumn, key int32, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32TimeUUIDMapValue(col Int32TimeUUIDMapColumn, key int32, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32UUIDMapValue(col Int32UUIDMapColumn, key int32, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32BooleanMapValue(col Int32BooleanMapColumn, key int32, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32DecimalMapValue(col Int32DecimalMapColumn, key int32, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32VarintMapValue(col Int32VarintMapColumn, key int32, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt32BytesMapValue(col Int32BytesMapColumn, key int32, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64StringMapValue(col Int64StringMapColumn, key int64, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64Int32MapValue(col Int64Int32MapColumn, key int64, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64Int64MapValue(col Int64Int64MapColumn, key int64, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64Float32MapValue(col Int64Float32MapColumn, key int64, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64Float64MapValue(col Int64Float64MapColumn, key int64, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64TimestampMapValue(col Int64TimestampMapColumn, key int64, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64TimeUUIDMapValue(col Int64TimeUUIDMapColumn, key int64, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64UUIDMapValue(col Int64UUIDMapColumn, key int64, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64BooleanMapValue(col Int64BooleanMapColumn, key int64, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64DecimalMapValue(col Int64DecimalMapColumn, key int64, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64VarintMapValue(col Int64VarintMapColumn, key int64, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetInt64BytesMapValue(col Int64BytesMapColumn, key int64, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32StringMapValue(col Float32StringMapColumn, key float32, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32Int32MapValue(col Float32Int32MapColumn, key float32, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32Int64MapValue(col Float32Int64MapColumn, key float32, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32Float32MapValue(col Float32Float32MapColumn, key float32, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32Float64MapValue(col Float32Float64MapColumn, key float32, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32TimestampMapValue(col Float32TimestampMapColumn, key float32, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32TimeUUIDMapValue(col Float32TimeUUIDMapColumn, key float32, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32UUIDMapValue(col Float32UUIDMapColumn, key float32, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32BooleanMapValue(col Float32BooleanMapColumn, key float32, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32DecimalMapValue(col Float32DecimalMapColumn, key float32, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32VarintMapValue(col Float32VarintMapColumn, key float32, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat32BytesMapValue(col Float32BytesMapColumn, key float32, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64StringMapValue(col Float64StringMapColumn, key float64, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64Int32MapValue(col Float64Int32MapColumn, key float64, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64Int64MapValue(col Float64Int64MapColumn, key float64, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64Float32MapValue(col Float64Float32MapColumn, key float64, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64Float64MapValue(col Float64Float64MapColumn, key float64, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64TimestampMapValue(col Float64TimestampMapColumn, key float64, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64TimeUUIDMapValue(col Float64TimeUUIDMapColumn, key float64, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64UUIDMapValue(col Float64UUIDMapColumn, key float64, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64BooleanMapValue(col Float64BooleanMapColumn, key float64, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64DecimalMapValue(col Float64DecimalMapColumn, key float64, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64VarintMapValue(col Float64VarintMapColumn, key float64, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetFloat64BytesMapValue(col Float64BytesMapColumn, key float64, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampStringMapValue(col TimestampStringMapColumn, key time.Time, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampInt32MapValue(col TimestampInt32MapColumn, key time.Time, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampInt64MapValue(col TimestampInt64MapColumn, key time.Time, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampFloat32MapValue(col TimestampFloat32MapColumn, key time.Time, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampFloat64MapValue(col TimestampFloat64MapColumn, key time.Time, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampTimestampMapValue(col TimestampTimestampMapColumn, key time.Time, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampTimeUUIDMapValue(col TimestampTimeUUIDMapColumn, key time.Time, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampUUIDMapValue(col TimestampUUIDMapColumn, key time.Time, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampBooleanMapValue(col TimestampBooleanMapColumn, key time.Time, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampDecimalMapValue(col TimestampDecimalMapColumn, key time.Time, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampVarintMapValue(col TimestampVarintMapColumn, key time.Time, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimestampBytesMapValue(col TimestampBytesMapColumn, key time.Time, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDStringMapValue(col TimeUUIDStringMapColumn, key gocql.UUID, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDInt32MapValue(col TimeUUIDInt32MapColumn, key gocql.UUID, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDInt64MapValue(col TimeUUIDInt64MapColumn, key gocql.UUID, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDFloat32MapValue(col TimeUUIDFloat32MapColumn, key gocql.UUID, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDFloat64MapValue(col TimeUUIDFloat64MapColumn, key gocql.UUID, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDTimestampMapValue(col TimeUUIDTimestampMapColumn, key gocql.UUID, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDTimeUUIDMapValue(col TimeUUIDTimeUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDUUIDMapValue(col TimeUUIDUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDBooleanMapValue(col TimeUUIDBooleanMapColumn, key gocql.UUID, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDDecimalMapValue(col TimeUUIDDecimalMapColumn, key gocql.UUID, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDVarintMapValue(col TimeUUIDVarintMapColumn, key gocql.UUID, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetTimeUUIDBytesMapValue(col TimeUUIDBytesMapColumn, key gocql.UUID, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDStringMapValue(col UUIDStringMapColumn, key gocql.UUID, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDInt32MapValue(col UUIDInt32MapColumn, key gocql.UUID, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDInt64MapValue(col UUIDInt64MapColumn, key gocql.UUID, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDFloat32MapValue(col UUIDFloat32MapColumn, key gocql.UUID, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDFloat64MapValue(col UUIDFloat64MapColumn, key gocql.UUID, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDTimestampMapValue(col UUIDTimestampMapColumn, key gocql.UUID, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDTimeUUIDMapValue(col UUIDTimeUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDUUIDMapValue(col UUIDUUIDMapColumn, key gocql.UUID, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDBooleanMapValue(col UUIDBooleanMapColumn, key gocql.UUID, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDDecimalMapValue(col UUIDDecimalMapColumn, key gocql.UUID, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDVarintMapValue(col UUIDVarintMapColumn, key gocql.UUID, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetUUIDBytesMapValue(col UUIDBytesMapColumn, key gocql.UUID, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanStringMapValue(col BooleanStringMapColumn, key bool, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanInt32MapValue(col BooleanInt32MapColumn, key bool, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanInt64MapValue(col BooleanInt64MapColumn, key bool, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanFloat32MapValue(col BooleanFloat32MapColumn, key bool, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanFloat64MapValue(col BooleanFloat64MapColumn, key bool, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanTimestampMapValue(col BooleanTimestampMapColumn, key bool, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanTimeUUIDMapValue(col BooleanTimeUUIDMapColumn, key bool, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanUUIDMapValue(col BooleanUUIDMapColumn, key bool, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanBooleanMapValue(col BooleanBooleanMapColumn, key bool, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanDecimalMapValue(col BooleanDecimalMapColumn, key bool, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanVarintMapValue(col BooleanVarintMapColumn, key bool, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetBooleanBytesMapValue(col BooleanBytesMapColumn, key bool, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalStringMapValue(col DecimalStringMapColumn, key *inf.Dec, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalInt32MapValue(col DecimalInt32MapColumn, key *inf.Dec, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalInt64MapValue(col DecimalInt64MapColumn, key *inf.Dec, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalFloat32MapValue(col DecimalFloat32MapColumn, key *inf.Dec, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalFloat64MapValue(col DecimalFloat64MapColumn, key *inf.Dec, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalTimestampMapValue(col DecimalTimestampMapColumn, key *inf.Dec, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalTimeUUIDMapValue(col DecimalTimeUUIDMapColumn, key *inf.Dec, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalUUIDMapValue(col DecimalUUIDMapColumn, key *inf.Dec, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalBooleanMapValue(col DecimalBooleanMapColumn, key *inf.Dec, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalDecimalMapValue(col DecimalDecimalMapColumn, key *inf.Dec, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalVarintMapValue(col DecimalVarintMapColumn, key *inf.Dec, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetDecimalBytesMapValue(col DecimalBytesMapColumn, key *inf.Dec, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintStringMapValue(col VarintStringMapColumn, key *big.Int, value string) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintInt32MapValue(col VarintInt32MapColumn, key *big.Int, value int32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintInt64MapValue(col VarintInt64MapColumn, key *big.Int, value int64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintFloat32MapValue(col VarintFloat32MapColumn, key *big.Int, value float32) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintFloat64MapValue(col VarintFloat64MapColumn, key *big.Int, value float64) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintTimestampMapValue(col VarintTimestampMapColumn, key *big.Int, value time.Time) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintTimeUUIDMapValue(col VarintTimeUUIDMapColumn, key *big.Int, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintUUIDMapValue(col VarintUUIDMapColumn, key *big.Int, value gocql.UUID) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintBooleanMapValue(col VarintBooleanMapColumn, key *big.Int, value bool) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintDecimalMapValue(col VarintDecimalMapColumn, key *big.Int, value *inf.Dec) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintVarintMapValue(col VarintVarintMapColumn, key *big.Int, value *big.Int) SetValueStep { + setMap(c, col, key, value) + return c +} + +func (c *Context) SetVarintBytesMapValue(col VarintBytesMapColumn, key *big.Int, value []byte) SetValueStep { + setMap(c, col, key, value) + return c +} + func (c *Context) SetString(col StringColumn, value string) SetValueStep { set(c, col, value) return c diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index a78aa93..e91dc48 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -57,6 +57,8 @@ const ( Append Prepend RemoveByValue + RemoveByKey + SetByKey ) var ( @@ -556,7 +558,6 @@ func (c *Context) RenderCQL() (string, error) { var buf bytes.Buffer - // TODO This should be a switch switch c.Operation { case ReadOperation: { @@ -605,6 +606,11 @@ func set(c *Context, col Column, value interface{}) { c.Bindings = append(c.Bindings, ColumnBinding{Column: col, Value: value}) } +func setMap(c *Context, col Column, key interface{}, value interface{}) { + b := ColumnBinding{Column: col, Value: []interface{}{key, value}, CollectionType: MapType, CollectionOperationType: SetByKey} + c.Bindings = append(c.Bindings, b) +} + func appendList(c *Context, col ListColumn, values interface{}) { b := ColumnBinding{Column: col, Value: values, Incremental: true, CollectionType: ListType, CollectionOperationType: Append} c.Bindings = append(c.Bindings, b) diff --git a/cqlc/cqlc_test.go b/cqlc/cqlc_test.go index 461b3eb..0490d4f 100644 --- a/cqlc/cqlc_test.go +++ b/cqlc/cqlc_test.go @@ -286,6 +286,16 @@ func (s *CqlTestSuite) TestUpdate() { cql, err := c.RenderCQL() assert.NoError(s.T(), err) assert.Equal(s.T(), cql, "UPDATE foo SET bar = ?, quux = ? WHERE id = ?") + + // set string map value by key, not entire map + c = NewContext() + c.Upsert(s.table). + SetStringStringMapValue(barCol, "dz1", `{"json":"string"}`). + SetInt32(quuxCol, 10). + Where(idCol.Eq("x")) + cql, err = c.RenderCQL() + assert.NoError(s.T(), err) + assert.Equal(s.T(), cql, "UPDATE foo SET bar[?] = ?, quux = ? WHERE id = ?") } func (s *CqlTestSuite) TestCounter() { diff --git a/cqlc/render.go b/cqlc/render.go index b6b2778..a65ee86 100644 --- a/cqlc/render.go +++ b/cqlc/render.go @@ -134,6 +134,20 @@ func renderUpdate(ctx *Context, buf *bytes.Buffer, counterTable bool) { case RemoveByValue: setFragments[i] = fmt.Sprintf("%s = %s - ?", col, col) } + case MapType: + switch binding.CollectionOperationType { + case SetByKey: + setFragments[i] = fmt.Sprintf("%s[?] = ?", col) + // TODO: it seems in C*2 and C*3 the + has different semantic + // https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_map_t.html + // https://docs.datastax.com/en/cql/3.3/cql/cql_using/useInsertMap.html + //case Append: + // setFragments[i] = fmt.Sprintf("%s = %s + ?", col, col) + //case RemoveByKey: + // setFragments[i] = fmt.Sprintf("%s = %s - ?", col, col) + default: + panic(fmt.Sprintf("unsupported Map CollectionOperationType %d", binding.CollectionOperationType)) + } default: setFragments[i] = fmt.Sprintf("%s = ?", col) } diff --git a/cqlc/tmpl/columns.tmpl b/cqlc/tmpl/columns.tmpl index 27a4c49..6780087 100644 --- a/cqlc/tmpl/columns.tmpl +++ b/cqlc/tmpl/columns.tmpl @@ -78,6 +78,7 @@ type SetValueStep interface { {{ range $_, $it := $inner }} {{ if ne $ot.Prefix "Bytes" }} Set{{ $ot.Prefix }}{{ $it.Prefix }}Map(col {{ $ot.Prefix }}{{ $it.Prefix }}MapColumn, value map[{{ $ot.Literal }}]{{ $it.Literal }}) SetValueStep + Set{{ $ot.Prefix }}{{ $it.Prefix }}MapValue(col {{ $ot.Prefix }}{{ $it.Prefix }}MapColumn, key {{ $ot.Literal }}, value {{ $it.Literal }}) SetValueStep {{ end }}{{ end }}{{ end }} {{ range $_, $t := .types }} @@ -97,6 +98,15 @@ func (c *Context) Set{{ $ot.Prefix }}{{ $it.Prefix }}Map(col {{ $ot.Prefix }}{{ } {{ end }}{{ end }}{{ end }} +{{ range $_, $ot := $outer }} +{{ range $_, $it := $inner }} +{{ if ne $ot.Prefix "Bytes" }} +func (c *Context) Set{{ $ot.Prefix }}{{ $it.Prefix }}MapValue(col {{ $ot.Prefix }}{{ $it.Prefix }}MapColumn, key {{ $ot.Literal }}, value {{ $it.Literal }}) SetValueStep { + setMap(c, col, key, value) + return c +} +{{ end }}{{ end }}{{ end }} + {{ range $_, $t := .types }} func (c *Context) Set{{ $t.Prefix }}(col {{ $t.Prefix }}Column, value {{ $t.Literal }}) SetValueStep { set(c, col, value) From 361e785c42e60cef923afebdd240d5eacf2721d1 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 01:16:55 -0700 Subject: [PATCH 14/39] [test] Can't connect to C* using docker on Mac #6 --- e2e/Makefile | 12 ++++++++++++ e2e/README.md | 4 ++++ e2e/create_schema_test.go | 23 +++++++++++++++++++++++ e2e/docker-compose.yaml | 13 +++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 e2e/Makefile create mode 100644 e2e/README.md create mode 100644 e2e/create_schema_test.go create mode 100644 e2e/docker-compose.yaml diff --git a/e2e/Makefile b/e2e/Makefile new file mode 100644 index 0000000..479fda4 --- /dev/null +++ b/e2e/Makefile @@ -0,0 +1,12 @@ +.PHONY: run-c2 run-c3 shell-c2 shell-c3 down + +run-c2: + docker-compose up c2 +run-c3: + docker-compose up c3 +shell-c2: + docker-compose exec c2 /bin/bash +shell-c3: + docker-compose exec c3 /bin/bash +down: + docker-compose down diff --git a/e2e/README.md b/e2e/README.md new file mode 100644 index 0000000..c4a8567 --- /dev/null +++ b/e2e/README.md @@ -0,0 +1,4 @@ +# e2e + +This is a small e2e test because I couldn't figure out how to run existing integration test properly and I want to use +docker instead of ccm \ No newline at end of file diff --git a/e2e/create_schema_test.go b/e2e/create_schema_test.go new file mode 100644 index 0000000..af03798 --- /dev/null +++ b/e2e/create_schema_test.go @@ -0,0 +1,23 @@ +package e2e + +import ( + "testing" + + "github.com/gocql/gocql" + requir "github.com/stretchr/testify/require" +) + +func TestCreateSchema(t *testing.T) { + require := requir.New(t) + + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = "system" + sess, err := cluster.CreateSession() + require.Nil(err, "connect to cassandra using system keyspace for create new keyspace") + + createKeyspace := `CREATE KEYSPACE cqlc WITH replication = +{ 'class' : 'SimpleStrategy', 'replication_factor' : 1 };` + err = sess.Query(createKeyspace).Exec() + require.Nil(err, "create keyspace") + +} diff --git a/e2e/docker-compose.yaml b/e2e/docker-compose.yaml new file mode 100644 index 0000000..fc59b70 --- /dev/null +++ b/e2e/docker-compose.yaml @@ -0,0 +1,13 @@ +version: '3.3' +services: + c2: + image: 'cassandra:2.1' + network_mode: host + c3: + image: 'cassandra:3.1' + environment: + - CASSANDRA_BROADCAST_ADDRESS=127.0.0.1 + ports: + - target: 904 + published: 9042 + protocol: tcp \ No newline at end of file From d623f380e3e9509a7364d63d2ac75b9faa99e75f Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 01:24:31 -0700 Subject: [PATCH 15/39] Fix #6 set broadcast_addr and correct port - in port mapping, was using 904 instead of 9042 ... --- e2e/docker-compose.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/e2e/docker-compose.yaml b/e2e/docker-compose.yaml index fc59b70..a42e7d4 100644 --- a/e2e/docker-compose.yaml +++ b/e2e/docker-compose.yaml @@ -2,12 +2,17 @@ version: '3.3' services: c2: image: 'cassandra:2.1' - network_mode: host + environment: + - CASSANDRA_BROADCAST_ADDRESS=127.0.0.1 + ports: + - target: 9042 + published: 9042 + protocol: tcp c3: image: 'cassandra:3.1' environment: - - CASSANDRA_BROADCAST_ADDRESS=127.0.0.1 + - CASSANDRA_BROADCAST_ADDRESS=127.0.0.1 ports: - - target: 904 + - target: 9042 published: 9042 protocol: tcp \ No newline at end of file From 3df587070e04376915f7bc20c93812f29a8cb91d Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 01:41:23 -0700 Subject: [PATCH 16/39] [gen] C*3 seems to be broken --- README.md | 3 +- e2e/c3_broken.go.log | 375 ++++++++++++++++++++++++++++++++++++++ e2e/create_schema_test.go | 37 +++- generator/generator.go | 31 +++- 4 files changed, 430 insertions(+), 16 deletions(-) create mode 100644 e2e/c3_broken.go.log diff --git a/README.md b/README.md index 33fb142..4d6d81b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ This a fork of [relops/cqlc](https://github.com/relops/cqlc) which is no longer ## Usage ````bash -make build +make install +cqlc --instance=127.0.0.1 --keyspace=cqlc --package=foo --output=foo.go --symbols ```` ## Dev diff --git a/e2e/c3_broken.go.log b/e2e/c3_broken.go.log new file mode 100644 index 0000000..9a6549c --- /dev/null +++ b/e2e/c3_broken.go.log @@ -0,0 +1,375 @@ +// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +// GENERATED USING KEYSPACE cqlc +// AT 2018-09-15 01:39:27.314369 -0700 PDT m=+0.059257435 USING cqlc VERSION 0.10.5 +// AGAINST HOST ID 7276c9e8-28dc-4032-90a1-53aa078997ff (SERVER VERSION 3.1.1) +// CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.3.1) + + + + +package foo + +import ( + + "github.com/gocql/gocql" + + "log" + + "time" + + "github.com/relops/cqlc/cqlc" + +) + +const ( + CQLC_VERSION = "0.10.5" +) + + + + + + + + + type T1IdColumn struct{ + + } + + func (b * T1IdColumn ) ColumnName() string { + return "id" + } + + + + func (b * T1IdColumn ) To(value *) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} + } + + + + + + + func (b * T1IdColumn ) Eq(value ) cqlc.Condition { + column := &T1IdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.EqPredicate} + } + + func (b * T1IdColumn ) PartitionBy() cqlc.Column { + return b + } + + func (b * T1IdColumn ) In(value ...) cqlc.Condition { + column := &T1IdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.InPredicate} + } + + + + + + + + + type T1StringListColumn struct{ + + } + + func (b * T1StringListColumn ) ColumnName() string { + return "string_list" + } + + + + func (b * T1StringListColumn ) ListType() cqlc.Column { + return &T1StringListColumn{} + } + + + + func (b * T1StringListColumn ) To(value *[]) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} + } + + + + + + + + + + + + type T1StringMapColumn struct{ + + } + + func (b * T1StringMapColumn ) ColumnName() string { + return "string_map" + } + + + + func (b * T1StringMapColumn ) To(value *map[]) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} + } + + + + + + + + + + + + type T1TsColumn struct{ + + } + + func (b * T1TsColumn ) ColumnName() string { + return "ts" + } + + + + func (b * T1TsColumn ) To(value *time.Time) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} + } + + + + + + + + + + + type T1 struct { + + Id + + StringList [] + + StringMap map[] + + Ts time.Time + + } + + + func (s * T1) IdValue() { + return s.Id + } + + func (s * T1) StringListValue() [] { + return s.StringList + } + + func (s * T1) StringMapValue() map[] { + return s.StringMap + } + + func (s * T1) TsValue() time.Time { + return s.Ts + } + + + type T1Def struct { + + ID + + STRING_LIST + + STRING_MAP + + TS cqlc.TimestampColumn + + } + + func BindT1(iter *gocql.Iter) ([]T1, error) { + array := make([]T1, 0) + err := MapT1(iter, func(t T1) (bool, error) { + array = append(array, t) + return true, nil + }) + return array, err + } + + func MapT1(iter *gocql.Iter, callback func(t T1) (bool, error)) error { + columns := iter.Columns() + row := make([]interface{}, len(columns)) + + for { + t := T1{} + + for i := 0; i < len(columns); i++ { + switch columns[i].Name { + + case "id": row[i] = &t.Id + + case "string_list": row[i] = &t.StringList + + case "string_map": row[i] = &t.StringMap + + case "ts": row[i] = &t.Ts + + default: + log.Fatal("unhandled column: ", columns[i].Name) + } + } + if !iter.Scan(row...) { + break + } + + readNext, err := callback(t) + if err != nil { + return err + } + if !readNext { + return nil + } + } + + return nil + } + + + func (s * T1Def ) SupportsUpsert() bool { + return true + } + + + func (s * T1Def ) TableName() string { + return "t1" + } + + func (s * T1Def ) Keyspace() string { + return "cqlc" + } + + func (s * T1Def ) Bind(v T1) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + + + cqlc.ColumnBinding{Column: &T1IdColumn{}, Value: v.Id}, + + + + cqlc.ColumnBinding{Column: &T1StringListColumn{}, Value: v.StringList}, + + + + cqlc.ColumnBinding{Column: &T1StringMapColumn{}, Value: v.StringMap}, + + + + cqlc.ColumnBinding{Column: &T1TsColumn{}, Value: v.Ts}, + + } + return cqlc.TableBinding{Table: &T1Def{}, Columns: cols} + } + + func (s * T1Def ) To(v *T1) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + + + cqlc.ColumnBinding{Column: &T1IdColumn{}, Value: &v.Id}, + + + + cqlc.ColumnBinding{Column: &T1StringListColumn{}, Value: &v.StringList}, + + + + cqlc.ColumnBinding{Column: &T1StringMapColumn{}, Value: &v.StringMap}, + + + + cqlc.ColumnBinding{Column: &T1TsColumn{}, Value: &v.Ts}, + + } + return cqlc.TableBinding{Table: &T1Def{}, Columns: cols} + } + + func (s * T1Def ) ColumnDefinitions() []cqlc.Column { + return []cqlc.Column{ + + + + &T1IdColumn{}, + + + + &T1StringListColumn{}, + + + + &T1StringMapColumn{}, + + + + &T1TsColumn{}, + + } + } + + func T1TableDef() *T1Def { + return &T1Def{ + + + + ID : &T1IdColumn{}, + + + + STRING_LIST : &T1StringListColumn{}, + + + + STRING_MAP : &T1StringMapColumn{}, + + + + TS : &T1TsColumn{}, + + } + } + + + + + + + func (s *T1Def) IdColumn() { + return &T1IdColumn{} + } + + + + func (s *T1Def) StringListColumn() { + return &T1StringListColumn{} + } + + + + func (s *T1Def) StringMapColumn() { + return &T1StringMapColumn{} + } + + + + func (s *T1Def) TsColumn() cqlc.TimestampColumn { + return &T1TsColumn{} + } + + + diff --git a/e2e/create_schema_test.go b/e2e/create_schema_test.go index af03798..adee32b 100644 --- a/e2e/create_schema_test.go +++ b/e2e/create_schema_test.go @@ -8,16 +8,37 @@ import ( ) func TestCreateSchema(t *testing.T) { - require := requir.New(t) + t.Run("create keyspace", func(t *testing.T) { + require := requir.New(t) - cluster := gocql.NewCluster("127.0.0.1") - cluster.Keyspace = "system" - sess, err := cluster.CreateSession() - require.Nil(err, "connect to cassandra using system keyspace for create new keyspace") + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = "system" + sess, err := cluster.CreateSession() + require.Nil(err, "connect to cassandra using system keyspace for create new keyspace") - createKeyspace := `CREATE KEYSPACE cqlc WITH replication = + createKeyspace := `CREATE KEYSPACE cqlc WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };` - err = sess.Query(createKeyspace).Exec() - require.Nil(err, "create keyspace") + err = sess.Query(createKeyspace).Exec() + require.Nil(err, "create keyspace") + }) + t.Run("create table", func(t *testing.T) { + require := requir.New(t) + + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = "cqlc" + sess, err := cluster.CreateSession() + require.Nil(err, "connect to cassandra using cqlc keyspace for create new table") + + createTable := ` +CREATE TABLE cqlc.t1 ( + id text PRIMARY KEY, + ts timestamp, + string_map map, + string_list list, +) +` + err = sess.Query(createTable).Exec() + require.Nil(err, "create table") + }) } diff --git a/generator/generator.go b/generator/generator.go index 8be7e2e..0e1bbf7 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -4,15 +4,17 @@ import ( "bytes" "errors" "fmt" - "github.com/gocql/gocql" - "go/format" + //"go/format" "io" "io/ioutil" + "log" "os" "path/filepath" "strconv" "strings" "time" + + "github.com/gocql/gocql" ) var ( @@ -47,6 +49,7 @@ func Generate(opts *Options, version string) error { if err != nil { return err } + log.Println("valid options") var b bytes.Buffer if err = generateBinding(opts, version, &b); err != nil { @@ -85,7 +88,7 @@ func coalesceImports(md *gocql.KeyspaceMetadata) []string { set["log"] = true paths := make([]string, 0) - for path, _ := range set { + for path := range set { paths = append(paths, path) } @@ -109,6 +112,8 @@ func generateBinding(opts *Options, version string, w io.Writer) error { return fmt.Errorf("Connect error %s", err) } + log.Println("connected") + defer s.Close() var protoString, release, cqlVersion string @@ -140,6 +145,8 @@ func generateBinding(opts *Options, version string, w io.Writer) error { return err } + log.Printf("keyspace meta %v\n", md) + provenance := Provenance{ Keyspace: opts.Keyspace, Version: version, @@ -161,15 +168,21 @@ func generateBinding(opts *Options, version string, w io.Writer) error { return err } - bfmt, err := format.Source(b.Bytes()) - if err != nil { - return err - } + log.Println("template rendered") + + // FIXME: got error when formatting source + //bfmt, err := format.Source(b.Bytes()) + //if err != nil { + // return err + //} + bfmt := b.Bytes() if _, err := w.Write(bfmt); err != nil { return err } + log.Println("generateBinding finished") + return nil } @@ -216,3 +229,7 @@ func importPaths(md *gocql.KeyspaceMetadata) (imports []string) { return imports } + +func init() { + log.SetFlags(log.Llongfile) +} From 69d21885120bd2d208ae0af57d5b74521915c801 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 02:04:00 -0700 Subject: [PATCH 17/39] [gen] Set Map value didn't work ... - got "can not marshal []interface {} into map(varchar, varchar)" --- e2e/create_schema_test.go | 29 ++++- e2e/t1gen/generated.go | 256 ++++++++++++++++++++++++++++++++++++++ generator/generator.go | 15 ++- 3 files changed, 291 insertions(+), 9 deletions(-) create mode 100644 e2e/t1gen/generated.go diff --git a/e2e/create_schema_test.go b/e2e/create_schema_test.go index adee32b..7fc8488 100644 --- a/e2e/create_schema_test.go +++ b/e2e/create_schema_test.go @@ -1,7 +1,10 @@ package e2e import ( + "github.com/relops/cqlc/cqlc" + "github.com/relops/cqlc/e2e/t1gen" "testing" + "time" "github.com/gocql/gocql" requir "github.com/stretchr/testify/require" @@ -30,8 +33,9 @@ func TestCreateSchema(t *testing.T) { sess, err := cluster.CreateSession() require.Nil(err, "connect to cassandra using cqlc keyspace for create new table") + // NOTE: the table name need to have some lower case to avoid conflict .... if we use t1, it will break ... createTable := ` -CREATE TABLE cqlc.t1 ( +CREATE TABLE cqlc.t1abc ( id text PRIMARY KEY, ts timestamp, string_map map, @@ -40,5 +44,28 @@ CREATE TABLE cqlc.t1 ( ` err = sess.Query(createTable).Exec() require.Nil(err, "create table") + + // cqlc --instance=127.0.0.1 --keyspace=cqlc --package=t1gen --output=t1gen/generated.go --verbose --symbols + }) + + t.Run("insert", func(t *testing.T) { + require := requir.New(t) + + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = "cqlc" + sess, err := cluster.CreateSession() + require.Nil(err, "connect to cassandra using cqlc keyspace for create new table") + + c := cqlc.NewContext() + c.Debug = true + // FIXME: StringMapValue didn't work + //err = c.Upsert(t1gen.T1abcTableDef()). + // SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "2").Exec(sess) + //require.Nil(err, "insert map") + + err = c.Upsert(t1gen.T1abcTableDef()). + SetString(t1gen.T1ABC.ID, "1"). + SetTimestamp(t1gen.T1ABC.TS, time.Now()).Exec(sess) + require.Nil(err, "insert map") }) } diff --git a/e2e/t1gen/generated.go b/e2e/t1gen/generated.go new file mode 100644 index 0000000..58130a0 --- /dev/null +++ b/e2e/t1gen/generated.go @@ -0,0 +1,256 @@ +// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +// GENERATED USING KEYSPACE cqlc +// AT 2018-09-15 01:51:09.978716 -0700 PDT m=+0.075402320 USING cqlc VERSION 0.10.5 +// AGAINST HOST ID 9e053a42-f26c-4cb8-af0d-af1c795d68f9 (SERVER VERSION 2.1.20) +// CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.2.1) + +package t1gen + +import ( + "time" + + "github.com/relops/cqlc/cqlc" + + "github.com/gocql/gocql" + + "log" +) + +const ( + CQLC_VERSION = "0.10.5" +) + +type T1abcIdColumn struct { +} + +func (b *T1abcIdColumn) ColumnName() string { + return "id" +} + +func (b *T1abcIdColumn) To(value *string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +func (b *T1abcIdColumn) Eq(value string) cqlc.Condition { + column := &T1abcIdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.EqPredicate} +} + +func (b *T1abcIdColumn) PartitionBy() cqlc.Column { + return b +} + +func (b *T1abcIdColumn) In(value ...string) cqlc.Condition { + column := &T1abcIdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.InPredicate} +} + +type T1abcStringListColumn struct { +} + +func (b *T1abcStringListColumn) ColumnName() string { + return "string_list" +} + +func (b *T1abcStringListColumn) ListType() cqlc.Column { + return &T1abcStringListColumn{} +} + +func (b *T1abcStringListColumn) To(value *[]string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +type T1abcStringMapColumn struct { +} + +func (b *T1abcStringMapColumn) ColumnName() string { + return "string_map" +} + +func (b *T1abcStringMapColumn) To(value *map[string]string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +type T1abcTsColumn struct { +} + +func (b *T1abcTsColumn) ColumnName() string { + return "ts" +} + +func (b *T1abcTsColumn) To(value *time.Time) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +type T1abc struct { + Id string + + StringList []string + + StringMap map[string]string + + Ts time.Time +} + +func (s *T1abc) IdValue() string { + return s.Id +} + +func (s *T1abc) StringListValue() []string { + return s.StringList +} + +func (s *T1abc) StringMapValue() map[string]string { + return s.StringMap +} + +func (s *T1abc) TsValue() time.Time { + return s.Ts +} + +type T1abcDef struct { + ID cqlc.LastPartitionedStringColumn + + STRING_LIST cqlc.StringSliceColumn + + STRING_MAP cqlc.StringStringMapColumn + + TS cqlc.TimestampColumn +} + +func BindT1abc(iter *gocql.Iter) ([]T1abc, error) { + array := make([]T1abc, 0) + err := MapT1abc(iter, func(t T1abc) (bool, error) { + array = append(array, t) + return true, nil + }) + return array, err +} + +func MapT1abc(iter *gocql.Iter, callback func(t T1abc) (bool, error)) error { + columns := iter.Columns() + row := make([]interface{}, len(columns)) + + for { + t := T1abc{} + + for i := 0; i < len(columns); i++ { + switch columns[i].Name { + + case "id": + row[i] = &t.Id + + case "string_list": + row[i] = &t.StringList + + case "string_map": + row[i] = &t.StringMap + + case "ts": + row[i] = &t.Ts + + default: + log.Fatal("unhandled column: ", columns[i].Name) + } + } + if !iter.Scan(row...) { + break + } + + readNext, err := callback(t) + if err != nil { + return err + } + if !readNext { + return nil + } + } + + return nil +} + +func (s *T1abcDef) SupportsUpsert() bool { + return true +} + +func (s *T1abcDef) TableName() string { + return "t1abc" +} + +func (s *T1abcDef) Keyspace() string { + return "cqlc" +} + +func (s *T1abcDef) Bind(v T1abc) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + cqlc.ColumnBinding{Column: &T1abcIdColumn{}, Value: v.Id}, + + cqlc.ColumnBinding{Column: &T1abcStringListColumn{}, Value: v.StringList}, + + cqlc.ColumnBinding{Column: &T1abcStringMapColumn{}, Value: v.StringMap}, + + cqlc.ColumnBinding{Column: &T1abcTsColumn{}, Value: v.Ts}, + } + return cqlc.TableBinding{Table: &T1abcDef{}, Columns: cols} +} + +func (s *T1abcDef) To(v *T1abc) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + cqlc.ColumnBinding{Column: &T1abcIdColumn{}, Value: &v.Id}, + + cqlc.ColumnBinding{Column: &T1abcStringListColumn{}, Value: &v.StringList}, + + cqlc.ColumnBinding{Column: &T1abcStringMapColumn{}, Value: &v.StringMap}, + + cqlc.ColumnBinding{Column: &T1abcTsColumn{}, Value: &v.Ts}, + } + return cqlc.TableBinding{Table: &T1abcDef{}, Columns: cols} +} + +func (s *T1abcDef) ColumnDefinitions() []cqlc.Column { + return []cqlc.Column{ + + &T1abcIdColumn{}, + + &T1abcStringListColumn{}, + + &T1abcStringMapColumn{}, + + &T1abcTsColumn{}, + } +} + +func T1abcTableDef() *T1abcDef { + return &T1abcDef{ + + ID: &T1abcIdColumn{}, + + STRING_LIST: &T1abcStringListColumn{}, + + STRING_MAP: &T1abcStringMapColumn{}, + + TS: &T1abcTsColumn{}, + } +} + +var T1ABC = T1abcTableDef() + +func (s *T1abcDef) IdColumn() cqlc.LastPartitionedStringColumn { + return &T1abcIdColumn{} +} + +func (s *T1abcDef) StringListColumn() cqlc.StringSliceColumn { + return &T1abcStringListColumn{} +} + +func (s *T1abcDef) StringMapColumn() cqlc.StringStringMapColumn { + return &T1abcStringMapColumn{} +} + +func (s *T1abcDef) TsColumn() cqlc.TimestampColumn { + return &T1abcTsColumn{} +} diff --git a/generator/generator.go b/generator/generator.go index 0e1bbf7..46bcb2d 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -4,7 +4,7 @@ import ( "bytes" "errors" "fmt" - //"go/format" + "go/format" "io" "io/ioutil" "log" @@ -170,12 +170,11 @@ func generateBinding(opts *Options, version string, w io.Writer) error { log.Println("template rendered") - // FIXME: got error when formatting source - //bfmt, err := format.Source(b.Bytes()) - //if err != nil { - // return err - //} - bfmt := b.Bytes() + // FIXME: got error when formatting source https://github.com/pingginp/cqlc/issues/7 + bfmt, err := format.Source(b.Bytes()) + if err != nil { + return err + } if _, err := w.Write(bfmt); err != nil { return err @@ -231,5 +230,5 @@ func importPaths(md *gocql.KeyspaceMetadata) (imports []string) { } func init() { - log.SetFlags(log.Llongfile) + log.SetFlags(log.Lshortfile) } From 6b9a8cc51c9f60cf43c0c0517e832e9b4d77e6c3 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 02:16:45 -0700 Subject: [PATCH 18/39] [gen] Bind value for map didn't work #2 - when insert, use SetStringStringMap - when update, SetStringStringMapValue didn't work ... got gocql: expected 3 values send got 2 --- cqlc/cqlc.go | 5 +++-- e2e/create_schema_test.go | 40 +++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index e91dc48..683c71c 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -519,7 +519,8 @@ func debugStmt(stmt string, placeHolders []interface{}) { buffer.WriteString("CQL: ") buffer.WriteString(infused) buffer.WriteString("\n") - fmt.Printf(buffer.String(), placeHolders...) + log.Printf(buffer.String(), placeHolders...) + //panic("debugStmt") } func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err error) { @@ -606,7 +607,7 @@ func set(c *Context, col Column, value interface{}) { c.Bindings = append(c.Bindings, ColumnBinding{Column: col, Value: value}) } -func setMap(c *Context, col Column, key interface{}, value interface{}) { +func setMap(c *Context, col Column, key interface{}, value interface{}) { b := ColumnBinding{Column: col, Value: []interface{}{key, value}, CollectionType: MapType, CollectionOperationType: SetByKey} c.Bindings = append(c.Bindings, b) } diff --git a/e2e/create_schema_test.go b/e2e/create_schema_test.go index 7fc8488..bbf2996 100644 --- a/e2e/create_schema_test.go +++ b/e2e/create_schema_test.go @@ -1,12 +1,13 @@ package e2e import ( - "github.com/relops/cqlc/cqlc" - "github.com/relops/cqlc/e2e/t1gen" + "errors" + "log" "testing" - "time" "github.com/gocql/gocql" + "github.com/relops/cqlc/cqlc" + "github.com/relops/cqlc/e2e/t1gen" requir "github.com/stretchr/testify/require" ) @@ -58,14 +59,33 @@ CREATE TABLE cqlc.t1abc ( c := cqlc.NewContext() c.Debug = true - // FIXME: StringMapValue didn't work - //err = c.Upsert(t1gen.T1abcTableDef()). - // SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "2").Exec(sess) - //require.Nil(err, "insert map") - + // FIXME: StringMapValue didn't work "can not marshal []interface {} into map(varchar, varchar)" err = c.Upsert(t1gen.T1abcTableDef()). - SetString(t1gen.T1ABC.ID, "1"). - SetTimestamp(t1gen.T1ABC.TS, time.Now()).Exec(sess) + SetString(t1gen.T1ABC.ID, "2"). + //SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "2").Exec(sess) + SetStringStringMap(t1gen.T1ABC.STRING_MAP, map[string]string{"1": "2"}).Exec(sess) require.Nil(err, "insert map") + + + // cqlc.go:522: CQL: INSERT INTO t1abc (id, string_map) VALUES ( 2, map[1:2]) + // cqlc.go:522: CQL: UPDATE t1abc SET string_map[ [1 3]] = 2 WHERE id = %!v(MISSING) + // --- FAIL: TestCreateSchema/insert (0.03s) + // require.go:765: + // Error Trace: create_schema_test.go:72 + //Error: Expected nil, but got: &errors.errorString{s:"gocql: expected 3 values send got 2"} + err = c.Upsert(t1gen.T1abcTableDef()). + SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "3"). + Where(t1gen.T1ABC.ID.Eq("2")). + Exec(sess) + require.Nil(err, "update map") + + //err = c.Upsert(t1gen.T1abcTableDef()). + // SetString(t1gen.T1ABC.ID, "1"). + // SetTimestamp(t1gen.T1ABC.TS, time.Now()).Exec(sess) + //require.Nil(err, "insert map") }) } + +func init() { + log.SetFlags(log.Lshortfile) +} From faf7b6a2efd2ae91329403b77b7f68813b51fcf5 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 03:07:56 -0700 Subject: [PATCH 19/39] [gen] Flatten binding in BuildStatement #2 works - BuildStatement is called by Exec, Prepare is called by Fetch, previously flatten is only applied in Prepare --- README.md | 11 ++++++ cqlc/cqlc.go | 75 +++++++++++++++++++++++++++++++++++++-- e2e/create_schema_test.go | 25 +++++++------ 3 files changed, 98 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4d6d81b..119abc8 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,21 @@ make cqlc/columns.go ```` ````go +// NOTE: in order to support set map by value, we must flatten binding, +// previously it is only did in Prepare and ignored in BuildStatement + +// Prepare is used in Select, it only has where condition binding +// Prepare is only called by Fetch func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) { stmt, err := c.RenderCQL() } +// BuildStatement is used in update, thus it has binding and where condition binding +// BuildStatement is called by Exec, Batch, Swap +func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err error) { + +} + // cqlc.go func (c *Context) RenderCQL() (string, error) { switch c.Operation { diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index 683c71c..9ab604c 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -15,12 +15,13 @@ package cqlc import ( "bytes" - "errors" "fmt" - "github.com/gocql/gocql" "log" "reflect" "strings" + + "github.com/gocql/gocql" + "github.com/pkg/errors" ) type OperationType int @@ -448,7 +449,9 @@ func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) { } default: { - placeHolders = append(placeHolders, &v) + // TODO: (pingginp) why it took address of interface and it worked ... + //placeHolders = append(placeHolders, &v) + placeHolders = append(placeHolders, v) } } } @@ -523,7 +526,73 @@ func debugStmt(stmt string, placeHolders []interface{}) { //panic("debugStmt") } +// BuildStatement is the new BuildStatement based on Prepare to support set map value by key func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err error) { + stmt, err = c.RenderCQL() + if err != nil { + return "", nil, errors.Wrap(err, "error render CQL") + } + + placeHolders = make([]interface{}, 0) + + // NOTE: for all the binding we need to expand slice due to multiple place holders in one binding + // in bindings we have foo[?] = ? + // in where bindings we have where foo in (?, ?, ?) + + for _, bind := range c.Bindings { + v := bind.Value + switch reflect.TypeOf(v).Kind() { + case reflect.Slice: + s := reflect.ValueOf(v) + for i := 0; i < s.Len(); i++ { + placeHolders = append(placeHolders, s.Index(i).Interface()) + } + case reflect.Array: + + // Not really happy about having to special case UUIDs + // but this works for now + + if val, ok := v.(gocql.UUID); ok { + placeHolders = append(placeHolders, val.Bytes()) + } else { + return "", nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v)) + } + default: + placeHolders = append(placeHolders, v) + } + } + + for _, cond := range c.Conditions { + v := cond.Binding.Value + switch reflect.TypeOf(v).Kind() { + case reflect.Slice: + s := reflect.ValueOf(v) + for i := 0; i < s.Len(); i++ { + placeHolders = append(placeHolders, s.Index(i).Interface()) + } + case reflect.Array: + + // Not really happy about having to special case UUIDs + // but this works for now + + if val, ok := v.(gocql.UUID); ok { + placeHolders = append(placeHolders, val.Bytes()) + } else { + return "", nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v)) + } + default: + placeHolders = append(placeHolders, v) + } + } + + c.Dispose() + + return stmt, placeHolders, nil +} + +// Deprecated +// NOTE: (pingginp) this is used by Exec and unlike Prepare, it didn't handle expand binding +func BuildStatementOld(c *Context) (stmt string, placeHolders []interface{}, err error) { // TODO Does this function need to get exported? stmt, err = c.RenderCQL() if err != nil { diff --git a/e2e/create_schema_test.go b/e2e/create_schema_test.go index bbf2996..eb8f92e 100644 --- a/e2e/create_schema_test.go +++ b/e2e/create_schema_test.go @@ -1,7 +1,6 @@ package e2e import ( - "errors" "log" "testing" @@ -63,22 +62,28 @@ CREATE TABLE cqlc.t1abc ( err = c.Upsert(t1gen.T1abcTableDef()). SetString(t1gen.T1ABC.ID, "2"). //SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "2").Exec(sess) - SetStringStringMap(t1gen.T1ABC.STRING_MAP, map[string]string{"1": "2"}).Exec(sess) + SetStringStringMap(t1gen.T1ABC.STRING_MAP, map[string]string{"1": "2"}). + Exec(sess) require.Nil(err, "insert map") - - // cqlc.go:522: CQL: INSERT INTO t1abc (id, string_map) VALUES ( 2, map[1:2]) - // cqlc.go:522: CQL: UPDATE t1abc SET string_map[ [1 3]] = 2 WHERE id = %!v(MISSING) - // --- FAIL: TestCreateSchema/insert (0.03s) - // require.go:765: - // Error Trace: create_schema_test.go:72 - //Error: Expected nil, but got: &errors.errorString{s:"gocql: expected 3 values send got 2"} err = c.Upsert(t1gen.T1abcTableDef()). - SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "3"). + SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "4"). Where(t1gen.T1ABC.ID.Eq("2")). Exec(sess) + //stmt, holders, err := cqlc.BuildStatement(c) + //t.Log(stmt) + //t.Log(holders) require.Nil(err, "update map") + var row t1gen.T1abc + + found, err := c.Select(t1gen.T1ABC.STRING_MAP).From(t1gen.T1ABC). + Where(t1gen.T1ABC.ID.Eq("2")). + Into(t1gen.T1ABC.To(&row)).FetchOne(sess) + require.Nil(err) + require.True(found, "found the row") + require.Equal("4", row.StringMap["1"]) + //err = c.Upsert(t1gen.T1abcTableDef()). // SetString(t1gen.T1ABC.ID, "1"). // SetTimestamp(t1gen.T1ABC.TS, time.Now()).Exec(sess) From 30cbe8e20d8c5548a9616235ae8efa41fe6551ff Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 03:39:11 -0700 Subject: [PATCH 20/39] [dep] Remove seelog add pkg/errors --- .travis.yml | 10 +++++----- Makefile | 5 +++-- generator/generator.go | 12 +++++++----- glide.lock | 8 ++++---- glide.yaml | 3 +-- test/schema_generator.go | 23 +---------------------- 6 files changed, 21 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index a7cda3e..189e9fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,11 +32,11 @@ before_install: - cd ${GOPATH}/src/github.com/relops/cqlc install: - - pip install --user PyYAML six - - git clone https://github.com/pcmanus/ccm.git - - pushd ccm - - ./setup.py install --user - - popd +# - pip install --user PyYAML six +# - git clone https://github.com/pcmanus/ccm.git +# - pushd ccm +# - ./setup.py install --user +# - popd - glide install - make install diff --git a/Makefile b/Makefile index 8a95d49..6ba9bbd 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,9 @@ columns: cqlc/columns.go input: test/.fixtures/collections/input.go test/collections.cql # FIXME: generator won't work due to go vendor ... inspect type does not equal -test: columns schema test/.fixtures/collections/input.go - go test -v ./cqlc +#test: columns schema test/.fixtures/collections/input.go +# go test -v ./cqlc +test: test-unit test-unit: go test -v ./cqlc diff --git a/generator/generator.go b/generator/generator.go index 46bcb2d..3e5e7a7 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -2,7 +2,6 @@ package generator import ( "bytes" - "errors" "fmt" "go/format" "io" @@ -15,6 +14,7 @@ import ( "time" "github.com/gocql/gocql" + "github.com/pkg/errors" ) var ( @@ -109,7 +109,7 @@ func generateBinding(opts *Options, version string, w io.Writer) error { s, err := cluster.CreateSession() if err != nil { - return fmt.Errorf("Connect error %s", err) + return errors.Errorf("Connect error %s", err) } log.Println("connected") @@ -121,12 +121,12 @@ func generateBinding(opts *Options, version string, w io.Writer) error { err = s.Query(`SELECT native_protocol_version, release_version, cql_version, host_id FROM system.local`).Scan(&protoString, &release, &cqlVersion, &hostId) if err != nil { - return fmt.Errorf("System metadata error %s", err) + return errors.Errorf("System metadata error %s", err) } proto, err := strconv.Atoi(protoString) if err != nil { - return fmt.Errorf("Could not parse protocol version %s", err) + return errors.Errorf("Could not parse protocol version %s", err) } if proto > 3 { @@ -135,7 +135,7 @@ func generateBinding(opts *Options, version string, w io.Writer) error { s, err = cluster.CreateSession() if err != nil { - return fmt.Errorf("Re-connect error %s", err) + return errors.Errorf("Re-connect error %s", err) } } @@ -176,6 +176,8 @@ func generateBinding(opts *Options, version string, w io.Writer) error { return err } + log.Println("formatted rendered code") + if _, err := w.Write(bfmt); err != nil { return err } diff --git a/glide.lock b/glide.lock index db7e1be..1bd00cc 100644 --- a/glide.lock +++ b/glide.lock @@ -1,8 +1,6 @@ -hash: 7068a4d17fe81a559838fd967b24bbe472d33bce86ca270c19176cd5ef2ade0f -updated: 2018-09-14T19:15:26.835783-07:00 +hash: d4bb692c7281da9ad8d3c490e1125de6946522c7d0243f0f0b603b1e1e3e7b6d +updated: 2018-09-15T03:35:20.97843-07:00 imports: -- name: github.com/cihub/seelog - version: d2c6e5aa9fbfdd1c624e140287063c7730654115 - name: github.com/gocql/gocql version: 045d8d6abc70b5bd02bb18b8fdb05ee54d8c87aa subpackages: @@ -15,6 +13,8 @@ imports: version: e80d13ce29ede4452c43dea11e79b9bc8a15b478 - name: github.com/jessevdk/go-flags version: c6ca198ec95c841fdb89fc0de7496fed11ab854e +- name: github.com/pkg/errors + version: c059e472caf75dbe73903f6521a20abac245b17f - name: gopkg.in/inf.v0 version: d2d2541c53f18d2a059457998ce2876cc8e67cbf testImports: diff --git a/glide.yaml b/glide.yaml index ac55af4..d7570e1 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,8 +1,7 @@ package: github.com/relops/cqlc import: -- package: github.com/cihub/seelog - version: ^2.6.0 - package: github.com/gocql/gocql +- package: github.com/pkg/errors - package: github.com/jessevdk/go-flags version: ^1.4.0 - package: gopkg.in/inf.v0 diff --git a/test/schema_generator.go b/test/schema_generator.go index b896941..ba7045e 100644 --- a/test/schema_generator.go +++ b/test/schema_generator.go @@ -5,32 +5,11 @@ package main import ( "bytes" "fmt" - log "github.com/cihub/seelog" + "log" "io/ioutil" "text/template" ) -var logConfig = ` - - - - - - - -` - -func init() { - logger, err := log.LoggerFromConfigAsString(logConfig) - - if err != nil { - fmt.Printf("Could not load seelog configuration: %s\n", err) - return - } - - log.ReplaceLogger(logger) -} - type TypeInfo struct { Pre string Cql string From 11e8efc36a4c00753204b7a2764fd62da7ffbda1 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 09:52:28 -0700 Subject: [PATCH 21/39] [gen] Use separated type for map key value - previous implementation is wrong, it blindly expand all value slice, which would break AppendSlice, now we use struct KeyValue as binding value and expand based on CollectionType and CollectionOperationType --- cqlc/cqlc.go | 34 +++++++++++++++++----------------- generator/generator.go | 1 - 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index 9ab604c..a3da41c 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -222,6 +222,12 @@ type ColumnBinding struct { CollectionOperationType CollectionOperationType } +// KeyValue is used for bind map value by key +type KeyValue struct { + Key interface{} + Value interface{} +} + type TableBinding struct { Table Table Columns []ColumnBinding @@ -535,27 +541,21 @@ func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err er placeHolders = make([]interface{}, 0) - // NOTE: for all the binding we need to expand slice due to multiple place holders in one binding + // NOTE: for all binding we need to expand value due to multiple placeholders in one binding // in bindings we have foo[?] = ? // in where bindings we have where foo in (?, ?, ?) for _, bind := range c.Bindings { v := bind.Value - switch reflect.TypeOf(v).Kind() { - case reflect.Slice: - s := reflect.ValueOf(v) - for i := 0; i < s.Len(); i++ { - placeHolders = append(placeHolders, s.Index(i).Interface()) - } - case reflect.Array: - - // Not really happy about having to special case UUIDs - // but this works for now - - if val, ok := v.(gocql.UUID); ok { - placeHolders = append(placeHolders, val.Bytes()) - } else { - return "", nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v)) + switch bind.CollectionType { + case MapType: + switch bind.CollectionOperationType { + case SetByKey: + kv, ok := v.(KeyValue) + if !ok { + return "", nil, errors.Errorf("map set by key requires key value on column %s", bind.Column.ColumnName()) + } + placeHolders = append(placeHolders, kv.Key, kv.Value) } default: placeHolders = append(placeHolders, v) @@ -677,7 +677,7 @@ func set(c *Context, col Column, value interface{}) { } func setMap(c *Context, col Column, key interface{}, value interface{}) { - b := ColumnBinding{Column: col, Value: []interface{}{key, value}, CollectionType: MapType, CollectionOperationType: SetByKey} + b := ColumnBinding{Column: col, Value: KeyValue{Key: key, Value: value}, CollectionType: MapType, CollectionOperationType: SetByKey} c.Bindings = append(c.Bindings, b) } diff --git a/generator/generator.go b/generator/generator.go index 3e5e7a7..d6658be 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -2,7 +2,6 @@ package generator import ( "bytes" - "fmt" "go/format" "io" "io/ioutil" From 52941fa8a4d158971b78d124b8277f4621655f32 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 11:02:30 -0700 Subject: [PATCH 22/39] [test] Run gocql and cqlc in parallel - string map worked fine, not sure about slice though ... --- e2e/create_schema_test.go | 180 ++++++++++++------ e2e/g1/cqlc_generated.go | 383 ++++++++++++++++++++++++++++++++++++++ e2e/t1gen/generated.go | 256 ------------------------- generator/tmpl.go | 4 +- 4 files changed, 508 insertions(+), 315 deletions(-) create mode 100644 e2e/g1/cqlc_generated.go delete mode 100644 e2e/t1gen/generated.go diff --git a/e2e/create_schema_test.go b/e2e/create_schema_test.go index eb8f92e..7653b37 100644 --- a/e2e/create_schema_test.go +++ b/e2e/create_schema_test.go @@ -1,96 +1,162 @@ package e2e import ( + "fmt" "log" + "os" + "os/exec" "testing" "github.com/gocql/gocql" - "github.com/relops/cqlc/cqlc" - "github.com/relops/cqlc/e2e/t1gen" + asst "github.com/stretchr/testify/assert" requir "github.com/stretchr/testify/require" + + "github.com/relops/cqlc/cqlc" + "github.com/relops/cqlc/e2e/g1" ) -func TestCreateSchema(t *testing.T) { - t.Run("create keyspace", func(t *testing.T) { - require := requir.New(t) +const ( + cqlcKs = "cqlc" + gocqlKs = "gocql" +) + +func TestCreateKeyspace(t *testing.T) { + require := requir.New(t) + + // create two ks, one for cqlc, one for gocql, so table for gocql won't get dumped by cqlc generator + for _, ks := range []string{cqlcKs, gocqlKs} { + createKeyspace := fmt.Sprintf(`CREATE KEYSPACE %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };`, ks) cluster := gocql.NewCluster("127.0.0.1") cluster.Keyspace = "system" sess, err := cluster.CreateSession() - require.Nil(err, "connect to cassandra using system keyspace for create new keyspace") - - createKeyspace := `CREATE KEYSPACE cqlc WITH replication = -{ 'class' : 'SimpleStrategy', 'replication_factor' : 1 };` + require.Nil(err, "connect to cassandra using system keyspace for create new keyspace"+ks) err = sess.Query(createKeyspace).Exec() require.Nil(err, "create keyspace") - }) + log.Printf("created keyspace %s", ks) + } +} + +const tblStringMap = ` +CREATE TABLE %s ( + id text PRIMARY KEY, + ssm map +) +` + +const tblMapSlice = ` +CREATE TABLE %s ( + id text PRIMARY KEY, + ssm map, + sl list +) +` - t.Run("create table", func(t *testing.T) { - require := requir.New(t) +// for each ddl, we create two table, one for gocql, one for cqlc +func TestCreateTable(t *testing.T) { + require := requir.New(t) + for _, ks := range []string{cqlcKs, gocqlKs} { cluster := gocql.NewCluster("127.0.0.1") - cluster.Keyspace = "cqlc" + cluster.Keyspace = ks sess, err := cluster.CreateSession() require.Nil(err, "connect to cassandra using cqlc keyspace for create new table") - // NOTE: the table name need to have some lower case to avoid conflict .... if we use t1, it will break ... - createTable := ` -CREATE TABLE cqlc.t1abc ( - id text PRIMARY KEY, - ts timestamp, - string_map map, - string_list list, -) -` - err = sess.Query(createTable).Exec() - require.Nil(err, "create table") + ddls := []string{tblStringMap, tblMapSlice} + tbs := []string{"tbl_string_map", "tbl_map_slice"} + for i := 0; i < len(tbs); i++ { + err = sess.Query(fmt.Sprintf(ddls[i], tbs[i])).Exec() + require.Nil(err, "create table "+tbs[i]) + log.Printf("created %s.%s", ks, tbs[i]) + } + } +} - // cqlc --instance=127.0.0.1 --keyspace=cqlc --package=t1gen --output=t1gen/generated.go --verbose --symbols - }) +func TestGenerate(t *testing.T) { + // cqlc --instance=127.0.0.1 --keyspace=cqlc --package=g1 --output=g1/cqlc_generated.go --verbose --symbols + runCqlc(t, cqlcKs, "g1") +} - t.Run("insert", func(t *testing.T) { - require := requir.New(t) +func TestUpdate(t *testing.T) { + require := requir.New(t) + assert := asst.New(t) + sf := func(ks string) *gocql.Session { cluster := gocql.NewCluster("127.0.0.1") - cluster.Keyspace = "cqlc" + cluster.Keyspace = ks sess, err := cluster.CreateSession() require.Nil(err, "connect to cassandra using cqlc keyspace for create new table") + return sess + } + + sGocql := sf(gocqlKs) + sCqlc := sf(cqlcKs) + + t.Run("insert", func(t *testing.T) { + err := sGocql.Query("INSERT INTO tbl_string_map (id, ssm) VALUES (?,?)", "1", map[string]string{"k1": "v1"}).Exec() + require.Nil(err) c := cqlc.NewContext() c.Debug = true - // FIXME: StringMapValue didn't work "can not marshal []interface {} into map(varchar, varchar)" - err = c.Upsert(t1gen.T1abcTableDef()). - SetString(t1gen.T1ABC.ID, "2"). - //SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "2").Exec(sess) - SetStringStringMap(t1gen.T1ABC.STRING_MAP, map[string]string{"1": "2"}). - Exec(sess) - require.Nil(err, "insert map") - - err = c.Upsert(t1gen.T1abcTableDef()). - SetStringStringMapValue(t1gen.T1ABC.STRING_MAP, "1", "4"). - Where(t1gen.T1ABC.ID.Eq("2")). - Exec(sess) - //stmt, holders, err := cqlc.BuildStatement(c) - //t.Log(stmt) - //t.Log(holders) - require.Nil(err, "update map") - - var row t1gen.T1abc - - found, err := c.Select(t1gen.T1ABC.STRING_MAP).From(t1gen.T1ABC). - Where(t1gen.T1ABC.ID.Eq("2")). - Into(t1gen.T1ABC.To(&row)).FetchOne(sess) + err = c.Upsert(g1.TblStringMapTableDef()).SetString(g1.TBL_STRING_MAP.ID, "1"). + SetStringStringMap(g1.TBL_STRING_MAP.SSM, map[string]string{"k1": "v1"}).Exec(sCqlc) + require.Nil(err) + }) + + t.Run("update", func(t *testing.T) { + err := sGocql.Query("UPDATE tbl_string_map SET ssm[?] = ? WHERE id = ?", "k1", "v2", "1").Exec() require.Nil(err) - require.True(found, "found the row") - require.Equal("4", row.StringMap["1"]) - //err = c.Upsert(t1gen.T1abcTableDef()). - // SetString(t1gen.T1ABC.ID, "1"). - // SetTimestamp(t1gen.T1ABC.TS, time.Now()).Exec(sess) - //require.Nil(err, "insert map") + c := cqlc.NewContext() + c.Debug = true + err = c.Upsert(g1.TblStringMapTableDef()). + SetStringStringMapValue(g1.TBL_STRING_MAP.SSM, "k1", "v2"). + Where(g1.TBL_STRING_MAP.ID.Eq("1")).Exec(sCqlc) + require.Nil(err) + + }) + + t.Run("query", func(t *testing.T) { + iter := sGocql.Query("SELECT id, ssm FROM tbl_string_map WHERE id = ?", "1").Iter() + var id string + var m = map[string]string{} + scanned := iter.Scan(&id, &m) + assert.True(scanned) + require.Nil(iter.Close()) + require.Equal("1", id) + require.Equal("v2", m["k1"]) + + c := cqlc.NewContext() + c.Debug = true + var row g1.TblStringMap + ok, err := c.Select(g1.TBL_STRING_MAP.ID, g1.TBL_STRING_MAP.SSM).From(g1.TblStringMapTableDef()). + Where(g1.TBL_STRING_MAP.ID.Eq("1")).Into(g1.TBL_STRING_MAP.To(&row)).FetchOne(sCqlc) + require.Nil(err) + assert.True(ok) + require.Equal("1", row.Id) + require.Equal("v2", row.Ssm["k1"]) }) } +func runCqlc(t *testing.T, ks string, pkg string) { + // cqlc --instance=127.0.0.1 --keyspace=cqlc --package=t1gen --output=t1gen/generated.go --verbose --symbols + cmd := exec.Command("cqlc", + "--instance=127.0.0.1", + "--keyspace="+ks, + "--package="+pkg, + "--output="+pkg+"/cqlc_generated.go", + "--symbols", + "--verbose", + ) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + t.Fatal(err) + } + log.Printf("cqlc generate ks %s to %s", ks, pkg) +} + func init() { log.SetFlags(log.Lshortfile) } diff --git a/e2e/g1/cqlc_generated.go b/e2e/g1/cqlc_generated.go new file mode 100644 index 0000000..428bb3b --- /dev/null +++ b/e2e/g1/cqlc_generated.go @@ -0,0 +1,383 @@ +// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +// GENERATED USING KEYSPACE cqlc +// AT 2018-09-15 11:01:19.143063 -0700 PDT m=+0.078221167 USING cqlc VERSION 0.10.5 +// AGAINST HOST ID c4849d11-abee-4845-b655-521d116252ad (SERVER VERSION 2.1.20) +// CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.2.1) + +package g1 + +import ( + "github.com/gocql/gocql" + + "log" + + "github.com/relops/cqlc/cqlc" +) + +const ( + CQLC_VERSION = "0.10.5" +) + +type TblMapSliceIdColumn struct { +} + +func (b *TblMapSliceIdColumn) ColumnName() string { + return "id" +} + +func (b *TblMapSliceIdColumn) To(value *string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +func (b *TblMapSliceIdColumn) Eq(value string) cqlc.Condition { + column := &TblMapSliceIdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.EqPredicate} +} + +func (b *TblMapSliceIdColumn) PartitionBy() cqlc.Column { + return b +} + +func (b *TblMapSliceIdColumn) In(value ...string) cqlc.Condition { + column := &TblMapSliceIdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.InPredicate} +} + +type TblMapSliceSlColumn struct { +} + +func (b *TblMapSliceSlColumn) ColumnName() string { + return "sl" +} + +func (b *TblMapSliceSlColumn) ListType() cqlc.Column { + return &TblMapSliceSlColumn{} +} + +func (b *TblMapSliceSlColumn) To(value *[]string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +type TblMapSliceSsmColumn struct { +} + +func (b *TblMapSliceSsmColumn) ColumnName() string { + return "ssm" +} + +func (b *TblMapSliceSsmColumn) To(value *map[string]string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +type TblMapSlice struct { + Id string + + Sl []string + + Ssm map[string]string +} + +func (s *TblMapSlice) IdValue() string { + return s.Id +} + +func (s *TblMapSlice) SlValue() []string { + return s.Sl +} + +func (s *TblMapSlice) SsmValue() map[string]string { + return s.Ssm +} + +type TblMapSliceDef struct { + ID cqlc.LastPartitionedStringColumn + + SL cqlc.StringSliceColumn + + SSM cqlc.StringStringMapColumn +} + +func BindTblMapSlice(iter *gocql.Iter) ([]TblMapSlice, error) { + array := make([]TblMapSlice, 0) + err := MapTblMapSlice(iter, func(t TblMapSlice) (bool, error) { + array = append(array, t) + return true, nil + }) + return array, err +} + +func MapTblMapSlice(iter *gocql.Iter, callback func(t TblMapSlice) (bool, error)) error { + columns := iter.Columns() + row := make([]interface{}, len(columns)) + + for { + t := TblMapSlice{} + + for i := 0; i < len(columns); i++ { + switch columns[i].Name { + + case "id": + row[i] = &t.Id + + case "sl": + row[i] = &t.Sl + + case "ssm": + row[i] = &t.Ssm + + default: + log.Fatal("unhandled column: ", columns[i].Name) + } + } + if !iter.Scan(row...) { + break + } + + readNext, err := callback(t) + if err != nil { + return err + } + if !readNext { + return nil + } + } + + return nil +} + +func (s *TblMapSliceDef) SupportsUpsert() bool { + return true +} + +func (s *TblMapSliceDef) TableName() string { + return "tbl_map_slice" +} + +func (s *TblMapSliceDef) Keyspace() string { + return "cqlc" +} + +func (s *TblMapSliceDef) Bind(v TblMapSlice) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + {Column: &TblMapSliceIdColumn{}, Value: v.Id}, + + {Column: &TblMapSliceSlColumn{}, Value: v.Sl}, + + {Column: &TblMapSliceSsmColumn{}, Value: v.Ssm}, + } + return cqlc.TableBinding{Table: &TblMapSliceDef{}, Columns: cols} +} + +func (s *TblMapSliceDef) To(v *TblMapSlice) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + {Column: &TblMapSliceIdColumn{}, Value: &v.Id}, + + {Column: &TblMapSliceSlColumn{}, Value: &v.Sl}, + + {Column: &TblMapSliceSsmColumn{}, Value: &v.Ssm}, + } + return cqlc.TableBinding{Table: &TblMapSliceDef{}, Columns: cols} +} + +func (s *TblMapSliceDef) ColumnDefinitions() []cqlc.Column { + return []cqlc.Column{ + + &TblMapSliceIdColumn{}, + + &TblMapSliceSlColumn{}, + + &TblMapSliceSsmColumn{}, + } +} + +func TblMapSliceTableDef() *TblMapSliceDef { + return &TblMapSliceDef{ + + ID: &TblMapSliceIdColumn{}, + + SL: &TblMapSliceSlColumn{}, + + SSM: &TblMapSliceSsmColumn{}, + } +} + +var TBL_MAP_SLICE = TblMapSliceTableDef() + +func (s *TblMapSliceDef) IdColumn() cqlc.LastPartitionedStringColumn { + return &TblMapSliceIdColumn{} +} + +func (s *TblMapSliceDef) SlColumn() cqlc.StringSliceColumn { + return &TblMapSliceSlColumn{} +} + +func (s *TblMapSliceDef) SsmColumn() cqlc.StringStringMapColumn { + return &TblMapSliceSsmColumn{} +} + +type TblStringMapIdColumn struct { +} + +func (b *TblStringMapIdColumn) ColumnName() string { + return "id" +} + +func (b *TblStringMapIdColumn) To(value *string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +func (b *TblStringMapIdColumn) Eq(value string) cqlc.Condition { + column := &TblStringMapIdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.EqPredicate} +} + +func (b *TblStringMapIdColumn) PartitionBy() cqlc.Column { + return b +} + +func (b *TblStringMapIdColumn) In(value ...string) cqlc.Condition { + column := &TblStringMapIdColumn{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.InPredicate} +} + +type TblStringMapSsmColumn struct { +} + +func (b *TblStringMapSsmColumn) ColumnName() string { + return "ssm" +} + +func (b *TblStringMapSsmColumn) To(value *map[string]string) cqlc.ColumnBinding { + return cqlc.ColumnBinding{Column: b, Value: value} +} + +type TblStringMap struct { + Id string + + Ssm map[string]string +} + +func (s *TblStringMap) IdValue() string { + return s.Id +} + +func (s *TblStringMap) SsmValue() map[string]string { + return s.Ssm +} + +type TblStringMapDef struct { + ID cqlc.LastPartitionedStringColumn + + SSM cqlc.StringStringMapColumn +} + +func BindTblStringMap(iter *gocql.Iter) ([]TblStringMap, error) { + array := make([]TblStringMap, 0) + err := MapTblStringMap(iter, func(t TblStringMap) (bool, error) { + array = append(array, t) + return true, nil + }) + return array, err +} + +func MapTblStringMap(iter *gocql.Iter, callback func(t TblStringMap) (bool, error)) error { + columns := iter.Columns() + row := make([]interface{}, len(columns)) + + for { + t := TblStringMap{} + + for i := 0; i < len(columns); i++ { + switch columns[i].Name { + + case "id": + row[i] = &t.Id + + case "ssm": + row[i] = &t.Ssm + + default: + log.Fatal("unhandled column: ", columns[i].Name) + } + } + if !iter.Scan(row...) { + break + } + + readNext, err := callback(t) + if err != nil { + return err + } + if !readNext { + return nil + } + } + + return nil +} + +func (s *TblStringMapDef) SupportsUpsert() bool { + return true +} + +func (s *TblStringMapDef) TableName() string { + return "tbl_string_map" +} + +func (s *TblStringMapDef) Keyspace() string { + return "cqlc" +} + +func (s *TblStringMapDef) Bind(v TblStringMap) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + {Column: &TblStringMapIdColumn{}, Value: v.Id}, + + {Column: &TblStringMapSsmColumn{}, Value: v.Ssm}, + } + return cqlc.TableBinding{Table: &TblStringMapDef{}, Columns: cols} +} + +func (s *TblStringMapDef) To(v *TblStringMap) cqlc.TableBinding { + cols := []cqlc.ColumnBinding{ + + {Column: &TblStringMapIdColumn{}, Value: &v.Id}, + + {Column: &TblStringMapSsmColumn{}, Value: &v.Ssm}, + } + return cqlc.TableBinding{Table: &TblStringMapDef{}, Columns: cols} +} + +func (s *TblStringMapDef) ColumnDefinitions() []cqlc.Column { + return []cqlc.Column{ + + &TblStringMapIdColumn{}, + + &TblStringMapSsmColumn{}, + } +} + +func TblStringMapTableDef() *TblStringMapDef { + return &TblStringMapDef{ + + ID: &TblStringMapIdColumn{}, + + SSM: &TblStringMapSsmColumn{}, + } +} + +var TBL_STRING_MAP = TblStringMapTableDef() + +func (s *TblStringMapDef) IdColumn() cqlc.LastPartitionedStringColumn { + return &TblStringMapIdColumn{} +} + +func (s *TblStringMapDef) SsmColumn() cqlc.StringStringMapColumn { + return &TblStringMapSsmColumn{} +} diff --git a/e2e/t1gen/generated.go b/e2e/t1gen/generated.go deleted file mode 100644 index 58130a0..0000000 --- a/e2e/t1gen/generated.go +++ /dev/null @@ -1,256 +0,0 @@ -// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED -// GENERATED USING KEYSPACE cqlc -// AT 2018-09-15 01:51:09.978716 -0700 PDT m=+0.075402320 USING cqlc VERSION 0.10.5 -// AGAINST HOST ID 9e053a42-f26c-4cb8-af0d-af1c795d68f9 (SERVER VERSION 2.1.20) -// CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.2.1) - -package t1gen - -import ( - "time" - - "github.com/relops/cqlc/cqlc" - - "github.com/gocql/gocql" - - "log" -) - -const ( - CQLC_VERSION = "0.10.5" -) - -type T1abcIdColumn struct { -} - -func (b *T1abcIdColumn) ColumnName() string { - return "id" -} - -func (b *T1abcIdColumn) To(value *string) cqlc.ColumnBinding { - return cqlc.ColumnBinding{Column: b, Value: value} -} - -func (b *T1abcIdColumn) Eq(value string) cqlc.Condition { - column := &T1abcIdColumn{} - binding := cqlc.ColumnBinding{Column: column, Value: value} - return cqlc.Condition{Binding: binding, Predicate: cqlc.EqPredicate} -} - -func (b *T1abcIdColumn) PartitionBy() cqlc.Column { - return b -} - -func (b *T1abcIdColumn) In(value ...string) cqlc.Condition { - column := &T1abcIdColumn{} - binding := cqlc.ColumnBinding{Column: column, Value: value} - return cqlc.Condition{Binding: binding, Predicate: cqlc.InPredicate} -} - -type T1abcStringListColumn struct { -} - -func (b *T1abcStringListColumn) ColumnName() string { - return "string_list" -} - -func (b *T1abcStringListColumn) ListType() cqlc.Column { - return &T1abcStringListColumn{} -} - -func (b *T1abcStringListColumn) To(value *[]string) cqlc.ColumnBinding { - return cqlc.ColumnBinding{Column: b, Value: value} -} - -type T1abcStringMapColumn struct { -} - -func (b *T1abcStringMapColumn) ColumnName() string { - return "string_map" -} - -func (b *T1abcStringMapColumn) To(value *map[string]string) cqlc.ColumnBinding { - return cqlc.ColumnBinding{Column: b, Value: value} -} - -type T1abcTsColumn struct { -} - -func (b *T1abcTsColumn) ColumnName() string { - return "ts" -} - -func (b *T1abcTsColumn) To(value *time.Time) cqlc.ColumnBinding { - return cqlc.ColumnBinding{Column: b, Value: value} -} - -type T1abc struct { - Id string - - StringList []string - - StringMap map[string]string - - Ts time.Time -} - -func (s *T1abc) IdValue() string { - return s.Id -} - -func (s *T1abc) StringListValue() []string { - return s.StringList -} - -func (s *T1abc) StringMapValue() map[string]string { - return s.StringMap -} - -func (s *T1abc) TsValue() time.Time { - return s.Ts -} - -type T1abcDef struct { - ID cqlc.LastPartitionedStringColumn - - STRING_LIST cqlc.StringSliceColumn - - STRING_MAP cqlc.StringStringMapColumn - - TS cqlc.TimestampColumn -} - -func BindT1abc(iter *gocql.Iter) ([]T1abc, error) { - array := make([]T1abc, 0) - err := MapT1abc(iter, func(t T1abc) (bool, error) { - array = append(array, t) - return true, nil - }) - return array, err -} - -func MapT1abc(iter *gocql.Iter, callback func(t T1abc) (bool, error)) error { - columns := iter.Columns() - row := make([]interface{}, len(columns)) - - for { - t := T1abc{} - - for i := 0; i < len(columns); i++ { - switch columns[i].Name { - - case "id": - row[i] = &t.Id - - case "string_list": - row[i] = &t.StringList - - case "string_map": - row[i] = &t.StringMap - - case "ts": - row[i] = &t.Ts - - default: - log.Fatal("unhandled column: ", columns[i].Name) - } - } - if !iter.Scan(row...) { - break - } - - readNext, err := callback(t) - if err != nil { - return err - } - if !readNext { - return nil - } - } - - return nil -} - -func (s *T1abcDef) SupportsUpsert() bool { - return true -} - -func (s *T1abcDef) TableName() string { - return "t1abc" -} - -func (s *T1abcDef) Keyspace() string { - return "cqlc" -} - -func (s *T1abcDef) Bind(v T1abc) cqlc.TableBinding { - cols := []cqlc.ColumnBinding{ - - cqlc.ColumnBinding{Column: &T1abcIdColumn{}, Value: v.Id}, - - cqlc.ColumnBinding{Column: &T1abcStringListColumn{}, Value: v.StringList}, - - cqlc.ColumnBinding{Column: &T1abcStringMapColumn{}, Value: v.StringMap}, - - cqlc.ColumnBinding{Column: &T1abcTsColumn{}, Value: v.Ts}, - } - return cqlc.TableBinding{Table: &T1abcDef{}, Columns: cols} -} - -func (s *T1abcDef) To(v *T1abc) cqlc.TableBinding { - cols := []cqlc.ColumnBinding{ - - cqlc.ColumnBinding{Column: &T1abcIdColumn{}, Value: &v.Id}, - - cqlc.ColumnBinding{Column: &T1abcStringListColumn{}, Value: &v.StringList}, - - cqlc.ColumnBinding{Column: &T1abcStringMapColumn{}, Value: &v.StringMap}, - - cqlc.ColumnBinding{Column: &T1abcTsColumn{}, Value: &v.Ts}, - } - return cqlc.TableBinding{Table: &T1abcDef{}, Columns: cols} -} - -func (s *T1abcDef) ColumnDefinitions() []cqlc.Column { - return []cqlc.Column{ - - &T1abcIdColumn{}, - - &T1abcStringListColumn{}, - - &T1abcStringMapColumn{}, - - &T1abcTsColumn{}, - } -} - -func T1abcTableDef() *T1abcDef { - return &T1abcDef{ - - ID: &T1abcIdColumn{}, - - STRING_LIST: &T1abcStringListColumn{}, - - STRING_MAP: &T1abcStringMapColumn{}, - - TS: &T1abcTsColumn{}, - } -} - -var T1ABC = T1abcTableDef() - -func (s *T1abcDef) IdColumn() cqlc.LastPartitionedStringColumn { - return &T1abcIdColumn{} -} - -func (s *T1abcDef) StringListColumn() cqlc.StringSliceColumn { - return &T1abcStringListColumn{} -} - -func (s *T1abcDef) StringMapColumn() cqlc.StringStringMapColumn { - return &T1abcStringMapColumn{} -} - -func (s *T1abcDef) TsColumn() cqlc.TimestampColumn { - return &T1abcTsColumn{} -} diff --git a/generator/tmpl.go b/generator/tmpl.go index 702e6db..853f5e6 100644 --- a/generator/tmpl.go +++ b/generator/tmpl.go @@ -218,7 +218,7 @@ const ( {{range $_, $col := $cf.Columns}} {{ $ColStructType := snakeToCamel $col.Name }} {{ $QualifiedColStructType := sprint $StructType $ColStructType }} - cqlc.ColumnBinding{Column: &{{ $QualifiedColStructType }}Column{}, Value: v.{{snakeToCamel $col.Name}}}, + {Column: &{{ $QualifiedColStructType }}Column{}, Value: v.{{snakeToCamel $col.Name}}}, {{end}} } return cqlc.TableBinding{Table: &{{$StructType}}Def{}, Columns: cols} @@ -229,7 +229,7 @@ const ( {{range $_, $col := $cf.Columns}} {{ $ColStructType := snakeToCamel $col.Name }} {{ $QualifiedColStructType := sprint $StructType $ColStructType }} - cqlc.ColumnBinding{Column: &{{ $QualifiedColStructType }}Column{}, Value: &v.{{snakeToCamel $col.Name}}}, + {Column: &{{ $QualifiedColStructType }}Column{}, Value: &v.{{snakeToCamel $col.Name}}}, {{end}} } return cqlc.TableBinding{Table: &{{$StructType}}Def{}, Columns: cols} From 3cff150c62f7946d683617e1f2f3576cc3edba30 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 11:26:02 -0700 Subject: [PATCH 23/39] [test] Fix #3 use docker for e2e test - I don't know if old integration test still work though .... --- .travis.yml | 22 ++++++++++++---------- Makefile | 11 ++++++++++- README.md | 7 +++++++ e2e/g1/cqlc_generated.go | 8 ++++---- integration.sh | 33 --------------------------------- wait-on-c.sh | 9 +++++++++ 6 files changed, 42 insertions(+), 48 deletions(-) delete mode 100644 integration.sh create mode 100755 wait-on-c.sh diff --git a/.travis.yml b/.travis.yml index 189e9fe..98bdf66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,7 @@ +sudo: required language: go - -sudo: false - -cache: - directories: - - $HOME/.ccm/repository +services: +- docker matrix: fast_finish: true @@ -13,6 +10,7 @@ env: global: # TODO: why need this? - GOMAXPROCS=2 + - DOCKER_COMPOSE_VERSION=1.22.0 matrix: - CASS=2.2.1 # - CASS=3.11 @@ -23,8 +21,10 @@ go: # - "tip" before_install: - # NOTE: needed for generator test, it generate file like /tmp/092804891/binding.go https://travis-ci.org/pingginp/cqlc/builds/428906675 - - go get github.com/gocql/gocql + - sudo rm /usr/local/bin/docker-compose + - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose + - chmod +x docker-compose + - sudo mv docker-compose /usr/local/bin - curl -sSL https://github.com/Masterminds/glide/releases/download/v0.13.1/glide-v0.13.1-linux-amd64.tar.gz | tar -vxz -C ${GOPATH}/bin --strip=1 # FIXME: workaround for gopath - mkdir -p ${GOPATH}/src/github.com/relops/cqlc @@ -41,5 +41,7 @@ install: - make install script: - - set -e - - PATH=$PATH:$HOME/.local/bin bash -x integration.sh $CASS + - make test + # e2e + - make travis-test + diff --git a/Makefile b/Makefile index 6ba9bbd..a990668 100644 --- a/Makefile +++ b/Makefile @@ -40,4 +40,13 @@ test-unit: format: gofmt -w cqlc generator integration test -.PHONY: test columns bindata \ No newline at end of file +travis-test: + docker-compose -f e2e/docker-compose.yaml up -d c2 + ./wait-on-c.sh + sleep 5 + go test -v ./e2e + +travis-tear: + cd e2e && make down + +.PHONY: test columns \ No newline at end of file diff --git a/README.md b/README.md index 119abc8..57c6e5c 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,15 @@ cqlc --instance=127.0.0.1 --keyspace=cqlc --package=foo --output=foo.go --symbol ````bash # generate columns make cqlc/columns.go +# e2e test +# TODO: you need to run it twice if schema changed because first time it will dump the schema, which won't get compiled ... +# this same as when using latex ... you do xelatex several times when there is bib ... +make travis-test +make travis-tear ```` + + ````go // NOTE: in order to support set map by value, we must flatten binding, // previously it is only did in Prepare and ignored in BuildStatement diff --git a/e2e/g1/cqlc_generated.go b/e2e/g1/cqlc_generated.go index 428bb3b..4dd1123 100644 --- a/e2e/g1/cqlc_generated.go +++ b/e2e/g1/cqlc_generated.go @@ -1,17 +1,17 @@ // THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED // GENERATED USING KEYSPACE cqlc -// AT 2018-09-15 11:01:19.143063 -0700 PDT m=+0.078221167 USING cqlc VERSION 0.10.5 -// AGAINST HOST ID c4849d11-abee-4845-b655-521d116252ad (SERVER VERSION 2.1.20) +// AT 2018-09-15 11:23:04.216543 -0700 PDT m=+0.072188024 USING cqlc VERSION 0.10.5 +// AGAINST HOST ID 40460167-3d58-4468-a57d-0ecd51e05998 (SERVER VERSION 2.1.20) // CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.2.1) package g1 import ( + "github.com/relops/cqlc/cqlc" + "github.com/gocql/gocql" "log" - - "github.com/relops/cqlc/cqlc" ) const ( diff --git a/integration.sh b/integration.sh deleted file mode 100644 index edc53a1..0000000 --- a/integration.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -set -e - -function run_tests() { - local clusterSize=1 - local version=$1 - - local conf=( - "concurrent_reads: 2" - "concurrent_writes: 2" - "rpc_server_type: sync" - "rpc_min_threads: 2" - "rpc_max_threads: 2" - "write_request_timeout_in_ms: 5000" - "read_request_timeout_in_ms: 5000" - ) - - ccm remove test || true - - ccm create test -v binary:$version -n $clusterSize -d --vnodes --jvm_arg="-Xmx256m -XX:NewSize=100m" - ccm updateconf "${conf[@]}" - - ccm start -v - ccm status - ccm node1 nodetool status - - make test - - ccm remove -} - -run_tests $1 diff --git a/wait-on-c.sh b/wait-on-c.sh new file mode 100755 index 0000000..b5d3cf3 --- /dev/null +++ b/wait-on-c.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +echo "wait on cassandra" + +while ! nc -z localhost 9042; do + sleep 5 +done + +echo "cassandra started" From ff73b30519ec59fee571bd544c3367bae4564303 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 11:47:41 -0700 Subject: [PATCH 24/39] [gen] Change generated header to canonical form --- Makefile | 1 + README.md | 12 ++++++++++-- e2e/g1/cqlc_generated.go | 4 ++-- generator/tmpl.go | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a990668..0cd09ef 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ format: travis-test: docker-compose -f e2e/docker-compose.yaml up -d c2 ./wait-on-c.sh + docker ps sleep 5 go test -v ./e2e diff --git a/README.md b/README.md index 57c6e5c..d7b576e 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,18 @@ make install cqlc --instance=127.0.0.1 --keyspace=cqlc --package=foo --output=foo.go --symbols ```` +You need to change the repo path in `glide.yaml` to use this fork + +````yaml +- package: github.com/relops/cqlc + version: master + repo: https://github.com/pingginp/cqlc.git +```` + ## Dev +- clone the repo to `$GOPATH/src/github.com/relops/cqlc` + ````bash # generate columns make cqlc/columns.go @@ -23,8 +33,6 @@ make travis-test make travis-tear ```` - - ````go // NOTE: in order to support set map by value, we must flatten binding, // previously it is only did in Prepare and ignored in BuildStatement diff --git a/e2e/g1/cqlc_generated.go b/e2e/g1/cqlc_generated.go index 4dd1123..5c126a8 100644 --- a/e2e/g1/cqlc_generated.go +++ b/e2e/g1/cqlc_generated.go @@ -1,6 +1,6 @@ -// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +// Code generated by https://github.com/pingginp/cqlc DO NOT EDIT. // GENERATED USING KEYSPACE cqlc -// AT 2018-09-15 11:23:04.216543 -0700 PDT m=+0.072188024 USING cqlc VERSION 0.10.5 +// AT 2018-09-15 11:44:08.677703 -0700 PDT m=+0.045865489 USING cqlc VERSION 0.10.5 // AGAINST HOST ID 40460167-3d58-4468-a57d-0ecd51e05998 (SERVER VERSION 2.1.20) // CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.2.1) diff --git a/generator/tmpl.go b/generator/tmpl.go index 853f5e6..82f7f0e 100644 --- a/generator/tmpl.go +++ b/generator/tmpl.go @@ -1,6 +1,6 @@ package generator -const Tmpl = `// THIS FILE WAS AUTOGENERATED - ANY EDITS TO THIS WILL BE LOST WHEN IT IS REGENERATED +const Tmpl = `// Code generated by https://github.com/pingginp/cqlc DO NOT EDIT. // GENERATED USING KEYSPACE {{ .Provenance.Keyspace }} // AT {{ .Provenance.Timestamp }} USING cqlc VERSION {{ .Provenance.Version }} // AGAINST HOST ID {{ .Provenance.HostId }} (SERVER VERSION {{ .Provenance.ServerRelease }}) From e6dfa5d4f2e3d90db6ec69fbb248883491aefdf7 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 17:30:17 -0700 Subject: [PATCH 25/39] [runtime] Use logrus instead of stdlog - similar to #8 --- CHANGELOG.md | 15 +++++ Makefile | 60 ++++++++++---------- README.md | 79 +++++--------------------- build/.gitignore | 3 +- cqlc/cqlc.go | 66 +++++++++++++--------- doc/set-map-value-by-key.md | 108 ++++++++++++++++++++++++++++++++++++ e2e/g1/cqlc_generated.go | 8 +-- glide.lock | 15 ++++- main.go | 2 +- test/schema_generator.go | 2 +- 10 files changed, 229 insertions(+), 129 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 doc/set-map-value-by-key.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ac7496f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +NOTE: this file format is based on [gaocegege/maintainer](https://github.com/gaocegege/maintainer/blob/master/CHANGELOG.md) + +## Unreleased + +[Closed issues](https://github.com/pingginp/cqlc/issues?q=is%3Aissue+is%3Aclosed+milestone%3A0.11.0) + +Merged pull requests + +- Reboot [#4](https://github.com/pingginp/cqlc/pull/4) the project now compiles and support set map value by key + +## 0.10.5 (2015-09-10) + +The last commit in upstream https://github.com/relops/cqlc/commit/9427a2081fb4f4910b0af8fc80d09c109b4f9815 \ No newline at end of file diff --git a/Makefile b/Makefile index 0cd09ef..ec9253c 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,47 @@ -CCM_NODE ?= node1 -CQLSH_CMD ?= ccm $(CCM_NODE) cqlsh +VERSION = 0.11.0 +LDFLAGS = -X main.Version=$(VERSION) +GO = CGO_ENABLED=0 go +GO_LINUX = GOOS=linux GOARCH=amd64 $(GO) +GO_MAC = GOOS=darwin GOARCH=amd64 $(GO) +GO_WINDOWS = GOOS=windows GOARCH=amd64 $(GO) + +.PHONY: gen fmt build install test + +fmt: + gofmt -d -l -w cqlc generator e2e -.PHONY: build build: - go build -o build/cqlc . + $(GO) build -ldflags "$(LDFLAGS)" -o build/cqlc . -.PHONY: install -install: - go install . +build-all: build-linux build-mac build-windows -test/collections.cql: test/tmpl/schema.tmpl test/schema_generator.go - cd test; go run schema_generator.go +build-linux: + $(GO_LINUX) build -ldflags "$(LDFLAGS)" -o build/cqlc-linux . -test/.fixtures/collections/input.go: test/tmpl/input.tmpl test/schema_generator.go - cd test; go run schema_generator.go +build-mac: + $(GO_MAC) build -ldflags "$(LDFLAGS)" -o build/cqlc-mac . -schema: test/collections.cql - -$(CQLSH_CMD) -f test/keyspace.cql - $(CQLSH_CMD) -k cqlc -f test/schema.cql - $(CQLSH_CMD) -k cqlc -f test/collections.cql - $(CQLSH_CMD) -k cqlc -f test/shared.cql - $(CQLSH_CMD) -k cqlc2 -f test/shared.cql +build-windows: + $(GO_WINDOWS) build -ldflags "$(LDFLAGS)" -o build/cqlc-windows . -cqlc/columns.go: cqlc/tmpl/columns.tmpl cqlc/column_generator.go - cd cqlc; go run column_generator.go +install: + go install -ldflags "$(LDFLAGS)" . -columns: cqlc/columns.go +release: build-all + cd build; rm -f *.zip + cd build; zip cqlc-$(VERSION)-linux.zip cqlc-linux + cd build; zip cqlc-$(VERSION)-mac.zip cqlc-mac + cd build; zip cqlc-$(VERSION)-windows.zip cqlc-windows -input: test/.fixtures/collections/input.go test/collections.cql +# generate highly duplicated part in runtime +gen: + cd cqlc; go run column_generator.go -# FIXME: generator won't work due to go vendor ... inspect type does not equal -#test: columns schema test/.fixtures/collections/input.go -# go test -v ./cqlc test: test-unit test-unit: go test -v ./cqlc -format: - gofmt -w cqlc generator integration test - travis-test: docker-compose -f e2e/docker-compose.yaml up -d c2 ./wait-on-c.sh @@ -48,6 +50,4 @@ travis-test: go test -v ./e2e travis-tear: - cd e2e && make down - -.PHONY: test columns \ No newline at end of file + cd e2e && make down \ No newline at end of file diff --git a/README.md b/README.md index d7b576e..be35e3c 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,14 @@ [![Build Status](https://travis-ci.org/pingginp/cqlc.svg?branch=master)](https://travis-ci.org/pingginp/cqlc) -This a fork of [relops/cqlc](https://github.com/relops/cqlc) which is no longer maintained +This a fork of [relops/cqlc](https://github.com/relops/cqlc) the upstream is no longer maintained. ## Usage ````bash +# install the generator to $GOPATH/bin make install +# generate table and column definition based on schema in keyspace cqlc cqlc --instance=127.0.0.1 --keyspace=cqlc --package=foo --output=foo.go --symbols ```` @@ -27,75 +29,24 @@ You need to change the repo path in `glide.yaml` to use this fork # generate columns make cqlc/columns.go # e2e test -# TODO: you need to run it twice if schema changed because first time it will dump the schema, which won't get compiled ... +# TODO: you need to run it twice if schema changed because first time it will generate package based on schema, which won't get compiled ... # this same as when using latex ... you do xelatex several times when there is bib ... make travis-test make travis-tear ```` -````go -// NOTE: in order to support set map by value, we must flatten binding, -// previously it is only did in Prepare and ignored in BuildStatement +The code has two part, runtime and generator -// Prepare is used in Select, it only has where condition binding -// Prepare is only called by Fetch -func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) { - stmt, err := c.RenderCQL() -} +- [cqlc](cqlc) is the runtime, a query builder, don't get mislead by the [column_generator.go](cqlc/column_generator.go) +it is mainly for generating runtime code that ships with the library +- [generator](generator) generates table and column definition based on schema, NOTE: it does [NOT support Cassandra 3](https://github.com/pingginp/cqlc/issues/7) -// BuildStatement is used in update, thus it has binding and where condition binding -// BuildStatement is called by Exec, Batch, Swap -func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err error) { - -} +### Runtime -// cqlc.go -func (c *Context) RenderCQL() (string, error) { - switch c.Operation { - case ReadOperation: - renderSelect(c, &buf) - case WriteOperation: - if c.hasConditions() { - renderUpdate(c, &buf, false) - } else { - renderInsert(c, &buf) - } - renderCAS(c, &buf) - case CounterOperation: - renderUpdate(c, &buf, true) - case DeleteOperation: - renderDelete(c, &buf) - default: - return "", fmt.Errorf("Unknown operation type: %v", c.Operation) - } -} +The main modification we have are listed below + +- [support update map value by key](doc/set-map-value-by-key.md), previously, cqlc can only update entire map. (This change only requires update runtime) -// render.go -func renderUpdate(ctx *Context, buf *bytes.Buffer, counterTable bool) { - for i, binding := range ctx.Bindings { - col := binding.Column.ColumnName() - if counterTable { - setFragments[i] = fmt.Sprintf("%s = %s + ?", col, col) - } else { - switch binding.CollectionType { - case ListType: - switch binding.CollectionOperationType { - case Append: - setFragments[i] = fmt.Sprintf("%s = %s + ?", col, col) - case Prepend: - setFragments[i] = fmt.Sprintf("%s = ? + %s", col, col) - case RemoveByValue: - setFragments[i] = fmt.Sprintf("%s = %s - ?", col, col) - } - case MapType: - switch binding.CollectionOperationType { - case SetByKey: - setFragments[i] = fmt.Sprintf("%s[?] = ?", col) - } - default: - setFragments[i] = fmt.Sprintf("%s = ?", col) - } - } - } -} -```` \ No newline at end of file +### Generator + +- generator now compiles, caused by breaking change of constant name in gocql diff --git a/build/.gitignore b/build/.gitignore index a581644..07b8e15 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1 +1,2 @@ -cqlc \ No newline at end of file +cqlc +cqlc-* \ No newline at end of file diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index a3da41c..18186f4 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -22,6 +22,7 @@ import ( "github.com/gocql/gocql" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) type OperationType int @@ -93,6 +94,7 @@ type Context struct { Keyspace string // Setting StaticKeyspace to true will cause the generated CQL to be qualified by the keyspace the code was generated against. StaticKeyspace bool + logger *logrus.Entry } func defaultReadOptions() *ReadOptions { @@ -102,7 +104,19 @@ func defaultReadOptions() *ReadOptions { // NewContext creates a fresh Context instance. // If you want statement debugging, set the Debug property to true func NewContext() *Context { - return &Context{Debug: false, ReadOptions: defaultReadOptions()} + // TODO: (pingginp) might change value to version number + return NewContextWithLogger(logrus.WithField("cqlc", true)) +} + +func NewContextWithLogger(logger *logrus.Entry) *Context { + return &Context{Debug: false, ReadOptions: defaultReadOptions(), logger: logger.WithField("cqlc", true)} +} + +// NewDebugContext creates a fresh Context with debug turned on +func NewDebugContext() *Context { + c := NewContext() + c.Debug = true + return c } type Executable interface { @@ -271,6 +285,7 @@ func (c *Context) OrderBy(cols ...ClusteredColumn) Fetchable { func (c *Context) From(t Table) SelectWhereStep { c.Table = t + c.logger = c.logger.WithField("table", t.TableName()) return c } @@ -299,6 +314,7 @@ func (c *Context) Having(cond ...Condition) Executable { func (c *Context) Upsert(u Upsertable) SetValueStep { c.Table = u c.Operation = WriteOperation + c.logger = c.logger.WithField("table", u.TableName()) return c } @@ -416,6 +432,8 @@ func (c *Context) Fetch(s *gocql.Session) (*gocql.Iter, error) { return q.Iter(), nil } +// Prepare is used in Select, it only has where condition binding +// Prepare is only called by Fetch func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) { stmt, err := c.RenderCQL() @@ -435,37 +453,31 @@ func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) { switch reflect.TypeOf(v).Kind() { case reflect.Slice: - { - s := reflect.ValueOf(v) - for i := 0; i < s.Len(); i++ { - placeHolders = append(placeHolders, s.Index(i).Interface()) - } + s := reflect.ValueOf(v) + for i := 0; i < s.Len(); i++ { + placeHolders = append(placeHolders, s.Index(i).Interface()) } case reflect.Array: - { - // Not really happy about having to special case UUIDs - // but this works for now + // Not really happy about having to special case UUIDs + // but this works for now - if val, ok := v.(gocql.UUID); ok { - placeHolders = append(placeHolders, val.Bytes()) - } else { - return nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v)) - } + if val, ok := v.(gocql.UUID); ok { + placeHolders = append(placeHolders, val.Bytes()) + } else { + return nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v)) } default: - { - // TODO: (pingginp) why it took address of interface and it worked ... - //placeHolders = append(placeHolders, &v) - placeHolders = append(placeHolders, v) - } + // TODO: (pingginp) why it took address of interface and it worked ... + //placeHolders = append(placeHolders, &v) + placeHolders = append(placeHolders, v) } } c.Dispose() if c.Debug { - debugStmt(stmt, placeHolders) + debugStmt(c.logger, stmt, placeHolders) } return s.Query(stmt, placeHolders...), nil @@ -479,7 +491,7 @@ func (c *Context) Exec(s *gocql.Session) error { } if c.Debug { - debugStmt(stmt, placeHolders) + debugStmt(c.logger, stmt, placeHolders) } return s.Query(stmt, placeHolders...).Exec() @@ -514,7 +526,7 @@ func (c *Context) Batch(b *gocql.Batch) error { } if c.Debug { - debugStmt(stmt, placeHolders) + debugStmt(c.logger, stmt, placeHolders) } b.Query(stmt, placeHolders...) @@ -522,23 +534,25 @@ func (c *Context) Batch(b *gocql.Batch) error { return nil } -func debugStmt(stmt string, placeHolders []interface{}) { +func debugStmt(logger *logrus.Entry, stmt string, placeHolders []interface{}) { infused := strings.Replace(stmt, "?", " %+v", -1) var buffer bytes.Buffer buffer.WriteString("CQL: ") buffer.WriteString(infused) - buffer.WriteString("\n") - log.Printf(buffer.String(), placeHolders...) + logger.Printf(buffer.String(), placeHolders...) //panic("debugStmt") } // BuildStatement is the new BuildStatement based on Prepare to support set map value by key +// BuildStatement is used in update, thus it has binding and where condition binding +// BuildStatement is called by Exec, Batch, Swap func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err error) { stmt, err = c.RenderCQL() if err != nil { return "", nil, errors.Wrap(err, "error render CQL") } + // placeHolders are the bindings that will be passed to gocql placeHolders = make([]interface{}, 0) // NOTE: for all binding we need to expand value due to multiple placeholders in one binding @@ -553,7 +567,7 @@ func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err er case SetByKey: kv, ok := v.(KeyValue) if !ok { - return "", nil, errors.Errorf("map set by key requires key value on column %s", bind.Column.ColumnName()) + return "", nil, errors.Errorf("map set by key requires KeyValue binding on column %s", bind.Column.ColumnName()) } placeHolders = append(placeHolders, kv.Key, kv.Value) } diff --git a/doc/set-map-value-by-key.md b/doc/set-map-value-by-key.md new file mode 100644 index 0000000..87091c4 --- /dev/null +++ b/doc/set-map-value-by-key.md @@ -0,0 +1,108 @@ +# Set map value by key instead of entire map + +This doc describes https://github.com/pingginp/cqlc/issues/2 + +- in `tmpl/columns.tmpl` + - in `SetStepValue` interface, add `Set{{Type1}}{{Type2}}MapValue(col, key {{type1}}, value {{type2}}` + - in `Context` methods, add the impl method with same name and call `setMap` +- run `make cqlc/columns.go` to generate using `column_generator.go` +- add `setMap` and use `[]interface{}{key, value}` as `Value` for binding, set type to MapType and op to `SetByKey` +- in `renderUpdate`, use `%s[?] = ?` where `%s` is from col +- `BuildStatement`, flatten binding, (copy from Prepare), former is used by Exec (update & insert) and latter is used by Fetch (select) + - NOTE: we added new struct `KeyValue` to avoid flatten slice value that should be kept as slice + - [ ] in old code, they were using `&v` for placeholder, it's pointer to interface, I don't know why it didn't trigger error, because gocql traverse ptr until it's a value? + +````go +// KeyValue is used for bind map value by key +type KeyValue struct { + Key interface{} + Value interface{} +} + + +// Prepare is used in Select, it only has where condition binding +// Prepare is only called by Fetch +func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) { + stmt, err := c.RenderCQL() + + // nothing is changed for update map +} + +// BuildStatement is the new BuildStatement based on Prepare to support set map value by key +// BuildStatement is used in update, thus it has binding and where condition binding +// BuildStatement is called by Exec, Batch, Swap +func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err error) { + stmt, err = c.RenderCQL() + + // placeHolders are the bindings that will be passed to gocql + placeHolders = make([]interface{}, 0) + + for _, bind := range c.Bindings { + v := bind.Value + switch bind.CollectionType { + case MapType: + switch bind.CollectionOperationType { + case SetByKey: + kv, ok := v.(KeyValue) + if !ok { + return "", nil, errors.Errorf("map set by key requires KeyValue binding on column %s", bind.Column.ColumnName()) + } + placeHolders = append(placeHolders, kv.Key, kv.Value) + } + default: + placeHolders = append(placeHolders, v) + } + } + +} + +// cqlc.go +func (c *Context) RenderCQL() (string, error) { + switch c.Operation { + case ReadOperation: + renderSelect(c, &buf) + case WriteOperation: + if c.hasConditions() { + renderUpdate(c, &buf, false) + } else { + renderInsert(c, &buf) + } + renderCAS(c, &buf) + case CounterOperation: + renderUpdate(c, &buf, true) + case DeleteOperation: + renderDelete(c, &buf) + default: + return "", fmt.Errorf("Unknown operation type: %v", c.Operation) + } +} + +// render.go +func renderUpdate(ctx *Context, buf *bytes.Buffer, counterTable bool) { + for i, binding := range ctx.Bindings { + col := binding.Column.ColumnName() + if counterTable { + setFragments[i] = fmt.Sprintf("%s = %s + ?", col, col) + } else { + switch binding.CollectionType { + case ListType: + switch binding.CollectionOperationType { + case Append: + setFragments[i] = fmt.Sprintf("%s = %s + ?", col, col) + case Prepend: + setFragments[i] = fmt.Sprintf("%s = ? + %s", col, col) + case RemoveByValue: + setFragments[i] = fmt.Sprintf("%s = %s - ?", col, col) + } + case MapType: + switch binding.CollectionOperationType { + case SetByKey: + setFragments[i] = fmt.Sprintf("%s[?] = ?", col) + } + default: + setFragments[i] = fmt.Sprintf("%s = ?", col) + } + } + } +} +```` \ No newline at end of file diff --git a/e2e/g1/cqlc_generated.go b/e2e/g1/cqlc_generated.go index 5c126a8..fc2bd00 100644 --- a/e2e/g1/cqlc_generated.go +++ b/e2e/g1/cqlc_generated.go @@ -1,17 +1,17 @@ // Code generated by https://github.com/pingginp/cqlc DO NOT EDIT. // GENERATED USING KEYSPACE cqlc -// AT 2018-09-15 11:44:08.677703 -0700 PDT m=+0.045865489 USING cqlc VERSION 0.10.5 -// AGAINST HOST ID 40460167-3d58-4468-a57d-0ecd51e05998 (SERVER VERSION 2.1.20) +// AT 2018-09-15 15:50:28.089101 -0700 PDT m=+0.089762602 USING cqlc VERSION 0.10.5 +// AGAINST HOST ID 893e34b1-fe2a-4817-83f5-236636320f6e (SERVER VERSION 2.1.20) // CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.2.1) package g1 import ( - "github.com/relops/cqlc/cqlc" - "github.com/gocql/gocql" "log" + + "github.com/relops/cqlc/cqlc" ) const ( diff --git a/glide.lock b/glide.lock index 1bd00cc..353c95d 100644 --- a/glide.lock +++ b/glide.lock @@ -1,8 +1,8 @@ hash: d4bb692c7281da9ad8d3c490e1125de6946522c7d0243f0f0b603b1e1e3e7b6d -updated: 2018-09-15T03:35:20.97843-07:00 +updated: 2018-09-15T15:46:20.378092-07:00 imports: - name: github.com/gocql/gocql - version: 045d8d6abc70b5bd02bb18b8fdb05ee54d8c87aa + version: 5a139e8dcc59d560335dbda641b9f42085e59b0a subpackages: - internal/lru - internal/murmur @@ -15,6 +15,17 @@ imports: version: c6ca198ec95c841fdb89fc0de7496fed11ab854e - name: github.com/pkg/errors version: c059e472caf75dbe73903f6521a20abac245b17f +- name: github.com/sirupsen/logrus + version: 3e01752db0189b9157070a0e1668a620f9a85da2 +- name: golang.org/x/crypto + version: 0e37d006457bf46f9e6692014ba72ef82c33022c + subpackages: + - ssh/terminal +- name: golang.org/x/sys + version: d0be0721c37eeb5299f245a996a483160fc36940 + subpackages: + - unix + - windows - name: gopkg.in/inf.v0 version: d2d2541c53f18d2a059457998ce2876cc8e67cbf testImports: diff --git a/main.go b/main.go index 203d8c4..a587082 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( var opts generator.Options var parser = flags.NewParser(&opts, flags.Default) -var Version = "0.10.5" +var Version string func init() { opts.Version = printVersionAndExit diff --git a/test/schema_generator.go b/test/schema_generator.go index ba7045e..52140d4 100644 --- a/test/schema_generator.go +++ b/test/schema_generator.go @@ -5,8 +5,8 @@ package main import ( "bytes" "fmt" - "log" "io/ioutil" + "log" "text/template" ) From d457ca9ea59b9494785ab7933de29dc018b45737 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 17:48:59 -0700 Subject: [PATCH 26/39] [gen] Replace log.Fatalf w/ errors.Errorf - in generated table definitions, was using log.Fatalf, that function returns error, better just return errors.Errorf --- Makefile | 2 +- e2e/g1/cqlc_generated.go | 32 ++++++++++++-------------------- generator/generator.go | 4 ++-- generator/tmpl.go | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index ec9253c..4a77305 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ test: test-unit test-unit: go test -v ./cqlc -travis-test: +travis-test: install docker-compose -f e2e/docker-compose.yaml up -d c2 ./wait-on-c.sh docker ps diff --git a/e2e/g1/cqlc_generated.go b/e2e/g1/cqlc_generated.go index fc2bd00..e35e421 100644 --- a/e2e/g1/cqlc_generated.go +++ b/e2e/g1/cqlc_generated.go @@ -1,21 +1,19 @@ // Code generated by https://github.com/pingginp/cqlc DO NOT EDIT. // GENERATED USING KEYSPACE cqlc -// AT 2018-09-15 15:50:28.089101 -0700 PDT m=+0.089762602 USING cqlc VERSION 0.10.5 -// AGAINST HOST ID 893e34b1-fe2a-4817-83f5-236636320f6e (SERVER VERSION 2.1.20) +// AT 2018-09-15 17:48:05.653436 -0700 PDT m=+0.071792159 USING cqlc VERSION 0.11.0 +// AGAINST HOST ID 099d1b1c-5ebe-4c29-951b-81df44232180 (SERVER VERSION 2.1.20) // CLIENT NEGOTIATED CQL VERSION 3.0.0 (SERVER SUPPORTS UP TO 3.2.1) package g1 import ( "github.com/gocql/gocql" - - "log" - + "github.com/pkg/errors" "github.com/relops/cqlc/cqlc" ) const ( - CQLC_VERSION = "0.10.5" + CQLC_VERSION = "0.11.0" ) type TblMapSliceIdColumn struct { @@ -72,10 +70,8 @@ func (b *TblMapSliceSsmColumn) To(value *map[string]string) cqlc.ColumnBinding { } type TblMapSlice struct { - Id string - - Sl []string - + Id string + Sl []string Ssm map[string]string } @@ -92,10 +88,8 @@ func (s *TblMapSlice) SsmValue() map[string]string { } type TblMapSliceDef struct { - ID cqlc.LastPartitionedStringColumn - - SL cqlc.StringSliceColumn - + ID cqlc.LastPartitionedStringColumn + SL cqlc.StringSliceColumn SSM cqlc.StringStringMapColumn } @@ -128,7 +122,7 @@ func MapTblMapSlice(iter *gocql.Iter, callback func(t TblMapSlice) (bool, error) row[i] = &t.Ssm default: - log.Fatal("unhandled column: ", columns[i].Name) + return errors.Errorf("cqlc: unhandled column: %s", columns[i].Name) } } if !iter.Scan(row...) { @@ -258,8 +252,7 @@ func (b *TblStringMapSsmColumn) To(value *map[string]string) cqlc.ColumnBinding } type TblStringMap struct { - Id string - + Id string Ssm map[string]string } @@ -272,8 +265,7 @@ func (s *TblStringMap) SsmValue() map[string]string { } type TblStringMapDef struct { - ID cqlc.LastPartitionedStringColumn - + ID cqlc.LastPartitionedStringColumn SSM cqlc.StringStringMapColumn } @@ -303,7 +295,7 @@ func MapTblStringMap(iter *gocql.Iter, callback func(t TblStringMap) (bool, erro row[i] = &t.Ssm default: - log.Fatal("unhandled column: ", columns[i].Name) + return errors.Errorf("cqlc: unhandled column: %s", columns[i].Name) } } if !iter.Scan(row...) { diff --git a/generator/generator.go b/generator/generator.go index d6658be..ac14a98 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -82,9 +82,9 @@ func coalesceImports(md *gocql.KeyspaceMetadata) []string { set[path] = true } - set["github.com/relops/cqlc/cqlc"] = true set["github.com/gocql/gocql"] = true - set["log"] = true + set["github.com/pkg/errors"] = true + set["github.com/relops/cqlc/cqlc"] = true paths := make([]string, 0) for path := range set { diff --git a/generator/tmpl.go b/generator/tmpl.go index 82f7f0e..0757198 100644 --- a/generator/tmpl.go +++ b/generator/tmpl.go @@ -13,8 +13,8 @@ package {{ .Options.Package }} import ( {{range $_, $path := .Imports}} - "{{$path}}" - {{end}} + "{{$path -}}" + {{- end}} ) const ( @@ -138,8 +138,8 @@ const ( type {{$StructType}} struct { {{range $_, $col := $cf.Columns}} - {{snakeToCamel $col.Name}} {{valueType $col}} - {{end}} + {{snakeToCamel $col.Name}} {{valueType $col -}} + {{- end}} } {{range $_, $col := $cf.Columns}} @@ -150,8 +150,8 @@ const ( type {{$StructType}}Def struct { {{range $_, $col := $cf.Columns}} - {{toUpper $col.Name}} {{columnType $col $cf }} - {{end}} + {{toUpper $col.Name}} {{columnType $col $cf -}} + {{- end}} } func Bind{{$StructType}}(iter *gocql.Iter) ([]{{$StructType}}, error) { @@ -176,7 +176,7 @@ const ( case "{{$col.Name}}": row[i] = &t.{{snakeToCamel $col.Name}} {{end}} default: - log.Fatal("unhandled column: ", columns[i].Name) + return errors.Errorf("cqlc: unhandled column: %s", columns[i].Name) } } if !iter.Scan(row...) { @@ -219,7 +219,7 @@ const ( {{ $ColStructType := snakeToCamel $col.Name }} {{ $QualifiedColStructType := sprint $StructType $ColStructType }} {Column: &{{ $QualifiedColStructType }}Column{}, Value: v.{{snakeToCamel $col.Name}}}, - {{end}} + {{- end}} } return cqlc.TableBinding{Table: &{{$StructType}}Def{}, Columns: cols} } @@ -230,7 +230,7 @@ const ( {{ $ColStructType := snakeToCamel $col.Name }} {{ $QualifiedColStructType := sprint $StructType $ColStructType }} {Column: &{{ $QualifiedColStructType }}Column{}, Value: &v.{{snakeToCamel $col.Name}}}, - {{end}} + {{- end}} } return cqlc.TableBinding{Table: &{{$StructType}}Def{}, Columns: cols} } @@ -241,7 +241,7 @@ const ( {{ $ColStructType := snakeToCamel $col.Name }} {{ $QualifiedColStructType := sprint $StructType $ColStructType }} &{{ $QualifiedColStructType }}Column{}, - {{end}} + {{- end}} } } From 43a4e3a6601b965ff2f51919211f7adc8004b4ad Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sat, 15 Sep 2018 18:12:46 -0700 Subject: [PATCH 27/39] [runtime] Update version defined in runtime - make update-ver --- Makefile | 7 ++++++- README.md | 2 ++ cqlc/.gitignore | 1 + cqlc/cqlc.go | 9 ++++----- cqlc/ver.go | 4 ++++ 5 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 cqlc/.gitignore create mode 100644 cqlc/ver.go diff --git a/Makefile b/Makefile index 4a77305..1231acc 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,12 @@ build-windows: install: go install -ldflags "$(LDFLAGS)" . -release: build-all +# sync the version defined in runtime with Makefile +update-ver: +# NOTE: mac's default sed is not GNU sed https://stackoverflow.com/questions/4247068/sed-command-with-i-option-failing-on-mac-but-works-on-linux + sed -i .bak -E 's/const Version = "(.*)"/const Version = "$(VERSION)"/g' cqlc/ver.go + +release: update-ver build-all cd build; rm -f *.zip cd build; zip cqlc-$(VERSION)-linux.zip cqlc-linux cd build; zip cqlc-$(VERSION)-mac.zip cqlc-mac diff --git a/README.md b/README.md index be35e3c..4d21694 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ make cqlc/columns.go # this same as when using latex ... you do xelatex several times when there is bib ... make travis-test make travis-tear +# release, update cqlc/ver.go, build and zip binary for all three platforms, only mac is tested +make release ```` The code has two part, runtime and generator diff --git a/cqlc/.gitignore b/cqlc/.gitignore new file mode 100644 index 0000000..7664704 --- /dev/null +++ b/cqlc/.gitignore @@ -0,0 +1 @@ +*.bak \ No newline at end of file diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index 18186f4..ceb372b 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -101,15 +101,16 @@ func defaultReadOptions() *ReadOptions { return &ReadOptions{Distinct: false} } -// NewContext creates a fresh Context instance. +// NewContext creates a fresh Context instance with a default logrus entry with field {cqlc:version} // If you want statement debugging, set the Debug property to true func NewContext() *Context { // TODO: (pingginp) might change value to version number - return NewContextWithLogger(logrus.WithField("cqlc", true)) + return NewContextWithLogger(logrus.WithField("cqlc", Version)) } +// NewContextWithLogger creates a fresh Context and extend a new the logrus entry with field {cqlc:version} func NewContextWithLogger(logger *logrus.Entry) *Context { - return &Context{Debug: false, ReadOptions: defaultReadOptions(), logger: logger.WithField("cqlc", true)} + return &Context{Debug: false, ReadOptions: defaultReadOptions(), logger: logger.WithField("cqlc", Version)} } // NewDebugContext creates a fresh Context with debug turned on @@ -272,14 +273,12 @@ func (c *Context) Limit(lim int) Fetchable { } func (c *Context) OrderBy(cols ...ClusteredColumn) Fetchable { - spec := make([]OrderSpec, len(cols)) for i, c := range cols { spec[i] = OrderSpec{Col: c.ClusterWith(), Desc: c.IsDescending()} } c.ReadOptions.Ordering = spec - return c } diff --git a/cqlc/ver.go b/cqlc/ver.go new file mode 100644 index 0000000..6713b69 --- /dev/null +++ b/cqlc/ver.go @@ -0,0 +1,4 @@ +package cqlc + +// Version is the runtime version of cqlc, run make update-ver to sync it +const Version = "0.11.0" From f90e9494ddfe9ee56900f81b3ca6ac9eb91bdaf5 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 15:03:58 -0800 Subject: [PATCH 28/39] Fix C*3 https://github.com/pingginp/cqlc/issues/7 - `gocql.TypeText` was not mapped to string, so generated file is invalid, could be in C*2 there is no Text in mapping ... --- README.md | 6 ++++++ generator/generator.go | 21 +++++++++++++++++---- generator/schema.go | 1 + generator/template.go | 17 ++++++++++++----- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4d21694..3bd46ee 100644 --- a/README.md +++ b/README.md @@ -52,3 +52,9 @@ The main modification we have are listed below ### Generator - generator now compiles, caused by breaking change of constant name in gocql + +The overall generator logic is + +- get table meta using gocql +- render the template defined in `tmpl.go` using template helper methods defined in `template.go` + - `valueType` is returning empty value for `text`, just add a new mapping in `literalTypes` fixed this [#7](https://github.com/pingginp/cqlc/issues/7) \ No newline at end of file diff --git a/generator/generator.go b/generator/generator.go index ac14a98..cb3306b 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -144,7 +144,7 @@ func generateBinding(opts *Options, version string, w io.Writer) error { return err } - log.Printf("keyspace meta %v\n", md) + log.Printf("keyspace meta %v", md) provenance := Provenance{ Keyspace: opts.Keyspace, @@ -167,6 +167,8 @@ func generateBinding(opts *Options, version string, w io.Writer) error { return err } + //ioutil.WriteFile("testdata/tmp.go", b.Bytes(), 0664) + log.Println("template rendered") // FIXME: got error when formatting source https://github.com/pingginp/cqlc/issues/7 @@ -187,6 +189,8 @@ func generateBinding(opts *Options, version string, w io.Writer) error { } func importPaths(md *gocql.KeyspaceMetadata) (imports []string) { + log.Println("importPaths called") + // Ideally need to use a set paths := make(map[string]bool) @@ -203,15 +207,24 @@ func importPaths(md *gocql.KeyspaceMetadata) (imports []string) { switch t.Type() { case gocql.TypeList, gocql.TypeSet: // TODO should probably not swallow this - ct, _ := t.(gocql.CollectionType) + ct, ok := t.(gocql.CollectionType) + if !ok { + panic("list set") + } f(ct.Elem) case gocql.TypeMap: // TODO should probably not swallow this - ct, _ := t.(gocql.CollectionType) + ct, ok := t.(gocql.CollectionType) + if !ok { + panic("map") + } f(ct.Key) f(ct.Elem) default: - nt, _ := t.(gocql.NativeType) + nt, ok := t.(gocql.NativeType) + if !ok { + panic("native") + } f(nt) } } diff --git a/generator/schema.go b/generator/schema.go index 4b55d61..59d4b78 100644 --- a/generator/schema.go +++ b/generator/schema.go @@ -12,6 +12,7 @@ var ( var literalTypes = map[gocql.Type]string{ gocql.TypeAscii: "string", gocql.TypeVarchar: "string", + gocql.TypeText: "string", // the only fix needed for support C*3 ... gocql.TypeInt: "int32", gocql.TypeBigInt: "int64", gocql.TypeFloat: "float32", diff --git a/generator/template.go b/generator/template.go index ca09a16..70c62b0 100644 --- a/generator/template.go +++ b/generator/template.go @@ -132,19 +132,26 @@ func columnType(c gocql.ColumnMetadata, table *gocql.TableMetadata) string { return baseType } -func valueType(c gocql.ColumnMetadata) string { +func valueType(c gocql.ColumnMetadata) (res string) { + //defer func() { + // log.Printf("col %s %s %s", c.Name, c.Type, res) + //}() t := c.Type switch t.Type() { case gocql.TypeList, gocql.TypeSet: - // TODO should probably not swallow this - ct, _ := t.(gocql.CollectionType) + ct, ok := t.(gocql.CollectionType) + if !ok { + panic("valueType list, set not collection") + } literal := literalTypes[ct.Elem.Type()] return fmt.Sprintf("[]%s", literal) case gocql.TypeMap: - // TODO should probably not swallow this - ct, _ := t.(gocql.CollectionType) + ct, ok := t.(gocql.CollectionType) + if !ok { + panic("valueType map not collection") + } key := literalTypes[ct.Key.Type()] elem := literalTypes[ct.Elem.Type()] return fmt.Sprintf("map[%s]%s", key, elem) From 1893983a8c62f52179b725b9d204b1f1d0fc76e6 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 15:23:26 -0800 Subject: [PATCH 29/39] [dep] Remove logrus and use interface Fix #11 --- README.md | 5 ++++- cqlc/cqlc.go | 26 +++++++++++++++----------- glide.lock | 15 ++------------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 3bd46ee..7d74325 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,16 @@ it is mainly for generating runtime code that ships with the library ### Runtime -The main modification we have are listed below +The main modification to the runtime are listed below - [support update map value by key](doc/set-map-value-by-key.md), previously, cqlc can only update entire map. (This change only requires update runtime) ### Generator +The main modification to the generator are listed below + - generator now compiles, caused by breaking change of constant name in gocql +- support Cassandra 3 by adding a new literalType mapping for text -> string [#12](https://github.com/pingginp/cqlc/pull/12) The overall generator logic is diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index ceb372b..9db2154 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -17,12 +17,12 @@ import ( "bytes" "fmt" "log" + "os" "reflect" "strings" "github.com/gocql/gocql" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) type OperationType int @@ -94,23 +94,27 @@ type Context struct { Keyspace string // Setting StaticKeyspace to true will cause the generated CQL to be qualified by the keyspace the code was generated against. StaticKeyspace bool - logger *logrus.Entry + logger Logger +} + +type Logger interface { + Printf(format string, args ...interface{}) } func defaultReadOptions() *ReadOptions { return &ReadOptions{Distinct: false} } -// NewContext creates a fresh Context instance with a default logrus entry with field {cqlc:version} +// NewContext creates a fresh Context instance using standard logger and logs to stderr with cqlc prefix // If you want statement debugging, set the Debug property to true func NewContext() *Context { - // TODO: (pingginp) might change value to version number - return NewContextWithLogger(logrus.WithField("cqlc", Version)) + stdLogger := log.New(os.Stderr, "cqlc: ", log.Lshortfile|log.Ldate) + return NewContextWithLogger(stdLogger) } -// NewContextWithLogger creates a fresh Context and extend a new the logrus entry with field {cqlc:version} -func NewContextWithLogger(logger *logrus.Entry) *Context { - return &Context{Debug: false, ReadOptions: defaultReadOptions(), logger: logger.WithField("cqlc", Version)} +// NewContextWithLogger creates a fresh Context with custom logger +func NewContextWithLogger(logger Logger) *Context { + return &Context{Debug: false, ReadOptions: defaultReadOptions(), logger: logger} } // NewDebugContext creates a fresh Context with debug turned on @@ -284,7 +288,7 @@ func (c *Context) OrderBy(cols ...ClusteredColumn) Fetchable { func (c *Context) From(t Table) SelectWhereStep { c.Table = t - c.logger = c.logger.WithField("table", t.TableName()) + //c.logger = c.logger.WithField("table", t.TableName()) return c } @@ -313,7 +317,7 @@ func (c *Context) Having(cond ...Condition) Executable { func (c *Context) Upsert(u Upsertable) SetValueStep { c.Table = u c.Operation = WriteOperation - c.logger = c.logger.WithField("table", u.TableName()) + //c.logger = c.logger.WithField("table", u.TableName()) return c } @@ -533,7 +537,7 @@ func (c *Context) Batch(b *gocql.Batch) error { return nil } -func debugStmt(logger *logrus.Entry, stmt string, placeHolders []interface{}) { +func debugStmt(logger Logger, stmt string, placeHolders []interface{}) { infused := strings.Replace(stmt, "?", " %+v", -1) var buffer bytes.Buffer buffer.WriteString("CQL: ") diff --git a/glide.lock b/glide.lock index 353c95d..d69bdef 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: d4bb692c7281da9ad8d3c490e1125de6946522c7d0243f0f0b603b1e1e3e7b6d -updated: 2018-09-15T15:46:20.378092-07:00 +updated: 2019-02-18T15:22:23.586062-08:00 imports: - name: github.com/gocql/gocql version: 5a139e8dcc59d560335dbda641b9f42085e59b0a @@ -15,17 +15,6 @@ imports: version: c6ca198ec95c841fdb89fc0de7496fed11ab854e - name: github.com/pkg/errors version: c059e472caf75dbe73903f6521a20abac245b17f -- name: github.com/sirupsen/logrus - version: 3e01752db0189b9157070a0e1668a620f9a85da2 -- name: golang.org/x/crypto - version: 0e37d006457bf46f9e6692014ba72ef82c33022c - subpackages: - - ssh/terminal -- name: golang.org/x/sys - version: d0be0721c37eeb5299f245a996a483160fc36940 - subpackages: - - unix - - windows - name: gopkg.in/inf.v0 version: d2d2541c53f18d2a059457998ce2876cc8e67cbf testImports: @@ -38,7 +27,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: f35b8ab0b5a2cef36673838d662e249dd9c94686 + version: ffdc059bfe9ce6a4e144ba849dbedead332c6053 subpackages: - assert - require From f33f23367a55b66c9e75e65a4854fccd845206fd Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 15:29:30 -0800 Subject: [PATCH 30/39] [dep] Init go mod support Fix #10 --- go.mod | 13 +++++++++++++ go.sum | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..05acd83 --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module github.com/relops/cqlc + +require ( + github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 // indirect + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect + github.com/gocql/gocql v0.0.0-20180913162544-5a139e8dcc59 + github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect + github.com/jessevdk/go-flags v1.4.0 + github.com/kr/pretty v0.1.0 // indirect + github.com/pkg/errors v0.0.0-20180911062113-c059e472caf7 + github.com/stretchr/testify v1.3.0 + gopkg.in/inf.v0 v0.9.1 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..67c07ec --- /dev/null +++ b/go.sum @@ -0,0 +1,29 @@ +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gocql/gocql v0.0.0-20180913162544-5a139e8dcc59 h1:+5Ep1OCcZzu0NIxG2/RJ3Nk827wqmFereTaU+xImRPM= +github.com/gocql/gocql v0.0.0-20180913162544-5a139e8dcc59/go.mod h1:4Fw1eo5iaEhDUs8XyuhSVCVy52Jq3L+/3GJgYkwc+/0= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= +github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pkg/errors v0.0.0-20180911062113-c059e472caf7 h1:FBnmUJV+O80F5xekiALhCgT0/QvrSw9JgidANHTm4Cw= +github.com/pkg/errors v0.0.0-20180911062113-c059e472caf7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= From fda8beb4bd649671d7860d9d29547db058918ac9 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 15:34:42 -0800 Subject: [PATCH 31/39] [release] 0.12.0 - support Cassandra 3 - remove logrus and use interface --- CHANGELOG.md | 11 +++++++++++ Makefile | 2 +- cqlc/ver.go | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac7496f..3f50082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,22 @@ NOTE: this file format is based on [gaocegege/maintainer](https://github.com/gao ## Unreleased +## 0.12.0 (2019-02-18) + +[Closed issues](https://github.com/pingginp/cqlc/issues?q=is%3Aissue+milestone%3A0.12.0+is%3Aclosed) + +Merged pull requests + +- [#12](https://github.com/pingginp/cqlc/pull/12) one line fix to support Cassandra 3 + +## 0.11.0 (2018-09-15) + [Closed issues](https://github.com/pingginp/cqlc/issues?q=is%3Aissue+is%3Aclosed+milestone%3A0.11.0) Merged pull requests - Reboot [#4](https://github.com/pingginp/cqlc/pull/4) the project now compiles and support set map value by key +- [#9](https://github.com/pingginp/cqlc/pull/9) remove `log.Fatal` and use logrus ## 0.10.5 (2015-09-10) diff --git a/Makefile b/Makefile index 1231acc..756f0c7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 0.11.0 +VERSION = 0.12.0 LDFLAGS = -X main.Version=$(VERSION) GO = CGO_ENABLED=0 go GO_LINUX = GOOS=linux GOARCH=amd64 $(GO) diff --git a/cqlc/ver.go b/cqlc/ver.go index 6713b69..ad88a8a 100644 --- a/cqlc/ver.go +++ b/cqlc/ver.go @@ -1,4 +1,4 @@ package cqlc // Version is the runtime version of cqlc, run make update-ver to sync it -const Version = "0.11.0" +const Version = "0.12.0" From 1e4e23e322e439caaa1c7f5e69e6c745b276b4cb Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 15:41:41 -0800 Subject: [PATCH 32/39] [doc] Change not support C3 to support --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d74325..5e4d9aa 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ The code has two part, runtime and generator - [cqlc](cqlc) is the runtime, a query builder, don't get mislead by the [column_generator.go](cqlc/column_generator.go) it is mainly for generating runtime code that ships with the library -- [generator](generator) generates table and column definition based on schema, NOTE: it does [NOT support Cassandra 3](https://github.com/pingginp/cqlc/issues/7) +- [generator](generator) generates table and column definition based on schema, NOTE: it now [supports Cassandra 3](https://github.com/pingginp/cqlc/issues/7) ### Runtime From 33f951987d3cddc2789e1a1a732d241beaec0f1c Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 15:52:59 -0800 Subject: [PATCH 33/39] [doc] Add go mod instruction --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5e4d9aa..82436cd 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ You need to change the repo path in `glide.yaml` to use this fork repo: https://github.com/pingginp/cqlc.git ```` +If you use `go mod`, add the following in your `go.mod`, [go mod wiki](https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive) + +````text +replace github.com/relops/cqlc => github.com/pingginp/cqlc v0.12.0 +```` + ## Dev - clone the repo to `$GOPATH/src/github.com/relops/cqlc` From 7fc6fe0f2b4f50dad8c3c6ae13df774a9d1b5b6a Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 16:36:31 -0800 Subject: [PATCH 34/39] [gen] #7 forgot to update column type mapping --- generator/schema.go | 1 + 1 file changed, 1 insertion(+) diff --git a/generator/schema.go b/generator/schema.go index 59d4b78..6340b59 100644 --- a/generator/schema.go +++ b/generator/schema.go @@ -36,6 +36,7 @@ var customImportPaths = map[string]string{ var columnTypes = map[gocql.Type]string{ gocql.TypeAscii: "cqlc.String_Column", gocql.TypeVarchar: "cqlc.String_Column", + gocql.TypeText: "cqlc.String_Column", // the ~~only~~ second fix needed for support C*3 ... gocql.TypeInt: "cqlc.Int32_Column", gocql.TypeBigInt: "cqlc.Int64_Column", gocql.TypeFloat: "cqlc.Float32_Column", From 1de1d776534a6e4cdb00a1da2331344b8e401d8b Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Mon, 18 Feb 2019 16:38:23 -0800 Subject: [PATCH 35/39] [release] 0.12.1 - previous release didn't fix the generator entirely, columnTypes mapping also need to be updated to support text #7 --- CHANGELOG.md | 4 ++++ Makefile | 2 +- cqlc/ver.go | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f50082..b7649ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ NOTE: this file format is based on [gaocegege/maintainer](https://github.com/gao ## Unreleased +## 0.12.1 (2019-02-18) + +- previous release didn't update all the mapping in generator + ## 0.12.0 (2019-02-18) [Closed issues](https://github.com/pingginp/cqlc/issues?q=is%3Aissue+milestone%3A0.12.0+is%3Aclosed) diff --git a/Makefile b/Makefile index 756f0c7..38fcff7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 0.12.0 +VERSION = 0.12.1 LDFLAGS = -X main.Version=$(VERSION) GO = CGO_ENABLED=0 go GO_LINUX = GOOS=linux GOARCH=amd64 $(GO) diff --git a/cqlc/ver.go b/cqlc/ver.go index ad88a8a..f1c0f8f 100644 --- a/cqlc/ver.go +++ b/cqlc/ver.go @@ -1,4 +1,4 @@ package cqlc // Version is the runtime version of cqlc, run make update-ver to sync it -const Version = "0.12.0" +const Version = "0.12.1" From 268431100ccb9344842765c134f52a4bbe9efeea Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sun, 10 Mar 2019 15:09:53 -0700 Subject: [PATCH 36/39] [runtime] Support if in delete statement #13 --- CHANGELOG.md | 4 ++ README.md | 1 + cqlc/cqlc.go | 103 +++++++++++++++++++++------------------------- cqlc/cqlc_test.go | 10 +++++ cqlc/render.go | 16 ++++++- 5 files changed, 76 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7649ae..722cceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ NOTE: this file format is based on [gaocegege/maintainer](https://github.com/gao ## Unreleased +0.12.2 + +- support `IF` statement in `DELETE` + ## 0.12.1 (2019-02-18) - previous release didn't update all the mapping in generator diff --git a/README.md b/README.md index 82436cd..d25fbb3 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ it is mainly for generating runtime code that ships with the library The main modification to the runtime are listed below - [support update map value by key](doc/set-map-value-by-key.md), previously, cqlc can only update entire map. (This change only requires update runtime) +- support `IF` in `DELETE` ### Generator diff --git a/cqlc/cqlc.go b/cqlc/cqlc.go index 9db2154..5c3f82a 100644 --- a/cqlc/cqlc.go +++ b/cqlc/cqlc.go @@ -80,12 +80,15 @@ type ReadOptions struct { // Context represents the state of the CQL statement that is being built by the application. type Context struct { - Operation OperationType - Table Table - Columns []Column - Bindings []ColumnBinding - CASBindings []ColumnBinding - Conditions []Condition + Operation OperationType + Table Table + Columns []Column + Bindings []ColumnBinding + CASBindings []ColumnBinding + // Conditions is used by WHERE to locate primary key + Conditions []Condition + // IfConditions is used by IF which is put after WHERE to restrict non primary key columns + IfConditions []Condition ResultBindings map[string]ColumnBinding // Debug flag will cause all CQL statements to get logged Debug bool @@ -146,6 +149,11 @@ type UniqueFetchable interface { FetchOne(*gocql.Session) (bool, error) } +type IfQueryStep interface { + If(conditions ...Condition) Query + Query +} + type Query interface { Executable Fetchable @@ -155,7 +163,7 @@ type Query interface { type SelectWhereStep interface { Fetchable - Where(conditions ...Condition) Query + Where(conditions ...Condition) IfQueryStep } type SelectFromStep interface { @@ -370,14 +378,19 @@ func (c *Context) Apply(cols ...ColumnBinding) SetValueStep { return c } -// Adds column bindings whose values will nbe populated if a CAS operation +// Adds column bindings whose values will be populated if a CAS operation // is applied. func (c *Context) IfExists(cols ...ColumnBinding) CompareAndSwap { c.CASBindings = cols return c } -func (c *Context) Where(cond ...Condition) Query { +func (c *Context) If(cond ...Condition) Query { + c.IfConditions = cond + return c +} + +func (c *Context) Where(cond ...Condition) IfQueryStep { c.Conditions = cond return c } @@ -579,60 +592,37 @@ func BuildStatement(c *Context) (stmt string, placeHolders []interface{}, err er } } - for _, cond := range c.Conditions { - v := cond.Binding.Value - switch reflect.TypeOf(v).Kind() { - case reflect.Slice: - s := reflect.ValueOf(v) - for i := 0; i < s.Len(); i++ { - placeHolders = append(placeHolders, s.Index(i).Interface()) - } - case reflect.Array: + bindCondition := func(conditions []Condition) error { + for _, cond := range conditions { + v := cond.Binding.Value + switch reflect.TypeOf(v).Kind() { + case reflect.Slice: + s := reflect.ValueOf(v) + for i := 0; i < s.Len(); i++ { + placeHolders = append(placeHolders, s.Index(i).Interface()) + } + case reflect.Array: - // Not really happy about having to special case UUIDs - // but this works for now + // Not really happy about having to special case UUIDs + // but this works for now - if val, ok := v.(gocql.UUID); ok { - placeHolders = append(placeHolders, val.Bytes()) - } else { - return "", nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v)) + if val, ok := v.(gocql.UUID); ok { + placeHolders = append(placeHolders, val.Bytes()) + } else { + return bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v)) + } + default: + placeHolders = append(placeHolders, v) } - default: - placeHolders = append(placeHolders, v) } + return nil } - c.Dispose() - - return stmt, placeHolders, nil -} - -// Deprecated -// NOTE: (pingginp) this is used by Exec and unlike Prepare, it didn't handle expand binding -func BuildStatementOld(c *Context) (stmt string, placeHolders []interface{}, err error) { - // TODO Does this function need to get exported? - stmt, err = c.RenderCQL() - if err != nil { - return stmt, nil, err + if err := bindCondition(c.Conditions); err != nil { + return "", nil, err } - - bindings := len(c.Bindings) // TODO check whether this is nil - conditions := 0 - - if c.Conditions != nil { - conditions = len(c.Conditions) - } - - placeHolders = make([]interface{}, bindings+conditions) - - for i, bind := range c.Bindings { - placeHolders[i] = bind.Value - } - - if c.Conditions != nil { - for i, cond := range c.Conditions { - placeHolders[i+bindings] = cond.Binding.Value - } + if err := bindCondition(c.IfConditions); err != nil { + return "", nil, err } c.Dispose() @@ -681,6 +671,7 @@ func (c *Context) Dispose() { c.Table = nil c.Bindings = nil c.Conditions = nil + c.IfConditions = nil c.CASBindings = nil } diff --git a/cqlc/cqlc_test.go b/cqlc/cqlc_test.go index 0490d4f..0343b4a 100644 --- a/cqlc/cqlc_test.go +++ b/cqlc/cqlc_test.go @@ -317,6 +317,16 @@ func (s *CqlTestSuite) TestDeleteRow() { assert.Equal(s.T(), cql, "DELETE FROM foo WHERE id = ?") } +func (s *CqlTestSuite) TestDeleteRowIf() { + idCol := &MockAsciiColumn{name: "id"} + ageCol := &MockInt32Column{name: "age"} + c := NewContext() + c.Delete().From(s.table).Where(idCol.Eq("x")).If(ageCol.Eq(28)) + cql, err := c.RenderCQL() + assert.NoError(s.T(), err) + assert.Equal(s.T(), cql, "DELETE FROM foo WHERE id = ? IF age = ?") +} + func (s *CqlTestSuite) TestDeleteColumn() { idCol := &MockAsciiColumn{name: "id"} barCol := &MockAsciiColumn{name: "bar"} diff --git a/cqlc/render.go b/cqlc/render.go index a65ee86..6d86b1d 100644 --- a/cqlc/render.go +++ b/cqlc/render.go @@ -184,13 +184,25 @@ func renderDelete(ctx *Context, buf *bytes.Buffer) { } renderWhereClause(ctx, buf) + + if len(ctx.IfConditions) > 0 { + renderIfClause(ctx, buf) + } } func renderWhereClause(ctx *Context, buf *bytes.Buffer) { fmt.Fprint(buf, "WHERE ") + renderCondition(buf, ctx.Conditions) +} + +func renderIfClause(ctx *Context, buf *bytes.Buffer) { + fmt.Fprint(buf, " IF ") + renderCondition(buf, ctx.IfConditions) +} - whereFragments := make([]string, len(ctx.Conditions)) - for i, condition := range ctx.Conditions { +func renderCondition(buf *bytes.Buffer, conditions []Condition) { + whereFragments := make([]string, len(conditions)) + for i, condition := range conditions { col := condition.Binding.Column.ColumnName() pred := condition.Predicate From bb266353829ea5261e4965b20bdbc96d5d4b4a23 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sun, 10 Mar 2019 16:15:33 -0700 Subject: [PATCH 37/39] [gen] Allow Eq on all columns for DELTE IF #13 - previously only primary key and those with index support it --- Makefile | 2 +- generator/template.go | 5 ++++- generator/tmpl.go | 11 +++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 38fcff7..a4f5378 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 0.12.1 +VERSION = 0.13.0 LDFLAGS = -X main.Version=$(VERSION) GO = CGO_ENABLED=0 go GO_LINUX = GOOS=linux GOARCH=amd64 $(GO) diff --git a/generator/template.go b/generator/template.go index 70c62b0..2477313 100644 --- a/generator/template.go +++ b/generator/template.go @@ -94,7 +94,10 @@ func columnType(c gocql.ColumnMetadata, table *gocql.TableMetadata) string { replacement = ".LastPartitioned" } baseType = strings.Replace(baseType, ".", replacement, 1) - } else if c.Index.Name != "" { + //} else if c.Index.Name != "" { + } else { + // NOTE: this is changed to allow Eq on all columns to use DELETE ... WHERE ... IF ... + // see https://github.com/pingginp/cqlc/issues/13 replacement := ".Equality" baseType = strings.Replace(baseType, ".", replacement, 1) } diff --git a/generator/tmpl.go b/generator/tmpl.go index 0757198..9c24784 100644 --- a/generator/tmpl.go +++ b/generator/tmpl.go @@ -81,8 +81,7 @@ const ( return cqlc.Condition{Binding: binding, Predicate: cqlc.InPredicate} } {{ end }} - {{ end }} - {{ if supportsClustering $col }} + {{ else if supportsClustering $col }} func (b * {{$QualifiedColStructType}}Column ) ClusterWith() string { return b.ColumnName() @@ -131,6 +130,14 @@ const ( binding := cqlc.ColumnBinding{Column: column, Value: value} return cqlc.Condition{Binding: binding, Predicate: cqlc.LePredicate} } + {{ else }} +// Eq is used in DELETE IF statement to filter on non primary key columns, +// introduced in https://github.com/pingginp/cqlc/issues/13 + func (b * {{$QualifiedColStructType}}Column ) Eq(value {{valueType $col}}) cqlc.Condition { + column := &{{$QualifiedColStructType}}Column{} + binding := cqlc.ColumnBinding{Column: column, Value: value} + return cqlc.Condition{Binding: binding, Predicate: cqlc.EqPredicate} + } {{ end }} {{ end }} From 1910b32eaa80662e5147dc8bf743bfb65d0f5a55 Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sun, 10 Mar 2019 16:28:09 -0700 Subject: [PATCH 38/39] [doc] Update change log --- CHANGELOG.md | 8 ++++++-- README.md | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 722cceb..9532256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,13 @@ NOTE: this file format is based on [gaocegege/maintainer](https://github.com/gao ## Unreleased -0.12.2 +## 0.13.0 (2019-03-10) -- support `IF` statement in `DELETE` +Was going to make it 0.12.2 but since it breaks both runtime and generated code, bump minor version number + +- support `IF` in `DELETE` [#13](https://github.com/pingginp/cqlc/issues/13) +- in generated column bindings allow `Eq` on all columns, previously only primary key, index are allowed, which blocks using +other columns in condition queries after `If` ## 0.12.1 (2019-02-18) diff --git a/README.md b/README.md index d25fbb3..7db8068 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ it is mainly for generating runtime code that ships with the library The main modification to the runtime are listed below - [support update map value by key](doc/set-map-value-by-key.md), previously, cqlc can only update entire map. (This change only requires update runtime) -- support `IF` in `DELETE` +- support `IF` in `DELETE` [#13](https://github.com/pingginp/cqlc/issues/13) ### Generator @@ -62,6 +62,7 @@ The main modification to the generator are listed below - generator now compiles, caused by breaking change of constant name in gocql - support Cassandra 3 by adding a new literalType mapping for text -> string [#12](https://github.com/pingginp/cqlc/pull/12) +- allow `Eq` on all columns to support `IF` in `DELETE` The overall generator logic is From fc04d23c026c204032e9958cde04af4f28ac218d Mon Sep 17 00:00:00 2001 From: Pinglei Guo Date: Sun, 10 Mar 2019 16:30:02 -0700 Subject: [PATCH 39/39] [release] 0.13.0 --- cqlc/ver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cqlc/ver.go b/cqlc/ver.go index f1c0f8f..8ec8bb1 100644 --- a/cqlc/ver.go +++ b/cqlc/ver.go @@ -1,4 +1,4 @@ package cqlc // Version is the runtime version of cqlc, run make update-ver to sync it -const Version = "0.12.1" +const Version = "0.13.0"