26 [[nodiscard]] LIGHTWEIGHT_API std::string
Sanitized()
const;
29 [[nodiscard]] LIGHTWEIGHT_API
static std::string
SanitizePwd(std::string_view input);
32using SqlConnectionStringMap = std::map<std::string, std::string>;
35LIGHTWEIGHT_API SqlConnectionStringMap ParseConnectionString(
SqlConnectionString const& connectionString);
38LIGHTWEIGHT_API
SqlConnectionString BuildConnectionString(SqlConnectionStringMap
const& map);
50 std::chrono::seconds timeout { 5 };
59 .
value = std::format(
"DSN={};UID={};PWD={};TIMEOUT={}", datasource, username, password, timeout.count())
67using SqlConnectInfo = std::variant<SqlConnectionDataSource, SqlConnectionString>;
72struct std::formatter<Lightweight::SqlConnectInfo>: std::formatter<std::string>
74 auto format(Lightweight::SqlConnectInfo
const& info, format_context& ctx)
const -> format_context::iterator
76 if (
auto const* dsn = std::get_if<Lightweight::SqlConnectionDataSource>(&info))
78 return formatter<string>::format(
80 "DSN={};UID={};PWD={};TIMEOUT={}", dsn->datasource, dsn->username, dsn->password, dsn->timeout.count()),
83 else if (
auto const* connectionString = std::get_if<Lightweight::SqlConnectionString>(&info))
85 return formatter<string>::format(connectionString->value, ctx);
89 return formatter<string>::format(
"Invalid connection info", ctx);
Represents a connection data source as a DSN, username, password, and timeout.
auto operator<=>(SqlConnectionDataSource const &) const noexcept=default
Three-way comparison operator.
static LIGHTWEIGHT_API SqlConnectionDataSource FromConnectionString(SqlConnectionString const &value)
Constructs a SqlConnectionDataSource from the given connection string.
LIGHTWEIGHT_API SqlConnectionString ToConnectionString() const
Converts this data source to an ODBC connection string.
std::string datasource
The ODBC data source name (DSN).
std::string password
The password for authentication.
std::string username
The username for authentication.
Represents an ODBC connection string.
auto operator<=>(SqlConnectionString const &) const noexcept=default
Three-way comparison operator.
static LIGHTWEIGHT_API std::string SanitizePwd(std::string_view input)
Sanitizes the password in the given connection string input.
std::string value
The raw ODBC connection string value.
LIGHTWEIGHT_API std::string Sanitized() const
Returns a sanitized copy of the connection string with the password masked.