mongoose-model
TypeScript icon, indicating that this package has built-in type declarations

0.7.2 • Public • Published

mongoose-model

Build Status NPM version Dependencies status

Installation

Install with npm:

npm install mongoose-model

Usage

import { def, Model, model, prop, Query, ref } from 'mongoose-model';
 
export interface IContact {
  kind: string;
  value: string;
}
 
@model
export class User extends Model {
  @prop age: number;
  @prop({
    kind: String,
    value: String,
  })
  contacts: IContact[];
  @prop createdAt: Date;
  @prop email: string;
  @def(false) isActive: boolean;
  @prop name: string;
 
  get displayName() {
    return `${this.name} <${this.email}>`;
  }
 
  static findByEmail(email: string): Query<User> {
    return this.findOne({ email });
  }
}
 
@model
export class Post extends Model {
  @prop body: string;
  @ref  creator: User;
  @prop title: string;
 
  static findByTitle(title: string): Query<Post> {
    return this.findOne({ title });
  }
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.7.22latest

Version History

VersionDownloads (Last 7 Days)Published
0.7.22
0.7.10
0.7.01
0.6.00
0.5.50
0.5.40
0.5.30
0.5.20
0.5.00
0.4.00
0.3.90
0.3.80
0.3.70
0.3.60
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10
0.3.00
0.2.00
0.1.10
0.1.00
0.0.150
0.0.140
0.0.131
0.0.120
0.0.110
0.0.101
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10
0.0.00

Package Sidebar

Install

npm i mongoose-model

Weekly Downloads

5

Version

0.7.2

License

MIT

Unpacked Size

84.7 kB

Total Files

45

Last publish

Collaborators

  • megahertz