Skip to content

add unset for columns #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions codegen/numbers.tpl
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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