Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. // knexfile.js
  2. module.exports = {
  3. development: {
  4. client: 'mysql',
  5. connection: {
  6. host: 'localhost',
  7. port: 3306,
  8. user: 'root',
  9. password: '1234@abcd',
  10. database: 'boilerplate_api_master',
  11. }
  12. },
  13. production: {}
  14. };
  15.  
  16. ----------------------------------
  17.  
  18. //manifest.js
  19. const KnexFile = require('./knexfile');
  20. ....
  21. {
  22. plugin: {
  23. register: 'objections',
  24. options: KnexFile.development
  25. }
  26. },
  27.  
  28. -----------------------------------
  29. // Movie model
  30. var Model = require('objection').Model;
  31. function Movie() {
  32. Model.apply(this, arguments);
  33. }
  34. Model.extend(Movie);
  35. module.exports = Movie;
  36.  
  37. Movie.tableName = 'Movie';
  38. Movie.jsonSchema = {
  39. type: 'object',
  40. required: ['name'],
  41.  
  42. properties: {
  43. id: {type: 'integer'},
  44. name: {type: 'string', minLength: 1, maxLength: 255}
  45. }
  46. };
  47. -----------------------------------------
  48. // Movie route
  49. 'use strict';
  50. var Movie = require('./models/Movie');
  51. module.exports = [
  52. {
  53. method: 'post',
  54. path: '/movies',
  55. config: {
  56. tags: ['api'],
  57. handler: (request, reply) => {
  58. Movie
  59. .query()
  60. .insertAndFetch(request.payload.name)
  61. .then(function (person) { reply(person); })
  62. /*.catch(next);*/
  63. }
  64. }
  65. },
  66. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement