thinky-export-schema

    2.0.0 • Public • Published

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

    Install

    npm i thinky-export-schema

    DownloadsWeekly Downloads

    9

    Version

    2.0.0

    License

    MIT

    Last publish

    Collaborators

    • fractal
    • yocontra