-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathHybridNitroSQLite.cpp
More file actions
100 lines (81 loc) · 3.86 KB
/
HybridNitroSQLite.cpp
File metadata and controls
100 lines (81 loc) · 3.86 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "HybridNitroSQLite.hpp"
#include "HybridNativeQueryResult.hpp"
#include "NitroSQLiteException.hpp"
#include "logs.hpp"
#include "macros.hpp"
#include "sqliteExecuteBatch.hpp"
#include "importSqlFile.hpp"
#include "operations.hpp"
#include <iostream>
#include <map>
#include <string>
#include <vector>
namespace margelo::nitro::rnnitrosqlite {
const std::string getDocPath(const std::optional<std::string>& location) {
std::string tempDocPath = std::string(HybridNitroSQLite::docPath);
if (location) {
tempDocPath = tempDocPath + "/" + *location;
}
return tempDocPath;
}
void HybridNitroSQLite::open(const std::string& dbName, const std::optional<std::string>& location) {
const auto docPath = getDocPath(location);
sqliteOpenDb(dbName, docPath);
}
void HybridNitroSQLite::close(const std::string& dbName) {
sqliteCloseDb(dbName);
};
void HybridNitroSQLite::drop(const std::string& dbName, const std::optional<std::string>& location) {
const auto docPath = getDocPath(location);
sqliteRemoveDb(dbName, docPath);
};
void HybridNitroSQLite::attach(const std::string& mainDbName, const std::string& dbNameToAttach, const std::string& alias,
const std::optional<std::string>& location) {
std::string tempDocPath = std::string(docPath);
if (location) {
tempDocPath = tempDocPath + "/" + *location;
}
sqliteAttachDb(mainDbName, tempDocPath, dbNameToAttach, alias);
};
void HybridNitroSQLite::detach(const std::string& mainDbName, const std::string& alias) {
sqliteDetachDb(mainDbName, alias);
};
using ExecuteQueryResult = std::shared_ptr<HybridNativeQueryResultSpec>;
ExecuteQueryResult HybridNitroSQLite::execute(const std::string& dbName, const std::string& query,
const std::optional<SQLiteQueryParams>& params) {
SQLiteExecuteQueryResult result = sqliteExecute(dbName, query, params);
return std::make_shared<HybridNativeQueryResult>(std::move(result));
};
std::shared_ptr<Promise<std::shared_ptr<HybridNativeQueryResultSpec>>> HybridNitroSQLite::executeAsync(const std::string& dbName, const std::string& query,
const std::optional<SQLiteQueryParams>& params) {
return Promise<std::shared_ptr<HybridNativeQueryResultSpec>>::async([=, this]() -> std::shared_ptr<HybridNativeQueryResultSpec> {
auto result = execute(dbName, query, params);
return result;
});
};
BatchQueryResult HybridNitroSQLite::executeBatch(const std::string& dbName, const std::vector<NativeBatchQueryCommand>& batchParams) {
const auto commands = batchParamsToCommands(batchParams);
auto result = sqliteExecuteBatch(dbName, commands);
return BatchQueryResult(result.rowsAffected);
};
std::shared_ptr<Promise<BatchQueryResult>> HybridNitroSQLite::executeBatchAsync(const std::string& dbName,
const std::vector<NativeBatchQueryCommand>& batchParams) {
return Promise<BatchQueryResult>::async([=, this]() -> BatchQueryResult {
auto result = executeBatch(dbName, batchParams);
return result;
});
};
FileLoadResult HybridNitroSQLite::loadFile(const std::string& dbName, const std::string& location) {
const auto result = importSqlFile(dbName, location);
return FileLoadResult(result.commands, result.rowsAffected);
};
std::shared_ptr<Promise<FileLoadResult>> HybridNitroSQLite::loadFileAsync(const std::string& dbName, const std::string& location) {
return Promise<FileLoadResult>::async([=, this]() -> FileLoadResult {
auto result = loadFile(dbName, location);
return result;
});
};
void HybridNitroSQLite::loadExtension(const std::string& dbName, const std::string& path, const std::optional<std::string>& entryPoint) {
sqliteLoadExtension(dbName, path, entryPoint);
};
} // namespace margelo::nitro::rnnitrosqlite