thinky-export-schema

Export a thinky model to a serializable object

Usage no npm install needed!

<script type="module">
  import thinkyExportSchema from 'https://cdn.skypack.dev/thinky-export-schema';
</script>

README

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: {}
}
*/