| Server IP : 159.203.156.69 / Your IP : 216.73.216.37 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/drizzle-orm/sqlite-core/ |
Upload File : |
import { entityKind } from "../entity.js";
import { TableName } from "../table.utils.js";
class ForeignKeyBuilder {
static [entityKind] = "SQLiteForeignKeyBuilder";
/** @internal */
reference;
/** @internal */
_onUpdate;
/** @internal */
_onDelete;
constructor(config, actions) {
this.reference = () => {
const { name, columns, foreignColumns } = config();
return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
};
if (actions) {
this._onUpdate = actions.onUpdate;
this._onDelete = actions.onDelete;
}
}
onUpdate(action) {
this._onUpdate = action;
return this;
}
onDelete(action) {
this._onDelete = action;
return this;
}
/** @internal */
build(table) {
return new ForeignKey(table, this);
}
}
class ForeignKey {
constructor(table, builder) {
this.table = table;
this.reference = builder.reference;
this.onUpdate = builder._onUpdate;
this.onDelete = builder._onDelete;
}
static [entityKind] = "SQLiteForeignKey";
reference;
onUpdate;
onDelete;
getName() {
const { name, columns, foreignColumns } = this.reference();
const columnNames = columns.map((column) => column.name);
const foreignColumnNames = foreignColumns.map((column) => column.name);
const chunks = [
this.table[TableName],
...columnNames,
foreignColumns[0].table[TableName],
...foreignColumnNames
];
return name ?? `${chunks.join("_")}_fk`;
}
}
function foreignKey(config) {
function mappedConfig() {
if (typeof config === "function") {
const { name, columns, foreignColumns } = config();
return {
name,
columns,
foreignColumns
};
}
return config;
}
return new ForeignKeyBuilder(mappedConfig);
}
export {
ForeignKey,
ForeignKeyBuilder,
foreignKey
};
//# sourceMappingURL=foreign-keys.js.map