From d1a0212cb197e7216f1cb9c5bd33ce7cd5ab3140 Mon Sep 17 00:00:00 2001 From: aleidk Date: Tue, 26 Nov 2024 09:29:48 -0300 Subject: [PATCH] feat: add collection-node relationship in collection.FetchNodes() --- examples/usage.go | 10 +++++++++- pkg/collection.go | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/examples/usage.go b/examples/usage.go index 86a4be0..ea35ed7 100644 --- a/examples/usage.go +++ b/examples/usage.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "strconv" + "time" _ "modernc.org/sqlite" @@ -124,6 +125,13 @@ func getPokemons( } func main() { + start := time.Now() + + defer func() { + elapsed := time.Now().Sub(start) + fmt.Printf("\n\nExecution time took: %s", elapsed) + }() + connection, err := sql.Open("sqlite", "db.sql") if err != nil { fmt.Println(err) @@ -134,7 +142,7 @@ func main() { defer connection.Close() opts := synchronizator.DefaultOptions - opts.Log_level = synchronizator.DEBUG + // opts.Log_level = synchronizator.DEBUG opts.DANGEROUSLY_DROP_TABLES = true sync, err := synchronizator.New(connection, opts) diff --git a/pkg/collection.go b/pkg/collection.go index d3942fc..59fc476 100644 --- a/pkg/collection.go +++ b/pkg/collection.go @@ -100,6 +100,26 @@ func (collection *Collection) FetchNodes(fetcher NodeFetcher, start_pagination P } err = BulkCreateNode(collection._conn, collection.childs) + if err != nil { + return err + } + + for _, item := range collection.childs { + err := collection.AddRelationship( + &Relationship{ + _class: "COLLECTION_HAS_NODE", + From: collection.Id, + To: item.Id, + }) + if err != nil { + return err + } + } + + err = BulkCreateRelationships(collection._conn, collection._relationships) + if err != nil { + return err + } return nil }