norm is a lightweight, developer-friendly ORM framework designed specifically
for nebula graph.
It aims to simplify the Go development experience by enabling elegant, chainable nGQL
query construction and seamless
result mapping.
Whether you're building a graph-based social network or a knowledge graph platform, norm
helps you move fast without
sacrificing readability or maintainability.
go get github.com/haysons/norm
- 🔗 Chainable nGQL builder: Write readable, elegant queries with fluent chaining.
- 📦 Struct-based mapping: Map query results directly into Go structs.
- 🧠 Smart parsing: Supports nested types — vertex, edge, list, map, set — with ease.
- 📚 Struct embedding support: Maximize code reuse and maintain clarity.
- 🔄 Auto schema migration: Automatically create or update vertex and edge schemas from structs.
- 🧪 Fully unit tested: Confidently build production-grade apps.
- 💡 Developer-first design: Less boilerplate, more productivity.
package main
import (
"github.com/haysons/norm"
"log"
)
type Player struct {
VID string `norm:"vertex_id"`
Name string `norm:"prop:name"`
Age int `norm:"prop:age"`
}
func (p Player) VertexID() string {
return p.VID
}
func (p Player) VertexTagName() string {
return "player"
}
func main() {
// init norm.DB
conf := &norm.Config{
Username: "root",
Password: "nebula",
SpaceName: "test",
Addresses: []string{"127.0.0.1:9669"},
}
db, err := norm.Open(conf)
if err != nil {
log.Fatal(err)
}
defer db.Close()
// migrate vertex player tags
if err = db.Migrator().AutoMigrateVertexes(Player{}); err != nil {
log.Fatalf("auto migrate vertex palyer failed: %v", err)
}
// insert the player vertex
player := &Player{
VID: "player1001",
Name: "Kobe Bryant",
Age: 33,
}
if err := db.InsertVertex(player).Exec(); err != nil {
log.Fatalf("insert vertex player failed: %v", err)
}
// find the player vertex
player = new(Player)
err = db.
Fetch("player", "player1001").
Yield("vertex as v").
FindCol("v", player)
if err != nil {
log.Fatalf("fetch vertex player failed: %v", err)
}
log.Printf("player: %+v", player)
}
📚 See more usage patterns in the example directory.
We welcome contributions from the community!
- 🍴 Fork the repo
- 🔧 Create a feature branch
- ✅ Submit a pull request
Special thanks to the following projects that inspired and supported norm
:
- gorm: The beloved ORM for Golang — simple, powerful, elegant.
© 2024–NOW @hayson
Released under the MIT License