Skip to content

Commit f418710

Browse files
committed
fix: further resolve dependency cycle
1 parent 88a24ee commit f418710

File tree

6 files changed

+62
-58
lines changed

6 files changed

+62
-58
lines changed

package/src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { transaction } from './transaction'
1+
import { transaction } from './operations/transaction'
22
import { HybridQuickSQLite } from './nitro'
3-
import * as Operations from './operations'
3+
import { open } from './operations/session'
44
import QuickSQLiteOnLoad from './specs/NativeQuickSQLiteOnLoad'
5+
import { execute, executeAsync } from './operations/execute'
56

67
export * from './types'
78
export { typeORMDriver } from './typeORM'
@@ -16,10 +17,10 @@ export const QuickSQLite = {
1617
onInitialized,
1718
// Overwrite native functions with session-based JS implementations,
1819
// where the database name can be ommited once opened
19-
open: Operations.open,
20+
open,
2021
transaction,
21-
execute: Operations.execute,
22-
executeAsync: Operations.executeAsync,
22+
execute,
23+
executeAsync,
2324
}
2425

25-
export { open } from './operations'
26+
export { open } from './operations/session'

package/src/nitro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NitroModules } from 'react-native-nitro-modules'
22
import type { QuickSQLite as QuickSQLiteSpec } from './specs/QuickSQLite.nitro'
3-
import type { PendingTransaction } from './transaction'
3+
import type { PendingTransaction } from './operations/transaction'
44

55
export const HybridQuickSQLite =
66
NitroModules.createHybridObject<QuickSQLiteSpec>('QuickSQLite')

package/src/operations/execute.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { HybridQuickSQLite } from '../nitro'
2+
import type { NativeQueryResult } from '../specs/NativeQueryResult.nitro'
3+
import type { QueryResult, SQLiteItem, SQLiteQueryParams } from '../types'
4+
5+
export function execute<Data extends SQLiteItem = never>(
6+
dbName: string,
7+
query: string,
8+
params?: SQLiteQueryParams
9+
): QueryResult<Data> {
10+
const nativeResult = HybridQuickSQLite.execute(dbName, query, params)
11+
const result = buildJsQueryResult<Data>(nativeResult)
12+
return result
13+
}
14+
15+
export async function executeAsync<Data extends SQLiteItem = never>(
16+
dbName: string,
17+
query: string,
18+
params?: SQLiteQueryParams
19+
): Promise<QueryResult<Data>> {
20+
const nativeResult = await HybridQuickSQLite.executeAsync(
21+
dbName,
22+
query,
23+
params
24+
)
25+
const result = buildJsQueryResult<Data>(nativeResult)
26+
return result
27+
}
28+
29+
function buildJsQueryResult<Data extends SQLiteItem = never>({
30+
insertId,
31+
rowsAffected,
32+
results,
33+
}: NativeQueryResult): QueryResult<Data> {
34+
const data = results as Data[]
35+
36+
return {
37+
insertId,
38+
rowsAffected,
39+
rows: {
40+
_array: data,
41+
length: data.length,
42+
item: (idx: number) => data[idx],
43+
},
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { locks, HybridQuickSQLite } from './nitro'
2-
import type { NativeQueryResult } from './specs/NativeQueryResult.nitro'
1+
import { locks, HybridQuickSQLite } from '../nitro'
32
import { transaction } from './transaction'
43
import type {
54
BatchQueryCommand,
@@ -9,7 +8,8 @@ import type {
98
SQLiteItem,
109
SQLiteQueryParams,
1110
Transaction,
12-
} from './types'
11+
} from '../types'
12+
import { execute, executeAsync } from './execute'
1313

1414
export function open(
1515
options: QuickSQLiteConnectionOptions
@@ -56,45 +56,3 @@ export function close(dbName: string) {
5656
HybridQuickSQLite.close(dbName)
5757
delete locks[dbName]
5858
}
59-
60-
export function execute<Data extends SQLiteItem = never>(
61-
dbName: string,
62-
query: string,
63-
params?: SQLiteQueryParams
64-
): QueryResult<Data> {
65-
const nativeResult = HybridQuickSQLite.execute(dbName, query, params)
66-
const result = buildJsQueryResult<Data>(nativeResult)
67-
return result
68-
}
69-
70-
export async function executeAsync<Data extends SQLiteItem = never>(
71-
dbName: string,
72-
query: string,
73-
params?: SQLiteQueryParams
74-
): Promise<QueryResult<Data>> {
75-
const nativeResult = await HybridQuickSQLite.executeAsync(
76-
dbName,
77-
query,
78-
params
79-
)
80-
const result = buildJsQueryResult<Data>(nativeResult)
81-
return result
82-
}
83-
84-
function buildJsQueryResult<Data extends SQLiteItem = never>({
85-
insertId,
86-
rowsAffected,
87-
results,
88-
}: NativeQueryResult): QueryResult<Data> {
89-
const data = results as Data[]
90-
91-
return {
92-
insertId,
93-
rowsAffected,
94-
rows: {
95-
_array: data,
96-
length: data.length,
97-
item: (idx: number) => data[idx],
98-
},
99-
}
100-
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as Operations from './operations'
2-
import { locks, HybridQuickSQLite } from './nitro'
1+
import { locks, HybridQuickSQLite } from '../nitro'
32
import type {
43
QueryResult,
54
SQLiteItem,
65
SQLiteQueryParams,
76
Transaction,
8-
} from './types'
7+
} from '../types'
8+
import { execute, executeAsync } from './execute'
99

1010
export interface PendingTransaction {
1111
/*
@@ -39,7 +39,7 @@ export const transaction = async (
3939
`Quick SQLite Error: Cannot execute query on finalized transaction: ${dbName}`
4040
)
4141
}
42-
return Operations.execute(dbName, query, params)
42+
return execute(dbName, query, params)
4343
}
4444

4545
const executeAsyncOnTransaction = <Data extends SQLiteItem = never>(
@@ -51,7 +51,7 @@ export const transaction = async (
5151
`Quick SQLite Error: Cannot execute query on finalized transaction: ${dbName}`
5252
)
5353
}
54-
return Operations.executeAsync(dbName, query, params)
54+
return executeAsync(dbName, query, params)
5555
}
5656

5757
const commit = () => {

package/src/typeORM.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
SQLiteQueryParams,
1212
Transaction,
1313
} from './types'
14-
import * as Operations from './operations'
14+
import * as Operations from './operations/session'
1515

1616
interface TypeOrmQuickSQLiteConnection {
1717
executeSql: <RowData extends SQLiteItem = never>(

0 commit comments

Comments
 (0)