Skip to content

gmoben/phrame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phrame

branch status
master Build Status Coverage Status
dev Build Status Coverage Status

Models

Write ES6 classes instead of redundant mongoose configurations.

import {Model} from 'frame/server/core';

class User extends Model {
  constructor() {
    // Pass your schema and options directly to super.
    let schema = {...};
    super(schema, {virtuals: ['password']})
  }
  get password() { return this._password; }
  set password(password) {
    this._password = password;
    this.salt = crypto.randomBytes(16).toString('base64');
    this.hashedPassword = this.encryptPassword(password);
  }
}

export default new User();

Or instantiate a Model directly.

import {ref} from 'frame/server/utils'

var Album = new Model({
  name: 'Album',
  schema: {title: String, photos: [ref('Photo')]}
});

var Photo = new Model({
  name: 'Photo',
  schema: {url: String, album: ref('Album', 'photos')}
});

let album = Album.create({title: 'Kittens'});
['gizmo.jpg', 'luna.png'].forEach(url => Photo.create({url, album}));

Important: Aside from the base configuration you provide, Frame handles all mongoose related details for you. If your application requires a mongoose reference, DO NOT install it as a dependency for your project as node will instantiate them separately. Instead, import it from frame directly.

import mongoose from 'frame';

About

Web application framework

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors