10000 GitHub - canccevik/mondec: 🗄️Create simple and clean class-based Mongoose schemas with TypeScript decorators.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🗄️Create simple and clean class-based Mongoose schemas with TypeScript decorators.

License

Notifications You must be signed in to change notification settings

canccevik/mondec

Repository files navigation

Mondec Logo

🗄️Create simple and clean class-based Mongoose schemas with TypeScript decorators.

Features

  • Lightweight
  • Class based schemas
  • Easy usage with TS decorators

Installation

Using npm:

npm install mondec

Using yarn:

yarn add mondec

Using pnpm:

pnpm add mondec

You need to enable emitting decorator metadata in your Typescript config. Add these two lines to your tsconfig.json file under the compilerOptions key:

"emitDecoratorMetadata": true,
"experimentalDecorators": true

Usage

import mongoose from 'mongoose'
import { Prop, Schema, SchemaFactory } from 'mondec'

@Schema({
  versionKey: false
})
class User {
  @Prop({
    type: String,
    unique: true,
    required: true
  })
  public username!: string

  @Prop({
    type: Number
  })
  public age!: number
}

const UserSchema = SchemaFactory.createForClass(User)
const UserModel = mongoose.model('users', UserSchema)
type UserDocument = ReturnType<(typeof UserModel)['hydrate']>

Contributing

  1. Fork this repository.
  2. Create a new branch with feature name.
  3. Create your feature.
  4. Commit and set commit message with feature name.
  5. Push your code to your fork repository.
  6. Create pull request.

License

MIT

About

🗄️Create simple and clean class-based Mongoose schemas with TypeScript decorators.

Topics

Resources

License

Stars

Watchers

Forks

0