larpon / QtFirebase

An effort to bring Google's Firebase C++ API to Qt + QML
MIT License
284 stars 83 forks source link

Cloud Storage #142

Closed shariatraad closed 4 years ago

shariatraad commented 4 years ago

Is QtFirebase Cloud Storage still unavailable for c++? And I also noticed that real-time database is partially available. What functions are still not accessible?

shariatraad commented 4 years ago

A simple way to use Qtfirebase Real-time data base is this

1) Add a child named "tests" to your Database/Data in firebase consul.

2) Change your Database/Rules (Json file) in your firebase consul to :

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {
    ".read": true,
    ".write": true
  }
}

3) In your .h file include:

    QAndroidJniEnvironment *_jniEnv;
    ::firebase::App* _app;
    ::firebase::ModuleInitializer _initializer;
    QAndroidJniObject _jniObj;
    firebase::database::Database *database;

4) In your .cpp file include:

    _jniEnv = new QAndroidJniEnvironment();
    QAndroidJniObject jniObject = QtAndroid::androidActivity();
    ::firebase::App *instance = ::firebase::App::GetInstance();

    if (instance) {
        qDebug() << "instance already exists";
        _app = instance;
    } else {
        qDebug() << "Creating instance";
        jniObject = QtAndroid::androidActivity();
        _app = ::firebase::App::Create(*_jniEnv, jniObject.object<jobject>());
    }
    database=firebase::database::Database::GetInstance(_app);
    firebase::database::DatabaseReference dbref = database->GetReferenceFromUrl("Enter Your Real-time Database URL Here");

    dbref.Child("tests").SetValue(Add Your Custom Value Here);
shariatraad commented 4 years ago

(But I still wonder if there is a way to use Qtfirebase Cloud Storage and what functions are unavailable for Real-time Database)

larpon commented 4 years ago

Hi! Thanks for your interest!

Is QtFirebase Cloud Storage still unavailable for c++?

Yes, I'm currently unaware of the status. Maybe @Furkanzmc can give you more information on the status. If it's abandoned you're welcome to contribute an implementation!

And I also noticed that real-time database is partially available. What functions are still not accessible?

Correct. It need to be expanded further to cover the complete API. Pull requests are welcome! A quick grep through the code base for db:: (namespace db = ::firebase::database). Reveals this list of calls used:

qtfirebasedatabase.cpp
26:        m_db = db::Database::GetInstance(qFirebase->firebaseApp());

qtfirebasedatabase.h
67:    firebase::database::Database* m_db;
192:    firebase::database::DatabaseReference m_dbRef;

qtfirebasedatabase.cpp
10:    , m_db(nullptr)
26:        m_db = db::Database::GetInstance(qFirebase->firebaseApp());
230:            m_dbRef = qFirebaseDatabase->m_db->GetReference().GetRoot();
234:            m_dbRef = qFirebaseDatabase->m_db->GetReference().GetRoot().Child(path.toUtf8().constData());
244:        m_pushChildKey = m_dbRef.PushChild().key();
255:        firebase::Future<void> future = m_dbRef.RemoveValue();
268:            m_dbRef = m_dbRef.Child(m_pushChildKey.toUtf8().constData());
270:        firebase::Future<void> future = m_dbRef.SetValue(QtFirebaseService::fromQtVariant(value));
289:            firebase::Future<firebase::database::DataSnapshot> future = m_dbRef.GetValue();
302:    firebase::Future<void> future = qFirebaseDatabase->m_db->GetReference().UpdateChildren(vfb);
385:        m_query.setQuery(m_dbRef.OrderByKey());
392:        m_query.setQuery(m_dbRef.OrderByValue());
399:        m_query.setQuery(m_dbRef.OrderByChild(path.toUtf8().constData()));
406:        m_query.setQuery(m_dbRef.OrderByPriority());
413:        m_query.setQuery(m_dbRef.StartAt(QtFirebaseService::fromQtVariant(order_value)));
421:        m_query.setQuery(m_dbRef.StartAt(QtFirebaseService::fromQtVariant(order_value), child_key.toUtf8().constData()));
428:        m_query.setQuery(m_dbRef.EndAt(QtFirebaseService::fromQtVariant(order_value)));
435:        m_query.setQuery(m_dbRef.EndAt(QtFirebaseService::fromQtVariant(order_value), child_key.toUtf8().constData()));
442:        m_query.setQuery(m_dbRef.EqualTo(QtFirebaseService::fromQtVariant(order_value)));
449:        m_query.setQuery(m_dbRef.EqualTo(QtFirebaseService::fromQtVariant(order_value), child_key.toUtf8().constData()));
456:        m_query.setQuery(m_dbRef.LimitToFirst(limit));
463:                m_query.setQuery(m_dbRef.LimitToLast(limit));

So the API calls not available, are the ones missing from this list plus what's not present in qtfirebasedatabase.h. I remember another issue where some of the missing functionality at the time was also mentioned. So you'll have to do some investigation to find out the exact missing calls I guess.

Thanks for the quick example - much obliged!

(But I still wonder if there is a way to use Qtfirebase Cloud Storage ...)

There is only a way to use Cloud Storage through QtFirebase if someone contributes a wrap of storage.h - It looks pretty straight forward at first glance. I would be very cool to have it contributed! ... Untill then you're stuck with using it straight from the Firebase C++ SDK as provided by Google

shariatraad commented 4 years ago

@Larpon Hello Larpon. Thank you so much for your time and the detailed answer. It is all clear now! :) If I come up with a wrapper or find something helpful I will share it with you.
The example I provided is the most basic one just to make sure if you are successfully connected to the database. Thought it might be helpful for some beginners.

larpon commented 4 years ago

@shariatraad no problem - thanks for showing your interest in the project! People tend to contribute just wrappers for what they need on a per project basis - so that's why some of the larger components are missing features. So we expand only when people need the functionality - and are kind enough to contribute code back :)