Repository navigation
Expand file tree
/
Copy pathNitroSQLiteOperations.hpp
More file actions
73 lines (55 loc) · 3.52 KB
/
Copy pathNitroSQLiteOperations.hpp
File metadata and controls
73 lines (55 loc) · 3.52 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "NitroSQLiteDatabaseConnections.hpp"
#include "NitroSQLiteQueryResult.hpp"
#include "sqlite/sqlite3.h"
#include <functional>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
namespace margelo::nitro::rnnitrosqlite {
/** Open the default connection by database name. Read-only mode requires an existing file. */
void sqliteOpenDb(DatabaseConnections& connections, const std::string& dbName, const std::string& docPath, bool readOnly,
const std::optional<std::string>& encryptionKey);
/** Open a separate native handle and return its opaque connection ID. */
std::string sqliteOpenConnection(DatabaseConnections& connections, const std::string& dbName, const std::string& docPath, bool readOnly,
const std::optional<std::string>& encryptionKey);
/** Prepared SQL statement bound to one native connection. */
class SQLitePreparedStatement {
public:
~SQLitePreparedStatement();
/** Reset and execute with new bindings. Throws after finalization or connection closure. */
NitroSQLiteQueryResult execute(const std::optional<SQLiteQueryParams>& params);
/** Release the native statement. Repeated calls are safe. */
void finalize();
/** Check whether the native statement has been released. */
bool isFinalized() const;
/** Report this object's native memory size to the Nitro runtime. */
size_t getExternalMemorySize() const noexcept;
private:
struct State;
explicit SQLitePreparedStatement(std::shared_ptr<State> state);
std::shared_ptr<State> _state;
friend std::shared_ptr<SQLitePreparedStatement> sqlitePrepare(const SQLiteConnectionPtr& connection, const std::string& query);
};
/** Delete a database, optionally closing its independent connection first. */
void sqliteRemoveDb(DatabaseConnections& connections, const std::string& dbName, const std::string& docPath,
const std::optional<std::string>& connectionId = std::nullopt,
const std::optional<std::string>& otherDocPath = std::nullopt);
void sqliteAttachDb(const SQLiteConnectionPtr& connection, const std::string& docPath, const std::string& databaseToAttach,
const std::string& alias);
void sqliteDetachDb(const SQLiteConnectionPtr& connection, const std::string& alias);
/** Execute one statement. With @p onRows, full batches of rows go to it as they are read and the
* returned result holds only the rows after the last batch. Its rowBatchCount reports how many
* batches were sent; JavaScript delivery may still be pending when this function returns.
*/
NitroSQLiteQueryResult sqliteExecute(const SQLiteConnectionPtr& connection, const std::string& query,
const std::optional<SQLiteQueryParams>& params, const SQLiteRowBatchHandler& onRows = nullptr);
SQLiteOperationResult sqliteExecuteCommand(const SQLiteConnectionPtr& connection, const std::string& query,
const std::optional<SQLiteQueryParams>& params = std::nullopt);
/** Execute one SQL statement for each parameter set, preparing it once. */
SQLiteOperationResult sqliteExecuteCommandGroup(const SQLiteConnectionPtr& connection, const std::string& query,
const std::vector<SQLiteQueryParams>& parameterSets);
/** Prepare one SQL statement on an open default or independent connection. */
std::shared_ptr<SQLitePreparedStatement> sqlitePrepare(const SQLiteConnectionPtr& connection, const std::string& query);
} // namespace margelo::nitro::rnnitrosqlite