Skip to content

Commit d1d2542

Browse files
committed
fix: rename types
1 parent 56ef88c commit d1d2542

File tree

10 files changed

+53
-58
lines changed

10 files changed

+53
-58
lines changed

package/cpp/operations.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,12 @@ 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-
if (std::holds_alternative<NativeSQLiteNullValue>(value)) {
105+
if (std::holds_alternative<SQLiteNullValue>(value)) {
106106
sqlite3_bind_null(statement, sqliteIndex);
107107
} else if (std::holds_alternative<bool>(value)) {
108108
sqlite3_bind_int(statement, sqliteIndex, std::get<bool>(value));
109109
} else if (std::holds_alternative<double>(value)) {
110110
sqlite3_bind_double(statement, sqliteIndex, std::get<double>(value));
111-
} else if (std::holds_alternative<int64_t>(value)) {
112-
sqlite3_bind_int64(statement, sqliteIndex, std::get<int64_t>(value));
113111
} else if (std::holds_alternative<std::string>(value)) {
114112
const auto stringValue = std::get<std::string>(value);
115113
sqlite3_bind_text(statement, sqliteIndex, stringValue.c_str(), stringValue.length(), SQLITE_TRANSIENT);
@@ -189,7 +187,7 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
189187
case SQLITE_NULL:
190188
// Intentionally left blank to switch to default case
191189
default:
192-
row[column_name] = NativeSQLiteNullValue(true);
190+
row[column_name] = SQLiteNullValue(true);
193191
break;
194192
}
195193
i++;

package/cpp/types.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
#include <NitroModules/ArrayBuffer.hpp>
55
#include "SQLiteQueryColumnMetadata.hpp"
66
#include "ColumnType.hpp"
7-
#include "NativeSQLiteNullValue.hpp"
7+
#include "SQLiteNullValue.hpp"
88

99
using namespace margelo::nitro;
1010
using namespace margelo::nitro::rnnitrosqlite;
1111

1212
namespace margelo::rnnitrosqlite {
1313

14-
// using SQLiteValue = std::variant<std::string, double, int64_t, bool, std::shared_ptr<ArrayBuffer>, std::monostate>;
15-
using SQLiteValue = std::variant<std::string, double, int64_t, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>;
14+
using SQLiteValue = std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>;
1615
using SQLiteQueryParams = std::vector<SQLiteValue>;
1716
using SQLiteQueryResultRow = std::unordered_map<std::string, SQLiteValue>;
1817
using SQLiteQueryResults = std::vector<SQLiteQueryResultRow>;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020

2121
// Forward declaration of `ArrayBuffer` to properly resolve imports.
2222
namespace NitroModules { class ArrayBuffer; }
23-
// Forward declaration of `NativeSQLiteNullValue` to properly resolve imports.
24-
namespace margelo::nitro::rnnitrosqlite { struct NativeSQLiteNullValue; }
23+
// Forward declaration of `SQLiteNullValue` to properly resolve imports.
24+
namespace margelo::nitro::rnnitrosqlite { struct SQLiteNullValue; }
2525

2626
#include <string>
2727
#include <optional>
2828
#include <variant>
2929
#include <vector>
3030
#include <NitroModules/ArrayBuffer.hpp>
31-
#include "NativeSQLiteNullValue.hpp"
31+
#include "SQLiteNullValue.hpp"
3232

3333
namespace margelo::nitro::rnnitrosqlite {
3434

@@ -38,10 +38,10 @@ namespace margelo::nitro::rnnitrosqlite {
3838
struct BatchQueryCommand {
3939
public:
4040
std::string query SWIFT_PRIVATE;
41-
std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>>>> params SWIFT_PRIVATE;
41+
std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>>>> params SWIFT_PRIVATE;
4242

4343
public:
44-
explicit BatchQueryCommand(std::string query, std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>>>> params): query(query), params(params) {}
44+
explicit BatchQueryCommand(std::string query, std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>>>> params): query(query), params(params) {}
4545
};
4646

4747
} // namespace margelo::nitro::rnnitrosqlite
@@ -57,13 +57,13 @@ namespace margelo::nitro {
5757
jsi::Object obj = arg.asObject(runtime);
5858
return BatchQueryCommand(
5959
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "query")),
60-
JSIConverter<std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>>>>>::fromJSI(runtime, obj.getProperty(runtime, "params"))
60+
JSIConverter<std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>>>>>::fromJSI(runtime, obj.getProperty(runtime, "params"))
6161
);
6262
}
6363
static inline jsi::Value toJSI(jsi::Runtime& runtime, const BatchQueryCommand& arg) {
6464
jsi::Object obj(runtime);
6565
obj.setProperty(runtime, "query", JSIConverter<std::string>::toJSI(runtime, arg.query));
66-
obj.setProperty(runtime, "params", JSIConverter<std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>>>>>::toJSI(runtime, arg.params));
66+
obj.setProperty(runtime, "params", JSIConverter<std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>>>>>::toJSI(runtime, arg.params));
6767
return obj;
6868
}
6969
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -72,7 +72,7 @@ namespace margelo::nitro {
7272
}
7373
jsi::Object obj = value.getObject(runtime);
7474
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "query"))) return false;
75-
if (!JSIConverter<std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>>>>>::canConvert(runtime, obj.getProperty(runtime, "params"))) return false;
75+
if (!JSIConverter<std::optional<std::variant<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>, std::vector<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>>>>>::canConvert(runtime, obj.getProperty(runtime, "params"))) return false;
7676
return true;
7777
}
7878
};

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
// Forward declaration of `ArrayBuffer` to properly resolve imports.
1717
namespace NitroModules { class ArrayBuffer; }
18-
// Forward declaration of `NativeSQLiteNullValue` to properly resolve imports.
19-
namespace margelo::nitro::rnnitrosqlite { struct NativeSQLiteNullValue; }
18+
// Forward declaration of `SQLiteNullValue` to properly resolve imports.
19+
namespace margelo::nitro::rnnitrosqlite { struct SQLiteNullValue; }
2020
// Forward declaration of `SQLiteQueryColumnMetadata` to properly resolve imports.
2121
namespace margelo::nitro::rnnitrosqlite { struct SQLiteQueryColumnMetadata; }
2222

