Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept pqxx::binary concept in more places. #936

Closed
wants to merge 57 commits into from
Closed

Conversation

jtv
Copy link
Owner

@jtv jtv commented Jan 20, 2025

Fixes: #925

Extends a bunch more functions that accept pqxx::bytes_view with
variants which accept any type that satisfies the pqxx::binary
concept.

Also, change the pqxx::bytes_view type alies from being a
std::basic_string_view<std::byte> (which doesn't actually have to work
according to the standard!) to being a std::span<std::byte>. This
seems to be broadly compatible with existing code. For completeness I'm
adding a pqxx::writable_bytes_view as well.

Along the way I'm assuming support for C++17's std::filesystem::path,
and adding a conversion to pqxx::zview. With that, pqxx::blob no
longer needs explicit support for std::filesystem::path filenames; it
just accepts pqxx::zview and passing a std::filesystem::path will
just work. It avoids some ambiguities.

jtv added 30 commits January 19, 2025 15:11
This type has been deprecated since 7.2.0, more than 4 years ago.
This was a long-forgotten feature that somebody thought might be a
good idea, around 20 years ago.  It's only been deprecated for a
short time, but it's so obscure that I stronly doubt that anyone has
ever used it at all.

Meanwhile it was weighing down a pretty basic piece of code that
comes up in lots of loops, so... less is more.
jtv and others added 27 commits January 19, 2025 15:13
This has been deprecated for the entire 7.x cycle.
Use `pqxx::connection::encrypt_password()` instead.
Use `pqxx::params` instead.
Use the factory functions instead.
Use `unesc_bin()` and `quote(bytes_view)` instead.
These constructors have been documented as "do not use" in various ways
for a long time.

More generally, I'm settling on a deprecation horizon of 3 years.  It's
been so long since 7.0 came out that it's just not reasonable to keep
everything that was deprecated since then.  Instead, I'm now retiring
things that were deprecated in 7.6.
Not clear why those were there in the first place.
* Retire `binarystring`.

This type has been deprecated since 7.2.0, more than 4 years ago.

* String conversion to `string_view`.  More binary types.

Fixes: #694
Fixes: #827

Making much broader use of concepts.  String conversions now accept any
contiguous range of `std::byte` as binary data.  Traits specialisations
for integer and floating-point types are simpler now.  And you can now
just convert from string to `std::string_view` (or `char const *`), so
long as you don't access it after the original string's lifetime ends.

* Work around Visual Studio 2022 concepts problem.

This compiler was having trouble with the syntax I used to specialise
the generic `string_traits<T>` template to a _concept_ `T` (as opposed
to run-of-the-mill specialisation to a _type_ `T`).

So just for the floating-point string traits, I went back to the old
setup where I had a separate implementation type template
(`string_float_traits`) and derived the `string_traits` implementations
for those types from instantiations of that template.

* Forbid string conversion from `char const *`.

It was stupid of me to allow this.  I hope nobody ever used it.
Not sure how useful this is, but it's definitely more intuitive.

Theoretically we might be able to leave `nullness::is_null()` on such
types unimplemented altogether, though that might make things a little
too irregular.
Fixes: #925

Extends a bunch more functions that accept `pqxx::bytes_view` with
variants which accept any type that satisfies the `pqxx::binary`
concept.

Also, change the `pqxx::bytes_view` type alies from being a
`std::basic_string_view<std::byte>` (which doesn't actually have to work
according to the standard!) to being a `std::span<std::byte>`.  This
seems to be broadly compatible with existing code.  For completeness I'm
adding a `pqxx::writable_bytes_view` as well.

Along the way I'm assuming support for C++17's `std::filesystem::path`,
and adding a conversion to `pqxx::zview`.  With that, `pqxx::blob` no
longer needs explicit support for `std::filesystem::path` filenames; it
just accepts `pqxx::zview` and passing a `std::filesystem::path` will
just work.  It avoids some ambiguities.
@jtv
Copy link
Owner Author

jtv commented Jan 20, 2025

Oops, I wanted to merge this into the start-8 branch.

@jtv jtv closed this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accept ranges where we currently use pqxx::bytes and pqxx::bytes_view
1 participant