generated from alecodes/base-template
feat: add collection-node relationship in collection.FetchNodes()
This commit is contained in:
parent
c1684c8dea
commit
d1a0212cb1
2 changed files with 29 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
|
|
||||||
|
|
@ -124,6 +125,13 @@ func getPokemons(
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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")
|
connection, err := sql.Open("sqlite", "db.sql")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
@ -134,7 +142,7 @@ func main() {
|
||||||
defer connection.Close()
|
defer connection.Close()
|
||||||
|
|
||||||
opts := synchronizator.DefaultOptions
|
opts := synchronizator.DefaultOptions
|
||||||
opts.Log_level = synchronizator.DEBUG
|
// opts.Log_level = synchronizator.DEBUG
|
||||||
opts.DANGEROUSLY_DROP_TABLES = true
|
opts.DANGEROUSLY_DROP_TABLES = true
|
||||||
|
|
||||||
sync, err := synchronizator.New(connection, opts)
|
sync, err := synchronizator.New(connection, opts)
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,26 @@ func (collection *Collection) FetchNodes(fetcher NodeFetcher, start_pagination P
|
||||||
}
|
}
|
||||||
|
|
||||||
err = BulkCreateNode(collection._conn, collection.childs)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue