Skip to content

CloudNativeGBB/cosmos-odm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
    })
  }
}