Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .qmlls.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[General]
buildDir="/Users/enokas/WorkStation/01STUDIO/BMASTER/build"
no-cmake-calls=false
docDir=/Users/enokas/Qt/Docs/Qt-6.9.0
importPaths="/Users/enokas/Qt/6.9.0/macos/qml"
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
project(PocketBase LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 COMPONENTS Network Core Quick REQUIRED)
Expand All @@ -17,11 +17,6 @@ qt6_add_qml_module(PocketBase
SOURCES src/PocketBase.hpp
SOURCES src/PocketBaseCollection.h src/PocketBaseCollection.cpp
SOURCES src/PocketBaseCollectionPromise.h src/PocketBaseCollectionPromise.cpp
SOURCES src/PocketBaseCollectionSchema.h src/PocketBaseCollectionSchema.cpp
SOURCES src/PocketBaseCollectionField.h src/PocketBaseCollectionField.cpp
SOURCES src/CollectionFieldOptions.h src/CollectionFieldOptions.cpp
SOURCES src/CollectionTextFieldOptions.h src/CollectionTextFieldOptions.cpp
SOURCES src/CollectionFileFieldOptions.h src/CollectionFileFieldOptions.cpp
SOURCES src/PocketBaseClient.h src/PocketBaseClient.cpp
SOURCES src/PocketRequest.h src/PocketRequest.cpp
SOURCES src/PocketUtility.h src/PocketUtility.cpp
Expand Down
4 changes: 2 additions & 2 deletions Collection.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QtQuick
import PocketBase
import QtQuick 6.10
import PocketBase 1.0

BaseCollection {
id: collection
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
![](https://camo.githubusercontent.com/45afc34faad79c9a4591c3ec02a3e98ec3e99b0e1c8a6fbbf11b6ea8f402fdf6/68747470733a2f2f692e696d6775722e636f6d2f3571696d6e6d352e706e67)

# QtPocketBase
PocketBase Client for Qt/Qml
PocketBase client library for QML and C++.

This version targets Qt 6.10 and requires a C++20 capable compiler.
6 changes: 3 additions & 3 deletions src/CollectionSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void CollectionSubscriber::connect()
// manager->setTransferTimeout(2000);
QNetworkReply *reply = manager->get(subscriptionRequest);

QObject::connect(reply, &QNetworkReply::readyRead, this, [=]() {
QObject::connect(reply, &QNetworkReply::readyRead, this, [reply, this]() {
QString data = reply->readAll();

// If we see "clientId", parse out the ID if possible
Expand Down Expand Up @@ -158,7 +158,7 @@ void CollectionSubscriber::connect()
// qDebug() << "Error: " << data;
});

QObject::connect(reply, &QNetworkReply::finished, this, [=]() {
QObject::connect(reply, &QNetworkReply::finished, this, [reply, this]() {
reply->deleteLater();
connect();
});
Expand Down Expand Up @@ -188,7 +188,7 @@ void CollectionSubscriber::sub(QString topic, bool all)
QJsonDocument doc(json);
// qDebug () << "Sending subscription request" << doc.toJson();
QNetworkReply *subReply = manager->post(request, doc.toJson());
QObject::connect(subReply, &QNetworkReply::finished, this, [=]()
QObject::connect(subReply, &QNetworkReply::finished, this, [subReply, this]()
{
int statusCode = subReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString data = subReply->readAll();
Expand Down
12 changes: 1 addition & 11 deletions src/PocketBase.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
#include "CollectionSubscriber.h"
#include "PocketBaseCollection.h"
#include "PocketBaseCollectionField.h"
#include "PocketBaseCollectionSchema.h"
#include "CollectionFileFieldOptions.h"
#include "CollectionFieldOptions.h"
#include "CollectionTextFieldOptions.h"
#include "PocketBaseClient.h"
#include "PocketBaseServer.h"
#include <QtQml>

void registerPocketBaseType() {
qmlRegisterType<PocketBaseCollection>("PocketBase", 1, 0, "BaseCollection");
qmlRegisterType<PocketBaseCollectionField>("PocketBase", 1, 0, "CollectionField");
qmlRegisterType<PocketBaseCollectionSchema>("PocketBase", 1, 0, "CollectionSchema");
qmlRegisterType<CollectionFileFieldOptions>("PocketBase", 1, 0, "FileFieldOptions");
qmlRegisterType<CollectionTextFieldOptions>("PocketBase", 1, 0, "TextFieldOptions");
// qmlRegisterType<PocketBaseCollection>("PocketBase", 1, 0, "BaseCollection");
qmlRegisterSingletonType<PocketRequest>("PocketBase", 1, 0, "PocketRequest", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new PocketRequest();
});

qmlRegisterType<CollectionSubscriber>("PocketBase", 1, 0, "Subscriber");
qmlRegisterUncreatableType<CollectionFieldOptions>("PocketBase", 1, 0, "FieldOptions", "FieldOptions is an abstract class");

qmlRegisterSingletonType<PocketBaseClient>("PocketBase", 1, 0, "PocketBaseClient", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
Q_UNUSED(engine)
Expand Down
18 changes: 9 additions & 9 deletions src/PocketBaseClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ PocketBaseClient::PocketBaseClient(QObject *parent)
QObject::connect(subscriber, &CollectionSubscriber::connectedChanged, this, [this]()
{ setConnected(subscriber->connected()); });

QTimer *timer = new QTimer(this);
QObject::connect(timer, &QTimer::timeout, this, [=]()
{ isHealthy(); });
QTimer *timer = new QTimer(this);
QObject::connect(timer, &QTimer::timeout, this, [this]()
{ isHealthy(); });

timer->start(800);
isHealthy();
Expand Down Expand Up @@ -120,8 +120,8 @@ PocketBaseCollectionPromise *PocketBaseClient::authAdminWithPassword(QString ide
{
request.setRoute("/admins/auth-with-password");
PocketBaseCollectionPromise *promise = request.authWithPassword(identity, password);
QObject::connect(promise, &PocketBaseCollectionPromise::onThen, this, [=](QJSValueList response)
{
QObject::connect(promise, &PocketBaseCollectionPromise::onThen, this, [this](QJSValueList response)
{
QJsonObject data = QJsonDocument::fromJson(QByteArray::fromStdString(response.toList().at(0).toString().toStdString())).object();
setAuthToken(data.value("token").toString()); });
return promise;
Expand All @@ -131,8 +131,8 @@ PocketBaseCollectionPromise *PocketBaseClient::authWithCollection(QString collec
{
request.setRoute("/collections/" + collectionName + "/auth-with-password");
PocketBaseCollectionPromise *promise = request.authWithPassword(identity, password);
QObject::connect(promise, &PocketBaseCollectionPromise::onThen, this, [=](QJSValueList response)
{
QObject::connect(promise, &PocketBaseCollectionPromise::onThen, this, [this](QJSValueList response)
{
QJsonObject data = QJsonDocument::fromJson(QByteArray::fromStdString(response.toList().at(0).toString().toStdString())).object();
setAuthToken(data.value("token").toString()); });
return promise;
Expand All @@ -142,8 +142,8 @@ PocketBaseCollectionPromise *PocketBaseClient::authRefreshCollection(QString col
{
request.setRoute("/collections/" + collectionName + "/auth-refresh");
PocketBaseCollectionPromise *promise = request.authRefresh();
QObject::connect(promise, &PocketBaseCollectionPromise::onThen, this, [=](QJSValueList response)
{
QObject::connect(promise, &PocketBaseCollectionPromise::onThen, this, [this](QJSValueList response)
{
QJsonObject data = QJsonDocument::fromJson(QByteArray::fromStdString(response.toList().at(0).toString().toStdString())).object();
setAuthToken(data.value("token").toString()); });
return promise;
Expand Down
30 changes: 15 additions & 15 deletions src/PocketBaseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ class PocketBaseClient : public QObject
explicit PocketBaseClient(QObject *parent = nullptr);

Q_INVOKABLE void addCollection(PocketBaseCollection *collection);
Q_INVOKABLE PocketBaseCollectionPromise *updateCollection(QString collectionId, PocketBaseCollection *updateCollection);
Q_INVOKABLE PocketBaseCollectionPromise *createCollection(QJSValue data);
Q_INVOKABLE PocketBaseCollectionPromise *deleteCollection(QString collectionId);
Q_INVOKABLE PocketBaseCollectionPromise *getCollection(QString collectionId);
Q_INVOKABLE PocketBaseCollectionPromise *importCollection(QJSValue json);
Q_INVOKABLE PocketBaseCollectionPromise *update(QString collectionName, QString id, QJSValue data, QJSValue options = {});
Q_INVOKABLE PocketBaseCollectionPromise *getCollections();
Q_INVOKABLE PocketBaseCollectionPromise *isHealthy();

Q_INVOKABLE PocketBaseCollection *collection(const QString &collectionName);

Q_INVOKABLE PocketBaseCollectionPromise *authAdminWithPassword(QString identity, QString password);
Q_INVOKABLE PocketBaseCollectionPromise *authWithCollection(QString collectionName, QString identity, QString password);
Q_INVOKABLE PocketBaseCollectionPromise *authRefreshCollection(QString collectionName);
Q_INVOKABLE PocketBaseCollectionPromise *createNewAdmin(QString email, QString identity, QString password);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *updateCollection(QString collectionId, PocketBaseCollection *updateCollection);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *createCollection(QJSValue data);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *deleteCollection(QString collectionId);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *getCollection(QString collectionId);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *importCollection(QJSValue json);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *update(QString collectionName, QString id, QJSValue data, QJSValue options = {});
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *getCollections();
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *isHealthy();

[[nodiscard]] Q_INVOKABLE PocketBaseCollection *collection(const QString &collectionName);

[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *authAdminWithPassword(QString identity, QString password);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *authWithCollection(QString collectionName, QString identity, QString password);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *authRefreshCollection(QString collectionName);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *createNewAdmin(QString email, QString identity, QString password);

// Q_INVOKABLE QString getFileUrl(QString fileId);

Expand Down
42 changes: 1 addition & 41 deletions src/PocketBaseCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,7 @@ QJsonObject PocketBaseCollection::getOptions(QJSValue options)

void PocketBaseCollection::prepare()
{
PocketBaseCollectionSchema *schema = findChild<PocketBaseCollectionSchema*>();
QJsonObject collectionSchema = {};
collectionSchema["schema"] = schema->schemaJson();
collectionSchema["name"] = schema->name();
collectionSchema["type"] = "base";
collectionSchema["indexes"] = QJsonArray();
collectionSchema["listRule"] = schema->listRule();
collectionSchema["viewRule"] = schema->viewRule();
collectionSchema["createRule"] = schema->createRule();
collectionSchema["updateRule"] = schema->updateRule();
collectionSchema["deleteRule"] = schema->deleteRule();
collectionSchema["id"] = schema->collectionId();
collectionSchema["options"] = QJsonObject();

}


Expand Down Expand Up @@ -172,18 +160,6 @@ void PocketBaseCollection::setName(const QString &newName)
emit nameChanged();
}

PocketBaseCollectionSchema *PocketBaseCollection::schema() const
{
return m_schema;
}

void PocketBaseCollection::setSchema(PocketBaseCollectionSchema *newSchema)
{
if (m_schema == newSchema)
return;
m_schema = newSchema;
emit schemaChanged();
}

PocketRequest *PocketBaseCollection::getRequest() const
{
Expand All @@ -192,21 +168,5 @@ PocketRequest *PocketBaseCollection::getRequest() const

QJsonObject PocketBaseCollection::toJson()
{
if (m_schema) {
PocketBaseCollectionSchema *schema = findChild<PocketBaseCollectionSchema*>();
QJsonObject collectionSchema = {};
collectionSchema["schema"] = schema->schemaJson();
collectionSchema["name"] = schema->name();
collectionSchema["type"] = "base";
collectionSchema["indexes"] = QJsonArray();
collectionSchema["listRule"] = schema->listRule();
collectionSchema["viewRule"] = schema->viewRule();
collectionSchema["createRule"] = schema->createRule();
collectionSchema["updateRule"] = schema->updateRule();
collectionSchema["deleteRule"] = schema->deleteRule();
collectionSchema["id"] = schema->collectionId();
collectionSchema["options"] = QJsonObject();
return collectionSchema;
}
return QJsonObject();
}
40 changes: 18 additions & 22 deletions src/PocketBaseCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ class PocketBaseCollection : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_NAMED_ELEMENT(BaseCollection)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
Q_PROPERTY(QString expands READ expands WRITE setExpands NOTIFY expandChangeds FINAL)
Q_PROPERTY(QStringList fields READ fields WRITE setFields NOTIFY fieldsChanged FINAL)

Q_PROPERTY(PocketBaseCollectionSchema *schema READ schema WRITE setSchema NOTIFY schemaChanged FINAL)

public:
explicit PocketBaseCollection(QObject *parent = nullptr);

Q_INVOKABLE PocketBaseCollectionPromise *getOne(QString id, QJSValue options = {});
Q_INVOKABLE PocketBaseCollectionPromise *getList(int page = 1, int perPage = 15, QJSValue options = {});
Q_INVOKABLE PocketBaseCollectionPromise *create(QJSValue data);
Q_INVOKABLE PocketBaseCollectionPromise *create(QString data);
Q_INVOKABLE PocketBaseCollectionPromise *createWithFile(QJSValue data,
QJSValue files);
Q_INVOKABLE PocketBaseCollectionPromise *update(QString id, QJSValue data, QJSValue options = {});
Q_INVOKABLE PocketBaseCollectionPromise *updateWithFile(QString id, QJSValue data,
QJSValue files);
Q_INVOKABLE PocketBaseCollectionPromise *deleteFile(QString id, QJSValue files);
Q_INVOKABLE PocketBaseCollectionPromise *deleteOne(QString id);

Q_INVOKABLE PocketBaseCollectionPromise *getViewList(QString view, int page = 1, int perPage = 15, QJSValue options = {});
Q_INVOKABLE PocketBaseCollectionPromise *getViewOne(QString view, QString id, QJSValue options = {});
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *getOne(QString id, QJSValue options = {});
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *getList(int page = 1, int perPage = 15, QJSValue options = {});
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *create(QJSValue data);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *create(QString data);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *createWithFile(QJSValue data,
QJSValue files);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *update(QString id, QJSValue data, QJSValue options = {});
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *updateWithFile(QString id, QJSValue data,
QJSValue files);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *deleteFile(QString id, QJSValue files);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *deleteOne(QString id);

[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *getViewList(QString view, int page = 1, int perPage = 15, QJSValue options = {});
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *getViewOne(QString view, QString id, QJSValue options = {});

Q_INVOKABLE QString getFileUrl(QString fileId, QString fileName);

Q_INVOKABLE PocketBaseCollectionPromise *send(QString path, QString method, QJSValue data = {}, QJSValue options = {});
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise *send(QString path, QString method, QJSValue data = {}, QJSValue options = {});

QJsonObject getOptions(QJSValue options = {});
Q_INVOKABLE void prepare();
Expand All @@ -57,12 +57,9 @@ class PocketBaseCollection : public QObject
QString name() const;
void setName(const QString &newName);

PocketBaseCollectionSchema *schema() const;
void setSchema(PocketBaseCollectionSchema *newSchema);
[[nodiscard]] PocketRequest *getRequest() const;

PocketRequest *getRequest() const;

QJsonObject toJson();
QJsonObject toJson();

private:
QString m_name;
Expand All @@ -79,7 +76,6 @@ class PocketBaseCollection : public QObject
PocketRequest *viewRequest;


PocketBaseCollectionSchema *m_schema = nullptr;

signals:
void expandChangeds();
Expand Down
16 changes: 8 additions & 8 deletions src/PocketBaseCollectionPromise.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ class PocketBaseCollectionPromise : public QObject
public:
explicit PocketBaseCollectionPromise(QObject *parent = nullptr);

Q_INVOKABLE PocketBaseCollectionPromise * then(QJSValue callback);
Q_INVOKABLE PocketBaseCollectionPromise * error(QJSValue callback);
Q_INVOKABLE PocketBaseCollectionPromise * progress(QJSValue callback);
Q_INVOKABLE PocketBaseCollectionPromise * finally(QJSValue callback);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise * then(QJSValue callback);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise * error(QJSValue callback);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise * progress(QJSValue callback);
[[nodiscard]] Q_INVOKABLE PocketBaseCollectionPromise * finally(QJSValue callback);


QJSValue getThen() const;
QJSValue getError() const;
QJSValue getProgress() const;
QJSValue getFinally() const;
[[nodiscard]] QJSValue getThen() const;
[[nodiscard]] QJSValue getError() const;
[[nodiscard]] QJSValue getProgress() const;
[[nodiscard]] QJSValue getFinally() const;

void callThen(QJSValueList args);
void callError(QJSValueList args);
Expand Down
Loading