feat(db): add SQLite schema, Store CRUD, ULID generation
Foundation layer: entities table with card support, entity_tags join table, WAL mode, busy_timeout, full CRUD operations including promote/demote lifecycle and soft/hard delete. 33 tests passing.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package ulid
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"sync"
|
||||
|
||||
"github.com/oklog/ulid/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
entropy *ulid.MonotonicEntropy
|
||||
entropyOnce sync.Once
|
||||
)
|
||||
|
||||
func New() string {
|
||||
entropyOnce.Do(func() {
|
||||
entropy = ulid.Monotonic(rand.Reader, 0)
|
||||
})
|
||||
return ulid.MustNew(ulid.Now(), entropy).String()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package ulid
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNew_ReturnsValidULID(t *testing.T) {
|
||||
id := New()
|
||||
if len(id) != 26 {
|
||||
t.Errorf("expected 26 chars, got %d: %s", len(id), id)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew_Unique(t *testing.T) {
|
||||
a := New()
|
||||
b := New()
|
||||
if a == b {
|
||||
t.Errorf("two calls returned same ULID: %s", a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNew_Sortable(t *testing.T) {
|
||||
a := New()
|
||||
b := New()
|
||||
if b < a {
|
||||
t.Errorf("expected b >= a for sequential calls: a=%s b=%s", a, b)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user