GithubHelp home page GithubHelp logo

tinytinni / qtduckdbdriver Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 172 KB

Qt Driver Plugin for DuckDB ๐Ÿฆ†

License: GNU Lesser General Public License v3.0

CMake 54.79% C++ 45.21%
duckdb qt qt6 qt5

qtduckdbdriver's Introduction

image A DuckDB Driver Plugin for Qt

CMake
Implements a driver plugin for Qt's SQL Databases for DuckDB.
Just copy the .dll/.so to your Qt plugin file and you can add a "DUCKDB" database at any time. No other dependencies are required. You can use the full capabilities of DuckDB in your Qt program.

It also enables you to use duckdb in an easy way with Qt and Qt widgets, see the example below.

Exmaple for creating a in memory database:

QSqlDatabase db = QSqlDatabase::addDatabase("DUCKDB");
db.setDatabaseName("test.db"); // creates a persistent database file "test.db"
db.open(); 
db.exec("CREATE TABLE employee (Name VARCHAR, Salary INTEGER);");

You can also use it to load csv or parquet (if duckdb was compiled with parquet support) files:

QSqlDatabase db = QSqlDatabase::addDatabase("DUCKDB");
db.open(); // no database name given -> creates a in-memory database
db.exec("CREATE TABLE new_tbl AS SELECT * FROM read_csv_auto('my_csv.csv');");

Example

In order to show a widget with a Sql content, you can use QSqlTableModel.

Here is an example on how to use the built-in Qt widget to show the contents of a DuckDB database in a grid widget

QSqlDatabase db = QSqlDatabase::addDatabase("DUCKDB");

db.open();
QSqlQuery query(db);
query.exec("CREATE TABLE employee (Name VARCHAR, Salary INTEGER);");
query.exec("INSERT INTO employee VALUES ('Paul', 5000);");
query.exec("INSERT INTO employee VALUES ('Bert', 5500);");
query.exec("INSERT INTO employee VALUES ('Tina', 6500);");

QSqlTableModel *model = new QSqlTableModel(nullptr, db);
model->setTable("employee");
model->select();

QTableView *view = new QTableView;
view->setModel(model);
view->show();

Which results in the following widget:

Full example can be found in the example directory

Build requirements

DuckDB will be linked statically.

For pre-build dlls, please choose the right version (See Qt Doc about plugin version)
tl;dr: don't use the plugin on Qt version below the version it was build for.

You can manually select the Qt Version with the cmake variable QT_VERSION== 5 or == 6. Otherwise, the auto detection will select the highest version.

Prebuild MSVC DLL in the artifacts

Github Actions will offer a MSVC DLL in the artifacts.

The artifact might be expired, but you can just fork this project and start the action on your own. This DLL in the qt plugin directory is all you need to use it, but I would also recommend the header, when you want to have direct access to the DuckDB C++ API.

License

LGPL v3

Based on Qt's sqlite driver code, which is licensed under the LGPL v3.
Based on DuckDB under the MIT license.

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.