zussel / matador

Take your appclication by the horns
http://zussel.github.io/matador
GNU General Public License v3.0
63 stars 22 forks source link

项目生成出现错误 #135

Open dragon-dan opened 1 year ago

dragon-dan commented 1 year ago

按照文档在VS2019下新建项目引入matador学习使用时,按照文档尝试连接数据库,示例程序编译不能通过。

错误 C2039 "type": 不是 "std" 的成员

image

zussel commented 1 year ago

Hey, thanks for trying matatdor!

Could you provide me the complete source code of your test program? It seems, that there is missing include, but from your informations I can't determine which include.

dragon-dan commented 1 year ago

main.cpp

#include <iostream>
#include "pgdb.hpp"

int main()
{
    std::cout << "Hello World!\n";
    func1();
    system("pause");
}

pgdb.hpp

#include <string>
#include <type_traits>

#include "matador/orm/persistence.hpp"
#include "matador/orm/session.hpp"
#include "matador/utils/identifier.hpp"

#include "matador/json/json.hpp"

#pragma comment(lib,"matador-json.lib")

struct person
{
    matador::identifier<long> id;
    std::string name;
    int age;

    person() = default;
    person(long i, std::string n, int a)
        : id(i), name(std::move(n)), age(a)
    {}

    template < class SERIALIZER >
    void serialize(SERIALIZER& serializer)
    {
        serializer.serialize("id", id);
        serializer.serialize("name", name);
        serializer.serialize("age", age);
    }
};

int func_json()
{
    // create an empty object
    matador::json jo = matador::json::object();

    // is true
    std::cout << std::boolalpha << jo.is_object() << std::endl;

    // assigning values
    jo["name"] = "george";
    jo["age"] = 35;
    jo["weight"] = 78.5;
    jo["male"] = true;
}

int func1()
{
    matador::persistence p("postgresql://root:123456@127.0.0.1:5432/test");
    p.attach<person>("person");

    // After the persistance layer is configured all the database tables can be created
    //p.create();

    // create a database session
    matador::session s(p);

    // insert george
    // returns an matador::object_ptr<person>
    auto george = s.insert(new person(1L, "george", 22));
    s.flush();
}

如上,非常简单的代码,基本都是从文档复制下来一个一个尝试功能,文档上没有引入头文件的示例,只好自己探索

zussel commented 1 year ago

Hi!

Thanks for the code. At first sight it seems that you declared the id in your person class incorrect. Matador::identifier needs a template type, like Matador::identifier. Give it a try and let me know if it works.

dragon-dan commented 1 year ago

感谢你的建议,尝试了一下似乎不行,person结构体是从文档示例复制过来的,文档上没有看到id用到了什么模板类型.

struct person
{
    //matador::identifier<long> id;
    long id;
    std::string name;
    int age;

    person() = default;
    person(long i, std::string n, int a)
        : id(i), name(std::move(n)), age(a)
    {}

    template < class SERIALIZER >
    void serialize(SERIALIZER& serializer)
    {
        serializer.serialize("id", id);
        serializer.serialize("name", name);
        serializer.serialize("age", age);
    }
};

我尝试改成这样,依然不能通过编译,报错为【错误 C2039 "type": 不是 "std" 的成员】。 然后看了几遍文档并没有找到有关于结构体字段设计的特殊说明,嗯,现在有点不知道该怎么弄了

zussel commented 1 year ago

How did you provide matatdor? Did you compile it or have you installed it with installer package?

I can compile and start your program. But under linux.

dragon-dan commented 1 year ago

image 目前所有的使用环境只有windows,如图使用cmake和VS2019编译matador源码得到一些dll和lib文件,学习使用的时候我更据情况在代码中用#pragma comment引入可能需要的lib文件,编译后放在dll文件夹中运行。

测试json功能,编译运行都很正常,然后尝试读取数据库就不能成功,只要引入了

#include "matador/orm/persistence.hpp"
#include "matador/orm/session.hpp"

哪怕不编写任何相关的代码都不能编译通过,删除这两个include和相关代码,立马正常了。

嗯,目前就是这个情况,因为需要读写数据库,根据文档来看matador用起来会很优雅很酷,如果windows环境不能使用实在是太遗憾了 (PS:目前开发环境全都用的MSVC,所以还没有用g++尝试过)

zussel commented 1 year ago

Sorry, that you face these problems using matador under windows. I'll try to find a solution for you.

Meanwhile try to use the windows installer for version 0.8.0. Then create a clean cmake VS project and use the FindMatador.cmake and FindMatadorBackendPostgreSQL.cmake files from the cmake sub directory in the repo to let cmake find the needed matador libraries. I hope I can come up with a cmake based matador startup project soon.

dragon-dan commented 1 year ago

好的,热情的作者,非常感谢,我回头会去尝试下0.8.0的版本。

还有两个小问题想问一下: 1.目前会得到动态库文件(dll/so),可执行文件必须依赖这个,是否能支持全静态连接生成独立可执行程序,不依赖动态库。 2.文档上数据库这部分介绍的不多,那个数据库connection用连接池管理起来程序是否会有更好的性能(matador有没有可用的数据库连接池)

zussel commented 1 year ago

Let me know how it worked out with version 0.8.0!

1.目前会得到动态库文件(dll/so),可执行文件必须依赖这个,是否能支持全静态连接生成独立可执行程序,不依赖动态库。 There is a very old Ticket #59 which address this issue. I would like to provide a static version of matatdor in a future release. I cann see the advantages of that!

2.文档上数据库这部分介绍的不多,那个数据库connection用连接池管理起来程序是否会有更好的性能(matador有没有可用的数据库连接池) Currently there is no database connection pool. But I'm planning to add one.

Please keep in mind that there are so many cool features I'ld like to implement, but I'm the only developer ;-) So it takes some time to get it done.

dragon-dan commented 1 year ago

我尝试安装了0.8.0版本的安装包,然后把项目依赖切换到0.8.0版本的目录,编译不通过,报错情况和0.8.1版本一模一样

zussel commented 1 year ago

Thanks for the information! I figured out, that there is also a problem with the windows installer. So, I decided to fix this, provide static libraries and add a proper cmake starter project.

Could you tell me, if you setup a VS project or started with a cmake project?

dragon-dan commented 1 year ago

VS和cmake都会使用,自己学习的时候会使用VS创建空工程,添加相关依赖然后编写代码测试和学习(我觉得这样比较快,也比较顺手)。学习整理完成之后,如果想留下模板项目供自己以后方便使用,就会用cmake写一个