2.0.0 • Published 8 years ago

thinky-export-schema v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

thinky-export-schema NPM version Downloads Build Status

Exports a thinky model's schema as a plain object.

Install

npm install thinky-export-schema --save

API

exportSchema(model)

  • model argument is a thinky model object
  • Returns the model's schema as a plain object.

Example

var exportSchema = require('thinky-export-schema')

var User = thinky.createModel('User', {
  id: Number,
  name: String,
  times: {
    created: Date,
    updated: Date
  },
  friended: [String]
})
User.hasAndBelongsToMany(User, 'friends', 'friended', 'id')
console.log(exportSchema(User))
/*
{
  fields: {
    id: 'Number',
    name: 'String',
    times: {
      created: 'Date',
      updated: 'Date'
    },
    friended: ['String']
  },
  relationships: {
    friends: {
      type: 'hasAndBelongsToMany',
      rightKey: 'id',
      leftKey: 'friended'
    }
  },
  validation: {}
}
*/

###ES6

import exportSchema from 'thinky-export-schema'

const User = thinky.createModel('User', {
  id: type.number(),
  title: type.string(),
  times: {
    created: Date,
    updated: Date
  }
  friended: [String]
})
User.hasAndBelongsToMany(User, 'friends', 'friended', 'id')

console.log(exportSchema(User))
/*
{
  fields: {
    id: 'Number',
    name: 'String',
    times: {
      created: 'Date',
      updated: 'Date'
    },
    friended: ['String']
  },
  relationships: {
    friends: {
      type: 'hasAndBelongsToMany',
      rightKey: 'id',
      leftKey: 'friended'
    }
  },
  validation: {}
}
*/