feat: add collection-node relationship in collection.FetchNodes()

This commit is contained in:
Alexander Navarro 2024-11-26 09:29:48 -03:00
parent c1684c8dea
commit d1a0212cb1
2 changed files with 29 additions and 1 deletions

View file

@ -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)

View file

@ -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
}