Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

52 lines
831 B
Go

package bigquery
import (
"fmt"
"sync"
)
type BufferedWrite struct {
sync.RWMutex
Rows []Row
capacity int
}
func (b *BufferedWrite) Append(r Row) error {
if b.IsFull() {
return fmt.Errorf("cannot append to buffer, capacity exceeded: %d elements", len(b.Rows))
}
b.Lock()
defer b.Unlock()
b.Rows = append(b.Rows, r)
return nil
}
func (b *BufferedWrite) Length() int {
return len(b.Rows)
}
func (b *BufferedWrite) Capacity() int {
return b.capacity
}
func (b *BufferedWrite) IsFull() bool {
return len(b.Rows) == b.capacity
}
func (b *BufferedWrite) Reset() {
b.Lock()
defer b.Unlock()
b.Rows = make([]Row, 0, b.capacity)
}
func (b *BufferedWrite) Flush() []Row {
defer b.Reset()
return b.Rows
}
func NewBufferedWrite(c int) *BufferedWrite {
b := &BufferedWrite{capacity: c}
b.Reset()
return b
}