Skip to content

Can you return a setof<T> into a std::vector #1067

@pkfox

Description

@pkfox

Just to be clear this question relates to a hobby project

I have this class

#pragma once
#include "baseclass.h"
#include "stringhelper.h"
#include "wordlelevelhelper.h"

#include <string>
#include <cpprest/http_client.h>

class WordleAnswer
{ 
	public:
	WordleAnswer();
	std::string ToString() ;
	std::string GetJSON()  ;
	int id;
	std::string Answer;
	std::string  WordleDate;
	std::string  StarterWord;
	std::string  Notes;
	int Attempts;
	bool Solved;
	std::vector<std::string> Attemptslist;
	Wordlelevel WordleLevel;
};

No prizes for guessing my project, with the help of @jtv and others on here I've written string_traits to handle sending and retrieving this struct from pg, before I pull what is left of my hair out I thought I'd ask you knowledgeable lot if it's doable to return a pg setof wordleanswer into a std::vector at the moment I can retrieve a single with code as below where r is a pqxx::result

WordleAnswer wa = r[0][0].as<WordleAnswer>(); 

And I would like to be able to do

std::vector<WordleAnswer> was = r[0][0].as<std::vector<WordleAnswer>>(); 
Any help much appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions