31 lines
839 B
TypeScript
31 lines
839 B
TypeScript
type Param = {
|
|
type: "foreign_key" | "index" | "user" | "unique_constraint";
|
|
userId?: string | number;
|
|
addDate?: boolean;
|
|
};
|
|
|
|
/**
|
|
* # Grab Key Names
|
|
* @description Grab key names for foreign keys and indexes
|
|
*/
|
|
export default function grabSQLKeyName({ type, userId, addDate }: Param) {
|
|
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;
|
|
}
|