Skip to content

Commit 4e75c5d

Browse files
committed
feat: improve NITRO_SQLITE_NULL handling
1 parent 0a99a6c commit 4e75c5d

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

example/src/tests/unitTests.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
type BatchQueryCommand,
55
NITRO_SQLITE_NULL,
66
enableSimpleNullHandling,
7-
isSimpleNullHandlingEnabled,
87
} from 'react-native-nitro-sqlite'
98
import { beforeEach, describe, it } from './MochaRNAdapter'
109
import chai from 'chai'

package/nitrogen/generated/shared/c++/SQLiteNullValue.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ namespace margelo::nitro::rnnitrosqlite {
2929
*/
3030
struct SQLiteNullValue {
3131
public:
32-
bool isNull SWIFT_PRIVATE;
32+
bool isNitroSQLiteNull SWIFT_PRIVATE;
3333

3434
public:
35-
explicit SQLiteNullValue(bool isNull): isNull(isNull) {}
35+
explicit SQLiteNullValue(bool isNitroSQLiteNull): isNitroSQLiteNull(isNitroSQLiteNull) {}
3636
};
3737

3838
} // namespace margelo::nitro::rnnitrosqlite
@@ -47,20 +47,20 @@ namespace margelo::nitro {
4747
static inline SQLiteNullValue fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
4848
jsi::Object obj = arg.asObject(runtime);
4949
return SQLiteNullValue(
50-
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "isNull"))
50+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "isNitroSQLiteNull"))
5151
);
5252
}
5353
static inline jsi::Value toJSI(jsi::Runtime& runtime, const SQLiteNullValue& arg) {
5454
jsi::Object obj(runtime);
55-
obj.setProperty(runtime, "isNull", JSIConverter<bool>::toJSI(runtime, arg.isNull));
55+
obj.setProperty(runtime, "isNitroSQLiteNull", JSIConverter<bool>::toJSI(runtime, arg.isNitroSQLiteNull));
5656
return obj;
5757
}
5858
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
5959
if (!value.isObject()) {
6060
return false;
6161
}
6262
jsi::Object obj = value.getObject(runtime);
63-
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "isNull"))) return false;
63+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "isNitroSQLiteNull"))) return false;
6464
return true;
6565
}
6666
};

package/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ export function isSimpleNullHandlingEnabled() {
3636
return ENABLE_SIMPLE_NULL_HANDLING
3737
}
3838

39-
export const NITRO_SQLITE_NULL: SQLiteNullValue = { isNull: true }
39+
export const NITRO_SQLITE_NULL: SQLiteNullValue = { isNitroSQLiteNull: true }
40+
export function isNitroSQLiteNull(value: any): value is SQLiteNullValue {
41+
if (typeof value === 'object' && 'isNitroSQLiteNull' in value) {
42+
return true
43+
}
44+
return false
45+
}

package/src/operations/execute.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { NITRO_SQLITE_NULL, isSimpleNullHandlingEnabled } from '..'
1+
import {
2+
NITRO_SQLITE_NULL,
3+
isNitroSQLiteNull,
4+
isSimpleNullHandlingEnabled,
5+
} from '..'
26
import { HybridNitroSQLite } from '../nitro'
37
import type { NativeQueryResult } from '../specs/NativeQueryResult.nitro'
48
import type {
@@ -62,7 +66,7 @@ function buildJsQueryResult<Row extends QueryResultRow = never>({
6266
data = results.map((row) =>
6367
Object.fromEntries(
6468
Object.entries(row).map(([key, value]) => {
65-
if (typeof value === 'object' && 'isNull' in value) {
69+
if (isNitroSQLiteNull(value)) {
6670
return [key, null]
6771
}
6872
return [key, value]

package/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export enum ColumnType {
2828

2929
// Passing null/undefined in array types is not possible, so we us a special struct as a workaround.
3030
export type SQLiteNullValue = {
31-
isNull: true
31+
isNitroSQLiteNull: true
3232
}
3333
export type SQLiteValue =
3434
| boolean

0 commit comments

Comments
 (0)