Refactored repository structure.

This commit is contained in:
Jay
2026-03-03 13:34:10 -05:00
parent 96f1ceb362
commit e9e153c9a1
15 changed files with 159 additions and 144 deletions

39
cypher/cypher.go Normal file
View File

@@ -0,0 +1,39 @@
package cypher
import (
"fmt"
"strings"
)
// ========================================
// Cypher Formatting Functions
// ========================================
// ToCypherLabel converts a node label or relationship type into its Cypher
// format.
func ToCypherLabel(label string) string {
return fmt.Sprintf(":`%s`", label)
}
// ToCypherLabels converts a list of node labels into its Cypher format.
func ToCypherLabels(labels []string) string {
var cypherLabels []string
for _, label := range labels {
cypherLabels = append(cypherLabels, ToCypherLabel(label))
}
return strings.Join(cypherLabels, "")
}
func ToCypherProps(keys []string, prefix string) string {
if prefix == "" {
prefix = "$"
}
cypherPropsParts := []string{}
for _, key := range keys {
cypherPropsParts = append(
cypherPropsParts, fmt.Sprintf("%s: %s%s", key, prefix, key))
}
return strings.Join(cypherPropsParts, ", ")
}

43
cypher/cypher_test.go Normal file
View File

@@ -0,0 +1,43 @@
package cypher
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestToCypherLabel(t *testing.T) {
assert.Equal(t, ":`Event`", ToCypherLabel("Event"))
}
func TestToCypherLabels(t *testing.T) {
assert.Equal(t, ":`Event`:`ReplaceableEvent`",
ToCypherLabels([]string{"Event", "ReplaceableEvent"}))
}
func TestToCypherProps(t *testing.T) {
cases := []struct {
name string
keys []string
prefix string
expected string
}{
{
name: "default prefix",
keys: []string{"id", "name"},
prefix: "",
expected: "id: $id, name: $name",
},
{
name: "set prefix",
keys: []string{"id", "name"},
prefix: "entity.",
expected: "id: entity.id, name: entity.name",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expected, ToCypherProps(tc.keys, tc.prefix))
})
}
}