26constexpr std::size_t PrefetchDepthDefault = 1000;
35inline constexpr std::size_t PreparedStatementCacheCapacityDefault = 0;
39inline constexpr std::size_t PreparedStatementCacheCapacitySuggested = 64;
77[[nodiscard]] LIGHTWEIGHT_API
SqlEncryptionMode ParseEncryptionMode(std::string_view value)
noexcept;
84[[nodiscard]] LIGHTWEIGHT_API std::string_view FormatEncryptionMode(
SqlEncryptionMode mode)
noexcept;
97 [[nodiscard]] LIGHTWEIGHT_API std::string
Sanitized()
const;
100 [[nodiscard]] LIGHTWEIGHT_API
static std::string
SanitizePwd(std::string_view input);
103using SqlConnectionStringMap = std::map<std::string, std::string>;
106LIGHTWEIGHT_API SqlConnectionStringMap ParseConnectionString(
SqlConnectionString const& connectionString);
109LIGHTWEIGHT_API
SqlConnectionString BuildConnectionString(SqlConnectionStringMap
const& map);
123[[nodiscard]] LIGHTWEIGHT_API
bool EnsureSqliteDatabaseFileExists(
SqlConnectionString const& connectionString);
136 std::chrono::seconds timeout { 5 };
143 std::size_t defaultPrefetchDepth = PrefetchDepthDefault;
158 std::size_t preparedStatementCacheCapacity = PreparedStatementCacheCapacityDefault;
170 auto value = std::format(
"DSN={};UID={};PWD={};TIMEOUT={}", datasource, username, password, timeout.count());
171 if (
auto const encryptValue = FormatEncryptionMode(encryption); !encryptValue.empty())
172 value += std::format(
";Encrypt={}", encryptValue);
180using SqlConnectInfo = std::variant<SqlConnectionDataSource, SqlConnectionString>;
185struct std::formatter<Lightweight::SqlConnectInfo>: std::formatter<std::string>
187 auto format(Lightweight::SqlConnectInfo
const& info, format_context& ctx)
const -> format_context::iterator
189 if (
auto const* dsn = std::get_if<Lightweight::SqlConnectionDataSource>(&info))
191 return formatter<string>::format(dsn->ToConnectionString().value, ctx);
193 else if (
auto const* connectionString = std::get_if<Lightweight::SqlConnectionString>(&info))
195 return formatter<string>::format(connectionString->value, ctx);
199 return formatter<string>::format(
"Invalid connection info", ctx);
SqlEncryptionMode
Whether the client/server connection is TLS-encrypted.
@ Enabled
Request an encrypted connection (SQL_EN_ON).
@ Disabled
Request an unencrypted connection (SQL_EN_OFF).
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
std::string datasource
The ODBC data source name (DSN).
std::string password
The password for authentication.
std::string username
The username for authentication.
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.