Socket
Socket
Sign inDemoInstall

@raulingg/models

Package Overview
Dependencies
336
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @raulingg/models

[![Build Status](https://travis-ci.com/Laboratoria/models.svg?branch=master)](https://travis-ci.com/Laboratoria/models)


Version published
Maintainers
1
Created

Readme

Source

Laboratoria/models

Build Status

This module is meant to be used with Node.js and expects the Node.js version of the mongoose module as an argument. If you are looking for schemas to be used in the front-end please check Laboratoria/schemas.

Installation

npm install --save Laboratoria/models

Or add it in your package.json and then npm install:

{
  "dependencies": {
    "models": "Laboratoria/models#v1.0.0-alpha.1"
  }
}

Usage

For more detailed information, please check the official mongoose docs

Creating and saving a model:

const mongoose = require('mongoose');
const { Project } = require('models')(mongoose);

const project = new Project({
  slug: 'cipher',
  repo: 'Laboratoria/curricula-js',
  path: 'projects/01-cipher',
  // ...
});

project.save()
  .then(console.log)
  .catch(console.error);

Finding models:

// Querying for all documents in collection
Project.find({}, (err, docs) => {
  if (err) {
    console.error(err);
  }
  // doc something with `docs`...
});

// Alternatively using a promise
Project.find({})
  .then(console.log)
  .catch(console.error);

Using Model.validate as a Promise:

const mongoose = require('mongoose');
const { Project } = require('models')(mongoose);

const project = new Project({
  slug: 'cipher',
  repo: 'Laboratoria/curricula-js',
  path: 'projects/01-cipher',
  // ...
});

project.validate()
  .then(() => {
    // Validation succeeded ;-)
  })
  .catch((err) => {
    // Validation failed :-(
  });

Using Model.validate with a callback:

const mongoose = require('mongoose');
const { Project } = require('models')(mongoose);

// Creating a new instance of a Model
const project = new Project({
  slug: 'cipher',
  repo: 'Laboratoria/curricula-js',
  path: 'projects/01-cipher',
  // ...
});

// Validating model instance
project.validate((err) => {
  // ...
});

Testing

Unit tests (and linter):

yarn test

End-to-end tests:

yarn e2e

Models

Application

Campuses

Cohorts

Endorsement

Graduates

Organizations

Placement

Projects

Tags

Topics

Users

Schemas

See Laboratoria/schemas.

FAQs

Last updated on 28 Mar 2020

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc