Feature 02 task 2: Store helpers: transactions, ULIDs and time conventions (#11)
CI / ci (push) Successful in 48s

Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
Co-committed-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #11.
This commit is contained in:
2026-10-03 08:54:55 -04:00
committed by approver_agent
parent e9ee4e768a
commit b06d1680a3
8 changed files with 422 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
package store
import (
"crypto/rand"
"sync"
"time"
"github.com/oklog/ulid/v2"
)
var (
idMu sync.Mutex
idEntropy = ulid.Monotonic(rand.Reader, 0)
idLastMS uint64
)
// NewID returns a new ULID as its canonical 26-character string. IDs from
// this process sort strictly in creation order, including within one
// millisecond and across a backwards wall-clock step. It panics if the
// monotonic entropy overflows within a millisecond.
func NewID() string {
idMu.Lock()
defer idMu.Unlock()
ms := max(ulid.Timestamp(time.Now()), idLastMS)
idLastMS = ms
return ulid.MustNew(ms, idEntropy).String()
}