DevrexLabs / OrigoDB

In-memory event-sourced database engine for NET/Mono
http://origodb.com
MIT License
137 stars 34 forks source link

Create a generic relational model #18

Open rofr opened 9 years ago

rofr commented 9 years ago

Users should be able to use the CRUD pattern to store entities objects of any type. Entities that refer to each other should use foreign keys, not references. Something like:

  var db = Db.For<Relational>();
  db.CreateTable<Product>();
  var product = new Product();
  db.Insert(product);
  product.Name = "Coconuts";
  db.Update(product);
  db.Delete(product);

Some things to discuss:

Identity

Each entity needs to have a unique identity. We could allow a [Key] attribute on one or more fields, look for a field named Id or just let the user implement IComparable on each Entity. We could support all of these or a subset.

Generated keys

User assigned numeric keys is a problem, there is a risk for duplicates. We could just recommend guids but that takes away options from the user. Also guids use more memory than integer types. If the server generates during INSERT we might need the generated value to set as FK in related entities. These may also have to be in the same transaction.

Constraints

Constraints should probably be on the entity itself, using plain OO. Except unique constraints, we could use indexes for that.

Indexes

Creating indexes would be useful. Something like: db.Index<Product>("Product.Name", p => p.Name); We would have to serialize the lambda to make this work with a remote server.

How will origodb server know the user defined entity types?

Running embedded the user can put custom entities in a generic model but remote, the server needs to be able to load the types. One way would be to just add assemblies in the server UI but this kind of defeats the purpose of a generic model in the first place.

Here's an old blog article with some ideas http://origodb.com/2011/11/24/relational-modeling-and-crud.html EDIT: Link updated

TheOnlyRealTodd commented 8 years ago

Hello,

I am very interested in working on this... I have some experience using Entity Framework which uses format similar to what you described. Obviously, this will take some time and I am a junior dev so I am going to research it more and as long as it's something I can take on reasonably, I'd love to contribute!

This entire project sounds awesome actually and I have a strong interest in back-end development as well as relational databases.

Also, please note that the link is broken at the bottom of the post.

rofr commented 8 years ago

Awesome!

There is an embryo for relational modeling in the dev branch, you'll find it in the Modeling namespace. There is also a feature branch called f-relational-something-something with an earlier attempted implementation.

Fork the repo, start playing around and let's discuss details here or on gitter.