• Database
  • Database Class

    The Database class implements the on-disk storage of an individual U1DB database. More...

    Header: #include <Database>
    Inherits:

    Properties

    Public Functions

    Database(QObject * parent = 0)
    void deleteDoc(const QString & docId)
    QVariant getDoc(const QString & docId)
    QVariant getDocUnchecked(const QString & docId) const
    QStringList getIndexExpressions(const QString & indexName)
    QStringList getIndexKeys(const QString & indexName)
    QString getPath()
    QString lastError()
    QList<QString> listDocs()
    QString putDoc(QVariant contents, const QString & docId = QString())
    QString putIndex(const QString & indexName, QStringList expressions)
    void resetModel()
    void setPath(const QString & path)

    Signals

    void errorChanged(const QString & error)
    void pathChanged(const QString & path)

    Detailed Description

    The Database class implements the on-disk storage of an individual U1DB database.

    Database can be used as a QAbstractListModel, delegates will then have access to docId and contents analogous to the properties of Document.

    Property Documentation

    error : const QString

    The last error as a string if the last operation failed.

    Access functions:

    QString lastError()

    Notifier signal:

    void errorChanged(const QString & error)

    path : QString

    A relative filename can be given to store the database in an app-specific writable folder. This is recommended as it ensures to work with confinement. If more control is needed absolute paths can be used. By default everything is stored in memory.

    Access functions:

    QString getPath()
    void setPath(const QString & path)

    Notifier signal:

    void pathChanged(const QString & path)

    Member Function Documentation

    Database::​Database(QObject * parent = 0)

    Instantiate a new Database with an optional parent, usually by declaring it as a QML item.

    void Database::​deleteDoc(const QString & docId)

    Deletes the document identified by docId.

    QVariant Database::​getDoc(const QString & docId)

    Returns the contents of a document by docId in a form that QML recognizes as a Variant object, it's identical to Document::getContents() with the same docId.

    QVariant Database::​getDocUnchecked(const QString & docId) const

    Same functionality as Database::getDoc() except it won't set Database::lastError() and it doesn't implicitly try to initialize the underlying database. docId must be a valid unique ID string Use cases: model implementations, Document::getContents()

    QStringList Database::​getIndexExpressions(const QString & indexName)

    Gets the expressions saved with putIndex(). indexName: the unique name of an existing index

    QStringList Database::​getIndexKeys(const QString & indexName)

    Lists the index keys of an index created with putIndex(). indexName: the unique name of an existing index

    QList<QString> Database::​listDocs()

    Returns a list of all stored documents by their docId.

    QString Database::​putDoc(QVariant contents, const QString & docId = QString())

    Updates the existing contents of the document identified by docId if there's no error. If no docId is given or docId is an empty string the contents will be stored under an autogenerated name. Returns the new revision of the document, or -1 on failure.

    QString Database::​putIndex(const QString & indexName, QStringList expressions)

    Stores a new index under the given indexName, with expressions. An existing index won't be replaced implicitly, an error will be set in that case.

    void Database::​resetModel()

    Database::resetModel

    Resets the Database model.