1. 1 : /**
  2. 2 : * Providers are special pieces that give you easy access to various data storage systems
  3. 3 : * using a consistent and predictable set of methods
  4. 4 : * @module Provider
  5. 5 : * @example <caption> The following structure is needed for SettingGateway compatibility. </caption>
  6. 6 : * exports.hasTable = (table) => { // code here };
  7. 7 : * exports.createTable = (table) => { // code here };
  8. 8 : * exports.getAll = (table) => { // code here };
  9. 9 : * exports.get = (table, id) => { // code here };
  10. 10 : * exports.create = (table, id, document) => { // code here };
  11. 11 : * exports.delete = (table, id) => { // code here };
  12. 12 : * exports.update = (table, id, document) => { // code here };
  13. 13 : * exports.replace = (table, id, document) => { // code here };
  14. 14 : * exports.conf = {};
  15. 15 : */
  16. 16 :
  17. 17 : /**
  18. 18 : * Checks if a table exists.
  19. 19 : * @param {string} table The name of the table you want to check.
  20. 20 : * @return {Promise<boolean>}
  21. 21 : */
  22. 22 : exports.hasTable = (table) => ({}); // eslint-disable-line
  23. 23 :
  24. 24 : /**
  25. 25 : * Create a new table.
  26. 26 : * @param {string} table The name for the new table.
  27. 27 : * @return {Promise<*>}
  28. 28 : */
  29. 29 : exports.createTable = (table) => ({}); // eslint-disable-line
  30. 30 :
  31. 31 : /**
  32. 32 : * Get all entries from a table.
  33. 33 : * @param {string} table The name of the table to fetch from.
  34. 34 : * @return {Promise<Array<{}>>}
  35. 35 : */
  36. 36 : exports.getAll = (table) => ({}); // eslint-disable-line
  37. 37 :
  38. 38 : /**
  39. 39 : * Get an entry from a table.
  40. 40 : * @param {string} table The name of the table to fetch from.
  41. 41 : * @param {string} id The ID of the entry to get.
  42. 42 : * @return {Promise<Array<{}>>}
  43. 43 : */
  44. 44 : exports.get = (table, id) => ({}); // eslint-disable-line
  45. 45 :
  46. 46 : /**
  47. 47 : * Create a new entry into a table.
  48. 48 : * @param {string} table The name of the table to update.
  49. 49 : * @param {string} id The ID for the new entry.
  50. 50 : * @param {Object} document A JSON object.
  51. 51 : * @return {Promise<*>}
  52. 52 : */
  53. 53 : exports.create = (table, id, document) => ({}); // eslint-disable-line
  54. 54 :
  55. 55 : /**
  56. 56 : * Delete an entry from a table.
  57. 57 : * @param {string} table The name of the table to update.
  58. 58 : * @param {string} id The ID of the entry to delete.
  59. 59 : * @return {Promise<Array<{}>>}
  60. 60 : */
  61. 61 : exports.delete = (table, id) => ({}); // eslint-disable-line
  62. 62 :
  63. 63 : /**
  64. 64 : * Update an entry from a table.
  65. 65 : * @param {string} table The name of the table to update.
  66. 66 : * @param {string} id The ID of the entry to update.
  67. 67 : * @param {Object} document A JSON object.
  68. 68 : * @return {Promise<*>}
  69. 69 : */
  70. 70 : exports.update = (table, id, document) => ({}); // eslint-disable-line
  71. 71 :
  72. 72 : /**
  73. 73 : * Replace an entry from a table.
  74. 74 : * @param {string} table The name of the table to update.
  75. 75 : * @param {string} id The ID of the entry to update.
  76. 76 : * @param {Object} document The new JSON object for the document.
  77. 77 : * @return {Promise<*>}
  78. 78 : */
  79. 79 : exports.replace = (table, id, document) => ({}); // eslint-disable-line
  80. 80 :
  81. 81 : /**
  82. 82 : * An object that configures the provider.
  83. 83 : * @type {Conf}
  84. 84 : * @example
  85. 85 : * exports.conf = {
  86. 86 : * enabled: true,
  87. 87 : * moduleName: "json",
  88. 88 : * priority: 0
  89. 89 : * };
  90. 90 : */
  91. 91 : exports.conf = {};
  92. 92 :
  93. 93 : /**
  94. 94 : * Some providers are SQL, and due to the No-SQL environment that exists in SettingGateway,
  95. 95 : * they require extra methods/properties to work. All the previous methods are required to work.
  96. 96 : * @module ProviderSQL
  97. 97 : * @example <caption> SQL Compatibility </caption>
  98. 98 : * exports.updateColumns = (table, columns, schema) => { // code here };
  99. 99 : * exports.serialize = (data) => { // code here };
  100. 100 : * exports.sanitize = (string) => { // code here };
  101. 101 : * exports.CONSTANTS = {};
  102. 102 : */
  103. 103 :
  104. 104 : /**
  105. 105 : * Update the columns from a table (All the data is provided by the SQL class).
  106. 106 : * @param {string} table The name of the table.
  107. 107 : * @param {string[]} columns Array of columns.
  108. 108 : * @param {array[]} schema Tuples of keys/values from the schema.
  109. 109 : * @returns {boolean}
  110. 110 : */
  111. 111 : exports.updateColumns = (table, columns, schema) => ({}); // eslint-disable-line
  112. 112 :
  113. 113 : /**
  114. 114 : * Transform NoSQL queries into SQL.
  115. 115 : * @param {Object} data The object.
  116. 116 : * @returns {Object}
  117. 117 : */
  118. 118 : exports.serialize = (data) => ({}); // eslint-disable-line
  119. 119 :
  120. 120 : /**
  121. 121 : * Sanitize strings to be storable into the SQL database.
  122. 122 : * @param {*} string An object or string.
  123. 123 : * @returns {string}
  124. 124 : */
  125. 125 : exports.sanitize = (string) => ({}); // eslint-disable-line
  126. 126 :
  127. 127 : /**
  128. 128 : * An object that helps the SQL class creating compatible schemas for the provider.
  129. 129 : * @property {string} String The SQL compatible string datatype.
  130. 130 : * @property {string} Integer The SQL compatible integer datatype.
  131. 131 : * @property {string} Float The SQL compatible float datatype.
  132. 132 : * @example
  133. 133 : * exports.CONSTANTS = {
  134. 134 : * String: "TEXT",
  135. 135 : * Integer: "INTEGER",
  136. 136 : * Float: "INTEGER",
  137. 137 : * AutoID: "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE",
  138. 138 : * Timestamp: "DATETIME",
  139. 139 : * AutoTS: "DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL",
  140. 140 : * };
  141. 141 : */
  142. 142 : exports.CONSTANTS = {};