Skip to content

Commit

Permalink
add unset for columns
Browse files Browse the repository at this point in the history
  • Loading branch information
delaneyj committed Jan 6, 2024
1 parent 0af9c37 commit 0660ba4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
5 changes: 5 additions & 0 deletions codegen/numbers.tpl
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions column_bool.go
Expand Up @@ -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{
Expand Down
50 changes: 50 additions & 0 deletions column_numbers.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions column_record.go
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions column_strings.go
Expand Up @@ -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{
Expand Down

0 comments on commit 0660ba4

Please sign in to comment.