Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongorito-tcomb

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongorito-tcomb

Bring schema validation to Mongorito thanks to tcomb

  • 2.0.0-alpha.2
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by1000%
Maintainers
1
Weekly downloads
 
Created
Source

Mongorito Tcomb

Bring schema validation to Mongorito thanks to tcomb

Install

npm i -S mongorito-tcomb

Usage (ES6)

import Mongorito, {t, Model} from '../lib'

class Person extends Model {
  get Schema() {
    return t.struct({ // return a tcomb struct
      name: t.String,
      surname: t.maybe(t.String),
      age: t.Number
    })
  }
}

(async () => {
  try {
    await Mongorito.connect('localhost/mongorito-tcomb') // Connect like with Mongorito
    await Person.index('name', {unique: true}) // Ensure name is unique
    var paul = new Person({name: 'paul', age: 42})
    await paul.save()
    await paul.remove()
    await Mongorito.disconnect()
  } catch (e) {
    console.log(e.stack)
  }
})()

API

Mixins

patch: (Model) -> PatchedModel

The patch function can be useful to combine different Mongorito plugins. It take a class, extend it then return the extended class.

Customs tcomb types

t.ID

It represent the ID of an element in the database.
Usage: t.ID(ctx, M) where M is a Mongorito model and ctx the instance of the model
It ensure that ID is valid and exist in the database

Keywords

FAQs

Package last updated on 27 Mar 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc