Giter Club home page Giter Club logo

erdlib's Introduction

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())
		}

	}
}

erdlib's People

Contributors

hag0r avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.