You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to internal limitations with Nitro modules, we have to handle nullish values explicitly in NitroSQLite. There are two ways to send and receive null values:
146
+
147
+
#### Default null handling
148
+
149
+
By default, the user can pass the `NITRO_SQLITE_NULL` constant instead of `null` or `undefined` to query params and will also receive this constant for nullish values in e.g. `SELECT` queries. `NITRO_SQLITE_NULL` is the object that is used internally to handle nullish values, therefore **this approach does NOT introduce any performance overhead**.
150
+
151
+
A `INSERT` query with nullish values could look like this:
Query results that are received from e.g. `execute()` will also return this special object/struct. To check for null values, the user can use the a special function:
163
+
```
164
+
import { isNitroSQLiteNull } from 'react-native-nitro-sqlite'
165
+
166
+
const res = db.execute('SELECT * FROM User')
167
+
168
+
const firstItem = res.rows?.item(0)
169
+
if (isNitroSQLiteNull(firstItem.age) {
170
+
// Handle null value
171
+
}
172
+
```
173
+
174
+
#### Simplified null handling
175
+
To enable simple null handling, call `enableSimpleNullHandling()` in the root of your project. This will allow you to just pass `null` or `undefined` to NitroSQLite functions, e.g. as query params. in `execute()`:
Note that in SQLite, both `undefined` and `null` are transformed into the same representation in the database. Therefore, nullish values received from `SELECT` queries will always evaluate to `null`, even if `undefined` was used in the `INSERT` query.
185
+
186
+
```typescript
187
+
const res =db.execute('SELECT * FROM User')
188
+
189
+
const firstItem =res.rows?.item(0)
190
+
if (firstItem.age===null) { // Nullish values will always be null and never undefined.
191
+
// Handle null value
192
+
}
193
+
```
194
+
195
+
Simple null handling adds some logic to internally transform nullish values into a special object/struct and vice versa, that is sent/received from the native C++ side. This **might introduce some performance overhead**, since we have to loop over the params and query results and check for this structure.
196
+
144
197
### Dynamic Column Metadata
145
198
146
199
In some scenarios, dynamic applications may need to get some metadata information about the returned result set.
0 commit comments