Git Product home page Git Product logo

models's Introduction

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.

models's People

Contributors

corosteg avatar dependabot[bot] avatar gmoura avatar lupomontero avatar maiarojas avatar merycardenas27 avatar raulingg avatar xpktro avatar

Watchers

 avatar

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.