U1db.Database
The Database class implements on-disk storage for documents and indexes. More...
Header: | #include <Database> |
Instantiated By: | Database |
Inherits: |
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) |
Detailed Description
The Database class implements on-disk storage for documents and indexes.
Database can be used as a QAbstractListModel, delegates will then have access to docId and contents analogous to the properties of Document.
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
QString Database::getPath()
Returns the path of the database.
QString Database::lastError()
The last error as a string if the last operation failed.
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.
void Database::setPath(const QString & path)
A relative path 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 or local file URIs can be used. By default or if the path is empty everything is stored in memory.