refresh-materialized-view.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { entityKind } from "../../entity.js";
  2. import { QueryPromise } from "../../query-promise.js";
  3. import { tracer } from "../../tracing.js";
  4. class PgRefreshMaterializedView extends QueryPromise {
  5. constructor(view, session, dialect) {
  6. super();
  7. this.session = session;
  8. this.dialect = dialect;
  9. this.config = { view };
  10. }
  11. static [entityKind] = "PgRefreshMaterializedView";
  12. config;
  13. concurrently() {
  14. if (this.config.withNoData !== void 0) {
  15. throw new Error("Cannot use concurrently and withNoData together");
  16. }
  17. this.config.concurrently = true;
  18. return this;
  19. }
  20. withNoData() {
  21. if (this.config.concurrently !== void 0) {
  22. throw new Error("Cannot use concurrently and withNoData together");
  23. }
  24. this.config.withNoData = true;
  25. return this;
  26. }
  27. /** @internal */
  28. getSQL() {
  29. return this.dialect.buildRefreshMaterializedViewQuery(this.config);
  30. }
  31. toSQL() {
  32. const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
  33. return rest;
  34. }
  35. /** @internal */
  36. _prepare(name) {
  37. return tracer.startActiveSpan("drizzle.prepareQuery", () => {
  38. return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), void 0, name, true);
  39. });
  40. }
  41. prepare(name) {
  42. return this._prepare(name);
  43. }
  44. authToken;
  45. /** @internal */
  46. setToken(token) {
  47. this.authToken = token;
  48. return this;
  49. }
  50. execute = (placeholderValues) => {
  51. return tracer.startActiveSpan("drizzle.operation", () => {
  52. return this._prepare().execute(placeholderValues, this.authToken);
  53. });
  54. };
  55. }
  56. export {
  57. PgRefreshMaterializedView
  58. };
  59. //# sourceMappingURL=refresh-materialized-view.js.map