0.0.0 • Published 8 years ago
collectink v0.0.0
Collectink
An ES6 Javascript library that helps you writing relations between objects without any database. If you have ever used an ORM, you will feel at home.
// A simple example using a one-to-one relationship
import Model from "collectink";
class User extends Model {
initialize(fullname) {
this.fullname = fullname;
this.hasOne('phone', Phone)
}
}
class Phone extends Model {
initialize(brand) {
this.brand = brand;
this.belongsTo('owner', User)
}
}
let john = new User ("John Doe");
let phone = new Phone("SomeBrandName");
john.phone = phone;
// Relation has been updated
phone.owner.fullname; // => "John Doe"
// A developped example with multiples one-to-many relationship
import Model from "collectink";
class Post extends Model {
initialize() {
this.hasMany('comments', Comment);
this.belongsTo('author', User);
}
}
class User extends Model {
initialize(fullname) {
this.fullname = fullname;
this.hasMany('posts', Post);
this.hasMany('comments', Comment);
}
}
class Comment extends Model {
initialize() {
this.belongsTo('post', Post);
this.belongsTo('author', User);
}
}
let john = new User("John Doe");
let post = new Post;
post.title = "Lorem Ipum"
post.content = "Some dummy post content";
john.posts = [post];
post.author; // User:john
let comment = new Comment;
comment.content = "Hello World!";
comment.author = john;
john.comments; // => [comment]
post.comments = [comment];
comment.post; // => post
// Collections
Post.$where({author: john}); // => Collection<Post>
Installation
The easiest and fastest way to install Collectink is through the node package manager:
$ npm install collectink --save
Contributions
If you find a bug or have a feature suggestion, please feel free to submit an issue here or even to make a pull request !
For more information on how to submit a pull request, please read this guide on contributing to open-source projects.
0.0.0
8 years ago