Saturday, July 19, 2025

Cleaning Neptune


While refactoring, I realized that I didn't have any code to clean a Neptune database, or indeed, any idea about how to go about it. Presumably it is possible to MATCH an arbitrary node and then to say "for each such node, delete it". Let's try that.

In the Cypher Cheat Sheet, there is a section on DELETE and the last example is to delete the entire database. So let's try and get that to work.
func (c *Cleaner) Clean() error {
    clean := `    MATCH (n)
                DETACH DELETE n`
    cleanQuery := neptunedata.ExecuteOpenCypherQueryInput{OpenCypherQuery: aws.String(clean)}
    _, err := c.svc.ExecuteOpenCypherQuery(context.TODO(), &cleanQuery)
    return err
}

NEPTUNE_CLEAN:neptune/internal/neptune/clean.go

OK, that was easy. Can I really stop there and call this a whole episode?

Conclusions

Once you've done all the previous steps, finding the right query and just executing it seems to be fairly simple. Always assuming, of course, that we did succeed in deleting everything in the database.

No comments:

Post a Comment