1- import { NITRO_SQLITE_NULL } from '..'
1+ import { NITRO_SQLITE_NULL , simpleNullHandlingEnabled } from '..'
22import { HybridNitroSQLite } from '../nitro'
33import type { NativeQueryResult } from '../specs/NativeQueryResult.nitro'
44import type {
@@ -8,31 +8,35 @@ import type {
88 QueryResultRow ,
99} from '../types'
1010
11- export function execute < Data extends QueryResultRow = never > (
11+ export function execute < Row extends QueryResultRow = never > (
1212 dbName : string ,
1313 query : string ,
1414 params ?: SQLiteQueryParams
15- ) : QueryResult < Data > {
15+ ) : QueryResult < Row > {
1616 const nativeResult = HybridNitroSQLite . execute (
1717 dbName ,
1818 query ,
1919 toNativeQueryParams ( params )
2020 )
21- const result = buildJsQueryResult < Data > ( nativeResult )
21+ const result = buildJsQueryResult < Row > ( nativeResult )
2222 return result
2323}
2424
25- export async function executeAsync < Data extends QueryResultRow = never > (
25+ export async function executeAsync < Row extends QueryResultRow = never > (
2626 dbName : string ,
2727 query : string ,
2828 params ?: SQLiteQueryParams
29- ) : Promise < QueryResult < Data > > {
29+ ) : Promise < QueryResult < Row > > {
30+ const transformedParams = simpleNullHandlingEnabled ( )
31+ ? toNativeQueryParams ( params )
32+ : ( params as NativeSQLiteQueryParams )
33+
3034 const nativeResult = await HybridNitroSQLite . executeAsync (
3135 dbName ,
3236 query ,
33- toNativeQueryParams ( params )
37+ transformedParams
3438 )
35- const result = buildJsQueryResult < Data > ( nativeResult )
39+ const result = buildJsQueryResult < Row > ( nativeResult )
3640 return result
3741}
3842
@@ -47,21 +51,25 @@ function toNativeQueryParams(
4751 } )
4852}
4953
50- function buildJsQueryResult < Data extends QueryResultRow = never > ( {
54+ function buildJsQueryResult < Row extends QueryResultRow = never > ( {
5155 insertId,
5256 rowsAffected,
5357 results,
54- } : NativeQueryResult ) : QueryResult < Data > {
55- const data = results . map ( ( row ) =>
56- Object . fromEntries (
57- Object . entries ( row ) . map ( ( [ key , value ] ) => {
58- if ( value === NITRO_SQLITE_NULL ) {
59- return [ key , undefined ]
60- }
61- return [ key , value ]
62- } )
63- )
64- ) as Data [ ]
58+ } : NativeQueryResult ) : QueryResult < Row > {
59+ let data : Row [ ] = results as Row [ ]
60+
61+ if ( simpleNullHandlingEnabled ( ) ) {
62+ data = results . map ( ( row ) =>
63+ Object . fromEntries (
64+ Object . entries ( row ) . map ( ( [ key , value ] ) => {
65+ if ( value === NITRO_SQLITE_NULL ) {
66+ return [ key , undefined ]
67+ }
68+ return [ key , value ]
69+ } )
70+ )
71+ ) as Row [ ]
72+ }
6573
6674 return {
6775 insertId,
0 commit comments