https://github.com/megahertz/mongoose-model
Define your mongoose models easily with Typescript
https://github.com/megahertz/mongoose-model
Last synced: 4 months ago
JSON representation
Define your mongoose models easily with Typescript
- Host: GitHub
- URL: https://github.com/megahertz/mongoose-model
- Owner: megahertz
- License: mit
- Created: 2017-05-05T19:06:15.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-27T17:28:40.000Z (about 7 years ago)
- Last Synced: 2025-12-22T13:37:25.924Z (5 months ago)
- Language: TypeScript
- Size: 67.4 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongoose-model
[](https://travis-ci.org/megahertz/mongoose-model)
[](https://badge.fury.io/js/mongoose-model)
[](https://david-dm.org/megahertz/mongoose-model)
## Installation
Install with [npm](https://npmjs.org/package/mongoose-model):
npm install mongoose-model
## Usage
```typescript
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 {
return this.findOne({ email });
}
}
@model
export class Post extends Model {
@prop body: string;
@ref creator: User;
@prop title: string;
static findByTitle(title: string): Query {
return this.findOne({ title });
}
}
```