table: Added cql.builders for insert, update, delete to enable table batch timestamp at statement granularity.
This commit is contained in:
committed by
Michal Jan Matczuk
parent
ab2a96d9f3
commit
fc0b7be8ab
@@ -105,10 +105,20 @@ func (t *Table) Insert() (stmt string, names []string) {
|
|||||||
|
|
||||||
// Update returns update by primary key statement.
|
// Update returns update by primary key statement.
|
||||||
func (t *Table) Update(columns ...string) (stmt string, names []string) {
|
func (t *Table) Update(columns ...string) (stmt string, names []string) {
|
||||||
return qb.Update(t.metadata.Name).Set(columns...).Where(t.primaryKeyCmp...).ToCql()
|
return t.UpdateBuilder(columns...).ToCql()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateBuilder returns a builder initialised to update by primary key statement.
|
||||||
|
func (t *Table) UpdateBuilder(columns ...string) *qb.UpdateBuilder {
|
||||||
|
return qb.Update(t.metadata.Name).Set(columns...).Where(t.primaryKeyCmp...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete returns delete by primary key statement.
|
// Delete returns delete by primary key statement.
|
||||||
func (t *Table) Delete(columns ...string) (stmt string, names []string) {
|
func (t *Table) Delete(columns ...string) (stmt string, names []string) {
|
||||||
return qb.Delete(t.metadata.Name).Columns(columns...).Where(t.primaryKeyCmp...).ToCql()
|
return t.DeleteBuilder(columns...).ToCql()
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteBuilder returns a builder initialised to delete by primary key statement.
|
||||||
|
func (t *Table) DeleteBuilder(columns ...string) *qb.DeleteBuilder {
|
||||||
|
return qb.Delete(t.metadata.Name).Columns(columns...).Where(t.primaryKeyCmp...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,17 @@ func TestTableUpdate(t *testing.T) {
|
|||||||
t.Error(diff, names)
|
t.Error(diff, names)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run UpdateBuilder on the same data set
|
||||||
|
for _, test := range table {
|
||||||
|
stmt, names := New(test.M).UpdateBuilder(test.C...).ToCql()
|
||||||
|
if diff := cmp.Diff(test.S, stmt); diff != "" {
|
||||||
|
t.Error(diff)
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(test.N, names); diff != "" {
|
||||||
|
t.Error(diff, names)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTableDelete(t *testing.T) {
|
func TestTableDelete(t *testing.T) {
|
||||||
@@ -220,6 +231,17 @@ func TestTableDelete(t *testing.T) {
|
|||||||
t.Error(diff, names)
|
t.Error(diff, names)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run DeleteBuilder on the same data set
|
||||||
|
for _, test := range table {
|
||||||
|
stmt, names := New(test.M).DeleteBuilder(test.C...).ToCql()
|
||||||
|
if diff := cmp.Diff(test.S, stmt); diff != "" {
|
||||||
|
t.Error(diff)
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(test.N, names); diff != "" {
|
||||||
|
t.Error(diff, names)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTableConcurrentUsage(t *testing.T) {
|
func TestTableConcurrentUsage(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user