Skip to content
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

Adding record column #73

Merged
merged 4 commits into from Nov 26, 2022
Merged

Adding record column #73

merged 4 commits into from Nov 26, 2022

Conversation

kelindar
Copy link
Owner

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.

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
})

@kelindar kelindar merged commit a761108 into main Nov 26, 2022
@kelindar kelindar deleted the record branch November 26, 2022 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant