datasquirel/dist/package-shared/utils/grab-sql-key-name.js
2026-01-03 05:34:24 +01:00

31 lines
828 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = grabSQLKeyName;
/**
* # Grab Key Names
* @description Grab key names for foreign keys and indexes
*/
function grabSQLKeyName({ type, userId, addDate }) {
let prefixParadigm = (() => {
if (type == "unique_constraint")
return "unq";
if (type == "foreign_key")
return "fk";
if (type == "index")
return "indx";
if (type == "user")
return "user";
return null;
})();
const uuid = crypto.randomUUID();
const uidPrefx = uuid.split("-")[0];
let key = `dsql`;
if (prefixParadigm)
key += `_${prefixParadigm}`;
if (userId)
key += `_${userId}`;
if (addDate)
key += `_${uidPrefx}`;
return key;
}