From 4cb8ecf2c441db1eafbad9375d327485de9aa35c Mon Sep 17 00:00:00 2001 From: Alexander Trakhimenok Date: Wed, 22 Jul 2026 00:48:51 +0100 Subject: [PATCH] chore: migrate to dal-go/record --- batching.go | 29 +++++------ batching_test.go | 5 +- commit_message_test.go | 3 +- coverage_extra_test.go | 103 +++++++++++++++++++------------------- coverage_final_test.go | 31 ++++++------ coverage_gaps_test.go | 63 +++++++++++------------ db_github.go | 7 +-- db_github_getters_test.go | 11 ++-- db_github_test.go | 29 +++++------ error_paths_test.go | 33 ++++++------ go.mod | 19 ++++--- go.sum | 37 +++++++------- parent_chain_test.go | 29 +++++------ query.go | 19 +++---- query_test.go | 35 ++++++------- scoped_collection.go | 4 +- tree_reader_test.go | 4 +- tx_readonly.go | 17 ++++--- tx_readonly_test.go | 25 ++++----- tx_readwrite.go | 29 +++++------ tx_readwrite_test.go | 41 +++++++-------- update_batching_test.go | 19 +++---- update_readwrite_test.go | 11 ++-- updates.go | 2 +- 24 files changed, 311 insertions(+), 294 deletions(-) diff --git a/batching.go b/batching.go index 0a3700b..6026c49 100644 --- a/batching.go +++ b/batching.go @@ -6,8 +6,9 @@ import ( "fmt" "github.com/dal-go/dalgo/dal" - "github.com/dal-go/dalgo/update" + "github.com/dal-go/record/update" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -147,7 +148,7 @@ var _ dal.ReadwriteTransaction = (*batchingTx)(nil) // commit message via tx.Options().Message() / SetMessage during execution. func (t *batchingTx) Options() dal.TransactionOptions { return t.opts } -func (t *batchingTx) Set(ctx context.Context, record dal.Record) error { +func (t *batchingTx) Set(ctx context.Context, record dalrecord.Record) error { colDef, recordKey, err := t.resolveCollection(record.Key()) if err != nil { return err @@ -175,7 +176,7 @@ func (t *batchingTx) Set(ctx context.Context, record dal.Record) error { } } -func (t *batchingTx) Insert(ctx context.Context, record dal.Record, opts ...dal.InsertOption) error { +func (t *batchingTx) Insert(ctx context.Context, record dalrecord.Record, opts ...dal.InsertOption) error { _ = opts colDef, recordKey, err := t.resolveCollection(record.Key()) if err != nil { @@ -228,7 +229,7 @@ func (t *batchingTx) Insert(ctx context.Context, record dal.Record, opts ...dal. } } -func (t *batchingTx) Delete(ctx context.Context, key *dal.Key) error { +func (t *batchingTx) Delete(ctx context.Context, key *dalrecord.Key) error { colDef, recordKey, err := t.resolveCollection(key) if err != nil { return err @@ -325,12 +326,12 @@ func (t *batchingTx) flushChanges() ([]TreeChange, error) { // follow the upstream readwriteTx behavior: they are not implemented and // return an error. Set-mode callers loop Set / Delete instead. -func (t *batchingTx) SetMulti(ctx context.Context, records []dal.Record) error { +func (t *batchingTx) SetMulti(ctx context.Context, records []dalrecord.Record) error { _, _ = ctx, records return fmt.Errorf("not implemented by %s (batching)", DatabaseID) } -func (t *batchingTx) DeleteMulti(ctx context.Context, keys []*dal.Key) error { +func (t *batchingTx) DeleteMulti(ctx context.Context, keys []*dalrecord.Key) error { _, _ = ctx, keys return fmt.Errorf("not implemented by %s (batching)", DatabaseID) } @@ -340,8 +341,8 @@ func (t *batchingTx) DeleteMulti(ctx context.Context, keys []*dal.Key) error { // Set/Updated earlier in the tx, else reading the current file consistently via // the Git Data API), applies updates in memory, then buffers the result as a // write (exactly like Set). Unlike Delete, Update is NOT idempotent: updating a -// record that does not exist returns dal.ErrRecordNotFound. -func (t *batchingTx) Update(ctx context.Context, key *dal.Key, updates []update.Update, preconditions ...dal.Precondition) error { +// record that does not exist returns record.ErrRecordNotFound. +func (t *batchingTx) Update(ctx context.Context, key *dalrecord.Key, updates []update.Update, preconditions ...dal.Precondition) error { if len(preconditions) > 0 { return fmt.Errorf("%w: Update preconditions are not supported by %s (batching)", dal.ErrNotSupported, DatabaseID) } @@ -350,7 +351,7 @@ func (t *batchingTx) Update(ctx context.Context, key *dal.Key, updates []update. if errors.Is(err, errCollectionNotInDefinition) { // An unknown collection cannot hold the record → not-found (Update is // not idempotent). - return dal.ErrRecordNotFound + return dalrecord.ErrRecordNotFound } return err } @@ -363,7 +364,7 @@ func (t *batchingTx) Update(ctx context.Context, key *dal.Key, updates []update. } existing, exists := t.workingMaps[recordPath][recordKey] if !exists { - return dal.ErrRecordNotFound + return dalrecord.ErrRecordNotFound } data := ingitdb.ApplyLocaleToRead(existing, colDef.Columns) if applyErr := applyUpdates(data, updates); applyErr != nil { @@ -377,7 +378,7 @@ func (t *batchingTx) Update(ctx context.Context, key *dal.Key, updates []update. return loadErr } if !found { - return dal.ErrRecordNotFound + return dalrecord.ErrRecordNotFound } if applyErr := applyUpdates(data, updates); applyErr != nil { return applyErr @@ -409,16 +410,16 @@ func (t *batchingTx) loadSingleForUpdate(ctx context.Context, recordPath string, return t.readSingleRecord(ctx, recordPath, colDef) } -func (t *batchingTx) UpdateRecord(ctx context.Context, record dal.Record, updates []update.Update, preconditions ...dal.Precondition) error { +func (t *batchingTx) UpdateRecord(ctx context.Context, record dalrecord.Record, updates []update.Update, preconditions ...dal.Precondition) error { return t.Update(ctx, record.Key(), updates, preconditions...) } -func (t *batchingTx) UpdateMulti(ctx context.Context, keys []*dal.Key, updates []update.Update, preconditions ...dal.Precondition) error { +func (t *batchingTx) UpdateMulti(ctx context.Context, keys []*dalrecord.Key, updates []update.Update, preconditions ...dal.Precondition) error { _, _, _, _ = ctx, keys, updates, preconditions return fmt.Errorf("not implemented by %s (batching)", DatabaseID) } -func (t *batchingTx) InsertMulti(ctx context.Context, records []dal.Record, opts ...dal.InsertOption) error { +func (t *batchingTx) InsertMulti(ctx context.Context, records []dalrecord.Record, opts ...dal.InsertOption) error { _, _, _ = ctx, records, opts return fmt.Errorf("not implemented by %s (batching)", DatabaseID) } diff --git a/batching_test.go b/batching_test.go index 42af6d5..4b31a44 100644 --- a/batching_test.go +++ b/batching_test.go @@ -12,6 +12,7 @@ import ( "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -163,7 +164,7 @@ func TestBatchingGitHubDB_OneCommitPerBatch(t *testing.T) { // Worker writes three records — should produce ONE commit, not three. err = bdb.RunReadwriteTransaction(context.Background(), func(ctx context.Context, tx dal.ReadwriteTransaction) error { for _, name := range []string{"ie", "gb", "us"} { - rec := dal.NewRecordWithData(dal.NewKeyWithID("cities", name), map[string]any{"region": "world"}) + rec := record.NewRecordWithData(record.NewKeyWithID("cities", name), map[string]any{"region": "world"}) if setErr := tx.Set(ctx, rec); setErr != nil { return setErr } @@ -223,7 +224,7 @@ func TestBatchingGitHubDB_WorkerErrorSkipsFlush(t *testing.T) { wantErr := errors.New("worker decided to bail") err = bdb.RunReadwriteTransaction(context.Background(), func(ctx context.Context, tx dal.ReadwriteTransaction) error { - _ = tx.Set(ctx, dal.NewRecordWithData(dal.NewKeyWithID("cities", "ie"), map[string]any{"x": 1})) + _ = tx.Set(ctx, record.NewRecordWithData(record.NewKeyWithID("cities", "ie"), map[string]any{"x": 1})) return wantErr }) if !errors.Is(err, wantErr) { diff --git a/commit_message_test.go b/commit_message_test.go index cbae8d0..11441d9 100644 --- a/commit_message_test.go +++ b/commit_message_test.go @@ -10,6 +10,7 @@ import ( "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -71,7 +72,7 @@ func commitMessageTestDef() *ingitdb.Definition { func runOneSetTx(t *testing.T, bdb *BatchingGitHubDB, options ...dal.TransactionOption) { t.Helper() err := bdb.RunReadwriteTransaction(context.Background(), func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Set(ctx, dal.NewRecordWithData(dal.NewKeyWithID("cities", "ie"), map[string]any{"region": "eu"})) + return tx.Set(ctx, record.NewRecordWithData(record.NewKeyWithID("cities", "ie"), map[string]any{"region": "eu"})) }, options...) if err != nil { t.Fatalf("RunReadwriteTransaction: %v", err) diff --git a/coverage_extra_test.go b/coverage_extra_test.go index 2b6254a..ff37485 100644 --- a/coverage_extra_test.go +++ b/coverage_extra_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/dal-go/dalgo/dal" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -206,8 +207,8 @@ func TestReadRecordFromMap_ReadFileError(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{}) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -234,8 +235,8 @@ func TestReadRecordFromMap_FileNotFound(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{}) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -263,8 +264,8 @@ func TestResolveCollection_NilDef_ViaSet(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{}) return tx.Set(ctx, record) }) if err == nil { @@ -285,8 +286,8 @@ func TestResolveCollection_NilDef_ViaInsert(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{}) return tx.Insert(ctx, record) }) if err == nil { @@ -312,8 +313,8 @@ func TestResolveCollection_CollectionNotFound_ViaSet(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("unknown", "active") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("unknown", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{}) return tx.Set(ctx, record) }) if err == nil { @@ -335,8 +336,8 @@ func TestResolveCollection_CollectionNotFound_ViaInsert(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("unknown", "active") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("unknown", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{}) return tx.Insert(ctx, record) }) if err == nil { @@ -365,8 +366,8 @@ func TestSet_ReadFileWithSHA_Error_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{"title": "Active"}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "Active"}) return tx.Set(ctx, record) }) if err == nil { @@ -388,8 +389,8 @@ func TestSet_ReadFileWithSHA_Error_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{"title": "Active"}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "Active"}) return tx.Set(ctx, record) }) if err == nil { @@ -419,8 +420,8 @@ func TestSet_ParseError_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Set(ctx, record) }) if err == nil { @@ -450,8 +451,8 @@ func TestSet_WriteFile_Error_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{"title": "Updated"}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "Updated"}) return tx.Set(ctx, record) }) if err == nil { @@ -477,8 +478,8 @@ func TestSet_WriteFile_Error_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{"title": "Updated"}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "Updated"}) return tx.Set(ctx, record) }) if err == nil { @@ -522,8 +523,8 @@ func TestSet_EncodeError_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{"title": "Active"}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "Active"}) return tx.Set(ctx, record) }) if err == nil { @@ -545,9 +546,9 @@ func TestSet_EncodeError_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") ch := make(chan int) - record := dal.NewRecordWithData(key, map[string]any{"ch": ch}) + record := dalrecord.NewRecordWithData(key, map[string]any{"ch": ch}) return tx.Set(ctx, record) }) if err == nil { @@ -573,8 +574,8 @@ func TestInsert_ReadFileWithSHA_Error_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Insert(ctx, record) }) if err == nil { @@ -596,8 +597,8 @@ func TestInsert_ReadFileWithSHA_Error_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Insert(ctx, record) }) if err == nil { @@ -627,8 +628,8 @@ func TestInsert_ParseError_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Insert(ctx, record) }) if err == nil { @@ -654,8 +655,8 @@ func TestInsert_WriteFile_Error_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Insert(ctx, record) }) if err == nil { @@ -677,8 +678,8 @@ func TestInsert_WriteFile_Error_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Insert(ctx, record) }) if err == nil { @@ -718,8 +719,8 @@ func TestInsert_EncodeError_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Insert(ctx, record) }) if err == nil { @@ -741,9 +742,9 @@ func TestInsert_EncodeError_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") + key := dalrecord.NewKeyWithID("tags", "new") ch := make(chan int) - record := dal.NewRecordWithData(key, map[string]any{"ch": ch}) + record := dalrecord.NewRecordWithData(key, map[string]any{"ch": ch}) return tx.Insert(ctx, record) }) if err == nil { @@ -769,7 +770,7 @@ func TestDelete_ReadFileWithSHA_Error_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") return tx.Delete(ctx, key) }) if err == nil { @@ -791,7 +792,7 @@ func TestDelete_ReadFileWithSHA_Error_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") return tx.Delete(ctx, key) }) if err == nil { @@ -821,7 +822,7 @@ func TestDelete_ParseError_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") return tx.Delete(ctx, key) }) if err == nil { @@ -854,7 +855,7 @@ func TestDelete_MapOfRecords_LoopBodyCovered(t *testing.T) { // Delete "active" while "archived" remains → the for-range body executes for "archived". ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") return tx.Delete(ctx, key) }) if err != nil { @@ -907,7 +908,7 @@ func TestDelete_EncodeError_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") return tx.Delete(ctx, key) }) if err == nil { @@ -940,7 +941,7 @@ func TestDelete_WriteFile_Error_MapOfRecords(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") return tx.Delete(ctx, key) }) if err == nil { @@ -972,7 +973,7 @@ func TestDelete_DeleteFile_Error_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") + key := dalrecord.NewKeyWithID("tags", "active") return tx.Delete(ctx, key) }) if err == nil { @@ -1048,8 +1049,8 @@ func TestSet_EncodeError_UnsupportedFormat_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "active") - record := dal.NewRecordWithData(key, map[string]any{"title": "Active"}) + key := dalrecord.NewKeyWithID("tags", "active") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "Active"}) return tx.Set(ctx, record) }) if err == nil { @@ -1084,8 +1085,8 @@ func TestInsert_EncodeError_UnsupportedFormat_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "new") - record := dal.NewRecordWithData(key, map[string]any{"title": "New"}) + key := dalrecord.NewKeyWithID("tags", "new") + record := dalrecord.NewRecordWithData(key, map[string]any{"title": "New"}) return tx.Insert(ctx, record) }) if err == nil { diff --git a/coverage_final_test.go b/coverage_final_test.go index 6421c1d..1c0401a 100644 --- a/coverage_final_test.go +++ b/coverage_final_test.go @@ -24,6 +24,7 @@ import ( "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -124,7 +125,7 @@ func TestBatchingGitHubDB_RunRWTx_FlushChangesError(t *testing.T) { // Set on a MapOfRecords collection: ensureMapLoaded fires (empty map from // 404), then the entry is stored in workingMaps. The worker returns nil // so flushChanges is called, where EncodeMapOfRecordsContent fails on "xml". - rec := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) return tx.Set(ctx, rec) }) if err == nil { @@ -151,9 +152,9 @@ func TestBatchingTx_Set_InvalidRecordData(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "k") + key := record.NewKeyWithID("tags", "k") // Directly construct a record whose Data() returns a string, not map[string]any. - rec := dal.NewRecordWithData(key, "not-a-map") + rec := record.NewRecordWithData(key, "not-a-map") rec.SetError(nil) // clear the "no data" sentinel so Data() returns the string return tx.Set(ctx, rec) }) @@ -181,8 +182,8 @@ func TestBatchingTx_Insert_InvalidRecordData(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("tags", "k") - rec := dal.NewRecordWithData(key, "not-a-map") + key := record.NewKeyWithID("tags", "k") + rec := record.NewRecordWithData(key, "not-a-map") rec.SetError(nil) return tx.Insert(ctx, rec) }) @@ -215,7 +216,7 @@ func TestBatchingTx_Insert_MapOfRecords_EnsureLoadError(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) + rec := readyRecord(record.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) return tx.Insert(ctx, rec) }) if err == nil { @@ -245,7 +246,7 @@ func TestBatchingTx_Insert_SingleRecord_ReadError(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) return tx.Insert(ctx, rec) }) if err == nil { @@ -308,7 +309,7 @@ func TestBatchingTx_Insert_SingleRecord_EncodeError_AfterNotFound(t *testing.T) ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) return tx.Insert(ctx, rec) }) if err == nil { @@ -339,7 +340,7 @@ func TestBatchingTx_Delete_MapOfRecords_EnsureLoadError(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("tags", "active")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "active")) }) if err == nil { t.Fatal("Delete MapOfRecords load error: expected error, got nil") @@ -367,7 +368,7 @@ func TestBatchingTx_Delete_SingleRecord_ReadError(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("tags", "k")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "k")) }) if err == nil { t.Fatal("Delete SingleRecord API error: expected error, got nil") @@ -432,13 +433,13 @@ func TestEnsureMapLoaded_AlreadyLoaded(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { // First Set: ensureMapLoaded fires the GET /contents/ call. - rec1 := readyRecord(dal.NewKeyWithID("tags", "a"), map[string]any{"v": 1}) + rec1 := readyRecord(record.NewKeyWithID("tags", "a"), map[string]any{"v": 1}) if setErr := tx.Set(ctx, rec1); setErr != nil { return fmt.Errorf("first Set: %w", setErr) } // Second Set for a different key in the same map file: ensureMapLoaded // must take the early-return path (map already loaded). - rec2 := readyRecord(dal.NewKeyWithID("tags", "b"), map[string]any{"v": 2}) + rec2 := readyRecord(record.NewKeyWithID("tags", "b"), map[string]any{"v": 2}) if setErr := tx.Set(ctx, rec2); setErr != nil { return fmt.Errorf("second Set: %w", setErr) } @@ -471,7 +472,7 @@ func TestEnsureMapLoaded_ParseError(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "new"), map[string]any{"v": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "new"), map[string]any{"v": 1}) return tx.Set(ctx, rec) // triggers ensureMapLoaded → parseErr }) if err == nil { @@ -592,7 +593,7 @@ func TestReadwriteTx_Delete_SingleRecord_DeleteFileError(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("tags", "active")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "active")) }) if err == nil { t.Fatal("Delete: expected error from deleteFile, got nil") @@ -635,7 +636,7 @@ func TestReadwriteTx_Delete_MapOfRecords_EncodeError(t *testing.T) { return nil, fmt.Errorf("injected encode error") }, } - err = tx.Delete(ctx, dal.NewKeyWithID("tags", "active")) + err = tx.Delete(ctx, record.NewKeyWithID("tags", "active")) if err == nil { t.Fatal("Delete: expected encode error, got nil") } diff --git a/coverage_gaps_test.go b/coverage_gaps_test.go index c616c4f..00531c5 100644 --- a/coverage_gaps_test.go +++ b/coverage_gaps_test.go @@ -26,8 +26,9 @@ import ( "testing" "github.com/dal-go/dalgo/dal" - "github.com/dal-go/dalgo/update" + "github.com/dal-go/record/update" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -177,12 +178,12 @@ func makeBatchServer(t *testing.T, fixtures map[string]string) *httptest.Server })) } -// readyRecord creates a dal.Record with SetError(nil) already called so that +// readyRecord creates a record.Record with SetError(nil) already called so that // record.Data() does not panic. batchingTx.Insert/Set access record.Data() // before calling SetError internally — unlike readwriteTx which calls SetError // first. This is a production-code ordering quirk that tests must work around. -func readyRecord(key *dal.Key, data map[string]any) dal.Record { - rec := dal.NewRecordWithData(key, data) +func readyRecord(key *record.Key, data map[string]any) record.Record { + rec := record.NewRecordWithData(key, data) rec.SetError(nil) return rec } @@ -309,9 +310,9 @@ func TestBatchingTx_Update(t *testing.T) { err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { // Unknown collection → record cannot exist → not-found (Update is not // idempotent). - return tx.Update(ctx, dal.NewKeyWithID("col", "k"), nil) + return tx.Update(ctx, record.NewKeyWithID("col", "k"), nil) }) - if !dal.IsNotFound(err) { + if !record.IsNotFound(err) { t.Fatalf("Update error = %v, want not-found", err) } } @@ -326,11 +327,11 @@ func TestBatchingTx_UpdateRecord(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := dal.NewRecordWithData(dal.NewKeyWithID("col", "k"), map[string]any{}) + rec := record.NewRecordWithData(record.NewKeyWithID("col", "k"), map[string]any{}) // Unknown collection → not-found (UpdateRecord delegates to Update). return tx.UpdateRecord(ctx, rec, nil) }) - if !dal.IsNotFound(err) { + if !record.IsNotFound(err) { t.Fatalf("UpdateRecord error = %v, want not-found", err) } } @@ -392,7 +393,7 @@ func TestBatchingTx_Set_UnknownCollection(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("unknown", "k"), map[string]any{}) + rec := readyRecord(record.NewKeyWithID("unknown", "k"), map[string]any{}) return tx.Set(ctx, rec) }) if err == nil { @@ -411,7 +412,7 @@ func TestBatchingTx_Set_MapOfRecords_NewFile(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) + rec := readyRecord(record.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) return tx.Set(ctx, rec) }) if err != nil { @@ -432,7 +433,7 @@ func TestBatchingTx_Set_MapOfRecords_ExistingFile(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "active"), map[string]any{"title": "Updated"}) + rec := readyRecord(record.NewKeyWithID("tags", "active"), map[string]any{"title": "Updated"}) return tx.Set(ctx, rec) }) if err != nil { @@ -455,7 +456,7 @@ func TestBatchingTx_Set_MapOfRecords_EnsureLoadError(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"x": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"x": 1}) return tx.Set(ctx, rec) }) if err == nil { @@ -490,7 +491,7 @@ func TestBatchingTx_Set_SingleRecord_EncodeError(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"x": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"x": 1}) return tx.Set(ctx, rec) }) if err == nil { @@ -512,7 +513,7 @@ func TestBatchingTx_Insert_UnknownCollection(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("unknown", "k"), map[string]any{}) + rec := readyRecord(record.NewKeyWithID("unknown", "k"), map[string]any{}) return tx.Insert(ctx, rec) }) if err == nil { @@ -530,7 +531,7 @@ func TestBatchingTx_Insert_MapOfRecords_NewFile(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) + rec := readyRecord(record.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) return tx.Insert(ctx, rec) }) if err != nil { @@ -551,7 +552,7 @@ func TestBatchingTx_Insert_MapOfRecords_AlreadyExists(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "active"), map[string]any{"title": "Active"}) + rec := readyRecord(record.NewKeyWithID("tags", "active"), map[string]any{"title": "Active"}) return tx.Insert(ctx, rec) }) if err == nil { @@ -573,7 +574,7 @@ func TestBatchingTx_Insert_SingleRecord_NewFile(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) + rec := readyRecord(record.NewKeyWithID("tags", "new"), map[string]any{"title": "New"}) return tx.Insert(ctx, rec) }) if err != nil { @@ -598,7 +599,7 @@ func TestBatchingTx_Insert_SingleRecord_AlreadyExists(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - rec := readyRecord(dal.NewKeyWithID("tags", "active"), map[string]any{"title": "Active"}) + rec := readyRecord(record.NewKeyWithID("tags", "active"), map[string]any{"title": "Active"}) return tx.Insert(ctx, rec) }) if err == nil { @@ -625,11 +626,11 @@ func TestBatchingTx_Insert_SingleRecord_BufferedAsDelete(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { // Delete first (buffers as nil-content deletion). - if delErr := tx.Delete(ctx, dal.NewKeyWithID("tags", "active")); delErr != nil { + if delErr := tx.Delete(ctx, record.NewKeyWithID("tags", "active")); delErr != nil { return fmt.Errorf("Delete: %w", delErr) } // Now re-insert — should succeed because the record is "logically gone". - rec := readyRecord(dal.NewKeyWithID("tags", "active"), map[string]any{"title": "Recreated"}) + rec := readyRecord(record.NewKeyWithID("tags", "active"), map[string]any{"title": "Recreated"}) if insErr := tx.Insert(ctx, rec); insErr != nil { return fmt.Errorf("Insert after delete: %w", insErr) } @@ -653,12 +654,12 @@ func TestBatchingTx_Insert_SingleRecord_BufferedWrite_AlreadyExists(t *testing.T ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { // First insert succeeds. - rec := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) if insErr := tx.Insert(ctx, rec); insErr != nil { return fmt.Errorf("first Insert: %w", insErr) } // Second insert on same key → buffered-write collision. - rec2 := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"v": 2}) + rec2 := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"v": 2}) return tx.Insert(ctx, rec2) }) if err == nil { @@ -683,7 +684,7 @@ func TestBatchingTx_Delete_UnknownCollection(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("unknown", "k")) + return tx.Delete(ctx, record.NewKeyWithID("unknown", "k")) }) if err == nil { t.Fatal("Delete unknown collection: expected error, got nil") @@ -703,7 +704,7 @@ func TestBatchingTx_Delete_MapOfRecords_Found(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("tags", "active")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "active")) }) if err != nil { t.Fatalf("Delete MapOfRecords found: %v", err) @@ -723,7 +724,7 @@ func TestBatchingTx_Delete_MapOfRecords_NotFound(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("tags", "nonexistent")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "nonexistent")) }) if err != nil { t.Fatalf("Delete MapOfRecords not found must be idempotent (nil), got %v", err) @@ -745,7 +746,7 @@ func TestBatchingTx_Delete_SingleRecord_NotFound(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("tags", "missing")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "missing")) }) if err != nil { t.Fatalf("Delete SingleRecord not found must be idempotent (nil), got %v", err) @@ -766,12 +767,12 @@ func TestBatchingTx_Delete_SingleRecord_BufferedWrite_Converts(t *testing.T) { ctx := context.Background() err := bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { // Set buffers the record. - rec := readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) + rec := readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"v": 1}) if setErr := tx.Set(ctx, rec); setErr != nil { return fmt.Errorf("Set: %w", setErr) } // Delete converts the buffered write to a deletion. - return tx.Delete(ctx, dal.NewKeyWithID("tags", "k")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "k")) }) if err != nil { t.Fatalf("Delete after Set: %v", err) @@ -798,11 +799,11 @@ func TestBatchingTx_Delete_SingleRecord_AlreadyBufferedAsDelete(t *testing.T) { ctx := context.Background() err = bdb.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { // First delete succeeds. - if delErr := tx.Delete(ctx, dal.NewKeyWithID("tags", "k")); delErr != nil { + if delErr := tx.Delete(ctx, record.NewKeyWithID("tags", "k")); delErr != nil { return fmt.Errorf("first Delete: %w", delErr) } // Second delete → already buffered as deletion (idempotent no-op). - return tx.Delete(ctx, dal.NewKeyWithID("tags", "k")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "k")) }) if err != nil { t.Fatalf("Delete already deleted must be idempotent (nil), got %v", err) @@ -915,7 +916,7 @@ func TestReadwriteTx_Delete_SingleRecord_NotFound(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Delete(ctx, dal.NewKeyWithID("tags", "missing")) + return tx.Delete(ctx, record.NewKeyWithID("tags", "missing")) }) if err != nil { t.Fatalf("Delete SingleRecord not found must be idempotent (nil), got %v", err) diff --git a/db_github.go b/db_github.go index b388e6b..16a791a 100644 --- a/db_github.go +++ b/db_github.go @@ -11,6 +11,7 @@ import ( "github.com/dal-go/dalgo/dal" "github.com/dal-go/dalgo/recordset" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -80,17 +81,17 @@ func (db *githubDB) RunReadwriteTransaction(ctx context.Context, f dal.RWTxWorke return f(ctx, tx) } -func (db *githubDB) Get(ctx context.Context, record dal.Record) error { +func (db *githubDB) Get(ctx context.Context, record dalrecord.Record) error { tx := readonlyTx{db: db} return tx.Get(ctx, record) } -func (db *githubDB) Exists(ctx context.Context, key *dal.Key) (bool, error) { +func (db *githubDB) Exists(ctx context.Context, key *dalrecord.Key) (bool, error) { tx := readonlyTx{db: db} return tx.Exists(ctx, key) } -func (db *githubDB) GetMulti(ctx context.Context, records []dal.Record) error { +func (db *githubDB) GetMulti(ctx context.Context, records []dalrecord.Record) error { tx := readonlyTx{db: db} return tx.GetMulti(ctx, records) } diff --git a/db_github_getters_test.go b/db_github_getters_test.go index 9758d6b..f7c158e 100644 --- a/db_github_getters_test.go +++ b/db_github_getters_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/dal-go/dalgo/dal" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -148,9 +149,9 @@ func TestGitHubDB_Get(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") data := map[string]any{} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.Get(ctx, record) if err != nil { @@ -173,7 +174,7 @@ func TestGitHubDB_Exists(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } ctx := context.Background() - key := dal.NewKeyWithID("test", "test") + key := dalrecord.NewKeyWithID("test", "test") // The collection "test" is absent from the (empty) definition, so it is // treated as not-found: Exists reports false with no error. exists, err := db.Exists(ctx, key) @@ -196,8 +197,8 @@ func TestGitHubDB_GetMulti(t *testing.T) { ctx := context.Background() // A record in a collection absent from the definition must be marked // not-found per-record, not fail the whole batch. - rec := dal.NewRecordWithData(dal.NewKeyWithID("NonExistingKind", "x"), map[string]any{}) - records := []dal.Record{rec} + rec := dalrecord.NewRecordWithData(dalrecord.NewKeyWithID("NonExistingKind", "x"), map[string]any{}) + records := []dalrecord.Record{rec} err = db.GetMulti(ctx, records) if err != nil { t.Fatalf("GetMulti() unexpected error: %v", err) diff --git a/db_github_test.go b/db_github_test.go index 7ab9897..0d9609d 100644 --- a/db_github_test.go +++ b/db_github_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/dal-go/dalgo/dal" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -52,9 +53,9 @@ func TestGitHubDB_GetSingleRecord(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") data := map[string]any{} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -101,9 +102,9 @@ func TestGitHubDB_GetMapOfRecords(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") data := map[string]any{} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -146,8 +147,8 @@ func TestGitHubDB_GetNotFound(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "missing") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("todo.tags", "missing") + record := dalrecord.NewRecordWithData(key, map[string]any{}) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -191,9 +192,9 @@ func TestGitHubDB_SetSingleRecord(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") data := map[string]any{"title": "Updated"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Set(ctx, record) @@ -231,9 +232,9 @@ func TestGitHubDB_InsertSingleRecord(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "new") + key := dalrecord.NewKeyWithID("todo.tags", "new") data := map[string]any{"title": "New"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Insert(ctx, record) @@ -274,9 +275,9 @@ func TestGitHubDB_InsertSingleRecord_AlreadyExists(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") data := map[string]any{"title": "Active"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Insert(ctx, record) @@ -317,7 +318,7 @@ func TestGitHubDB_DeleteSingleRecord(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Delete(ctx, key) @@ -355,7 +356,7 @@ func TestGitHubDB_DeleteSingleRecord_NotFound(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "missing") + key := dalrecord.NewKeyWithID("todo.tags", "missing") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Delete(ctx, key) diff --git a/error_paths_test.go b/error_paths_test.go index 29abcc6..9554754 100644 --- a/error_paths_test.go +++ b/error_paths_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/dal-go/dalgo/dal" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -39,8 +40,8 @@ func TestReadwriteTx_Set_InvalidRecordData(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("test", "test") - record := dal.NewRecordWithData(key, "invalid-not-a-map") + key := dalrecord.NewKeyWithID("test", "test") + record := dalrecord.NewRecordWithData(key, "invalid-not-a-map") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Set(ctx, record) @@ -82,8 +83,8 @@ func TestReadwriteTx_Set_MapOfRecords_InvalidRecordData(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("test", "new") - record := dal.NewRecordWithData(key, "invalid-not-a-map") + key := dalrecord.NewKeyWithID("test", "new") + record := dalrecord.NewRecordWithData(key, "invalid-not-a-map") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Set(ctx, record) @@ -121,8 +122,8 @@ func TestReadwriteTx_Insert_InvalidRecordData(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("test", "test") - record := dal.NewRecordWithData(key, "invalid-not-a-map") + key := dalrecord.NewKeyWithID("test", "test") + record := dalrecord.NewRecordWithData(key, "invalid-not-a-map") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Insert(ctx, record) @@ -164,8 +165,8 @@ func TestReadwriteTx_Insert_MapOfRecords_InvalidRecordData(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("test", "new") - record := dal.NewRecordWithData(key, "invalid-not-a-map") + key := dalrecord.NewKeyWithID("test", "new") + record := dalrecord.NewRecordWithData(key, "invalid-not-a-map") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Insert(ctx, record) @@ -207,8 +208,8 @@ func TestReadonlyTx_Get_ReadError(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("test", "test") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("test", "test") + record := dalrecord.NewRecordWithData(key, map[string]any{}) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -246,8 +247,8 @@ func TestReadonlyTx_Get_ParseError_SingleRecord(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("test", "bad") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("test", "bad") + record := dalrecord.NewRecordWithData(key, map[string]any{}) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -285,8 +286,8 @@ func TestReadonlyTx_Get_ParseError_MapOfRecords(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("test", "key") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("test", "key") + record := dalrecord.NewRecordWithData(key, map[string]any{}) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) @@ -336,9 +337,9 @@ func TestReadwriteTx_InsertMapOfRecords_NewFile(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "new") + key := dalrecord.NewKeyWithID("todo.tags", "new") data := map[string]any{"title": "New"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Insert(ctx, record) diff --git a/go.mod b/go.mod index 4019655..f43cfcf 100644 --- a/go.mod +++ b/go.mod @@ -3,23 +3,22 @@ module github.com/ingitdb/dalgo2ingitdb4github go 1.26.0 require ( - github.com/dal-go/dalgo v0.62.10 + github.com/dal-go/dalgo v0.63.1 + github.com/dal-go/record v0.1.0 github.com/google/go-github/v88 v88.0.0 - github.com/ingitdb/ingitdb-go/ingitdb v0.0.1 - github.com/pelletier/go-toml/v2 v2.3.1 + github.com/ingitdb/ingitdb-go/ingitdb v0.5.2 + github.com/pelletier/go-toml/v2 v2.4.3 gopkg.in/yaml.v3 v3.0.1 ) require ( - github.com/RoaringBitmap/roaring/v2 v2.19.0 // indirect - github.com/bits-and-blooms/bitset v1.24.4 // indirect + github.com/RoaringBitmap/roaring/v2 v2.22.0 // indirect + github.com/bits-and-blooms/bitset v1.24.6 // indirect github.com/google/go-querystring v1.2.0 // indirect github.com/ingr-io/ingr-go v0.0.2 // indirect - github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect github.com/mschoch/smat v0.2.0 // indirect - github.com/rogpeppe/go-internal v1.15.0 // indirect github.com/strongo/random v0.0.1 // indirect - go.starlark.net v0.0.0-20260613233743-8ba36ccb83fb // indirect - golang.org/x/sys v0.45.0 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + go.starlark.net v0.0.0-20260708150628-5395d018f003 // indirect + golang.org/x/sys v0.47.0 // indirect ) diff --git a/go.sum b/go.sum index b2c9b69..c4a5260 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,12 @@ -github.com/RoaringBitmap/roaring/v2 v2.19.0 h1:zsWtVE+biht4eVl0YDLvykUqGkftR3Qc5UCbeKB4UQ4= -github.com/RoaringBitmap/roaring/v2 v2.19.0/go.mod h1:SfT3of9nYh3vis1dIbCj4Yw6KQGujTN+f345nrN/0JA= -github.com/bits-and-blooms/bitset v1.24.4 h1:95H15Og1clikBrKr/DuzMXkQzECs1M6hhoGXLwLQOZE= -github.com/bits-and-blooms/bitset v1.24.4/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/RoaringBitmap/roaring/v2 v2.22.0 h1:aGqjvTSkJSTP7W6q518EHiK9RRRb5gJbCaaciCFr/Lg= +github.com/RoaringBitmap/roaring/v2 v2.22.0/go.mod h1:SfT3of9nYh3vis1dIbCj4Yw6KQGujTN+f345nrN/0JA= +github.com/bits-and-blooms/bitset v1.24.6 h1:qcrftZUVBIwfs+m+nhoCBAPT+ZPZZjti8SbHbDQQkZ4= +github.com/bits-and-blooms/bitset v1.24.6/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/dal-go/dalgo v0.62.10 h1:a62m+mWfjch7za3G8iCUM/GDfSV7uF1o/1XVZ9k2DhA= -github.com/dal-go/dalgo v0.62.10/go.mod h1:afkKVmM5Nc7LyJXYKup+5lJwAK+qIT0PDbUcsHpF0AQ= +github.com/dal-go/dalgo v0.63.1 h1:GEJAGlNH5xGLdFasSIRrYdqGfd0+4A9DGQ843qJQbyA= +github.com/dal-go/dalgo v0.63.1/go.mod h1:LtD5XVzb1kAdXaRcWVNy4F2ROC4fqR4jqD3q/GD4fJQ= +github.com/dal-go/record v0.1.0 h1:hA4143oZwIgtBH/1BRTUEZMCpDfXQr3ONlVXX8USCNg= +github.com/dal-go/record v0.1.0/go.mod h1:quwsVJTT0f6y3Mhx+yHpTobY7luX1M6kyO6fdJ/AFYE= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -14,35 +16,32 @@ github.com/google/go-github/v88 v88.0.0 h1:dZA9IKkPK1eXZj4ypngnpRj5FwdpTv4whix2P github.com/google/go-github/v88 v88.0.0/go.mod h1:rufTDgn2N45wjhukLTyxmvc9nilSp3mr3Rgtt6b1MPw= github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= -github.com/ingitdb/ingitdb-go/ingitdb v0.0.1 h1:ka6xS7h6zXUnJ5vapyg/3mz8VI3V/ExPGeVTctTyjaQ= -github.com/ingitdb/ingitdb-go/ingitdb v0.0.1/go.mod h1:lPelTuuWeIZzQ9EO2ZhK7JjYz8u3WdkqwaQ3maBKwg0= +github.com/ingitdb/ingitdb-go/ingitdb v0.5.2 h1:ukWmulKRz22SW3iO0xReAqv13WI0x1aGENdd9PqwY/g= +github.com/ingitdb/ingitdb-go/ingitdb v0.5.2/go.mod h1:790hFdzCQlomKtLS/gdrLHplqW4z6FBKX17zI3hPAG4= github.com/ingr-io/ingr-go v0.0.2 h1:2AfFllqzCe2dCNtxIUo306oYzaZr//YzrVOHd0C73nI= github.com/ingr-io/ingr-go v0.0.2/go.mod h1:gb/dGW0qXziCq9iAIgk0yITyWY013w2bhdYiXO0RLuY= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= -github.com/pelletier/go-toml/v2 v2.3.1 h1:MYEvvGnQjeNkRF1qUuGolNtNExTDwct51yp7olPtrEc= -github.com/pelletier/go-toml/v2 v2.3.1/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdDPYVpY= +github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.15.0 h1:D0RCU5rMAp+SpgkiNdrjfJ+LX4J1M32V2NeCY7EJ6hc= github.com/rogpeppe/go-internal v1.15.0/go.mod h1:DrUVZyrJU+txYW5/1kwtXQSMFio52ZOxX7yM1VHvnxs= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/strongo/random v0.0.1 h1:OZHJBb/3uEa7OX8L2Dv2pLnSeewRmXMyTACoeto6O8I= github.com/strongo/random v0.0.1/go.mod h1:/pSI+SjBNLBkjljNtVdYr6ERddA+LqSa87o0/s+9iuU= -go.starlark.net v0.0.0-20260613233743-8ba36ccb83fb h1:NGUBN0jbH0IR3msRslALnoxlySm+6YvVKvVDjdDJrlA= -go.starlark.net v0.0.0-20260613233743-8ba36ccb83fb/go.mod h1:Iue6g6iirlfLoVi/DYCi5/x0h/bAOuWF3dULTKpt2Vo= -golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= -golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +go.starlark.net v0.0.0-20260708150628-5395d018f003 h1:cAxcqHgW8fnmT0cEBU3TzvVYHIFt8IIGDMWUF6rImk4= +go.starlark.net v0.0.0-20260708150628-5395d018f003/go.mod h1:Iue6g6iirlfLoVi/DYCi5/x0h/bAOuWF3dULTKpt2Vo= +go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= +go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/parent_chain_test.go b/parent_chain_test.go index 5fe8948..e8bb7f3 100644 --- a/parent_chain_test.go +++ b/parent_chain_test.go @@ -1,7 +1,7 @@ package dalgo2ghingitdb // parent_chain_test.go is the regression suite for the per-parent ("per-space") -// scoping fix. Before the fix the adapter mapped a dal.Key to an in-repo path +// scoping fix. Before the fix the adapter mapped a record.Key to an in-repo path // using only the leaf collection + record id, dropping the parent chain, so two // keys that share a leaf (e.g. contacts/c1) but live under different parents // (spaces/family vs spaces/work) collided on the same file and clobbered each @@ -20,6 +20,7 @@ import ( "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -120,8 +121,8 @@ func TestResolveScopedCollection_DistinctPathsForSameLeaf(t *testing.T) { t.Parallel() def := spacesWithContactsSubDef() - familyKey := dal.NewKeyWithParentAndID(dal.NewKeyWithID("spaces", "family"), "contacts", "c1") - workKey := dal.NewKeyWithParentAndID(dal.NewKeyWithID("spaces", "work"), "contacts", "c1") + familyKey := record.NewKeyWithParentAndID(record.NewKeyWithID("spaces", "family"), "contacts", "c1") + workKey := record.NewKeyWithParentAndID(record.NewKeyWithID("spaces", "work"), "contacts", "c1") familyDef, err := resolveScopedCollection(def, familyKey.Collection(), familyKey.Parent()) if err != nil { @@ -148,7 +149,7 @@ func TestResolveScopedCollection_DistinctPathsForSameLeaf(t *testing.T) { } // Top-level key is untouched: flat schema-declared DirPath. - topKey := dal.NewKeyWithID("spaces", "family") + topKey := record.NewKeyWithID("spaces", "family") topDef, err := resolveScopedCollection(def, topKey.Collection(), topKey.Parent()) if err != nil { t.Fatalf("resolveScopedCollection(top-level): %v", err) @@ -180,7 +181,7 @@ func TestResolveScopedCollection_DeepNesting(t *testing.T) { def := &ingitdb.Definition{Collections: map[string]*ingitdb.CollectionDef{"spaces": spaces}} // key: spaces/s1/projects/p1/tasks/t1 - parent := dal.NewKeyWithParentAndID(dal.NewKeyWithParentAndID(dal.NewKeyWithID("spaces", "s1"), "projects", "p1"), "tasks", "t1").Parent() + parent := record.NewKeyWithParentAndID(record.NewKeyWithParentAndID(record.NewKeyWithID("spaces", "s1"), "projects", "p1"), "tasks", "t1").Parent() colDef, err := resolveScopedCollection(def, "tasks", parent) if err != nil { t.Fatalf("resolveScopedCollection: %v", err) @@ -196,18 +197,18 @@ func TestResolveScopedCollection_Errors(t *testing.T) { t.Parallel() def := spacesWithContactsSubDef() - if _, err := resolveScopedCollection(nil, "contacts", dal.NewKeyWithID("spaces", "x")); err == nil { + if _, err := resolveScopedCollection(nil, "contacts", record.NewKeyWithID("spaces", "x")); err == nil { t.Error("nil definition: expected error, got nil") } // Unknown root collection with a parent. - if _, err := resolveScopedCollection(def, "contacts", dal.NewKeyWithID("unknown", "x")); err == nil || + if _, err := resolveScopedCollection(def, "contacts", record.NewKeyWithID("unknown", "x")); err == nil || !strings.Contains(err.Error(), "not found in definition") { t.Errorf("unknown root: got %v, want 'not found in definition'", err) } // Unknown subcollection under a known parent record. - if _, err := resolveScopedCollection(def, "widgets", dal.NewKeyWithID("spaces", "family")); err == nil || + if _, err := resolveScopedCollection(def, "widgets", record.NewKeyWithID("spaces", "family")); err == nil || !strings.Contains(err.Error(), "not found in definition") { t.Errorf("unknown subcollection: got %v, want 'not found in definition'", err) } @@ -232,21 +233,21 @@ func TestGitHubDB_NestedKeys_ScopedByParentRecord(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - familyContact := dal.NewKeyWithParentAndID(dal.NewKeyWithID("spaces", "family"), "contacts", "c1") - workContact := dal.NewKeyWithParentAndID(dal.NewKeyWithID("spaces", "work"), "contacts", "c1") + familyContact := record.NewKeyWithParentAndID(record.NewKeyWithID("spaces", "family"), "contacts", "c1") + workContact := record.NewKeyWithParentAndID(record.NewKeyWithID("spaces", "work"), "contacts", "c1") ctx := context.Background() if err := db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - if setErr := tx.Set(ctx, dal.NewRecordWithData(familyContact, map[string]any{"name": "Alice"})); setErr != nil { + if setErr := tx.Set(ctx, record.NewRecordWithData(familyContact, map[string]any{"name": "Alice"})); setErr != nil { return setErr } - return tx.Set(ctx, dal.NewRecordWithData(workContact, map[string]any{"name": "Bob"})) + return tx.Set(ctx, record.NewRecordWithData(workContact, map[string]any{"name": "Bob"})) }); err != nil { t.Fatalf("write nested contacts: %v", err) } - famRec := dal.NewRecordWithData(familyContact, map[string]any{}) - workRec := dal.NewRecordWithData(workContact, map[string]any{}) + famRec := record.NewRecordWithData(familyContact, map[string]any{}) + workRec := record.NewRecordWithData(workContact, map[string]any{}) if getErr := db.Get(ctx, famRec); getErr != nil { t.Fatalf("get family contact: %v", getErr) } diff --git a/query.go b/query.go index edce842..1146fa7 100644 --- a/query.go +++ b/query.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -63,7 +64,7 @@ func (r readonlyTx) executeQueryToRecordsReader(ctx context.Context, query dal.Q // Build data-backed records first so WHERE / ORDER BY can read fields; // for keys-only queries the data is stripped at the end, after filtering. - records := make([]dal.Record, 0, len(rows)) + records := make([]record.Record, 0, len(rows)) for _, row := range rows { records = append(records, buildQueryRecord(colDef.ID, row)) } @@ -83,7 +84,7 @@ func (r readonlyTx) executeQueryToRecordsReader(ctx context.Context, query dal.Q if sq.IntoRecord() == nil && sq.IDKind() != reflect.Invalid { for i, rec := range records { - keyOnly := dal.NewRecord(rec.Key()) + keyOnly := record.NewRecord(rec.Key()) keyOnly.SetError(nil) records[i] = keyOnly } @@ -227,15 +228,15 @@ func (r readonlyTx) scanMapOfRecords(ctx context.Context, colDef *ingitdb.Collec return rows, nil } -// buildQueryRecord converts a decoded row into a dal.Record shaped for the +// buildQueryRecord converts a decoded row into a record.Record shaped for the // query: keys-only records carry only the key; IntoRecord/default records carry // the row's data map. The record's key ID is the derived record key. -func buildQueryRecord(collection string, row keyedRow) dal.Record { - key := dal.NewKeyWithID(collection, row.key) +func buildQueryRecord(collection string, row keyedRow) record.Record { + key := record.NewKeyWithID(collection, row.key) // Always back the record with the decoded map so the shared WHERE / // ORDER BY helpers can read fields. Keys-only queries strip the data // after filtering (a keys-only WHERE still needs the row's fields). - rec := dal.NewRecordWithData(key, row.data) + rec := record.NewRecordWithData(key, row.data) rec.SetError(nil) return rec } @@ -270,7 +271,7 @@ func buildKeyExtractor(nameTemplate string) (func(relPath string) string, error) // applyWhere filters records by the query condition, reading fields from the // record's data map (and $id from the key). -func applyWhere(records []dal.Record, cond dal.Condition) ([]dal.Record, error) { +func applyWhere(records []record.Record, cond dal.Condition) ([]record.Record, error) { filtered := records[:0] for _, rec := range records { data := recordData(rec) @@ -287,7 +288,7 @@ func applyWhere(records []dal.Record, cond dal.Condition) ([]dal.Record, error) } // applyOrderBy sorts records in place, stably, honoring asc/desc per field. -func applyOrderBy(records []dal.Record, orderBy []dal.OrderExpression) { +func applyOrderBy(records []record.Record, orderBy []dal.OrderExpression) { sort.SliceStable(records, func(i, j int) bool { dataI := recordData(records[i]) dataJ := recordData(records[j]) @@ -320,7 +321,7 @@ func applyOrderBy(records []dal.Record, orderBy []dal.OrderExpression) { } // recordData returns the record's data map, or an empty map when absent. -func recordData(rec dal.Record) map[string]any { +func recordData(rec record.Record) map[string]any { if data, ok := rec.Data().(map[string]any); ok { return data } diff --git a/query_test.go b/query_test.go index 16893e7..09828a2 100644 --- a/query_test.go +++ b/query_test.go @@ -13,6 +13,7 @@ import ( "testing" "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" ) // queryMockServer mocks the subset of the GitHub API a structured query needs: @@ -116,9 +117,9 @@ func countriesBlobs() map[string]string { } } -func runQuery(t *testing.T, db dal.DB, q dal.Query) []dal.Record { +func runQuery(t *testing.T, db dal.DB, q dal.Query) []record.Record { t.Helper() - var out []dal.Record + var out []record.Record err := db.RunReadonlyTransaction(context.Background(), func(ctx context.Context, tx dal.ReadTransaction) error { reader, err := tx.ExecuteQueryToRecordsReader(ctx, q) if err != nil { @@ -142,7 +143,7 @@ func runQuery(t *testing.T, db dal.DB, q dal.Query) []dal.Record { return out } -func recordIDs(records []dal.Record) []string { +func recordIDs(records []record.Record) []string { ids := make([]string, len(records)) for i, rec := range records { ids[i] = rec.Key().ID.(string) @@ -157,8 +158,8 @@ func TestQuery_SelectAll(t *testing.T) { db := newQueryTestDB(t, srv) q := dal.From(dal.NewRootCollectionRef("countries", "")).NewQuery(). - SelectIntoRecord(func() dal.Record { - return dal.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) + SelectIntoRecord(func() record.Record { + return record.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) }) records := runQuery(t, db, q) @@ -189,8 +190,8 @@ func TestQuery_WhereFieldEquals(t *testing.T) { q := dal.From(dal.NewRootCollectionRef("countries", "")).NewQuery(). WhereField("name", dal.Equal, "Ireland"). - SelectIntoRecord(func() dal.Record { - return dal.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) + SelectIntoRecord(func() record.Record { + return record.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) }) records := runQuery(t, db, q) @@ -207,8 +208,8 @@ func TestQuery_OrderByAscendingAndDescending(t *testing.T) { asc := dal.From(dal.NewRootCollectionRef("countries", "")).NewQuery(). OrderBy(dal.AscendingField("population")). - SelectIntoRecord(func() dal.Record { - return dal.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) + SelectIntoRecord(func() record.Record { + return record.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) }) if got := recordIDs(runQuery(t, db, asc)); !reflect.DeepEqual(got, []string{"ie", "gb", "us"}) { t.Errorf("ORDER BY population ASC: got %v, want [ie gb us]", got) @@ -216,8 +217,8 @@ func TestQuery_OrderByAscendingAndDescending(t *testing.T) { desc := dal.From(dal.NewRootCollectionRef("countries", "")).NewQuery(). OrderBy(dal.DescendingField("population")). - SelectIntoRecord(func() dal.Record { - return dal.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) + SelectIntoRecord(func() record.Record { + return record.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) }) if got := recordIDs(runQuery(t, db, desc)); !reflect.DeepEqual(got, []string{"us", "gb", "ie"}) { t.Errorf("ORDER BY population DESC: got %v, want [us gb ie]", got) @@ -233,8 +234,8 @@ func TestQuery_Limit(t *testing.T) { q := dal.From(dal.NewRootCollectionRef("countries", "")).NewQuery(). OrderBy(dal.DescendingField("population")). Limit(2). - SelectIntoRecord(func() dal.Record { - return dal.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) + SelectIntoRecord(func() record.Record { + return record.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) }) if got := recordIDs(runQuery(t, db, q)); !reflect.DeepEqual(got, []string{"us", "gb"}) { t.Errorf("LIMIT 2 over DESC population: got %v, want [us gb]", got) @@ -270,8 +271,8 @@ func TestQuery_UnknownCollectionReturnsEmpty(t *testing.T) { db := newQueryTestDB(t, srv) q := dal.From(dal.NewRootCollectionRef("cities", "")).NewQuery(). - SelectIntoRecord(func() dal.Record { - return dal.NewRecordWithIncompleteKey("cities", reflect.String, map[string]any{}) + SelectIntoRecord(func() record.Record { + return record.NewRecordWithIncompleteKey("cities", reflect.String, map[string]any{}) }) if records := runQuery(t, db, q); len(records) != 0 { t.Fatalf("unknown collection: got %d records, want 0", len(records)) @@ -287,8 +288,8 @@ func TestQuery_UnsupportedClausesReturnNotSupported(t *testing.T) { newBase := func() dal.IQueryBuilder { return dal.From(dal.NewRootCollectionRef("countries", "")).NewQuery() } - into := func() dal.Record { - return dal.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) + into := func() record.Record { + return record.NewRecordWithIncompleteKey("countries", reflect.String, map[string]any{}) } cases := map[string]dal.Query{ "offset": newBase().Offset(1).SelectIntoRecord(into), diff --git a/scoped_collection.go b/scoped_collection.go index a3eae2a..38cc952 100644 --- a/scoped_collection.go +++ b/scoped_collection.go @@ -5,7 +5,7 @@ import ( "fmt" "path" - "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -44,7 +44,7 @@ var errCollectionNotInDefinition = errors.New("collection not found in definitio // only DirPath overridden; RecordFile, Columns, format, etc. still come from the // subcollection's own schema so encoding/decoding is unaffected. Paths use // forward slashes (path.Join) because inGitDB repo paths are always POSIX. -func resolveScopedCollection(def *ingitdb.Definition, collection string, parent *dal.Key) (*ingitdb.CollectionDef, error) { +func resolveScopedCollection(def *ingitdb.Definition, collection string, parent *record.Key) (*ingitdb.CollectionDef, error) { if def == nil { return nil, fmt.Errorf("definition is required") } diff --git a/tree_reader_test.go b/tree_reader_test.go index 6d4f444..ffa9d6a 100644 --- a/tree_reader_test.go +++ b/tree_reader_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/dal-go/dalgo/dal" + "github.com/dal-go/record" "github.com/google/go-github/v88/github" ) @@ -102,7 +102,7 @@ func TestBatchingGitHubDB_Get_ReadAfterWrite(t *testing.T) { t.Fatalf("NewBatchingGitHubDB: %v", err) } - rec := dal.NewRecordWithData(dal.NewKeyWithID("tags", "active"), map[string]any{}) + rec := record.NewRecordWithData(record.NewKeyWithID("tags", "active"), map[string]any{}) if getErr := bdb.Get(context.Background(), rec); getErr != nil { t.Fatalf("Get: %v", getErr) } diff --git a/tx_readonly.go b/tx_readonly.go index e041125..6dc2e3e 100644 --- a/tx_readonly.go +++ b/tx_readonly.go @@ -8,6 +8,7 @@ import ( "github.com/dal-go/dalgo/dal" "github.com/dal-go/dalgo/recordset" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -21,7 +22,7 @@ func (r readonlyTx) Options() dal.TransactionOptions { return nil } -func (r readonlyTx) Get(ctx context.Context, record dal.Record) error { +func (r readonlyTx) Get(ctx context.Context, record dalrecord.Record) error { if r.db.def == nil { return fmt.Errorf("definition is required") } @@ -44,7 +45,7 @@ func (r readonlyTx) Get(ctx context.Context, record dal.Record) error { return err } if !found { - record.SetError(dal.ErrRecordNotFound) + record.SetError(dalrecord.ErrRecordNotFound) return nil } record.SetError(nil) @@ -56,7 +57,7 @@ func (r readonlyTx) Get(ctx context.Context, record dal.Record) error { return err } if !found { - record.SetError(dal.ErrRecordNotFound) + record.SetError(dalrecord.ErrRecordNotFound) return nil } record.SetError(nil) @@ -68,8 +69,8 @@ func (r readonlyTx) Get(ctx context.Context, record dal.Record) error { return nil } -func (r readonlyTx) Exists(ctx context.Context, key *dal.Key) (bool, error) { - rec := dal.NewRecordWithData(key, map[string]any{}) +func (r readonlyTx) Exists(ctx context.Context, key *dalrecord.Key) (bool, error) { + rec := dalrecord.NewRecordWithData(key, map[string]any{}) if err := r.Get(ctx, rec); err != nil { return false, err } @@ -81,9 +82,9 @@ func (r readonlyTx) Exists(ctx context.Context, key *dal.Key) (bool, error) { // GetMulti loads each record by calling Get. Per-record not-found is reported // via record.SetError (set inside Get), not as a batch-level error — matching // the dalgo GetMulti contract. Only genuine errors abort the batch. -func (r readonlyTx) GetMulti(ctx context.Context, records []dal.Record) error { +func (r readonlyTx) GetMulti(ctx context.Context, records []dalrecord.Record) error { for _, rec := range records { - if err := r.Get(ctx, rec); err != nil && !dal.IsNotFound(err) { + if err := r.Get(ctx, rec); err != nil && !dalrecord.IsNotFound(err) { return err } } @@ -134,7 +135,7 @@ func (r readonlyTx) readRecordFromMap(ctx context.Context, recordPath, recordKey return localizedData, true, nil } -func (r readonlyTx) resolveCollection(key *dal.Key) (*ingitdb.CollectionDef, string, error) { +func (r readonlyTx) resolveCollection(key *dalrecord.Key) (*ingitdb.CollectionDef, string, error) { if r.db.def == nil { return nil, "", fmt.Errorf("definition is required") } diff --git a/tx_readonly_test.go b/tx_readonly_test.go index aefa24c..4805215 100644 --- a/tx_readonly_test.go +++ b/tx_readonly_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/dal-go/dalgo/dal" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -40,7 +41,7 @@ func TestReadonlyTx_Exists(t *testing.T) { } ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { - key := dal.NewKeyWithID("test", "test") + key := dalrecord.NewKeyWithID("test", "test") // Unknown collection → treated as not-found → Exists reports false, no error. exists, existsErr := tx.Exists(ctx, key) if existsErr != nil { @@ -68,8 +69,8 @@ func TestReadonlyTx_GetMulti(t *testing.T) { err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { // A record in a collection absent from the definition must be marked // not-found per-record, not fail the whole batch. - rec := dal.NewRecordWithData(dal.NewKeyWithID("NonExistingKind", "x"), map[string]any{}) - records := []dal.Record{rec} + rec := dalrecord.NewRecordWithData(dalrecord.NewKeyWithID("NonExistingKind", "x"), map[string]any{}) + records := []dalrecord.Record{rec} getMultiErr := tx.GetMulti(ctx, records) if getMultiErr != nil { t.Fatalf("GetMulti() unexpected error: %v", getMultiErr) @@ -148,8 +149,8 @@ func TestReadonlyTx_Get_NoDefinition(t *testing.T) { } ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { - key := dal.NewKeyWithID("test", "test") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("test", "test") + record := dalrecord.NewRecordWithData(key, map[string]any{}) getErr := tx.Get(ctx, record) if getErr == nil { t.Fatal("Get() expected error for missing definition, got nil") @@ -177,8 +178,8 @@ func TestReadonlyTx_Get_CollectionNotFound(t *testing.T) { } ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { - key := dal.NewKeyWithID("nonexistent", "test") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("nonexistent", "test") + record := dalrecord.NewRecordWithData(key, map[string]any{}) // A record in a collection absent from the definition is treated as // not-found (not a hard error), per the dalgo Getter contract: Get returns // nil and marks the record not-found so GetMulti can continue. @@ -225,8 +226,8 @@ func TestReadonlyTx_Get_UnsupportedRecordType(t *testing.T) { } ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { - key := dal.NewKeyWithID("test", "test") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("test", "test") + record := dalrecord.NewRecordWithData(key, map[string]any{}) getErr := tx.Get(ctx, record) if getErr == nil { t.Fatal("Get() expected error for unsupported record type, got nil") @@ -260,7 +261,7 @@ func TestReadonlyTx_ResolveCollection_NoRecordFile(t *testing.T) { } ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("test", "test") + key := dalrecord.NewKeyWithID("test", "test") deleteErr := tx.Delete(ctx, key) if deleteErr == nil { t.Fatal("Delete() expected error for missing record file, got nil") @@ -307,9 +308,9 @@ func TestReadonlyTx_GetMapOfRecords_RecordNotInMap(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "nonexistent") + key := dalrecord.NewKeyWithID("todo.tags", "nonexistent") data := map[string]any{} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadonlyTransaction(ctx, func(ctx context.Context, tx dal.ReadTransaction) error { return tx.Get(ctx, record) diff --git a/tx_readwrite.go b/tx_readwrite.go index f4a7f0e..cd46719 100644 --- a/tx_readwrite.go +++ b/tx_readwrite.go @@ -6,9 +6,10 @@ import ( "fmt" "github.com/dal-go/dalgo/dal" - "github.com/dal-go/dalgo/update" + "github.com/dal-go/record/update" "github.com/pelletier/go-toml/v2" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" "gopkg.in/yaml.v3" ) @@ -23,7 +24,7 @@ type readwriteTx struct { encodeRecordFn func(map[string]any, ingitdb.RecordFormat) ([]byte, error) } -func (r readwriteTx) Set(ctx context.Context, record dal.Record) error { +func (r readwriteTx) Set(ctx context.Context, record dalrecord.Record) error { colDef, recordKey, err := r.resolveCollection(record.Key()) if err != nil { return err @@ -84,7 +85,7 @@ func (r readwriteTx) Set(ctx context.Context, record dal.Record) error { return nil } -func (r readwriteTx) Insert(ctx context.Context, record dal.Record, opts ...dal.InsertOption) error { +func (r readwriteTx) Insert(ctx context.Context, record dalrecord.Record, opts ...dal.InsertOption) error { _ = opts colDef, recordKey, err := r.resolveCollection(record.Key()) if err != nil { @@ -155,7 +156,7 @@ func (r readwriteTx) Insert(ctx context.Context, record dal.Record, opts ...dal. return nil } -func (r readwriteTx) Delete(ctx context.Context, key *dal.Key) error { +func (r readwriteTx) Delete(ctx context.Context, key *dalrecord.Key) error { colDef, recordKey, err := r.resolveCollection(key) if err != nil { return err @@ -214,25 +215,25 @@ func (r readwriteTx) Delete(ctx context.Context, key *dal.Key) error { return nil } -func (r readwriteTx) SetMulti(ctx context.Context, records []dal.Record) error { +func (r readwriteTx) SetMulti(ctx context.Context, records []dalrecord.Record) error { _, _ = ctx, records return fmt.Errorf("not implemented by %s", DatabaseID) } -func (r readwriteTx) DeleteMulti(ctx context.Context, keys []*dal.Key) error { +func (r readwriteTx) DeleteMulti(ctx context.Context, keys []*dalrecord.Key) error { _, _ = ctx, keys return fmt.Errorf("not implemented by %s", DatabaseID) } // Update applies field-level updates by reading the record, mutating it in // memory, then writing it back via Set. Updating a non-existent record returns -// dal.ErrRecordNotFound (Update is not idempotent, unlike Delete). Preconditions +// record.ErrRecordNotFound (Update is not idempotent, unlike Delete). Preconditions // are not supported. -func (r readwriteTx) Update(ctx context.Context, key *dal.Key, updates []update.Update, preconditions ...dal.Precondition) error { +func (r readwriteTx) Update(ctx context.Context, key *dalrecord.Key, updates []update.Update, preconditions ...dal.Precondition) error { if len(preconditions) > 0 { return fmt.Errorf("%w: Update preconditions are not supported by %s", dal.ErrNotSupported, DatabaseID) } - rec := dal.NewRecordWithData(key, map[string]any{}) + rec := dalrecord.NewRecordWithData(key, map[string]any{}) if err := r.Get(ctx, rec); err != nil { return err } @@ -240,7 +241,7 @@ func (r readwriteTx) Update(ctx context.Context, key *dal.Key, updates []update. // nil. record.Error() masks not-found (returns nil), so detect absence via // Exists() and surface ErrRecordNotFound (Update is not idempotent). if !rec.Exists() { - return dal.ErrRecordNotFound + return dalrecord.ErrRecordNotFound } data, ok := rec.Data().(map[string]any) if !ok { @@ -249,19 +250,19 @@ func (r readwriteTx) Update(ctx context.Context, key *dal.Key, updates []update. if err := applyUpdates(data, updates); err != nil { return err } - return r.Set(ctx, dal.NewRecordWithData(key, data)) + return r.Set(ctx, dalrecord.NewRecordWithData(key, data)) } -func (r readwriteTx) UpdateRecord(ctx context.Context, record dal.Record, updates []update.Update, preconditions ...dal.Precondition) error { +func (r readwriteTx) UpdateRecord(ctx context.Context, record dalrecord.Record, updates []update.Update, preconditions ...dal.Precondition) error { return r.Update(ctx, record.Key(), updates, preconditions...) } -func (r readwriteTx) UpdateMulti(ctx context.Context, keys []*dal.Key, updates []update.Update, preconditions ...dal.Precondition) error { +func (r readwriteTx) UpdateMulti(ctx context.Context, keys []*dalrecord.Key, updates []update.Update, preconditions ...dal.Precondition) error { _, _, _, _ = ctx, keys, updates, preconditions return fmt.Errorf("not implemented by %s", DatabaseID) } -func (r readwriteTx) InsertMulti(ctx context.Context, records []dal.Record, opts ...dal.InsertOption) error { +func (r readwriteTx) InsertMulti(ctx context.Context, records []dalrecord.Record, opts ...dal.InsertOption) error { _, _, _ = ctx, records, opts return fmt.Errorf("not implemented by %s", DatabaseID) } diff --git a/tx_readwrite_test.go b/tx_readwrite_test.go index 1875f3c..2cc5050 100644 --- a/tx_readwrite_test.go +++ b/tx_readwrite_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/dal-go/dalgo/dal" + dalrecord "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -40,7 +41,7 @@ func TestReadwriteTx_SetMulti(t *testing.T) { } ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - records := []dal.Record{} + records := []dalrecord.Record{} setMultiErr := tx.SetMulti(ctx, records) if setMultiErr == nil { t.Fatal("SetMulti() expected error, got nil") @@ -66,7 +67,7 @@ func TestReadwriteTx_DeleteMulti(t *testing.T) { } ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - keys := []*dal.Key{} + keys := []*dalrecord.Key{} deleteMultiErr := tx.DeleteMulti(ctx, keys) if deleteMultiErr == nil { t.Fatal("DeleteMulti() expected error, got nil") @@ -92,11 +93,11 @@ func TestReadwriteTx_Update(t *testing.T) { } ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("test", "test") + key := dalrecord.NewKeyWithID("test", "test") // The collection is absent from the definition → the record cannot exist → // Update reports not-found (Update is not idempotent). updateErr := tx.Update(ctx, key, nil) - if !dal.IsNotFound(updateErr) { + if !dalrecord.IsNotFound(updateErr) { t.Fatalf("Update() error = %v, want not-found", updateErr) } return nil @@ -116,11 +117,11 @@ func TestReadwriteTx_UpdateRecord(t *testing.T) { } ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - key := dal.NewKeyWithID("test", "test") - record := dal.NewRecordWithData(key, map[string]any{}) + key := dalrecord.NewKeyWithID("test", "test") + record := dalrecord.NewRecordWithData(key, map[string]any{}) // Unknown collection → not-found (UpdateRecord delegates to Update). updateRecordErr := tx.UpdateRecord(ctx, record, nil) - if !dal.IsNotFound(updateRecordErr) { + if !dalrecord.IsNotFound(updateRecordErr) { t.Fatalf("UpdateRecord() error = %v, want not-found", updateRecordErr) } return nil @@ -140,7 +141,7 @@ func TestReadwriteTx_UpdateMulti(t *testing.T) { } ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - keys := []*dal.Key{} + keys := []*dalrecord.Key{} updateMultiErr := tx.UpdateMulti(ctx, keys, nil) if updateMultiErr == nil { t.Fatal("UpdateMulti() expected error, got nil") @@ -166,7 +167,7 @@ func TestReadwriteTx_InsertMulti(t *testing.T) { } ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - records := []dal.Record{} + records := []dalrecord.Record{} insertMultiErr := tx.InsertMulti(ctx, records) if insertMultiErr == nil { t.Fatal("InsertMulti() expected error, got nil") @@ -213,9 +214,9 @@ func TestReadwriteTx_SetMapOfRecords(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") data := map[string]any{"title": "Updated"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Set(ctx, record) @@ -253,9 +254,9 @@ func TestReadwriteTx_SetMapOfRecords_NewFile(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "new") + key := dalrecord.NewKeyWithID("todo.tags", "new") data := map[string]any{"title": "New"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Set(ctx, record) @@ -296,9 +297,9 @@ func TestReadwriteTx_InsertMapOfRecords(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "new") + key := dalrecord.NewKeyWithID("todo.tags", "new") data := map[string]any{"title": "New"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Insert(ctx, record) @@ -339,9 +340,9 @@ func TestReadwriteTx_InsertMapOfRecords_AlreadyExists(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") data := map[string]any{"title": "Active"} - record := dal.NewRecordWithData(key, data) + record := dalrecord.NewRecordWithData(key, data) ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Insert(ctx, record) @@ -386,7 +387,7 @@ func TestReadwriteTx_DeleteMapOfRecords(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Delete(ctx, key) @@ -424,7 +425,7 @@ func TestReadwriteTx_DeleteMapOfRecords_FileNotFound(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "active") + key := dalrecord.NewKeyWithID("todo.tags", "active") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Delete(ctx, key) @@ -465,7 +466,7 @@ func TestReadwriteTx_DeleteMapOfRecords_RecordNotInMap(t *testing.T) { t.Fatalf("NewGitHubDBWithDef: %v", err) } - key := dal.NewKeyWithID("todo.tags", "nonexistent") + key := dalrecord.NewKeyWithID("todo.tags", "nonexistent") ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { return tx.Delete(ctx, key) diff --git a/update_batching_test.go b/update_batching_test.go index 8df9aa7..53f6460 100644 --- a/update_batching_test.go +++ b/update_batching_test.go @@ -6,8 +6,9 @@ import ( "testing" "github.com/dal-go/dalgo/dal" - "github.com/dal-go/dalgo/update" + "github.com/dal-go/record/update" + "github.com/dal-go/record" "github.com/ingitdb/ingitdb-go/ingitdb" ) @@ -47,7 +48,7 @@ func runBatchUpdate(t *testing.T, collection, id, seedYAML string, updates []upd mapColDefs: make(map[string]*ingitdb.CollectionDef), mapLoaded: make(map[string]bool), } - updErr = txOuter.Update(context.Background(), dal.NewKeyWithID(collection, id), updates) + updErr = txOuter.Update(context.Background(), record.NewKeyWithID(collection, id), updates) if updErr == nil { buffered = txOuter.bufferedFiles[seedFixturePath(def, collection, id)].Content } @@ -151,10 +152,10 @@ func TestBatchingTx_Update_MissingRecord_NotFound(t *testing.T) { t.Fatalf("NewBatchingGitHubDB: %v", err) } upErr := bdb.RunReadwriteTransaction(context.Background(), func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Update(ctx, dal.NewKeyWithID("tags", "missing"), + return tx.Update(ctx, record.NewKeyWithID("tags", "missing"), []update.Update{update.ByFieldName("title", "X")}) }) - if !dal.IsNotFound(upErr) { + if !record.IsNotFound(upErr) { t.Fatalf("Update missing record error = %v, want not-found", upErr) } } @@ -185,7 +186,7 @@ func TestBatchingTx_Update_MapOfRecords(t *testing.T) { mapLoaded: make(map[string]bool), } ctx := context.Background() - if upErr := tx.Update(ctx, dal.NewKeyWithID("tags", "active"), []update.Update{ + if upErr := tx.Update(ctx, record.NewKeyWithID("tags", "active"), []update.Update{ update.ByFieldName("title", "New"), update.ByFieldName("count", dal.Increment(1)), }); upErr != nil { @@ -202,8 +203,8 @@ func TestBatchingTx_Update_MapOfRecords(t *testing.T) { } // Updating a missing entry must be not-found. - if upErr := tx.Update(ctx, dal.NewKeyWithID("tags", "ghost"), - []update.Update{update.ByFieldName("title", "X")}); !dal.IsNotFound(upErr) { + if upErr := tx.Update(ctx, record.NewKeyWithID("tags", "ghost"), + []update.Update{update.ByFieldName("title", "X")}); !record.IsNotFound(upErr) { t.Fatalf("Update missing map entry = %v, want not-found", upErr) } } @@ -233,10 +234,10 @@ func TestBatchingTx_Update_PrefersBufferedContent(t *testing.T) { mapLoaded: make(map[string]bool), } ctx := context.Background() - if setErr := tx.Set(ctx, readyRecord(dal.NewKeyWithID("tags", "k"), map[string]any{"count": 1})); setErr != nil { + if setErr := tx.Set(ctx, readyRecord(record.NewKeyWithID("tags", "k"), map[string]any{"count": 1})); setErr != nil { t.Fatalf("Set: %v", setErr) } - if upErr := tx.Update(ctx, dal.NewKeyWithID("tags", "k"), + if upErr := tx.Update(ctx, record.NewKeyWithID("tags", "k"), []update.Update{update.ByFieldName("count", dal.Increment(1))}); upErr != nil { t.Fatalf("Update: %v", upErr) } diff --git a/update_readwrite_test.go b/update_readwrite_test.go index e33abbd..7364fa4 100644 --- a/update_readwrite_test.go +++ b/update_readwrite_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/dal-go/dalgo/dal" - "github.com/dal-go/dalgo/update" + "github.com/dal-go/record" + "github.com/dal-go/record/update" ) // TestReadwriteTx_Update_SingleRecord verifies the non-batching Update path: @@ -32,7 +33,7 @@ func TestReadwriteTx_Update_SingleRecord(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Update(ctx, dal.NewKeyWithID("tags", "active"), []update.Update{ + return tx.Update(ctx, record.NewKeyWithID("tags", "active"), []update.Update{ update.ByFieldName("title", "New"), update.ByFieldName("count", dal.Increment(2)), update.ByFieldPath(update.FieldPath{"meta", "flag"}, true), @@ -42,7 +43,7 @@ func TestReadwriteTx_Update_SingleRecord(t *testing.T) { t.Fatalf("Update: %v", err) } - rec := dal.NewRecordWithData(dal.NewKeyWithID("tags", "active"), map[string]any{}) + rec := record.NewRecordWithData(record.NewKeyWithID("tags", "active"), map[string]any{}) if getErr := db.Get(ctx, rec); getErr != nil { t.Fatalf("Get after update: %v", getErr) } @@ -76,10 +77,10 @@ func TestReadwriteTx_Update_MissingRecord_NotFound(t *testing.T) { ctx := context.Background() err = db.RunReadwriteTransaction(ctx, func(ctx context.Context, tx dal.ReadwriteTransaction) error { - return tx.Update(ctx, dal.NewKeyWithID("tags", "missing"), + return tx.Update(ctx, record.NewKeyWithID("tags", "missing"), []update.Update{update.ByFieldName("title", "X")}) }) - if !dal.IsNotFound(err) { + if !record.IsNotFound(err) { t.Fatalf("Update missing = %v, want not-found", err) } } diff --git a/updates.go b/updates.go index 91a52a0..e60f2ae 100644 --- a/updates.go +++ b/updates.go @@ -5,7 +5,7 @@ import ( "time" "github.com/dal-go/dalgo/dal" - "github.com/dal-go/dalgo/update" + "github.com/dal-go/record/update" ) // applyUpdates mutates data according to updates. It mirrors the filesystem