view.cjs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var view_exports = {};
  20. __export(view_exports, {
  21. DefaultViewBuilderCore: () => DefaultViewBuilderCore,
  22. GelMaterializedView: () => GelMaterializedView,
  23. GelMaterializedViewConfig: () => GelMaterializedViewConfig,
  24. GelView: () => GelView,
  25. ManualMaterializedViewBuilder: () => ManualMaterializedViewBuilder,
  26. ManualViewBuilder: () => ManualViewBuilder,
  27. MaterializedViewBuilder: () => MaterializedViewBuilder,
  28. MaterializedViewBuilderCore: () => MaterializedViewBuilderCore,
  29. ViewBuilder: () => ViewBuilder,
  30. gelMaterializedViewWithSchema: () => gelMaterializedViewWithSchema,
  31. gelViewWithSchema: () => gelViewWithSchema
  32. });
  33. module.exports = __toCommonJS(view_exports);
  34. var import_entity = require("../entity.cjs");
  35. var import_selection_proxy = require("../selection-proxy.cjs");
  36. var import_utils = require("../utils.cjs");
  37. var import_query_builder = require("./query-builders/query-builder.cjs");
  38. var import_table = require("./table.cjs");
  39. var import_view_base = require("./view-base.cjs");
  40. var import_view_common = require("./view-common.cjs");
  41. class DefaultViewBuilderCore {
  42. constructor(name, schema) {
  43. this.name = name;
  44. this.schema = schema;
  45. }
  46. static [import_entity.entityKind] = "GelDefaultViewBuilderCore";
  47. config = {};
  48. with(config) {
  49. this.config.with = config;
  50. return this;
  51. }
  52. }
  53. class ViewBuilder extends DefaultViewBuilderCore {
  54. static [import_entity.entityKind] = "GelViewBuilder";
  55. as(qb) {
  56. if (typeof qb === "function") {
  57. qb = qb(new import_query_builder.QueryBuilder());
  58. }
  59. const selectionProxy = new import_selection_proxy.SelectionProxyHandler({
  60. alias: this.name,
  61. sqlBehavior: "error",
  62. sqlAliasedBehavior: "alias",
  63. replaceOriginalName: true
  64. });
  65. const aliasedSelection = new Proxy(qb.getSelectedFields(), selectionProxy);
  66. return new Proxy(
  67. new GelView({
  68. GelConfig: this.config,
  69. config: {
  70. name: this.name,
  71. schema: this.schema,
  72. selectedFields: aliasedSelection,
  73. query: qb.getSQL().inlineParams()
  74. }
  75. }),
  76. selectionProxy
  77. );
  78. }
  79. }
  80. class ManualViewBuilder extends DefaultViewBuilderCore {
  81. static [import_entity.entityKind] = "GelManualViewBuilder";
  82. columns;
  83. constructor(name, columns, schema) {
  84. super(name, schema);
  85. this.columns = (0, import_utils.getTableColumns)((0, import_table.gelTable)(name, columns));
  86. }
  87. existing() {
  88. return new Proxy(
  89. new GelView({
  90. GelConfig: void 0,
  91. config: {
  92. name: this.name,
  93. schema: this.schema,
  94. selectedFields: this.columns,
  95. query: void 0
  96. }
  97. }),
  98. new import_selection_proxy.SelectionProxyHandler({
  99. alias: this.name,
  100. sqlBehavior: "error",
  101. sqlAliasedBehavior: "alias",
  102. replaceOriginalName: true
  103. })
  104. );
  105. }
  106. as(query) {
  107. return new Proxy(
  108. new GelView({
  109. GelConfig: this.config,
  110. config: {
  111. name: this.name,
  112. schema: this.schema,
  113. selectedFields: this.columns,
  114. query: query.inlineParams()
  115. }
  116. }),
  117. new import_selection_proxy.SelectionProxyHandler({
  118. alias: this.name,
  119. sqlBehavior: "error",
  120. sqlAliasedBehavior: "alias",
  121. replaceOriginalName: true
  122. })
  123. );
  124. }
  125. }
  126. class MaterializedViewBuilderCore {
  127. constructor(name, schema) {
  128. this.name = name;
  129. this.schema = schema;
  130. }
  131. static [import_entity.entityKind] = "GelMaterializedViewBuilderCore";
  132. config = {};
  133. using(using) {
  134. this.config.using = using;
  135. return this;
  136. }
  137. with(config) {
  138. this.config.with = config;
  139. return this;
  140. }
  141. tablespace(tablespace) {
  142. this.config.tablespace = tablespace;
  143. return this;
  144. }
  145. withNoData() {
  146. this.config.withNoData = true;
  147. return this;
  148. }
  149. }
  150. class MaterializedViewBuilder extends MaterializedViewBuilderCore {
  151. static [import_entity.entityKind] = "GelMaterializedViewBuilder";
  152. as(qb) {
  153. if (typeof qb === "function") {
  154. qb = qb(new import_query_builder.QueryBuilder());
  155. }
  156. const selectionProxy = new import_selection_proxy.SelectionProxyHandler({
  157. alias: this.name,
  158. sqlBehavior: "error",
  159. sqlAliasedBehavior: "alias",
  160. replaceOriginalName: true
  161. });
  162. const aliasedSelection = new Proxy(qb.getSelectedFields(), selectionProxy);
  163. return new Proxy(
  164. new GelMaterializedView({
  165. GelConfig: {
  166. with: this.config.with,
  167. using: this.config.using,
  168. tablespace: this.config.tablespace,
  169. withNoData: this.config.withNoData
  170. },
  171. config: {
  172. name: this.name,
  173. schema: this.schema,
  174. selectedFields: aliasedSelection,
  175. query: qb.getSQL().inlineParams()
  176. }
  177. }),
  178. selectionProxy
  179. );
  180. }
  181. }
  182. class ManualMaterializedViewBuilder extends MaterializedViewBuilderCore {
  183. static [import_entity.entityKind] = "GelManualMaterializedViewBuilder";
  184. columns;
  185. constructor(name, columns, schema) {
  186. super(name, schema);
  187. this.columns = (0, import_utils.getTableColumns)((0, import_table.gelTable)(name, columns));
  188. }
  189. existing() {
  190. return new Proxy(
  191. new GelMaterializedView({
  192. GelConfig: {
  193. tablespace: this.config.tablespace,
  194. using: this.config.using,
  195. with: this.config.with,
  196. withNoData: this.config.withNoData
  197. },
  198. config: {
  199. name: this.name,
  200. schema: this.schema,
  201. selectedFields: this.columns,
  202. query: void 0
  203. }
  204. }),
  205. new import_selection_proxy.SelectionProxyHandler({
  206. alias: this.name,
  207. sqlBehavior: "error",
  208. sqlAliasedBehavior: "alias",
  209. replaceOriginalName: true
  210. })
  211. );
  212. }
  213. as(query) {
  214. return new Proxy(
  215. new GelMaterializedView({
  216. GelConfig: {
  217. tablespace: this.config.tablespace,
  218. using: this.config.using,
  219. with: this.config.with,
  220. withNoData: this.config.withNoData
  221. },
  222. config: {
  223. name: this.name,
  224. schema: this.schema,
  225. selectedFields: this.columns,
  226. query: query.inlineParams()
  227. }
  228. }),
  229. new import_selection_proxy.SelectionProxyHandler({
  230. alias: this.name,
  231. sqlBehavior: "error",
  232. sqlAliasedBehavior: "alias",
  233. replaceOriginalName: true
  234. })
  235. );
  236. }
  237. }
  238. class GelView extends import_view_base.GelViewBase {
  239. static [import_entity.entityKind] = "GelView";
  240. [import_view_common.GelViewConfig];
  241. constructor({ GelConfig, config }) {
  242. super(config);
  243. if (GelConfig) {
  244. this[import_view_common.GelViewConfig] = {
  245. with: GelConfig.with
  246. };
  247. }
  248. }
  249. }
  250. const GelMaterializedViewConfig = Symbol.for("drizzle:GelMaterializedViewConfig");
  251. class GelMaterializedView extends import_view_base.GelViewBase {
  252. static [import_entity.entityKind] = "GelMaterializedView";
  253. [GelMaterializedViewConfig];
  254. constructor({ GelConfig, config }) {
  255. super(config);
  256. this[GelMaterializedViewConfig] = {
  257. with: GelConfig?.with,
  258. using: GelConfig?.using,
  259. tablespace: GelConfig?.tablespace,
  260. withNoData: GelConfig?.withNoData
  261. };
  262. }
  263. }
  264. function gelViewWithSchema(name, selection, schema) {
  265. if (selection) {
  266. return new ManualViewBuilder(name, selection, schema);
  267. }
  268. return new ViewBuilder(name, schema);
  269. }
  270. function gelMaterializedViewWithSchema(name, selection, schema) {
  271. if (selection) {
  272. return new ManualMaterializedViewBuilder(name, selection, schema);
  273. }
  274. return new MaterializedViewBuilder(name, schema);
  275. }
  276. function gelView(name, columns) {
  277. return gelViewWithSchema(name, columns, void 0);
  278. }
  279. function gelMaterializedView(name, columns) {
  280. return gelMaterializedViewWithSchema(name, columns, void 0);
  281. }
  282. function isGelView(obj) {
  283. return (0, import_entity.is)(obj, GelView);
  284. }
  285. function isGelMaterializedView(obj) {
  286. return (0, import_entity.is)(obj, GelMaterializedView);
  287. }
  288. // Annotate the CommonJS export names for ESM import in node:
  289. 0 && (module.exports = {
  290. DefaultViewBuilderCore,
  291. GelMaterializedView,
  292. GelMaterializedViewConfig,
  293. GelView,
  294. ManualMaterializedViewBuilder,
  295. ManualViewBuilder,
  296. MaterializedViewBuilder,
  297. MaterializedViewBuilderCore,
  298. ViewBuilder,
  299. gelMaterializedViewWithSchema,
  300. gelViewWithSchema
  301. });
  302. //# sourceMappingURL=view.cjs.map