Git Product home page Git Product logo

rmlib's Introduction

RM Lib

RMLib - short for relational model library - models relations, attributes, as well as primary and foreign keys.

Currently, it parses relation definitions from strings into Go structs so that they can be evaluated by some other tool.

Syntax

The main syntax for defining relations with attributes is:

RelationName ( Attribute1, Attribute2, Attribute3, ... )

Each attribute can be a primary key, a foreign, none of them, or both.

  • Primary Key: Primary keys are defined by underscores before and after the attribute name: _mypk_ . There might be multiple attributes marked as primary key in a single relation
  • Foreign key: Foreign keys are defined by an arrow -> followed by the relation name and attributed being referenced: myfk -> R(a). myfk is an attribute that referenecs attribute a in relation R.

Dependencies

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

Limitations

  • Currently, a foreign key can only consist of a single attribute and reference one attribute

Example

func main() {

	s := "MyRelation(a -> OtherRelation(b),_b_,c,_d_ -> D(c))" //

	parser, err := CreateParser()

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

	relation, err := parser.Parse(s)

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

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

	for _, attr := range relation.Attributes {

		if !attr.IsPK() && !attr.IsFK() {
			fmt.Printf("%s is a plain attribute\n", *attr.Name())
		} else {
			if attr.IsPK() {
				fmt.Printf("%s is a PK \n", *attr.Name())
			}

			if attr.IsFK() {
				fmt.Printf("%s is a FK to attribute %s in relation %s \n", *attr.Name(), attr.FK.Attribute, attr.FK.RelationName)
			}
		}
	}
}

rmlib'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.