react-native-nitro-sqlite 9.1.2 → 9.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNNitroSQLite.podspec +1 -1
- package/cpp/operations.cpp +5 -9
- package/cpp/sqlite/sqlite3.c +112968 -89110
- package/cpp/sqlite/sqlite3.h +2462 -1303
- package/cpp/types.hpp +4 -4
- package/lib/commonjs/index.js +21 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/operations/execute.js +21 -3
- package/lib/commonjs/operations/execute.js.map +1 -1
- package/lib/commonjs/operations/session.js.map +1 -1
- package/lib/commonjs/types.js +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/index.js +16 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/operations/execute.js +21 -3
- package/lib/module/operations/execute.js.map +1 -1
- package/lib/module/operations/session.js.map +1 -1
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +6 -1
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/operations/execute.d.ts +3 -3
- package/lib/typescript/commonjs/operations/execute.d.ts.map +1 -1
- package/lib/typescript/commonjs/operations/transaction.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/NativeQueryResult.nitro.d.ts +2 -2
- package/lib/typescript/commonjs/specs/NativeQueryResult.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/NitroSQLite.nitro.d.ts +3 -3
- package/lib/typescript/commonjs/specs/NitroSQLite.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/typeORM.d.ts +2 -2
- package/lib/typescript/commonjs/typeORM.d.ts.map +1 -1
- package/lib/typescript/commonjs/types.d.ts +14 -8
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +6 -1
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/operations/execute.d.ts +3 -3
- package/lib/typescript/module/operations/execute.d.ts.map +1 -1
- package/lib/typescript/module/operations/transaction.d.ts.map +1 -1
- package/lib/typescript/module/specs/NativeQueryResult.nitro.d.ts +2 -2
- package/lib/typescript/module/specs/NativeQueryResult.nitro.d.ts.map +1 -1
- package/lib/typescript/module/specs/NitroSQLite.nitro.d.ts +3 -3
- package/lib/typescript/module/specs/NitroSQLite.nitro.d.ts.map +1 -1
- package/lib/typescript/module/typeORM.d.ts +2 -2
- package/lib/typescript/module/typeORM.d.ts.map +1 -1
- package/lib/typescript/module/types.d.ts +14 -8
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/RNNitroSQLite+autolinking.cmake +20 -1
- package/nitrogen/generated/android/RNNitroSQLite+autolinking.gradle +1 -1
- package/nitrogen/generated/android/RNNitroSQLiteOnLoad.cpp +5 -1
- package/nitrogen/generated/android/RNNitroSQLiteOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnnitrosqlite/RNNitroSQLiteOnLoad.kt +35 -0
- package/nitrogen/generated/ios/RNNitroSQLite+autolinking.rb +3 -1
- package/nitrogen/generated/ios/RNNitroSQLite-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/RNNitroSQLite-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/RNNitroSQLite-Swift-Cxx-Umbrella.hpp +1 -2
- package/nitrogen/generated/ios/RNNitroSQLiteAutolinking.mm +1 -1
- package/nitrogen/generated/ios/RNNitroSQLiteAutolinking.swift +1 -1
- package/nitrogen/generated/shared/c++/BatchQueryCommand.hpp +11 -7
- package/nitrogen/generated/shared/c++/BatchQueryResult.hpp +3 -2
- package/nitrogen/generated/shared/c++/ColumnType.hpp +2 -2
- package/nitrogen/generated/shared/c++/FileLoadResult.hpp +3 -2
- package/nitrogen/generated/shared/c++/HybridNativeQueryResultSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativeQueryResultSpec.hpp +6 -3
- package/nitrogen/generated/shared/c++/HybridNitroSQLiteSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNitroSQLiteSpec.hpp +7 -4
- package/nitrogen/generated/shared/c++/SQLiteNullValue.hpp +69 -0
- package/nitrogen/generated/shared/c++/SQLiteQueryColumnMetadata.hpp +3 -2
- package/package.json +3 -3
- package/src/index.ts +20 -2
- package/src/operations/execute.ts +54 -12
- package/src/operations/session.ts +6 -6
- package/src/operations/transaction.ts +4 -4
- package/src/specs/NativeQueryResult.nitro.ts +2 -2
- package/src/specs/NitroSQLite.nitro.ts +3 -3
- package/src/typeORM.ts +4 -4
- package/src/types.ts +23 -12
- package/nitrogen/generated/android/RNNitroSQLiteOnLoad.kt +0 -1
package/src/index.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { HybridNitroSQLite } from './nitro'
|
|
|
3
3
|
import { open } from './operations/session'
|
|
4
4
|
import NitroSQLiteOnLoad from './specs/NativeNitroSQLiteOnLoad'
|
|
5
5
|
import { execute, executeAsync } from './operations/execute'
|
|
6
|
-
|
|
7
|
-
export * from './types'
|
|
6
|
+
import { SQLiteNullValue } from './types'
|
|
7
|
+
export type * from './types'
|
|
8
8
|
export { typeORMDriver } from './typeORM'
|
|
9
9
|
|
|
10
10
|
export const onInitialized = new Promise<void>((resolve) => {
|
|
@@ -25,3 +25,21 @@ export const NitroSQLite = {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export { open } from './operations/session'
|
|
28
|
+
|
|
29
|
+
let ENABLE_SIMPLE_NULL_HANDLING = false
|
|
30
|
+
export function enableSimpleNullHandling(
|
|
31
|
+
shouldEnableSimpleNullHandling = true
|
|
32
|
+
) {
|
|
33
|
+
ENABLE_SIMPLE_NULL_HANDLING = shouldEnableSimpleNullHandling
|
|
34
|
+
}
|
|
35
|
+
export function isSimpleNullHandlingEnabled() {
|
|
36
|
+
return ENABLE_SIMPLE_NULL_HANDLING
|
|
37
|
+
}
|
|
38
|
+
|
|
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
|
+
}
|
|
@@ -1,37 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NITRO_SQLITE_NULL,
|
|
3
|
+
isNitroSQLiteNull,
|
|
4
|
+
isSimpleNullHandlingEnabled,
|
|
5
|
+
} from '..'
|
|
1
6
|
import { HybridNitroSQLite } from '../nitro'
|
|
2
7
|
import type { NativeQueryResult } from '../specs/NativeQueryResult.nitro'
|
|
3
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
QueryResult,
|
|
10
|
+
NativeSQLiteQueryParams,
|
|
11
|
+
SQLiteQueryParams,
|
|
12
|
+
QueryResultRow,
|
|
13
|
+
} from '../types'
|
|
4
14
|
|
|
5
|
-
export function execute<
|
|
15
|
+
export function execute<Row extends QueryResultRow = never>(
|
|
6
16
|
dbName: string,
|
|
7
17
|
query: string,
|
|
8
18
|
params?: SQLiteQueryParams
|
|
9
|
-
): QueryResult<
|
|
10
|
-
const nativeResult = HybridNitroSQLite.execute(
|
|
11
|
-
|
|
19
|
+
): QueryResult<Row> {
|
|
20
|
+
const nativeResult = HybridNitroSQLite.execute(
|
|
21
|
+
dbName,
|
|
22
|
+
query,
|
|
23
|
+
toNativeQueryParams(params)
|
|
24
|
+
)
|
|
25
|
+
const result = buildJsQueryResult<Row>(nativeResult)
|
|
12
26
|
return result
|
|
13
27
|
}
|
|
14
28
|
|
|
15
|
-
export async function executeAsync<
|
|
29
|
+
export async function executeAsync<Row extends QueryResultRow = never>(
|
|
16
30
|
dbName: string,
|
|
17
31
|
query: string,
|
|
18
32
|
params?: SQLiteQueryParams
|
|
19
|
-
): Promise<QueryResult<
|
|
33
|
+
): Promise<QueryResult<Row>> {
|
|
34
|
+
const transformedParams = isSimpleNullHandlingEnabled()
|
|
35
|
+
? toNativeQueryParams(params)
|
|
36
|
+
: (params as NativeSQLiteQueryParams)
|
|
37
|
+
|
|
20
38
|
const nativeResult = await HybridNitroSQLite.executeAsync(
|
|
21
39
|
dbName,
|
|
22
40
|
query,
|
|
23
|
-
|
|
41
|
+
transformedParams
|
|
24
42
|
)
|
|
25
|
-
const result = buildJsQueryResult<
|
|
43
|
+
const result = buildJsQueryResult<Row>(nativeResult)
|
|
26
44
|
return result
|
|
27
45
|
}
|
|
28
46
|
|
|
29
|
-
function
|
|
47
|
+
function toNativeQueryParams(
|
|
48
|
+
params: SQLiteQueryParams | undefined
|
|
49
|
+
): NativeSQLiteQueryParams | undefined {
|
|
50
|
+
return params?.map((param) => {
|
|
51
|
+
if (param === undefined || param === null) {
|
|
52
|
+
return NITRO_SQLITE_NULL
|
|
53
|
+
}
|
|
54
|
+
return param
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function buildJsQueryResult<Row extends QueryResultRow = never>({
|
|
30
59
|
insertId,
|
|
31
60
|
rowsAffected,
|
|
32
61
|
results,
|
|
33
|
-
}: NativeQueryResult): QueryResult<
|
|
34
|
-
|
|
62
|
+
}: NativeQueryResult): QueryResult<Row> {
|
|
63
|
+
let data: Row[] = results as Row[]
|
|
64
|
+
|
|
65
|
+
if (isSimpleNullHandlingEnabled()) {
|
|
66
|
+
data = results.map((row) =>
|
|
67
|
+
Object.fromEntries(
|
|
68
|
+
Object.entries(row).map(([key, value]) => {
|
|
69
|
+
if (isNitroSQLiteNull(value)) {
|
|
70
|
+
return [key, null]
|
|
71
|
+
}
|
|
72
|
+
return [key, value]
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
) as Row[]
|
|
76
|
+
}
|
|
35
77
|
|
|
36
78
|
return {
|
|
37
79
|
insertId,
|
|
@@ -5,9 +5,9 @@ import type {
|
|
|
5
5
|
NitroSQLiteConnection,
|
|
6
6
|
NitroSQLiteConnectionOptions,
|
|
7
7
|
QueryResult,
|
|
8
|
-
SQLiteItem,
|
|
9
|
-
SQLiteQueryParams,
|
|
10
8
|
Transaction,
|
|
9
|
+
SQLiteQueryParams,
|
|
10
|
+
QueryResultRow,
|
|
11
11
|
} from '../types'
|
|
12
12
|
import { execute, executeAsync } from './execute'
|
|
13
13
|
|
|
@@ -24,14 +24,14 @@ export function open(
|
|
|
24
24
|
detach: (alias: string) => HybridNitroSQLite.detach(options.name, alias),
|
|
25
25
|
transaction: (fn: (tx: Transaction) => Promise<void> | void) =>
|
|
26
26
|
transaction(options.name, fn),
|
|
27
|
-
execute: <
|
|
27
|
+
execute: <Row extends QueryResultRow = never>(
|
|
28
28
|
query: string,
|
|
29
29
|
params?: SQLiteQueryParams
|
|
30
|
-
): QueryResult<
|
|
31
|
-
executeAsync: <
|
|
30
|
+
): QueryResult<Row> => execute(options.name, query, params),
|
|
31
|
+
executeAsync: <Row extends QueryResultRow = never>(
|
|
32
32
|
query: string,
|
|
33
33
|
params?: SQLiteQueryParams
|
|
34
|
-
): Promise<QueryResult<
|
|
34
|
+
): Promise<QueryResult<Row>> => executeAsync(options.name, query, params),
|
|
35
35
|
executeBatch: (commands: BatchQueryCommand[]) =>
|
|
36
36
|
HybridNitroSQLite.executeBatch(options.name, commands),
|
|
37
37
|
executeBatchAsync: (commands: BatchQueryCommand[]) =>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { locks, HybridNitroSQLite } from '../nitro'
|
|
2
2
|
import type {
|
|
3
3
|
QueryResult,
|
|
4
|
-
SQLiteItem,
|
|
5
|
-
SQLiteQueryParams,
|
|
6
4
|
Transaction,
|
|
5
|
+
SQLiteQueryParams,
|
|
6
|
+
QueryResultRow,
|
|
7
7
|
} from '../types'
|
|
8
8
|
import { execute, executeAsync } from './execute'
|
|
9
9
|
|
|
@@ -30,7 +30,7 @@ export const transaction = (
|
|
|
30
30
|
let isFinalized = false
|
|
31
31
|
|
|
32
32
|
// Local transaction context object implementation
|
|
33
|
-
const executeOnTransaction = <Data extends
|
|
33
|
+
const executeOnTransaction = <Data extends QueryResultRow = never>(
|
|
34
34
|
query: string,
|
|
35
35
|
params?: SQLiteQueryParams
|
|
36
36
|
): QueryResult<Data> => {
|
|
@@ -42,7 +42,7 @@ export const transaction = (
|
|
|
42
42
|
return execute(dbName, query, params)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const executeAsyncOnTransaction = <Data extends
|
|
45
|
+
const executeAsyncOnTransaction = <Data extends QueryResultRow = never>(
|
|
46
46
|
query: string,
|
|
47
47
|
params?: SQLiteQueryParams
|
|
48
48
|
): Promise<QueryResult<Data>> => {
|
|
@@ -17,7 +17,7 @@ export interface NativeQueryResult
|
|
|
17
17
|
readonly insertId?: number
|
|
18
18
|
|
|
19
19
|
/** Query results */
|
|
20
|
-
readonly results:
|
|
20
|
+
readonly results: NativeSQLiteQueryResults
|
|
21
21
|
/** Table metadata */
|
|
22
22
|
readonly metadata?: Record<string, SQLiteQueryColumnMetadata>
|
|
23
23
|
}
|
|
@@ -30,7 +30,7 @@ export interface NativeQueryResult
|
|
|
30
30
|
// TODO: Investigate why this doesn't work with nitrogen
|
|
31
31
|
// export type SQLiteQueryResultRow = Record<string, SQLiteValue>
|
|
32
32
|
// export type SQLiteQueryResults = SQLiteQueryResultRow[]
|
|
33
|
-
export type
|
|
33
|
+
export type NativeSQLiteQueryResults = Record<string, SQLiteValue>[]
|
|
34
34
|
|
|
35
35
|
// TODO: Investigate why this doesn't work with nitrogen
|
|
36
36
|
// export type SQLiteQueryTableMetadata = Record<string, SQLiteQueryColumnMetadata>
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
BatchQueryResult,
|
|
4
4
|
FileLoadResult,
|
|
5
5
|
BatchQueryCommand,
|
|
6
|
-
|
|
6
|
+
NativeSQLiteQueryParams,
|
|
7
7
|
} from '../types'
|
|
8
8
|
import type { NativeQueryResult } from './NativeQueryResult.nitro'
|
|
9
9
|
|
|
@@ -22,12 +22,12 @@ export interface NitroSQLite
|
|
|
22
22
|
execute(
|
|
23
23
|
dbName: string,
|
|
24
24
|
query: string,
|
|
25
|
-
params?:
|
|
25
|
+
params?: NativeSQLiteQueryParams
|
|
26
26
|
): NativeQueryResult
|
|
27
27
|
executeAsync(
|
|
28
28
|
dbName: string,
|
|
29
29
|
query: string,
|
|
30
|
-
params?:
|
|
30
|
+
params?: NativeSQLiteQueryParams
|
|
31
31
|
): Promise<NativeQueryResult>
|
|
32
32
|
executeBatch(dbName: string, commands: BatchQueryCommand[]): BatchQueryResult
|
|
33
33
|
executeBatchAsync(
|
package/src/typeORM.ts
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
QueryResult,
|
|
10
|
-
SQLiteItem,
|
|
11
|
-
SQLiteQueryParams,
|
|
12
10
|
Transaction,
|
|
11
|
+
SQLiteQueryParams,
|
|
12
|
+
QueryResultRow,
|
|
13
13
|
} from './types'
|
|
14
14
|
import * as Operations from './operations/session'
|
|
15
15
|
|
|
16
16
|
interface TypeOrmNitroSQLiteConnection {
|
|
17
|
-
executeSql: <RowData extends
|
|
17
|
+
executeSql: <RowData extends QueryResultRow = never>(
|
|
18
18
|
sql: string,
|
|
19
19
|
params: SQLiteQueryParams | undefined,
|
|
20
20
|
okExecute: (res: QueryResult<RowData>) => void,
|
|
@@ -48,7 +48,7 @@ export const typeORMDriver = {
|
|
|
48
48
|
const db = Operations.open(options)
|
|
49
49
|
|
|
50
50
|
const connection: TypeOrmNitroSQLiteConnection = {
|
|
51
|
-
executeSql: async <RowData extends
|
|
51
|
+
executeSql: async <RowData extends QueryResultRow = never>(
|
|
52
52
|
sql: string,
|
|
53
53
|
params: SQLiteQueryParams | undefined,
|
|
54
54
|
okExecute: (res: QueryResult<RowData>) => void,
|
package/src/types.ts
CHANGED
|
@@ -26,41 +26,52 @@ export enum ColumnType {
|
|
|
26
26
|
NULL_VALUE,
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// Passing null/undefined in array types is not possible, so we us a special struct as a workaround.
|
|
30
|
+
export type SQLiteNullValue = {
|
|
31
|
+
isNitroSQLiteNull: true
|
|
32
|
+
}
|
|
33
|
+
export type SQLiteValue =
|
|
34
|
+
| boolean
|
|
35
|
+
| number
|
|
36
|
+
| string
|
|
37
|
+
| ArrayBuffer
|
|
38
|
+
| SQLiteNullValue
|
|
39
|
+
export type NativeSQLiteQueryParams = SQLiteValue[]
|
|
40
|
+
|
|
29
41
|
/**
|
|
30
42
|
* Represents a value that can be stored in a SQLite database
|
|
31
43
|
*/
|
|
32
|
-
export type
|
|
44
|
+
export type SQLiteQueryParamItem = SQLiteValue | null | undefined
|
|
45
|
+
export type SQLiteQueryParams = SQLiteQueryParamItem[]
|
|
33
46
|
|
|
34
|
-
export type
|
|
35
|
-
|
|
36
|
-
export interface QueryResult<
|
|
47
|
+
export type QueryResultRowItem = SQLiteValue | undefined
|
|
48
|
+
export type QueryResultRow = Record<string, QueryResultRowItem>
|
|
49
|
+
export interface QueryResult<Row extends QueryResultRow = QueryResultRow> {
|
|
37
50
|
readonly insertId?: number
|
|
38
51
|
readonly rowsAffected: number
|
|
39
52
|
|
|
40
53
|
readonly rows?: {
|
|
41
54
|
/** Raw array with all dataset */
|
|
42
|
-
_array:
|
|
55
|
+
_array: Row[]
|
|
43
56
|
/** The lengh of the dataset */
|
|
44
57
|
length: number
|
|
45
58
|
/** A convenience function to acess the index based the row object
|
|
46
59
|
* @param idx the row index
|
|
47
60
|
* @returns the row structure identified by column names
|
|
48
61
|
*/
|
|
49
|
-
item: (idx: number) =>
|
|
62
|
+
item: (idx: number) => Row | undefined
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
export type
|
|
54
|
-
|
|
55
|
-
export type ExecuteQuery = <RowData extends SQLiteItem = SQLiteItem>(
|
|
66
|
+
export type ExecuteQuery = <Row extends QueryResultRow = QueryResultRow>(
|
|
56
67
|
query: string,
|
|
57
68
|
params?: SQLiteQueryParams
|
|
58
|
-
) => QueryResult<
|
|
69
|
+
) => QueryResult<Row>
|
|
59
70
|
|
|
60
|
-
export type ExecuteAsyncQuery = <
|
|
71
|
+
export type ExecuteAsyncQuery = <Row extends QueryResultRow = QueryResultRow>(
|
|
61
72
|
query: string,
|
|
62
73
|
params?: SQLiteQueryParams
|
|
63
|
-
) => Promise<QueryResult<
|
|
74
|
+
) => Promise<QueryResult<Row>>
|
|
64
75
|
|
|
65
76
|
export interface Transaction {
|
|
66
77
|
commit(): QueryResult
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|