README
thinky-export-schema
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: {}
}
*/