Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const _ = require('lodash');
- const Util = require('util');
- const Knex = require( 'knex' )( require('./config').database );
- const Bookshelf = require('bookshelf')( Knex );
- Bookshelf.plugin( require( 'bookshelf-soft-delete' ) );
- Bookshelf.plugin( 'visibility' );
- Bookshelf.plugin('virtuals')
- var Server = Bookshelf.Model.extend({
- tableName: 'servers',
- soft: true,
- hidden: ['root_password'],
- hasTimestamps: true,
- virtuals: {
- environment: function() {
- let env = this.get('server_hostname').match(/^[a-z]{1}([a-z]{1})/im);
- switch( env[1] ){
- case 'p': return 'prod' break;
- case 'd': return 'dev'; break;
- case 's': return 'stage'; break;
- case 'q': return 'qa'; break;
- default: return 'N/A'; break;
- }
- }
- },
- operating_system: function() {
- return this.belongsTo( OS );
- },
- application: function(){
- return this.belongsToMany( Application );
- }
- });
- var OS = Bookshelf.Model.extend({
- tableName: 'operating_systems',
- hasTimestamps: true,
- server: function() {
- return this.hasMany( Server );
- }
- });
- var Application = Bookshelf.Model.extend({
- tableName: 'applications',
- hasTimestamps: true,
- appServer: function() {
- return this.belongsToMany( Server );
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment