This module allows you to create CRUD services over GRPC in less than 5 minutes.
- Just define your protos, and your mongoose models.
- Setup your service using condor-framework and extending the
CrudBaseServiceclass. - Voilá, you have a working CRUD service over gRPC, connected to mongo (using mongoose).
- Automatic CRUD generation (list, insert, update, get, delete)
- Supports subdocuments and related models
- Allows queries (where, fields, limit, skip, sort)
- Allows automatic population of related models (populate)
npm i --save condor-framework mongoose condor-mongoose- Define the proto file.
syntax="proto3";
packagebussiness;
messageWhere {
stringfield=1;
stringvalue=2;
Matchermatcher=3;
}
messageSort {
stringfield=1;
int32value=2;
}
enumMatcher {
STRING=0;
REGEX=1;
OBJECT=2;
}
messageQueryRequest {
repeatedWherewhere=1; // empty => allrepeatedstringfields=2; // empty => allint32limit=3; // 0 => unlimitedint32skip=4; // 0 => nonerepeatedSortsort=5;
}
messagePersonUpdate {
stringid=1;
repeatedstringfields=2;
Persondata=3;
}
messageEmpty {}
messageIdRequest {
stringid=1;
}
messagePerson {
stringid=1;
stringname=2;
int32age=3;
}
servicePersonsService {
rpcList (QueryRequest) returns (Person) {}
rpcInsert (Person) returns (Person) {}
rpcUpdate (PersonUpdate) returns (Person) {}
rpcGet (IdRequest) returns (Person) {}
rpcDelete (IdRequest) returns (Empty) {}
}- Create a service that extends from CrudBaseService.
constCrudBaseService=require('condor-mongoose');constmongoose=require('mongoose');constpersonSchema={'name': String,'age': Number,};constPerson=mongoose.model('Person',newmongoose.Schema(personSchema));module.exports=classextendsCrudBaseService{constructor(){super(Person);}};Note:CrudBaseService contains base methods (insert, update, delete, get, list), sub documents methods (push, addToSet, remove, update and replace) and related models methods (push, addToSet, remove and replace).
- Initialize the service.
constmongoose=require('mongoose');constCondor=require('condor-framework');constPromise=require('bluebird');constPersonService=require('./models/personService');mongoose.Promise=Promise;mongoose.connect('mongodb://localhost/business');constprotoPath='./bussiness.proto';condor=newCondor().addService(protoPath,'business.PersonService',newPersonService()).start();MIT License. Copyright 2017 Devsu LLC, a great node development team