Skip to content

Commit 843db89

Browse files
committed
fix: remove buildJsQueryResult and simplify types
1 parent 58ebc85 commit 843db89

2 files changed

Lines changed: 3 additions & 31 deletions

File tree

package/src/operations/execute.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { HybridNitroSQLite } from '../nitro'
2-
import type { NitroSQLiteQueryResult } from '../specs/NitroSQLiteQueryResult.nitro'
32
import type { QueryResult, QueryResultRow, SQLiteQueryParams } from '../types'
43
import NitroSQLiteError from '../NitroSQLiteError'
54

@@ -10,7 +9,7 @@ export function execute<Row extends QueryResultRow = never>(
109
): QueryResult<Row> {
1110
try {
1211
const result = HybridNitroSQLite.execute(dbName, query, params)
13-
return buildJsQueryResult<Row>(result)
12+
return result as QueryResult<Row>
1413
} catch (error) {
1514
throw NitroSQLiteError.fromError(error)
1615
}
@@ -23,25 +22,8 @@ export async function executeAsync<Row extends QueryResultRow = never>(
2322
): Promise<QueryResult<Row>> {
2423
try {
2524
const result = await HybridNitroSQLite.executeAsync(dbName, query, params)
26-
return buildJsQueryResult<Row>(result)
25+
return result as QueryResult<Row>
2726
} catch (error) {
2827
throw NitroSQLiteError.fromError(error)
2928
}
3029
}
31-
32-
function buildJsQueryResult<Row extends QueryResultRow = never>(
33-
result: NitroSQLiteQueryResult,
34-
): QueryResult<Row> {
35-
const data = result.results as Row[]
36-
37-
return {
38-
...result,
39-
insertId: result.insertId,
40-
rowsAffected: result.rowsAffected,
41-
rows: {
42-
_array: data,
43-
length: data.length,
44-
item: (idx: number) => data[idx],
45-
},
46-
} as QueryResult<Row>
47-
}

package/src/types.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {
2-
NitroSQLiteQueryColumnMetadata,
32
NitroSQLiteQueryResult,
43
NitroSQLiteQueryResultRows,
54
} from './specs/NitroSQLiteQueryResult.nitro'
@@ -42,17 +41,8 @@ export type QueryResultRow = Record<string, SQLiteValue>
4241

4342
export type QueryResult<Row extends QueryResultRow = QueryResultRow> =
4443
NitroSQLiteQueryResult & {
45-
readonly rowsAffected: number
46-
readonly insertId?: number
47-
48-
/** Query results */
49-
readonly results: Row[]
50-
5144
/** Query results in a row format for TypeORM compatibility */
52-
readonly rows?: NitroSQLiteQueryResultRows<Row>
53-
54-
/** Table metadata */
55-
readonly metadata?: Record<string, NitroSQLiteQueryColumnMetadata>
45+
rows?: NitroSQLiteQueryResultRows<Row>
5646
}
5747

5848
export type ExecuteQuery = <Row extends QueryResultRow = QueryResultRow>(

0 commit comments

Comments
 (0)