Skip to content

Losant/cosa

This branch is 2 commits behind master.

Folders and files

NameName
Last commit message
Last commit date
Aug 30, 2024
Aug 29, 2024
Feb 7, 2024
Feb 6, 2024
Oct 12, 2018
Aug 29, 2024
Feb 7, 2024
Feb 7, 2024
Aug 29, 2024
Aug 30, 2024
Aug 30, 2024

Repository files navigation

Cosa

Build Status npm version

Simplified object modeling for MongoDB

Installation

Use your favorite package manager to add cosa to your project.

yarn add cosa

Usage

First define a model:

import { Model } from 'cosa';

const UserModel = Model.define({
  name: 'UserModel',
  collection: 'users',
  properties: {
    name: { type: 'string', required: true },
    email: { type: 'string', required: true, email: true }
  }
})

Use the model to add users to the database:

const newUser = UserModel.create({
  name: 'John Smith',
  email: '[email protected]'
})
newUser.save()

Fetch all the users in the database:

UserModel
  .find({}, { array: true })
  .then((users) => {
    // loop over the array of users and do something
  })

Reference

License

The module is available as open source under the terms of the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published