Skip to content

Commit

Permalink
feat docs: add an example for retrieving binary data from a 'bytea' P…
Browse files Browse the repository at this point in the history
…ostgreSQL field

The main part is

```cpp
row["data"].To(pg::Bytea(tgt_bin_str))
```

Tests: протестировано CI
1c95306de4f096f725f66307f939094defaaecf4

Pull Request resolved: #590
  • Loading branch information
TertiumOrganum1 authored and alexiprof committed May 31, 2024
1 parent bc6d877 commit c2c33e0
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,23 @@
/// @code{.cpp}
/// namespace pg = storages::postgres;
/// using namespace std::string_literals;
/// // using a "binary string"
/// std::string s = "\0\xff\x0afoobar"s;
/// trx.Execute("select $1", pg::Bytea(tp));
/// std::vector<std::uint8_t> tgt_bin_str;
/// // note: pg::Bytea(const T &) is used
/// trx.Execute("select $1", pg::Bytea(s));
/// // storing a byte array:
/// std::vector<std::uint8_t> bin_str{1, 2, 3, 4, 5, 6, 7, 8, 9};
/// trx.Execute("INSERT INTO mytable (data) VALUES ($1)", pg::Bytea(bin_str));
/// // note: pg::Bytea(const T &) is used
/// @endcode
///
/// To read data from bytea field:
/// @code{.cpp}
/// // SQL: data BYTEA {NOT} NULL
/// auto res = trx.Execute("SELECT id, data FROM mytable WHERE id = $1", id);
/// std::vector<std::uint8_t> tgt_bin_str; const auto& row = res.Front();
/// row["data"].To(pg::Bytea(tgt_bin_str)); // note: pg::Bytea(T &) is used
/// @endcode
///
/// @par Network types
Expand Down

0 comments on commit c2c33e0

Please sign in to comment.