index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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} = 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} ColumnSet
  26. * {@link helpers.ColumnSet ColumnSet} class constructor.
  27. *
  28. * @property {function} Column
  29. * {@link helpers.Column Column} class constructor.
  30. *
  31. * @property {function} insert
  32. * {@link helpers.insert insert} static method.
  33. *
  34. * @property {function} update
  35. * {@link helpers.update update} static method.
  36. *
  37. * @property {function} values
  38. * {@link helpers.values values} static method.
  39. *
  40. * @property {function} sets
  41. * {@link helpers.sets sets} static method.
  42. *
  43. * @property {function} concat
  44. * {@link helpers.concat concat} static method.
  45. */
  46. module.exports = config => {
  47. const capSQL = () => config.options && config.options.capSQL;
  48. const res = {
  49. insert(data, columns, table) {
  50. return method.insert(data, columns, table, capSQL());
  51. },
  52. update(data, columns, table, options) {
  53. return method.update(data, columns, table, options, capSQL());
  54. },
  55. concat(queries) {
  56. return method.concat(queries, capSQL());
  57. },
  58. values(data, columns) {
  59. return method.values(data, columns, capSQL());
  60. },
  61. sets(data, columns) {
  62. return method.sets(data, columns, capSQL());
  63. },
  64. TableName,
  65. ColumnSet,
  66. Column
  67. };
  68. return res;
  69. };