Advertisement
Guest User

Untitled

a guest
May 16th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #### KNEXFILE:
  2.  
  3. module.exports = {
  4. development: {
  5. client: process.env.DB_CLIENT,
  6. connection: process.env.DB_CONNECTION,
  7. migrations: {
  8. directory: process.env.DB_MIGRATION_DIR,
  9. },
  10. seeds: {
  11. directory: process.env.DB_SEEDS_DIR
  12. },
  13. useNullAsDefault: true
  14. },
  15.  
  16. production: {
  17. client: process.env.DB_CLIENT,
  18. connection: process.env.DB_CONNECTION,
  19. migrations: {
  20. directory: process.env.DB_MIGRATION_DIR,
  21. },
  22. seeds: {
  23. directory: process.env.DB_SEEDS_DIR
  24. },
  25. useNullAsDefault: true
  26. }
  27.  
  28. };
  29.  
  30.  
  31.  
  32. ######### demonstrating environment properties are setup--
  33. #checking .env file for properties:
  34.  
  35. $ node
  36. > process.env.DB_CLIENT
  37. 'postgresql'
  38.  
  39. > const dotenv = require('dotenv').config();
  40. undefined
  41. > dotenv
  42. { parsed:
  43. { NODE_ENV: 'production',
  44. DB_CLIENT: 'postgresql',
  45. DB_CONNECTION: 'postgres://pat:secret@localhost:5432/timetracker',
  46. DB_MIGRATION_DIR: './db/migrations',
  47. DB_SEEDS_DIR: './db/seeds' } }
  48.  
  49. #### problem code:
  50. const dotenv = require('dotenv').config();
  51. const knex = require('knex');
  52. const environment = process.env.NODE_ENV;
  53. const knex_config = require('./knexfile')[environment];
  54. const database = require('knex')(knex_config);
  55.  
  56. # CAUSES ERROR:
  57. TypeError: Cannot read property 'client' of undefined
  58. at Knex (/home/pat/apps/timetracker/node_modules/knex/lib/index.js:49:41)
  59.  
  60.  
  61. FROM KNEX SOURCE FILE FILE -- ASTERISKS == LINE 49
  62. // The client names we'll allow in the `{name: lib}` pairing.
  63. var aliases = {
  64. 'mariadb': 'maria',
  65. 'mariasql': 'maria',
  66. 'pg': 'postgres',
  67. 'postgresql': 'postgres',
  68. 'sqlite': 'sqlite3'
  69. };
  70.  
  71. function Knex(config) {
  72. if (typeof config === 'string') {
  73. return new Knex((0, _assign3.default)((0, _parseConnection2.default)(config), arguments[2]));
  74. }
  75. var Dialect = void 0;
  76. if (arguments.length === 0 || !config.client && !config.dialect) { // ************* LINE 49 *************
  77. Dialect = _client2.default;
  78. } else if (typeof config.client === 'function' && config.client.prototype instanceof _client2.default) {
  79. Dialect = config.client;
  80. } else {
  81. var clientName = config.client || config.dialect;
  82. Dialect = require('./dialects/' + (aliases[clientName] || clientName) + '/index.js');
  83. }
  84. if (typeof config.connection === 'string') {
  85. config = (0, _assign3.default)({}, config, { connection: (0, _parseConnection2.default)(config.connection).connection });
  86. }
  87. return (0, _makeKnex2.default)(new Dialect(config));
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement