Skip to content

Commit 1a7f2a6

Browse files
committed
Merge branch 'main' into test/array-buffers
2 parents 6a09bfe + a8b6efc commit 1a7f2a6

File tree

11 files changed

+51
-169
lines changed

11 files changed

+51
-169
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ import {
258258
open,
259259
NitroSQLiteError,
260260
typeORMDriver,
261-
enableSimpleNullHandling, // no-op from 9.3.0
262261
} from 'react-native-nitro-sqlite'
263262
import type { QueryResult, BatchQueryCommand, NitroSQLiteConnection, ... } from 'react-native-nitro-sqlite'
264263
```

example/src/tests/unit/common.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Chance } from 'chance'
2-
import {
3-
enableSimpleNullHandling,
4-
NitroSQLiteError,
5-
} from 'react-native-nitro-sqlite'
2+
import { NitroSQLiteError } from 'react-native-nitro-sqlite'
63
import { resetTestDb } from '../db'
74
import chai from 'chai'
85

@@ -22,6 +19,5 @@ export const expect = chai.expect
2219
export const chance = new Chance()
2320

2421
export function setupTestDb() {
25-
enableSimpleNullHandling(false)
2622
resetTestDb()
2723
}

package/cpp/specs/HybridNitroSQLiteQueryResult.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ SQLiteQueryResults HybridNitroSQLiteQueryResult::getResults() {
2020
return _results;
2121
};
2222

23-
std::optional<NitroSQLiteQueryResultRows> HybridNitroSQLiteQueryResult::getRows() {
24-
return _rows;
25-
}
26-
2723
std::optional<SQLiteQueryTableMetadata> HybridNitroSQLiteQueryResult::getMetadata() {
2824
return _metadata;
2925
}

package/cpp/specs/HybridNitroSQLiteQueryResult.hpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,19 @@ class HybridNitroSQLiteQueryResult : public HybridNitroSQLiteQueryResultSpec {
1313
HybridNitroSQLiteQueryResult() : HybridObject(TAG) {}
1414
HybridNitroSQLiteQueryResult(SQLiteQueryResults results, std::optional<double> insertId, double rowsAffected,
1515
std::optional<SQLiteQueryTableMetadata> metadata)
16-
: HybridObject(TAG), _insertId(insertId), _rowsAffected(rowsAffected), _results(std::move(results)), _metadata(metadata) {
17-
if (_results.empty()) {
18-
// Empty rows: empty vector, length 0, item callback always returns null
19-
auto emptyItem = [](double /* idx */) -> std::shared_ptr<Promise<std::optional<SQLiteQueryResultRow>>> {
20-
return Promise<std::optional<SQLiteQueryResultRow>>::async([]() -> std::optional<SQLiteQueryResultRow> { return std::nullopt; });
21-
};
22-
_rows = NitroSQLiteQueryResultRows(SQLiteQueryResults{}, 0.0, std::move(emptyItem));
23-
return;
24-
}
25-
26-
auto rows = _results;
27-
auto itemFunction = [rows](double idx) -> std::shared_ptr<Promise<std::optional<SQLiteQueryResultRow>>> {
28-
return Promise<std::optional<SQLiteQueryResultRow>>::async([rows, idx]() -> std::optional<SQLiteQueryResultRow> {
29-
const auto index = static_cast<size_t>(idx);
30-
if (index >= rows.size()) {
31-
return std::nullopt;
32-
}
33-
return rows[index];
34-
});
35-
};
36-
37-
const auto length = static_cast<double>(rows.size());
38-
_rows = NitroSQLiteQueryResultRows(std::move(rows), length, std::move(itemFunction));
39-
}
16+
: HybridObject(TAG), _insertId(insertId), _rowsAffected(rowsAffected), _results(std::move(results)), _metadata(metadata) {}
4017

4118
private:
4219
std::optional<double> _insertId;
4320
double _rowsAffected;
4421
SQLiteQueryResults _results;
45-
std::optional<NitroSQLiteQueryResultRows> _rows;
4622
std::optional<SQLiteQueryTableMetadata> _metadata;
4723

4824
public:
4925
// Properties
5026
std::optional<double> getInsertId() override;
5127
double getRowsAffected() override;
5228
SQLiteQueryResults getResults() override;
53-
std::optional<NitroSQLiteQueryResultRows> getRows() override;
5429
std::optional<SQLiteQueryTableMetadata> getMetadata() override;
5530
};
5631

package/nitrogen/generated/shared/c++/HybridNitroSQLiteQueryResultSpec.cpp

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 99 deletions
This file was deleted.

package/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export const NitroSQLite = {
2121
executeBatchAsync,
2222
}
2323

24-
/** NOOP on NitroSQLite versions >= 9.3.0 */
25-
export function enableSimpleNullHandling() {}
26-
2724
export { open } from './operations/session'
2825
export { default as NitroSQLiteError } from './NitroSQLiteError'
2926
export type * from './types'

package/src/operations/execute.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { HybridNitroSQLite } from '../nitro'
22
import type { QueryResult, QueryResultRow, SQLiteQueryParams } from '../types'
33
import NitroSQLiteError from '../NitroSQLiteError'
4+
import type { NitroSQLiteQueryResult } from '../specs/NitroSQLiteQueryResult.nitro'
45

56
export function execute<Row extends QueryResultRow = never>(
67
dbName: string,
78
query: string,
89
params?: SQLiteQueryParams,
910
): QueryResult<Row> {
1011
try {
11-
const result = HybridNitroSQLite.execute(dbName, query, params)
12-
return result as QueryResult<Row>
12+
const nativeResult = HybridNitroSQLite.execute(dbName, query, params)
13+
return buildJSQueryResult<Row>(nativeResult)
1314
} catch (error) {
1415
throw NitroSQLiteError.fromError(error)
1516
}
@@ -21,9 +22,35 @@ export async function executeAsync<Row extends QueryResultRow = never>(
2122
params?: SQLiteQueryParams,
2223
): Promise<QueryResult<Row>> {
2324
try {
24-
const result = await HybridNitroSQLite.executeAsync(dbName, query, params)
25-
return result as QueryResult<Row>
25+
const nativeResult = await HybridNitroSQLite.executeAsync(
26+
dbName,
27+
query,
28+
params,
29+
)
30+
return buildJSQueryResult<Row>(nativeResult)
2631
} catch (error) {
2732
throw NitroSQLiteError.fromError(error)
2833
}
2934
}
35+
36+
function buildJSQueryResult<Row extends QueryResultRow = never>(
37+
result: NitroSQLiteQueryResult,
38+
): QueryResult<Row> {
39+
const resultWithRows = result as QueryResult<Row>
40+
41+
resultWithRows.rows = {
42+
_array: result.results as Row[],
43+
length: result.results.length,
44+
item: (idx: number) => result.results[idx] as Row | undefined,
45+
}
46+
47+
return resultWithRows
48+
49+
// return Object.assign(result, {
50+
// rows: {
51+
// _array: result.results,
52+
// length: result.results.length,
53+
// item: (idx: number) => result.results[idx],
54+
// },
55+
// })
56+
}

package/src/specs/NitroSQLiteQueryResult.nitro.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export interface NitroSQLiteQueryResult
1919
/** Query results */
2020
readonly results: Record<string, SQLiteValue>[]
2121

22-
/** Query results in a row format for TypeORM compatibility */
23-
readonly rows?: NitroSQLiteQueryResultRows
24-
2522
/** Table metadata */
2623
readonly metadata?: Record<string, NitroSQLiteQueryColumnMetadata>
2724
}
@@ -33,20 +30,6 @@ export interface NitroSQLiteQueryResult
3330

3431
// type NitroQueryResultRow = Record<string, SQLiteValue>
3532

36-
export type NitroSQLiteQueryResultRows<
37-
Row extends Record<string, SQLiteValue> = Record<string, SQLiteValue>,
38-
> = {
39-
/** Raw array with all dataset */
40-
_array: Row[]
41-
/** The lengh of the dataset */
42-
length: number
43-
/** A convenience function to acess the index based the row object
44-
* @param idx the row index
45-
* @returns the row structure identified by column names
46-
*/
47-
item: (idx: number) => Row | undefined
48-
}
49-
5033
export type NitroSQLiteQueryColumnMetadata = {
5134
/** The name used for this column for this result set */
5235
name: string

0 commit comments

Comments
 (0)