defaults.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict'
  2. let user
  3. try {
  4. user = process.platform === 'win32' ? process.env.USERNAME : process.env.USER
  5. } catch {
  6. // ignore, e.g., Deno without --allow-env
  7. }
  8. module.exports = {
  9. // database host. defaults to localhost
  10. host: 'localhost',
  11. // database user's name
  12. user,
  13. // name of database to connect
  14. database: undefined,
  15. // database user's password
  16. password: null,
  17. // a Postgres connection string to be used instead of setting individual connection items
  18. // NOTE: Setting this value will cause it to override any other value (such as database or user) defined
  19. // in the defaults object.
  20. connectionString: undefined,
  21. // database port
  22. port: 5432,
  23. // number of rows to return at a time from a prepared statement's
  24. // portal. 0 will return all rows at once
  25. rows: 0,
  26. // binary result mode
  27. binary: false,
  28. // Connection pool options - see https://github.com/brianc/node-pg-pool
  29. // number of connections to use in connection pool
  30. // 0 will disable connection pooling
  31. max: 10,
  32. // max milliseconds a client can go unused before it is removed
  33. // from the pool and destroyed
  34. idleTimeoutMillis: 30000,
  35. client_encoding: '',
  36. ssl: false,
  37. application_name: undefined,
  38. fallback_application_name: undefined,
  39. options: undefined,
  40. parseInputDatesAsUTC: false,
  41. // max milliseconds any query using this connection will execute for before timing out in error.
  42. // false=unlimited
  43. statement_timeout: false,
  44. // Abort any statement that waits longer than the specified duration in milliseconds while attempting to acquire a lock.
  45. // false=unlimited
  46. lock_timeout: false,
  47. // Terminate any session with an open transaction that has been idle for longer than the specified duration in milliseconds
  48. // false=unlimited
  49. idle_in_transaction_session_timeout: false,
  50. // max milliseconds to wait for query to complete (client side)
  51. query_timeout: false,
  52. connect_timeout: 0,
  53. keepalives: 1,
  54. keepalives_idle: 0,
  55. }
  56. const pgTypes = require('pg-types')
  57. // save default parsers
  58. const parseBigInteger = pgTypes.getTypeParser(20, 'text')
  59. const parseBigIntegerArray = pgTypes.getTypeParser(1016, 'text')
  60. // parse int8 so you can get your count values as actual numbers
  61. module.exports.__defineSetter__('parseInt8', function (val) {
  62. pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger)
  63. pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray)
  64. })