ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
database_name_service Class Reference

Service for generating whimsical database names. More...

#include <database_name_service.hpp>

Collaboration diagram for database_name_service:
Collaboration graph

Public Member Functions

 database_name_service (database::context ctx)
 Constructs a database_name_service with database context.
 
std::string generate_whimsical_name ()
 Generates a whimsical name without prefix.
 
std::string generate_whimsical_name (bool with_suffix)
 Generates a whimsical name with optional numeric suffix.
 
std::string generate_database_name (bool with_suffix=false)
 Generates a database name with the 'ores_' prefix.
 
std::string generate_unique_database_name (const std::vector< std::string > &existing_names={}, int max_attempts=10)
 Generates a unique database name not in the provided list.
 
std::string generate_unique_database_name_from_server ()
 Generates a unique database name by checking the server.
 

Detailed Description

Service for generating whimsical database names.

The database_name_service generates Heroku-style memorable names for tenant databases. Names follow the pattern: ores_<adjective>_<noun>[_<number>]

Examples:

The service delegates to PostgreSQL functions defined in admin_whimsical_names_create.sql (in ores_admin database), ensuring a single source of truth for the word lists and generation logic.

NOTE: This service must connect to the ores_admin database to access the name generation functions.

Usage patterns:

Constructor & Destructor Documentation

◆ database_name_service()

Constructs a database_name_service with database context.

Parameters
ctxThe database context for executing SQL functions

Member Function Documentation

◆ generate_whimsical_name() [1/2]

std::string generate_whimsical_name ( )

Generates a whimsical name without prefix.

Returns
A name like "silent_meadow" or "autumn_frost"

◆ generate_whimsical_name() [2/2]

std::string generate_whimsical_name ( bool  with_suffix)

Generates a whimsical name with optional numeric suffix.

Parameters
with_suffixIf true, appends a 4-digit number (e.g., "_4217")
Returns
A name like "silent_meadow" or "silent_meadow_4217"

◆ generate_database_name()

std::string generate_database_name ( bool  with_suffix = false)

Generates a database name with the 'ores_' prefix.

Parameters
with_suffixIf true, appends a 4-digit number
Returns
A name like "ores_silent_meadow" or "ores_silent_meadow_4217"

◆ generate_unique_database_name()

std::string generate_unique_database_name ( const std::vector< std::string > &  existing_names = {},
int  max_attempts = 10 
)

Generates a unique database name not in the provided list.

Attempts to generate a name without suffix first. If all attempts collide with existing names, falls back to adding a numeric suffix.

Parameters
existing_namesList of already-used database names to avoid
max_attemptsMaximum attempts before adding suffix (default 10)
Returns
A unique database name not in existing_names

◆ generate_unique_database_name_from_server()

std::string generate_unique_database_name_from_server ( )

Generates a unique database name by checking the server.

Queries all existing databases on the PostgreSQL server that match the ores_* pattern and generates a name that doesn't conflict.

Returns
A unique database name not conflicting with any ores_* database