Skip to content

Commit cc68867

Browse files
authored
expose SelectBuilder for table Get operation (#251)
* expose select builder for get * add comment
1 parent 3ea85fd commit cc68867

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: table/table.go

+9
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ func (t *Table) GetQueryContext(ctx context.Context, session gocqlx.Session, col
102102
return t.GetQuery(session, columns...).WithContext(ctx)
103103
}
104104

105+
// GetBuilder returns a builder initialised to select by primary key
106+
func (t *Table) GetBuilder(columns ...string) *qb.SelectBuilder {
107+
if len(columns) == 0 {
108+
return qb.Select(t.metadata.Name).Where(t.primaryKeyCmp...)
109+
}
110+
111+
return qb.Select(t.metadata.Name).Columns(columns...).Where(t.primaryKeyCmp...)
112+
}
113+
105114
// Select returns select by partition key statement.
106115
func (t *Table) Select(columns ...string) (stmt string, names []string) {
107116
if len(columns) == 0 {

Diff for: table/table_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ func TestTableGet(t *testing.T) {
6060
t.Error(diff, names)
6161
}
6262
}
63+
64+
// run GetBuilder on the same data set
65+
for _, test := range table {
66+
stmt, names := New(test.M).GetBuilder(test.C...).ToCql()
67+
if diff := cmp.Diff(test.S, stmt); diff != "" {
68+
t.Error(diff)
69+
}
70+
if diff := cmp.Diff(test.N, names); diff != "" {
71+
t.Error(diff, names)
72+
}
73+
}
6374
}
6475

6576
func TestTableSelect(t *testing.T) {

0 commit comments

Comments
 (0)