AK-21/Graphite-Industrial-Intelligence
0
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7 for (var name in all)8 __defProp(target, name, { get: all[name], enumerable: true });9};10var __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};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var foreign_keys_exports = {};20__export(foreign_keys_exports, {21 ForeignKey: () => ForeignKey,22 ForeignKeyBuilder: () => ForeignKeyBuilder,23 foreignKey: () => foreignKey24});25module.exports = __toCommonJS(foreign_keys_exports);26var import_entity = require("../entity.cjs");27var import_table_utils = require("../table.utils.cjs");28class ForeignKeyBuilder {29 static [import_entity.entityKind] = "SQLiteForeignKeyBuilder";30 /** @internal */31 reference;32 /** @internal */33 _onUpdate;34 /** @internal */35 _onDelete;36 constructor(config, actions) {37 this.reference = () => {38 const { name, columns, foreignColumns } = config();39 return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };40 };41 if (actions) {42 this._onUpdate = actions.onUpdate;43 this._onDelete = actions.onDelete;44 }45 }46 onUpdate(action) {47 this._onUpdate = action;48 return this;49 }50 onDelete(action) {51 this._onDelete = action;52 return this;53 }54 /** @internal */55 build(table) {56 return new ForeignKey(table, this);57 }58}59class ForeignKey {60 constructor(table, builder) {61 this.table = table;62 this.reference = builder.reference;63 this.onUpdate = builder._onUpdate;64 this.onDelete = builder._onDelete;65 }66 static [import_entity.entityKind] = "SQLiteForeignKey";67 reference;68 onUpdate;69 onDelete;70 getName() {71 const { name, columns, foreignColumns } = this.reference();72 const columnNames = columns.map((column) => column.name);73 const foreignColumnNames = foreignColumns.map((column) => column.name);74 const chunks = [75 this.table[import_table_utils.TableName],76 ...columnNames,77 foreignColumns[0].table[import_table_utils.TableName],78 ...foreignColumnNames79 ];80 return name ?? `${chunks.join("_")}_fk`;81 }82}83function foreignKey(config) {84 function mappedConfig() {85 if (typeof config === "function") {86 const { name, columns, foreignColumns } = config();87 return {88 name,89 columns,90 foreignColumns91 };92 }93 return config;94 }95 return new ForeignKeyBuilder(mappedConfig);96}97// Annotate the CommonJS export names for ESM import in node:980 && (module.exports = {99 ForeignKey,100 ForeignKeyBuilder,101 foreignKey102});103//# sourceMappingURL=foreign-keys.cjs.map