New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

krc-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

krc-mongodb

krc - mongo database

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

krc-mongodb

Features

- Define interface wrap for entity
- Define common dbcontext
- Define db connect hub
- Define base repository with repository pattern

Install

  • Before install require packages:
npm install mongoose@^5.9.3
  • Install krc-mongodb
npm install krc-mongodb

How it work

MongoDB context

  • using:
import { connectMongoDb } from "krc-mongodb";

await connectMongoDb();
  • output: MongoDB connected...

Repository pattern

  • Define model schema:
import { Schema } from "mongoose";

const CategorySchema: Schema = new Schema({
  categoryId: {
    type: String,
    required: true,
  },
  parentId: {
    type: String,
  },
  name: {
    type: String,
    required: true,
  },
  context: {
    type: String,
    required: true,
  },
  active: {
    type: Boolean,
  },
  createdBy: {
    type: String,
  },
  updatedBy: {
    type: String,
  },
  createdTime: {
    type: Date,
  },
  updatedTime: {
    type: Date,
  },
});
  • Define model instance:
const Category = model("categories", CategorySchema);
  • Define entity interface:
import { IDocument } from "krc-mongodb";

interface ICategory extends IDocument<string> {
  categoryId: string;
  parentId: string;
  name: string;
  context: string;
  active: boolean;
  createdBy: string;
  updatedBy: string;
  createdTime: Date;
  updatedTime: Date;
}
  • Declare repository into service to query:
import { Repository } from "krc-mongodb";

_categoryRepository = Repository<string, ICategory>(Category);

const allCategories = _categoryRepository.find({});

Keywords

@krc

FAQs

Package last updated on 23 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts