kindagoose

Форк
0

README.md

Kindagoose

Fresh NestJS wrapper for Typegoose that solves the main drawback of nestjs-typegoose

GPLv3 License Link to NPM

Authors

Support

For support, email me grapeoff.official@gmail.com or write an issue straight in kindagoose repository!

Installation

To install kindagoose, you need to execute one of these simple commands:

NPM

$ npm i kindagoose @typegoose/typegoose mongoose

Yarn

$ yarn add kindagoose @typegoose/typegoose mongoose

Documentation

Full documentation is available here!

Usage

Define a schema

@modelOptions({ schemaOptions: { collection: 'Users' } })
export class User extends TimeStamps {
@prop({ unique: true })
login: string;
@prop()
firstName: string;
@prop()
lastName: string;
@prop({ type: () => Date })
age: Date;
@prop()
password: string;
@prop({ type: () => [Task], localField: '_id', foreignField: 'owner_id' })
tasks: Ref<Task>[];
}

Register your schema like this

@Module({
imports: [
KindagooseModule.forFeature([
User,
]),
],
controllers: [],
providers: [UsersService],
})
export class UsersModule {}

Use it wherever within the module

import { InjectModel } from "kindagoose";
import { ReturnModelType } from "@typegoose/typegoose";
@Injectable()
export class UsersService {
constructor(
@InjectModel(User)
private readonly userModel: ReturnModelType<typeof User>,
) {}
async create(createUserDto: CreateUserDto) {
return this.userModel.create(createUserDto);
}
async get({ limit, offset }: PaginationDto) {
return this.userModel.find().skip(offset).limit(limit).exec();
}
async getById(id: string) {
return this.userModel.findById(id).exec();
}
}

License

GPL 3.0

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.