dsql-admin/dsql-app/package-shared/utils/backend/names/replace-datasquirel-db-name.ts

15 lines
385 B
TypeScript
Raw Normal View History

2025-02-12 16:56:44 +00:00
type Param = {
str: string;
userId: string | number;
};
export default function replaceDatasquirelDbName({
str,
userId,
}: Param): string {
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
const userNameRegex = new RegExp(`${dbNamePrefix}\\d+_`, "g");
const newPrefix = `${dbNamePrefix}${userId}_`;
return str.replace(userNameRegex, newPrefix);
}