Skip to content

Commit 5e5aff9

Browse files
committed
refactor: move null handling code
1 parent 46f58cb commit 5e5aff9

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

package/src/index.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { transaction } from './operations/transaction'
22
import { HybridNitroSQLite } from './nitro'
33
import { open } from './operations/session'
44
import { execute, executeAsync } from './operations/execute'
5-
import { SQLiteNullValue } from './types'
65
import { init } from './OnLoad'
76
export type * from './types'
87
export { typeORMDriver } from './typeORM'
@@ -22,21 +21,9 @@ export const NitroSQLite = {
2221
}
2322

2423
export { open } from './operations/session'
25-
26-
let ENABLE_SIMPLE_NULL_HANDLING = false
27-
export function enableSimpleNullHandling(
28-
shouldEnableSimpleNullHandling = true
29-
) {
30-
ENABLE_SIMPLE_NULL_HANDLING = shouldEnableSimpleNullHandling
31-
}
32-
export function isSimpleNullHandlingEnabled() {
33-
return ENABLE_SIMPLE_NULL_HANDLING
34-
}
35-
36-
export const NITRO_SQLITE_NULL: SQLiteNullValue = { isNitroSQLiteNull: true }
37-
export function isNitroSQLiteNull(value: any): value is SQLiteNullValue {
38-
if (typeof value === 'object' && 'isNitroSQLiteNull' in value) {
39-
return true
40-
}
41-
return false
42-
}
24+
export {
25+
isNitroSQLiteNull,
26+
NITRO_SQLITE_NULL,
27+
isSimpleNullHandlingEnabled,
28+
enableSimpleNullHandling,
29+
} from './nullHandling'

package/src/nullHandling.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { SQLiteNullValue, SQLiteValue } from './types'
2+
import { SQLiteQueryParamItem } from './types'
3+
4+
let ENABLE_SIMPLE_NULL_HANDLING = false
5+
6+
export function enableSimpleNullHandling(
7+
shouldEnableSimpleNullHandling = true
8+
) {
9+
ENABLE_SIMPLE_NULL_HANDLING = shouldEnableSimpleNullHandling
10+
}
11+
12+
export function isSimpleNullHandlingEnabled() {
13+
return ENABLE_SIMPLE_NULL_HANDLING
14+
}
15+
16+
export const NITRO_SQLITE_NULL: SQLiteNullValue = { isNitroSQLiteNull: true }
17+
export function isNitroSQLiteNull(value: any): value is SQLiteNullValue {
18+
if (typeof value === 'object' && 'isNitroSQLiteNull' in value) {
19+
return true
20+
}
21+
return false
22+
}
23+
24+
export function replaceWithNativeNullValue(
25+
value: SQLiteQueryParamItem
26+
): SQLiteValue {
27+
if (value === undefined || value === null) {
28+
return NITRO_SQLITE_NULL
29+
}
30+
return value
31+
}

0 commit comments

Comments
 (0)