31 lines
828 B
JavaScript
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;
|
|
}
|