Skip to content

Commit

Permalink
Added load strategy validation to config, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitawootten committed Jan 12, 2022
1 parent c80b3ab commit 21b5357
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ go get -u github.com/mindstand/gogm/v2
Primary key strategies allow more customization over primary keys. A strategy is provided to gogm on initialization.
<br/>
Built in primary key strategies are:
- gogm.DefaultPrimaryKeyStrategy -- just use the graph id from neo4j as the primary key
- gogm.UUIDPrimaryKeyStrategy -- uuid's as primary keys
- `gogm.DefaultPrimaryKeyStrategy` -- just use the graph id from neo4j as the primary key
- `gogm.UUIDPrimaryKeyStrategy` -- uuid's as primary keys
```go
// Example of the internal UUID strategy
PrimaryKeyStrategy{
Expand All @@ -52,6 +52,17 @@ PrimaryKeyStrategy{
}
```

### Load Strategy
Load strategies allow control over the queries generated by `Load` operations.
Different strategies change the size of the queries sent to the database as well as the amount of work the database has to do.
A load strategy is provided to gomg on initialization.

The defined load strategies are:
- `gogm.PATH_LOAD_STRATEGY` -- Use cypher path queries to generate simple queries for load operations.
- `gogm.SCHEMA_LOAD_STRATEGY` -- Leverage the GoGM schema to generate more complex queries for load operations which results in less work for the database.

Depending on your use case, `PATH_LOAD_STRATEGY` may result in higher latency.

### Struct Configuration
##### <s>text</s> notates deprecation

Expand Down
17 changes: 17 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ func (c *Config) validate() error {
c.TargetDbs = []string{"neo4j"}
}

if err := c.IndexStrategy.validate(); err != nil {
return err
}

if err := c.LoadStrategy.validate(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -128,3 +136,12 @@ const (
// IGNORE_INDEX skips the index step of setup
IGNORE_INDEX IndexStrategy = 2
)

func (is IndexStrategy) validate() error {
switch is {
case ASSERT_INDEX, VALIDATE_INDEX, IGNORE_INDEX:
return nil
default:
return fmt.Errorf("invalid index strategy %d", is)
}
}
9 changes: 9 additions & 0 deletions load_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ const (
SCHEMA_LOAD_STRATEGY
)

func (ls LoadStrategy) validate() error {
switch ls {
case PATH_LOAD_STRATEGY, SCHEMA_LOAD_STRATEGY:
return nil
default:
return fmt.Errorf("invalid load strategy %d", ls)
}
}

// PathLoadStrategyMany loads many using path strategy
func PathLoadStrategyMany(variable, label string, depth int, additionalConstraints dsl.ConditionOperator) (dsl.Cypher, error) {
if variable == "" {
Expand Down

0 comments on commit 21b5357

Please sign in to comment.