erdlib

command module
v0.0.0-...-8b6e9fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2020 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ERD Lib

ERDlib - short for Entity-Relationship-Diagram library - allows to parse textual representations of database ERDs.

The library does not make any sanity checks of the parsed ERD text (PKs on relationships, only one entity type reference in a relationship, etc.).

Syntax

The supported syntax is something like

Entity1 ( Attribute1, Attribute2, _PrimaryKey_ )
Entity2 ( _PrimaryKey_, Attribute1, Attribute2)

relationship(Entity1[0,*], Entity2 [1,4], anotherattribute)

Dependencies

We use the great https://github.com/alecthomas/participle parser library

Limitations

  • Attribute names must contain only characters (in upper or lower case) and numbers, but no "special" characters (_,-, etc).

Example

func main() {

	s := "relationShip1(Entity1 [0,*], Entity2[1,3], attribute1, _pkattr_)"

	parser, err := CreateParser()

	if err != nil {
		fmt.Println("Failed to create parser", err)
		return
	}

	erdObject, err := parser.Parse(s)

	if err != nil {
		fmt.Println("got an error during parse", err)
		return
	}

	fmt.Printf("Successfully parsed relation: %v\n", erdObject)

	fmt.Println("Found elem: " + erdObject.Name)
	for _, attr := range erdObject.EntitiesAndAttributes {
		if attr.IsEntityRef() {
			fmt.Printf("--> %v is entity -> min: %v, max: %v\n", attr.Name(), attr.Cardinality.Min, attr.Cardinality.Max)
		} else {
			fmt.Printf("--> %v is attr. PK: %v \n", attr.Name(), attr.RefName.IsPK())
		}

	}
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址