gahabeen / biota

A simple database framework for Fauna
https://gahabeen.github.io/biota
MIT License
54 stars 2 forks source link

Add relations to collections #10

Open gahabeen opened 4 years ago

gahabeen commented 4 years ago

Summary

Goal is to be able to insure relations between documents in collections.

  1. one to one

    • adds a unique constraint
    • a field on one of the two collection refers to the other one
    • scaffolding of indexes to query against it
  2. one to many (also many to one)

    • a field on one of the two collection refers to the other one
    • scaffolding of indexes to query against it
  3. many to many

    • creation of a new collection name biota.relation.<relation-name>
    • scaffolding of indexes to query against it

Basic example

How the api would look like:

// one to one
db.relation('user_address').one("address").connects.one("user", "contact.address")
// where 'address' refers to the Collection("addresses")
// where 'user' refers to the Collection("users") and "contact.address" is the field to be looked up

// many to one
db.relation('question_answers').many("answers", "question").connects.one("question")
// where 'answers' refers to the Collection("answers") and "question" is the field to be looked up
// where 'question' refers to the Collection("questions")

// many to many
db.relation('participations').many("polls", "users").connects.many("users", "polls")
// where 'polls' refers to the Collection("polls") and "users" the users ref list (added in the relations obj)
// where 'users' refers to the Collection("users") and "polls" the polls ref list (added in the relations obj)

Motivation

Simplify the relations management between collections.