Skip to content

Commit d286dbb

Browse files
committed
Merge branch 'main' into rename-to-nitro-sqlite
2 parents 0663f85 + f37bc1f commit d286dbb

File tree

19 files changed

+603
-46
lines changed

19 files changed

+603
-46
lines changed

.github/workflows/lint-cpp.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
- "**/*.cpp"
1212
- "**/*.c"
1313
- "**/*.mm"
14+
paths-ignore:
15+
- "node_modules"
16+
- "**/node_modules"
1417
pull_request:
1518
paths:
1619
- ".github/workflows/lint-cpp.yml"
@@ -19,6 +22,9 @@ on:
1922
- "**/*.cpp"
2023
- "**/*.c"
2124
- "**/*.mm"
25+
paths-ignore:
26+
- "node_modules"
27+
- "**/node_modules"
2228

2329
jobs:
2430
lint:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.margelo.rnnitrosqlite
2+
3+
import com.facebook.react.bridge.ReactApplicationContext
4+
5+
object DocPathSetter {
6+
@JvmStatic
7+
fun setDocPath(context: ReactApplicationContext) {
8+
val path = context.filesDir.absolutePath
9+
setDocPathInJNI(path)
10+
}
11+
12+
private external fun setDocPathInJNI(docPath: String)
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.margelo.rnnitrosqlite
2+
3+
import com.facebook.react.TurboReactPackage
4+
import com.facebook.react.bridge.NativeModule
5+
import com.facebook.react.bridge.ReactApplicationContext
6+
import com.facebook.react.module.model.ReactModuleInfo
7+
import com.facebook.react.module.model.ReactModuleInfoProvider
8+
9+
class RNNitroSQLitePackage : TurboReactPackage() {
10+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
11+
return if (name == RNNitroSQLiteOnLoadModule.NAME) {
12+
RNNitroSQLiteOnLoadModule(reactContext)
13+
} else {
14+
null
15+
}
16+
}
17+
18+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
19+
return ReactModuleInfoProvider {
20+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
21+
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
22+
moduleInfos[RNNitroSQLiteOnLoadModule.NAME] = ReactModuleInfo(
23+
RNNitroSQLiteOnLoadModule.NAME,
24+
RNNitroSQLiteOnLoadModule.NAME,
25+
canOverrideExistingModule=false,
26+
needsEagerInit=true,
27+
hasConstants=true,
28+
isCxxModule=false,
29+
isTurboModule=isTurboModule
30+
)
31+
moduleInfos
32+
}
33+
}
34+
35+
companion object {
36+
init {
37+
System.loadLibrary("RNNitroSQLite")
38+
}
39+
}
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.margelo.rnnitrosqlite
2+
3+
import com.facebook.react.bridge.Callback
4+
import com.facebook.react.bridge.ReactApplicationContext
5+
import com.margelo.rnnitrosqlite.NativeNitroSQLiteOnLoadSpec
6+
7+
class RNNitroSQLiteOnLoadModule(reactContext: ReactApplicationContext) :
8+
NativeNitroSQLiteOnLoadSpec(reactContext) {
9+
private var reactApplicationContextReadyCallback: Callback? = null
10+
11+
init {
12+
Companion.reactContext = reactContext
13+
DocPathSetter.setDocPath(reactContext)
14+
15+
if (reactApplicationContextReadyCallback != null) {
16+
reactApplicationContextReadyCallback!!.invoke()
17+
}
18+
}
19+
20+
override fun getName(): String {
21+
return NAME
22+
}
23+
24+
override fun onReactApplicationContextReady(callback: Callback) {
25+
if (reactContext != null) {
26+
callback.invoke()
27+
return
28+
}
29+
30+
reactApplicationContextReadyCallback = callback
31+
}
32+
33+
companion object {
34+
const val NAME: String = "RNNitroSQLiteOnLoad"
35+
36+
var reactContext: ReactApplicationContext? = null
37+
private set
38+
var reactApplicationContextReadyCallback: Callback? = null
39+
private set
40+
}
41+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.margelo.rnnitrosqlite
2+
3+
import com.facebook.react.bridge.Callback
4+
import com.facebook.react.bridge.ReactApplicationContext
5+
import com.facebook.react.bridge.ReactContextBaseJavaModule
6+
import com.facebook.react.bridge.ReactMethod
7+
8+
class RNNitroSQLiteOnLoadModule(reactContext: ReactApplicationContext) :
9+
ReactContextBaseJavaModule(reactContext) {
10+
11+
12+
init {
13+
Companion.reactContext = reactContext
14+
DocPathSetter.setDocPath(reactContext)
15+
16+
if (reactApplicationContextReadyCallback != null) {
17+
reactApplicationContextReadyCallback!!.invoke()
18+
}
19+
}
20+
21+
override fun getName(): String {
22+
return NAME
23+
}
24+
25+
@ReactMethod
26+
fun onReactApplicationContextReady(callback: Callback) {
27+
if (reactContext != null) {
28+
callback.invoke()
29+
return
30+
}
31+
32+
reactApplicationContextReadyCallback = callback
33+
}
34+
35+
companion object {
36+
const val NAME: String = "RNNNitroSQLiteOnLoad"
37+
38+
var reactContext: ReactApplicationContext? = null
39+
private set
40+
var reactApplicationContextReadyCallback: Callback? = null
41+
private set
42+
}
43+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <iostream>
5+
#include <exception>
6+
7+
enum NitroSQLiteExceptionType {
8+
UnknownError,
9+
DatabaseCannotBeOpened,
10+
DatabaseNotOpen,
11+
UnableToAttachToDatabase,
12+
SqlExecutionError,
13+
CouldNotLoadFile,
14+
NoBatchCommandsProvided
15+
};
16+
17+
inline std::unordered_map<NitroSQLiteExceptionType, std::string> exceptionTypeStrings = {
18+
{UnknownError, "UnknownError"},
19+
{DatabaseCannotBeOpened, "DatabaseCannotBeOpened"},
20+
{DatabaseNotOpen, "DatabaseNotOpen"},
21+
{UnableToAttachToDatabase, "UnableToAttachToDatabase"},
22+
{SqlExecutionError, "SqlExecutionError"},
23+
{CouldNotLoadFile, "CouldNotLoadFile"},
24+
{NoBatchCommandsProvided, "NoBatchCommandsProvided"}
25+
};
26+
27+
inline std::string typeToString(NitroSQLiteExceptionType type) {
28+
return exceptionTypeStrings[type];
29+
}
30+
31+
class NitroSQLiteException : public std::exception {
32+
public:
33+
explicit NitroSQLiteException(const char* message): NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
34+
explicit NitroSQLiteException(const std::string& message): NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
35+
NitroSQLiteException(const NitroSQLiteExceptionType& type, const char* message) : NitroSQLiteException(type, std::string(message)) {}
36+
NitroSQLiteException(const NitroSQLiteExceptionType& type, const std::string& message)
37+
: _exceptionString("[react-native-nitro-sqlite] " + typeToString(type) + ": " + message) {}
38+
39+
private:
40+
const std::string _exceptionString;
41+
42+
public:
43+
[[nodiscard]] const char* what() const noexcept override {
44+
return this->_exceptionString.c_str();
45+
}
46+
47+
static NitroSQLiteException DatabaseNotOpen(const std::string& dbName) {
48+
return NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase, dbName + " is not open");
49+
}
50+
51+
static NitroSQLiteException SqlExecution(const std::string& errorMessage) {
52+
return NitroSQLiteException(NitroSQLiteExceptionType::SqlExecutionError, errorMessage);
53+
}
54+
55+
static NitroSQLiteException DatabaseFileNotFound(const std::string& dbFilePath) {
56+
return NitroSQLiteException(NitroSQLiteExceptionType::SqlExecutionError, "Database file not found: " + dbFilePath);
57+
}
58+
59+
static NitroSQLiteException CouldNotLoadFile(const std::string& fileLocation, std::optional<std::string> additionalLine = std::nullopt) {
60+
const auto message = "Could not load file: " + fileLocation + (additionalLine ? (". " + *additionalLine) : "");
61+
return NitroSQLiteException(NitroSQLiteExceptionType::CouldNotLoadFile, message);
62+
}
63+
};

package/cpp/operations.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ void bindStatement(sqlite3_stmt* statement, const SQLiteQueryParams& values) {
102102
for (int valueIndex = 0; valueIndex < values.size(); valueIndex++) {
103103
int sqliteIndex = valueIndex+1;
104104
SQLiteValue value = values.at(valueIndex);
105-
106105
// if (std::holds_alternative<std::monostate>(value))
107106
// {
108107
// sqlite3_bind_null(statement, sqliteIndex);
@@ -148,7 +147,6 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
148147
std::string column_name;
149148
ColumnType column_declared_type;
150149
SQLiteQueryResultRow row;
151-
152150
auto results = std::make_unique<SQLiteQueryResults>();
153151
auto metadata = new SQLiteQueryTableMetadata();
154152

@@ -232,7 +230,6 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
232230
? std::make_optional(std::move(*metadata))
233231
: std::nullopt
234232
);
235-
236233
return {
237234
.rowsAffected = rowsAffected,
238235
.insertId = static_cast<double>(latestInsertRowId),

package/cpp/specs/HybridNativeQueryResult.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
#include "types.hpp"
55
#include <map>
66

7+
<<<<<<< HEAD
78
using namespace margelo::rnnitrosqlite;
89

910
namespace margelo::nitro::rnnitrosqlite {
11+
=======
12+
using namespace margelo::rnnitrosqlite;
13+
14+
namespace margelo::nitro::rnnitrosqlite {
15+
>>>>>>> main
1016

1117
class HybridNativeQueryResult : public HybridNativeQueryResultSpec {
1218
public:
@@ -32,4 +38,8 @@ class HybridNativeQueryResult : public HybridNativeQueryResultSpec {
3238
std::optional<SQLiteQueryTableMetadata> getMetadata() override;
3339
};
3440

41+
<<<<<<< HEAD
42+
} // namespace margelo::nitro::rnnitrosqlite
43+
=======
3544
} // namespace margelo::nitro::rnnitrosqlite
45+
>>>>>>> main

0 commit comments

Comments
 (0)