Skip to content

Commit

Permalink
Merge pull request #103 from mindstand/nikitawootten/issue99
Browse files Browse the repository at this point in the history
Nikitawootten/issue99
  • Loading branch information
Eric Solender authored May 13, 2022
2 parents 9f5f9bb + c0c6876 commit 85610d0
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 8 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '16 4 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
28 changes: 20 additions & 8 deletions save.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ func generateCurRels(gogm *Gogm, parentPtr uintptr, current *reflect.Value, curr
// createNodes updates existing nodes and creates new nodes while also making a lookup table for ptr -> neoid
func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]*nodeCreate, nodeRef map[uintptr]*reflect.Value, nodeIdRef map[uintptr]int64) error {
for label, nodes := range crNodes {
// used when the id of the node hasn't been set yet
var i uint64 = 0
var nodesArr []*nodeCreate

var updateRows, newRows []interface{}
for ptr, config := range nodes {
row := map[string]interface{}{
Expand All @@ -509,9 +513,12 @@ func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]*
row["id"] = id
updateRows = append(updateRows, row)
} else {
row["ptr"] = fmt.Sprintf("%v", ptr)
row["i"] = fmt.Sprintf("%d", i)
newRows = append(newRows, row)
}

nodesArr = append(nodesArr, config)
i++
}

// create new stuff
Expand All @@ -521,8 +528,8 @@ func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]*
Cypher(fmt.Sprintf("CREATE(n:`%s`)", label)).
Cypher("SET n += row.obj").
Return(false, dsl.ReturnPart{
Name: "row.ptr",
Alias: "ptr",
Name: "row.i",
Alias: "i",
}, dsl.ReturnPart{
Function: &dsl.FunctionConfig{
Name: "ID",
Expand Down Expand Up @@ -555,25 +562,30 @@ func createNodes(transaction neo4j.Transaction, crNodes map[string]map[uintptr]*
return fmt.Errorf("cannot cast row[0] to string, %w", ErrInternal)
}

ptrInt, err := strconv.ParseUint(strPtr, 10, 64)
i, err = strconv.ParseUint(strPtr, 10, 64)
if err != nil {
return fmt.Errorf("failed to parse ptr string to int64, %w", err)
return fmt.Errorf("failed to parse i string to uint64, %w", err)
}

ptr := uintptr(ptrInt)
if i > uint64(len(nodesArr)) {
return fmt.Errorf("returned node index %d is outside of node array bounds", i)
}

graphId, ok := row[1].(int64)
if !ok {
return fmt.Errorf("cannot cast row[1] to int64, %w", ErrInternal)
}

// get node reference from index
ptr := nodesArr[i].Pointer

// update the lookup
nodeIdRef[ptr] = graphId

//set the new id
// set the new id
val, ok := nodeRef[ptr]
if !ok {
return fmt.Errorf("cannot find val for ptr [%v]", ptr)
return fmt.Errorf("cannot find val for ptr [%d]", ptr)
}

reflect.Indirect(*val).FieldByName(DefaultPrimaryKeyStrategy.FieldName).Set(reflect.ValueOf(&graphId))
Expand Down

0 comments on commit 85610d0

Please sign in to comment.