@@ -26,7 +26,7 @@ namespace margelo::nitro::rnnitrosqlite { struct SQLiteQueryColumnMetadata; }
2626
#include <string>
2727
#include <variant>
2828
#include <NitroModules/ArrayBuffer.hpp>
29-
#include "NativeSQLiteNullValue.hpp"
29+
#include "SQLiteNullValue.hpp"
3030
#include "SQLiteQueryColumnMetadata.hpp"
3131

3232
namespace margelo::nitro::rnnitrosqlite {
@@ -58,7 +58,7 @@ namespace margelo::nitro::rnnitrosqlite {
5858
// Properties
5959
virtual double getRowsAffected() = 0;
6060
virtual std::optional<double> getInsertId() = 0;
61-
virtual std::vector<std::unordered_map<std::string, std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>> getResults() = 0;
61+
virtual std::vector<std::unordered_map<std::string, std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>> getResults() = 0;
6262
virtual std::optional<std::unordered_map<std::string, SQLiteQueryColumnMetadata>> getMetadata() = 0;
6363

6464
public:

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
namespace margelo::nitro::rnnitrosqlite { class HybridNativeQueryResultSpec; }
1818
// Forward declaration of `ArrayBuffer` to properly resolve imports.
1919
namespace NitroModules { class ArrayBuffer; }
20-
// Forward declaration of `NativeSQLiteNullValue` to properly resolve imports.
21-
namespace margelo::nitro::rnnitrosqlite { struct NativeSQLiteNullValue; }
20+
// Forward declaration of `SQLiteNullValue` to properly resolve imports.
21+
namespace margelo::nitro::rnnitrosqlite { struct SQLiteNullValue; }
2222
// Forward declaration of `BatchQueryResult` to properly resolve imports.
2323
namespace margelo::nitro::rnnitrosqlite { struct BatchQueryResult; }
2424
// Forward declaration of `BatchQueryCommand` to properly resolve imports.
@@ -33,7 +33,7 @@ namespace margelo::nitro::rnnitrosqlite { struct FileLoadResult; }
3333
#include <vector>
3434
#include <variant>
3535
#include <NitroModules/ArrayBuffer.hpp>
36-
#include "NativeSQLiteNullValue.hpp"
36+
#include "SQLiteNullValue.hpp"
3737
#include <NitroModules/Promise.hpp>
3838
#include "BatchQueryResult.hpp"
3939
#include "BatchQueryCommand.hpp"
@@ -75,8 +75,8 @@ namespace margelo::nitro::rnnitrosqlite {
7575
virtual void drop(const std::string& dbName, const std::optional<std::string>& location) = 0;
7676
virtual void attach(const std::string& mainDbName, const std::string& dbNameToAttach, const std::string& alias, const std::optional<std::string>& location) = 0;
7777
virtual void detach(const std::string& mainDbName, const std::string& alias) = 0;
78-
virtual std::shared_ptr<margelo::nitro::rnnitrosqlite::HybridNativeQueryResultSpec> execute(const std::string& dbName, const std::string& query, const std::optional<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>>& params) = 0;
79-
virtual std::shared_ptr<Promise<std::shared_ptr<margelo::nitro::rnnitrosqlite::HybridNativeQueryResultSpec>>> executeAsync(const std::string& dbName, const std::string& query, const std::optional<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, NativeSQLiteNullValue>>>& params) = 0;
78+
virtual std::shared_ptr<margelo::nitro::rnnitrosqlite::HybridNativeQueryResultSpec> execute(const std::string& dbName, const std::string& query, const std::optional<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>>& params) = 0;
79+
virtual std::shared_ptr<Promise<std::shared_ptr<margelo::nitro::rnnitrosqlite::HybridNativeQueryResultSpec>>> executeAsync(const std::string& dbName, const std::string& query, const std::optional<std::vector<std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>, SQLiteNullValue>>>& params) = 0;
8080
virtual BatchQueryResult executeBatch(const std::string& dbName, const std::vector<BatchQueryCommand>& commands) = 0;
8181
virtual std::shared_ptr<Promise<BatchQueryResult>> executeBatchAsync(const std::string& dbName, const std::vector<BatchQueryCommand>& commands) = 0;
8282
virtual FileLoadResult loadFile(const std::string& dbName, const std::string& location) = 0;

package/nitrogen/generated/shared/c++/NativeSQLiteNullValue.hpp renamed to package/nitrogen/generated/shared/c++/SQLiteNullValue.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///
2-
/// NativeSQLiteNullValue.hpp
2+
/// SQLiteNullValue.hpp
33
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
44
/// https://github.com/mrousavy/nitro
55
/// Copyright © 2025 Marc Rousavy @ Margelo
@@ -25,14 +25,14 @@
2525
namespace margelo::nitro::rnnitrosqlite {
2626

2727
/**
28-
* A struct which can be represented as a JavaScript object (NativeSQLiteNullValue).
28+
* A struct which can be represented as a JavaScript object (SQLiteNullValue).
2929
*/
30-
struct NativeSQLiteNullValue {
30+
struct SQLiteNullValue {
3131
public:
3232
bool isNull SWIFT_PRIVATE;
3333

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

3838
} // namespace margelo::nitro::rnnitrosqlite
@@ -41,16 +41,16 @@ namespace margelo::nitro {
4141

4242
using namespace margelo::nitro::rnnitrosqlite;
4343

44-
// C++ NativeSQLiteNullValue <> JS NativeSQLiteNullValue (object)
44+
// C++ SQLiteNullValue <> JS SQLiteNullValue (object)
4545
template <>
46-
struct JSIConverter<NativeSQLiteNullValue> {
47-
static inline NativeSQLiteNullValue fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
46+
struct JSIConverter<SQLiteNullValue> {
47+
static inline SQLiteNullValue fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
4848
jsi::Object obj = arg.asObject(runtime);
49-
return NativeSQLiteNullValue(
49+
return SQLiteNullValue(
5050
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "isNull"))
5151
);
5252
}
53-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const NativeSQLiteNullValue& arg) {
53+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const SQLiteNullValue& arg) {
5454
jsi::Object obj(runtime);
5555
obj.setProperty(runtime, "isNull", JSIConverter<bool>::toJSI(runtime, arg.isNull));
5656
return obj;

package/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HybridNitroSQLite } from './nitro'
33
import { open } from './operations/session'
44
import NitroSQLiteOnLoad from './specs/NativeNitroSQLiteOnLoad'
55
import { execute, executeAsync } from './operations/execute'
6-
import { NativeSQLiteNullValue } from './types'
6+
import { SQLiteNullValue } from './types'
77
export type * from './types'
88
export { typeORMDriver } from './typeORM'
99

@@ -36,4 +36,4 @@ export function simpleNullHandlingEnabled() {
3636
return ENABLE_SIMPLE_NULL_HANDLING
3737
}
3838

39-
export const NITRO_SQLITE_NULL: NativeSQLiteNullValue = { isNull: true }
39+
export const NITRO_SQLITE_NULL: SQLiteNullValue = { isNull: true }

package/src/operations/session.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export function open(
2424
detach: (alias: string) => HybridNitroSQLite.detach(options.name, alias),
2525
transaction: (fn: (tx: Transaction) => Promise<void> | void) =>
2626
transaction(options.name, fn),
27-
execute: <Data extends QueryResultRow = never>(
27+
execute: <Row extends QueryResultRow = never>(
2828
query: string,
2929
params?: SQLiteQueryParams
30-
): QueryResult<Data> => execute(options.name, query, params),
31-
executeAsync: <Data extends QueryResultRow = never>(
30+
): QueryResult<Row> => execute(options.name, query, params),
31+
executeAsync: <Row extends QueryResultRow = never>(
3232
query: string,
3333
params?: SQLiteQueryParams
34-
): Promise<QueryResult<Data>> => executeAsync(options.name, query, params),
34+
): Promise<QueryResult<Row>> => executeAsync(options.name, query, params),
3535
executeBatch: (commands: BatchQueryCommand[]) =>
3636
HybridNitroSQLite.executeBatch(options.name, commands),
3737
executeBatchAsync: (commands: BatchQueryCommand[]) =>

package/src/specs/NativeQueryResult.nitro.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { HybridObject } from 'react-native-nitro-modules'
2-
import type { ColumnType, NativeSQLiteValue } from '../types'
2+
import type { ColumnType, SQLiteValue } from '../types'
33

44
/**
55
* Object returned by SQL Query executions {
@@ -30,7 +30,7 @@ export interface NativeQueryResult
3030
// TODO: Investigate why this doesn't work with nitrogen
3131
// export type SQLiteQueryResultRow = Record<string, SQLiteValue>
3232
// export type SQLiteQueryResults = SQLiteQueryResultRow[]
33-
export type NativeSQLiteQueryResults = Record<string, NativeSQLiteValue>[]
33+
export type NativeSQLiteQueryResults = Record<string, SQLiteValue>[]
3434

3535
// TODO: Investigate why this doesn't work with nitrogen
3636
// export type SQLiteQueryTableMetadata = Record<string, SQLiteQueryColumnMetadata>

package/src/types.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,51 @@ export enum ColumnType {
2727
}
2828

2929
// Passing null/undefined in array types is not possible, so we us a special struct as a workaround.
30-
export type NativeSQLiteNullValue = {
30+
export type SQLiteNullValue = {
3131
isNull: true
3232
}
33-
export type NativeSQLiteValue =
33+
export type SQLiteValue =
3434
| boolean
3535
| number
3636
| string
3737
| ArrayBuffer
38-
| NativeSQLiteNullValue
39-
export type NativeSQLiteQueryParams = NativeSQLiteValue[]
38+
| SQLiteNullValue
39+
export type NativeSQLiteQueryParams = SQLiteValue[]
4040

4141
/**
4242
* Represents a value that can be stored in a SQLite database
4343
*/
44-
export type SQLiteValue = NativeSQLiteValue | null | undefined
45-
export type SQLiteQueryParams = SQLiteValue[]
44+
export type SQLiteQueryParamItem = SQLiteValue | null | undefined
45+
export type SQLiteQueryParams = SQLiteQueryParamItem[]
4646

47-
export type QueryResultItem = NativeSQLiteValue | undefined
48-
export type QueryResultRow = Record<string, QueryResultItem>
49-
export interface QueryResult<RowData extends QueryResultRow = QueryResultRow> {
47+
export type QueryResultRowItem = SQLiteValue | undefined
48+
export type QueryResultRow = Record<string, QueryResultRowItem>
49+
export interface QueryResult<Row extends QueryResultRow = QueryResultRow> {
5050
readonly insertId?: number
5151
readonly rowsAffected: number
5252

5353
readonly rows?: {
5454
/** Raw array with all dataset */
55-
_array: RowData[]
55+
_array: Row[]
5656
/** The lengh of the dataset */
5757
length: number
5858
/** A convenience function to acess the index based the row object
5959
* @param idx the row index
6060
* @returns the row structure identified by column names
6161
*/
62-
item: (idx: number) => RowData | undefined
62+
item: (idx: number) => Row | undefined
6363
}
6464
}
6565

66-
export type ExecuteQuery = <RowData extends QueryResultRow = QueryResultRow>(
66+
export type ExecuteQuery = <Row extends QueryResultRow = QueryResultRow>(
6767
query: string,
6868
params?: SQLiteQueryParams
69-
) => QueryResult<RowData>
69+
) => QueryResult<Row>
7070

71-
export type ExecuteAsyncQuery = <
72-
RowData extends QueryResultRow = QueryResultRow,
73-
>(
71+
export type ExecuteAsyncQuery = <Row extends QueryResultRow = QueryResultRow>(
7472
query: string,
7573
params?: SQLiteQueryParams
76-
) => Promise<QueryResult<RowData>>
74+
) => Promise<QueryResult<Row>>
7775

7876
export interface Transaction {
7977
commit(): QueryResult

0 commit comments

Comments
 (0)