Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions generator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,19 +48,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:
Expand All @@ -82,13 +83,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"
Expand Down