Giter Site home page Giter Site logo

base-repository's Introduction

Build Status

Coverage Status

  • The purpose of this project is to support define REST Api Query quickly by mapping url params with mongodb query
  • Compatible with koa (generator)

Examples:

  • Querying article with commentsCount between 5 and 10
  • Given: minCommentsCount=5&maxCommentsCount=10
  • And you have the config file like file: tests/process-filter.test.js & tests/article.model.js
  • It will parse the filter into {commentsCount: {$gte: 5,$lte: 10}

Usage:

BaseRepository

import * as ArticleSchema from './article.model';
const repository = new BaseRepository(Article, ArticleSchema.config);
const Article = mongoose.model(ArticleSchema.schemaName, ArticleSchema.schema);

View more at '/tests/base-repository.tests.js'

createController

import { createController } from 'base-repository';
const controller = createController(repository);

Controller Function:

  • query
  • insert
  • update
  • getByKey
  • getById
  • getByFilter
  • deleteById
  • addChild
  • removeChild

TODO

  • Add Code Coverage

Run Test

  • npm install
  • npm test

Run Examples

npm install

Generate Data

node examples/generate-data

Run Example

node examples

Steps for generate Test Data

  • Need a list of entities (real data).
  • Transfer a list of entities into mongodb data & use as initial testing data

base-repository's People

Contributors

0512107 avatar joehua87 avatar

Watchers

 avatar  avatar  avatar

base-repository's Issues

Features

  • Population
  • Query by population. E.g: Post content category (_id: Schema.ObjectId) - How to query post by category.slug?
  • Real Time: Notify when create, updated, delete (use socket.io)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.