Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // knexfile.js
- module.exports = {
- development: {
- client: 'mysql',
- connection: {
- host: 'localhost',
- port: 3306,
- user: 'root',
- password: '1234@abcd',
- database: 'boilerplate_api_master',
- }
- },
- production: {}
- };
- ----------------------------------
- //manifest.js
- const KnexFile = require('./knexfile');
- ....
- {
- plugin: {
- register: 'objections',
- options: KnexFile.development
- }
- },
- -----------------------------------
- // Movie model
- var Model = require('objection').Model;
- function Movie() {
- Model.apply(this, arguments);
- }
- Model.extend(Movie);
- module.exports = Movie;
- Movie.tableName = 'Movie';
- Movie.jsonSchema = {
- type: 'object',
- required: ['name'],
- properties: {
- id: {type: 'integer'},
- name: {type: 'string', minLength: 1, maxLength: 255}
- }
- };
- -----------------------------------------
- // Movie route
- 'use strict';
- var Movie = require('./models/Movie');
- module.exports = [
- {
- method: 'post',
- path: '/movies',
- config: {
- tags: ['api'],
- handler: (request, reply) => {
- Movie
- .query()
- .insertAndFetch(request.payload.name)
- .then(function (person) { reply(person); })
- /*.catch(next);*/
- }
- }
- },
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement