Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 1.01 KB

README.md

File metadata and controls

63 lines (48 loc) · 1.01 KB

Cosmos DB SQL/Core API ODM

This project is meant to be a simple ODM library for Cosmos DB via the SQL/"Core" API.

Dependencies

How to use:

npm install --save @cloudnativegbb/cosmos-odm
// models/user-model.js

const CosmosODM = require('cosmos-odm');
const User = CosmosODM.model("collectionName");

module.exports = User;
// controllers/users-controller.js
const User = require('../models/user-model');

const index = async function(req, res, next) {
  try {
    const users = await User.findAll();

    res.send({
      users: users
    })
  }
  catch(e){
    next(e);
  }
}

const show = async function(req, res, next) {
  try {
    const user = await User.findById(req.params.user)

    res.send({
      user: user
    });
  }
  catch(e) {
    next(e)
  }
}

const create = async function(req, res, next) {
  try {
    const newUser = await User.save(req.body)

    res.send({
      user: newUser
    })
  }
}