Giter Site home page Giter Site logo

qtdao's Introduction

qt database object library

这是一个数据库查询与对象转换的操作库,支持基本增删改查操作,它能简单的将查询结果转换为定义好的类实例,基本原理是通过代码生成器和模板配合进行转换,下面是一个简单的示例展示了如何查询一个结果

Test1::Fields sf1;
Test1 d1 = dao::_select<Test1>()
        .filter(sf1.name == "client", _or(sf1.number == 12, sf1.name == "bob"))
        .build().one();

等价于下面的sql语句:

select *from test1 where name='client' and (number=12 or name='bob')

下面是当前受支持的数据库

  • sqlite
  • mysql
  • sqlserver

如何使用

打开工程(QtDao.sln/qtdao.pro/CMakeLists.txt)使用当前qt5库编译生成静态库(qtdao.lib),使用步骤看这

  • CMake中配置qtdao
#添加qtdao库子项目
add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/qtdao/src)

#添加entity文件列表,entity.cmake由vscode-qtdao插件自动生成
include(${CMAKE_CURRENT_SOURCE_DIR}/entity/entity.cmake)

#...
add_executable(${PROJECT_NAME} WIN32 
    #...

    #添加数据库连接配置文件
    entity/sqliteconfig.h
    #添加entity文件列表,此变量由entity.cmake提供
    ${ENTITY_FILE_LIST}
)

target_link_libraries(${PROJECT_NAME}
    #...

    #静态链接到qtdao库
    qtdao::lib
)

支持的功能

  • 数据库初始化
    • 检查连接
    • 自动创建数据库/数据表
    • 检查版本并升级
  • 日志
    • 打印执行的sql语句
    • 打印执行的sql值列表
  • 连接池
    • 多线程查询
    • 连接名复用
  • 查询
    • insert(demo)
      • 对象(/批量)插入
      • 部分值插入
      • 插入或替换(insert or replace)
      • 使用查询结果插入(insert into select)
    • select(demo)
      • 对象查询
      • 联合(union)
      • join
      • 递归查询(recursive)(mysql)
      • 子查询(嵌套查询)
      • 自定义语句查询
      • 计数(count)
    • update(demo)
      • 条件更新
      • 对象(/批量)更新
    • delete(demo)
      • 条件删除
      • 对象(/批量)删除
    • 其他
      • 事务
      • 解释
      • sqlite写同步

qtdao's People

Contributors

daonvshu avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.