Tags: kelindar/column
Tags
CreateTrigger and DropTrigger (#79) This PR adds `trigger` functionality for the cases where built-in capabilities aren't sufficient. Triggers allow you to add a callback function that will get called whether a value is `inserted`, `updated` or `deleted`. It functions similarly to the bitmap index. ```go players.CreateTrigger("on_balance", "balance", func(r Reader) { switch { case r.IsDelete(): updates = append(updates, fmt.Sprintf("delete %d", r.Index())) case r.IsUpsert(): updates = append(updates, fmt.Sprintf("upsert %d=%v", r.Index(), r.Float())) } }) // Perform a few deletions and insertions for i := 0; i < 3; i++ { players.DeleteAt(uint32(i)) players.Insert(func(r Row) error { r.SetFloat64("balance", 50.0) return nil }) } // Must keep track of all operations assert.Len(t, updates, 6) assert.Equal(t, []string{ "delete 0", "upsert 500=50", "delete 1", "upsert 501=50", "delete 2", "upsert 502=50", }, updates) ```
Fix swap and record index (#76) ## Bugfixes * `Swap...` was not properly swapping when an underlying buffer was re-allocated due to `append()` * Index for `Record` types was not working when strings are being merged due to the fact that it could not see the newly appended values. ## Optimizations * When swapping strings, if the string is of exactly the same size as before, it will be swapped in-place (same as for other values).
Adding record column (#73) This PR contains some refactoring and a new `record` column that allows you to use a `BinaryMarshaler` and `BinaryUnmarshaler` type to be stored. As such, it supports types that implement this standard way of encoding, for example `time.Time`. ```go col := NewCollection() col.CreateColumn("timestamp", ForRecord(func() *time.Time { return new(time.Time) }, nil)) // Insert the time, it implements binary marshaler idx, _ := col.Insert(func(r Row) error { now := time.Unix(1667745766, 0) r.SetRecord("timestamp", &now) return nil }) // We should be able to read back the time col.QueryAt(idx, func(r Row) error { ts, ok := r.Record("timestamp") assert.True(t, ok) assert.Equal(t, "November", ts.(*time.Time).UTC().Month().String()) return nil }) ```