UNPKG

kysely-replication

Version:

Replication-aware Kysely query execution

68 lines (63 loc) 2.19 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/force/index.mts var force_exports = {}; __export(force_exports, { WithDialectPlugin: () => WithDialectPlugin }); module.exports = __toCommonJS(force_exports); // src/force/module-augmentation.mts var import_kysely = require("kysely"); // src/force/plugin.mts var WithDialectPlugin = class { #dialect; #replicaIndex; constructor(dialect, replicaIndex) { this.#dialect = dialect; this.#replicaIndex = replicaIndex; } transformQuery(args) { return { ...args.node, // @ts-expect-error __dialect__: this.#dialect, __replicaIndex__: this.#replicaIndex }; } async transformResult(args) { return args.result; } }; // src/force/module-augmentation.mts import_kysely.QueryCreator.prototype.withPrimary = function() { return this.withPlugin(new WithDialectPlugin("primary")); }; import_kysely.QueryCreator.prototype.withReplica = function(replicaIndex) { return this.withPlugin(new WithDialectPlugin("replica", replicaIndex)); }; import_kysely.SchemaModule.prototype.withPrimary = function() { return this.withPlugin(new WithDialectPlugin("primary")); }; import_kysely.SchemaModule.prototype.withReplica = function(replicaIndex) { return this.withPlugin(new WithDialectPlugin("replica", replicaIndex)); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { WithDialectPlugin });