Potential Improvements (Relationships & Finders)
jpotts18 opened this issue · 2 comments
Hey @emilsjolander I love this library! I want to see if there is something I can do to help it progress. I am thinking of 2 main things.
- Adding relationship to models.
@Table("Notes")
public class Note extends Model {
@AutoIncrementPrimaryKey
@Column("id")
private long id;
@Column("title")
public String title;
@Column("body")
public String body;
// suggested model relationships automatically generates UserId into this table for future lookup
@BelongsTo("User")
public User user;
// suggested model relationship
@HasMany("Tags")
public List<Tag> tags;
public long getId() {
return id;
}
}
- Adding Finders. This is pretty familiar pattern that I have seen in web development. Instead of writing any SQL queries, you could just add default finders. I don't know exactly how to implement this, but I think it would be a great addition.
// this would execute "SELECT * FROM Notes";
List<Note> notes = Notes.findAll();
// this would execute "SELECT * FROM Notes WHERE id = 1"
Note notes = Notes.find(1);
This is a pattern i explicitly did not want in sprinkles. If you read the README i clearly state that i am against these kinds of abstractions as i don't feel they provide much help, rather i think they often cause weird bugs because things don't map exactly as you thought to sql. However! i suggest people adopt this pattern in their model subclasses as an abstraction layer on top of sprinkles.
That said i could look into making sprinkles more extendable for custom annotations. This would open up for third party plugins which could implement the patterns you are looking for. That however is a totally other story ;)