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:
154
-
155
-
### Default null handling
156
-
157
-
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**.
158
-
159
-
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:
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.
195
-
196
-
```typescript
197
-
constres=db.execute('SELECT * FROM User')
198
-
199
-
constfirstItem=res.rows?.item(0)
200
-
if (firstItem.age===null) { // Nullish values will always be null and never undefined.
201
-
// Handle null value
202
-
}
203
-
```
204
-
205
-
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.
206
-
207
151
## Dynamic Column Metadata
208
152
209
153
In some scenarios, dynamic applications may need to get some metadata information about the returned result set.
0 commit comments