Skip to content

expo-sqlite query args should support null type #18077

@tsheaff

Description

@tsheaff

Summary

The type signature for expo-sqlite's transaction.executeSql method is:

  executeSql(
    sqlStatement: string,
    args?: (number | string)[],
    callback?: SQLStatementCallback,
    errorCallback?: SQLStatementErrorCallback
  ): void;

So the args can only take types (number | string) in a typescript codebase. But when I cast my array like [null, 1234, 'foobar'] as (string | number)[] and pass it through, the sqlite DB properly ends up with a NULL type in the right place.

Proposal is simple: Update the type of args to (number | string | null). Unless I'm missing something subtle in the library, this should be just a matter of updating the type definitions, as the underlying code does work properly and insert the NULL into the DB in this case.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android, iOS

SDK Version (managed workflow only)

expo-sqlite@10.2.0, expo@45.0.6

Environment

npx: installed 2 in 2.164s

  expo-env-info 1.0.4 environment info:
    System:
      OS: macOS 11.6.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.18.3 - ~/.nvm/versions/node/v14.18.3/bin/node
      Yarn: 1.22.18 - ~/.nvm/versions/node/v14.18.3/bin/yarn
      npm: 6.14.15 - ~/.nvm/versions/node/v14.18.3/bin/npm
    Managers:
      CocoaPods: 1.11.3 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
      Android SDK:
        API Levels: 32
        Build Tools: 32.0.0, 32.1.0, 33.0.0
        System Images: android-31 | Google APIs Intel x86 Atom_64
    IDEs:
      Android Studio: 2021.1 AI-211.7628.21.2111.8309675
      Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
    npmPackages:
      @expo/metro-config: ^0.3.17 => 0.3.17
      expo: ~45.0.0 => 45.0.6
      react: 17.0.2 => 17.0.2
      react-dom: 17.0.2 => 17.0.2
      react-native: ^0.68.2 => 0.68.2
      react-native-web: 0.17.7 => 0.17.7
    npmGlobalPackages:
      eas-cli: 0.52.0
      expo-cli: 5.4.12
    Expo Workflow: managed

Reproducible demo

import * as SQLite from 'expo-sqlite';

SQLite.openDatabase('my-db.db').transaction((tx) => {
  tx.executeSql(
    'insert into my_table (nullable_column, number_column, text_column) values (?, ?, ?)',
    [
      null,
      1234,
      'foobar',
    ],
  );
});

gives typescript error Type 'null' is not assignable to type 'string | number'.ts(2322)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions