首页 > 解决方案 > POCO::PostgreSQL:如何将 std::vector 支持添加到`Binder::bind`?

问题描述

我想把结构像

struct Person{
 int age;
 std::string name;
 std::vector<std::string> links;
};

进入 psql 表:

CREATE TABLE persons (
    age          integer,
    name         text,
    links        text[]
);

如何将 std::vector 支持添加到 Poco::PostgreSQL 中?

看一下绑定方法:

void Binder::bind(std::size_t /*pos*/, const std::vector<std::string>& /*val*/, Direction /*dir*/)
{
    throw NotImplementedException();
}

我知道用于自定义的 TypeHandler,但它只是将原始类型处理到您的类中,例如 int、std::string 等。

template <>
    class TypeHandler<struct CustomClass>
{}

标签: c++postgresqlpoco-libraries

解决方案


这是这样做的:

std::vector<Person> persons;
ses << "SELECT NAME FROM NAME", into(persons), now;

您应该阅读 Poco Data 用户指南,因为它包含大量信息并在此处包含您的答案。它还告诉您一些不要做的事情,因此值得一读。


推荐阅读