diff --git a/codegen/numbers.tpl b/codegen/numbers.tpl index 18e8c55..2a15abb 100644 --- a/codegen/numbers.tpl +++ b/codegen/numbers.tpl @@ -44,6 +44,11 @@ func (s rw{{.Name}}) Set(value {{.Type}}) { s.writer.Put{{.Name}}(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rw{{.Name}}) Unset() { + s.writer.Put{{.Name}}(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rw{{.Name}}) Merge(delta {{.Type}}) { s.writer.Put{{.Name}}(commit.Merge, s.txn.cursor, delta) diff --git a/column_bool.go b/column_bool.go index b6a8435..f19f062 100644 --- a/column_bool.go +++ b/column_bool.go @@ -72,6 +72,11 @@ func (s rwBool) Set(value bool) { s.writer.PutBool(*s.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwBool) Unset() { + s.writer.PutBool(*s.cursor, false) +} + // Bool returns a bool column accessor func (txn *Txn) Bool(columnName string) rwBool { return rwBool{ diff --git a/column_numbers.go b/column_numbers.go index 8838e4b..1b0b2ee 100644 --- a/column_numbers.go +++ b/column_numbers.go @@ -44,6 +44,11 @@ func (s rwInt) Set(value int) { s.writer.PutInt(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwInt) Unset() { + s.writer.PutInt(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwInt) Merge(delta int) { s.writer.PutInt(commit.Merge, s.txn.cursor, delta) @@ -93,6 +98,11 @@ func (s rwInt16) Set(value int16) { s.writer.PutInt16(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwInt16) Unset() { + s.writer.PutInt16(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwInt16) Merge(delta int16) { s.writer.PutInt16(commit.Merge, s.txn.cursor, delta) @@ -142,6 +152,11 @@ func (s rwInt32) Set(value int32) { s.writer.PutInt32(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwInt32) Unset() { + s.writer.PutInt32(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwInt32) Merge(delta int32) { s.writer.PutInt32(commit.Merge, s.txn.cursor, delta) @@ -191,6 +206,11 @@ func (s rwInt64) Set(value int64) { s.writer.PutInt64(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwInt64) Unset() { + s.writer.PutInt64(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwInt64) Merge(delta int64) { s.writer.PutInt64(commit.Merge, s.txn.cursor, delta) @@ -240,6 +260,11 @@ func (s rwUint) Set(value uint) { s.writer.PutUint(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwUint) Unset() { + s.writer.PutUint(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwUint) Merge(delta uint) { s.writer.PutUint(commit.Merge, s.txn.cursor, delta) @@ -289,6 +314,11 @@ func (s rwUint16) Set(value uint16) { s.writer.PutUint16(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwUint16) Unset() { + s.writer.PutUint16(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwUint16) Merge(delta uint16) { s.writer.PutUint16(commit.Merge, s.txn.cursor, delta) @@ -338,6 +368,11 @@ func (s rwUint32) Set(value uint32) { s.writer.PutUint32(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwUint32) Unset() { + s.writer.PutUint32(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwUint32) Merge(delta uint32) { s.writer.PutUint32(commit.Merge, s.txn.cursor, delta) @@ -387,6 +422,11 @@ func (s rwUint64) Set(value uint64) { s.writer.PutUint64(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwUint64) Unset() { + s.writer.PutUint64(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwUint64) Merge(delta uint64) { s.writer.PutUint64(commit.Merge, s.txn.cursor, delta) @@ -436,6 +476,11 @@ func (s rwFloat32) Set(value float32) { s.writer.PutFloat32(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwFloat32) Unset() { + s.writer.PutFloat32(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwFloat32) Merge(delta float32) { s.writer.PutFloat32(commit.Merge, s.txn.cursor, delta) @@ -485,6 +530,11 @@ func (s rwFloat64) Set(value float64) { s.writer.PutFloat64(commit.Put, s.txn.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwFloat64) Unset() { + s.writer.PutFloat64(commit.Delete, s.txn.cursor, 0) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwFloat64) Merge(delta float64) { s.writer.PutFloat64(commit.Merge, s.txn.cursor, delta) diff --git a/column_record.go b/column_record.go index 8e06ade..bcc29f9 100644 --- a/column_record.go +++ b/column_record.go @@ -94,6 +94,11 @@ func (s rwRecord) Set(value encoding.BinaryMarshaler) error { return s.write(commit.Put, value.MarshalBinary) } +// Unset unsets the value at the current transaction index +func (s rwRecord) Unset() error { + return s.write(commit.Delete, nil) +} + // Merge atomically merges a delta to the value at the current transaction cursor func (s rwRecord) Merge(delta encoding.BinaryMarshaler) error { return s.write(commit.Merge, delta.MarshalBinary) diff --git a/column_strings.go b/column_strings.go index ccc5422..9300d9d 100644 --- a/column_strings.go +++ b/column_strings.go @@ -140,6 +140,11 @@ func (s rwEnum) Set(value string) { s.writer.PutString(commit.Put, *s.cursor, value) } +// Unset unsets the value at the current transaction cursor +func (s rwEnum) Unset() { + s.writer.PutString(commit.Delete, *s.cursor, "") +} + // Enum returns a enumerable column accessor func (txn *Txn) Enum(columnName string) rwEnum { return rwEnum{