index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2015-present, Vitaly Tomilov
  3. *
  4. * See the LICENSE file at the top-level directory of this distribution
  5. * for licensing information.
  6. *
  7. * Removal or modification of this copyright notice is prohibited.
  8. */
  9. const {Column} = require('./column');
  10. const {ColumnSet} = require('./column-set');
  11. const {TableName, _TN} = require('./table-name');
  12. const method = require('./methods');
  13. /**
  14. * @namespace helpers
  15. * @description
  16. * Namespace for query-formatting generators, available as {@link module:pg-promise~helpers pgp.helpers}, after initializing the library.
  17. *
  18. * It unifies the approach to generating multi-row `INSERT` / `UPDATE` queries with the single-row ones.
  19. *
  20. * See also: $[Performance Boost].
  21. *
  22. * @property {function} TableName
  23. * {@link helpers.TableName TableName} class constructor.
  24. *
  25. * @property {function} _TN
  26. * {@link helpers._TN _TN} Table-Name conversion function.
  27. *
  28. * @property {function} ColumnSet
  29. * {@link helpers.ColumnSet ColumnSet} class constructor.
  30. *
  31. * @property {function} Column
  32. * {@link helpers.Column Column} class constructor.
  33. *
  34. * @property {function} insert
  35. * {@link helpers.insert insert} static method.
  36. *
  37. * @property {function} update
  38. * {@link helpers.update update} static method.
  39. *
  40. * @property {function} values
  41. * {@link helpers.values values} static method.
  42. *
  43. * @property {function} sets
  44. * {@link helpers.sets sets} static method.
  45. *
  46. * @property {function} concat
  47. * {@link helpers.concat concat} static method.
  48. */
  49. module.exports = config => {
  50. const capSQL = () => config.options && config.options.capSQL;
  51. const res = {
  52. insert(data, columns, table) {
  53. return method.insert(data, columns, table, capSQL());
  54. },
  55. update(data, columns, table, options) {
  56. return method.update(data, columns, table, options, capSQL());
  57. },
  58. concat(queries) {
  59. return method.concat(queries, capSQL());
  60. },
  61. values(data, columns) {
  62. return method.values(data, columns, capSQL());
  63. },
  64. sets(data, columns) {
  65. return method.sets(data, columns, capSQL());
  66. },
  67. TableName,
  68. _TN,
  69. ColumnSet,
  70. Column
  71. };
  72. return res;
  73. };