summaryrefslogtreecommitdiffstats
path: root/store/database.h
blob: e752ff50551332b608b880e50f39bd759b598f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once

#include <string>
#include <QString>

class Database {
public:
    enum TransactionType { ReadOnly, ReadWrite };

    Database(const QString &storageRoot, const QString &name);
    ~Database();
    bool isInTransaction() const;
    bool startTransaction(TransactionType type = ReadWrite);
    bool commitTransaction();
    void abortTransaction();
    bool write(const char *key, size_t keySize, const char *value, size_t valueSize);
    bool write(const std::string &sKey, const std::string &sValue);
    //Perhaps prefer iterators (assuming we need to be able to match multiple values
    void read(const std::string &sKey, const std::function<void(const std::string &value)> &);
    void read(const std::string &sKey, const std::function<void(void *ptr, int size)> &);

    qint64 diskUsage() const;
    void removeFromDisk() const;
private:
    class Private;
    Private * const d;
};