tursodatabase / tursodatabase/libsql-client-ts

Support for array parameter in "WHERE IN" clause

Open
#195 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
576
Forks
69
PR merge metrics
No merged PRs in 30d

Description

Hello.
I have the following code:

import { Client as LibsqlClient, createClient } from '@libsql/client/web';
...
const res = await client.execute({
	sql: 'SELECT * FROM watched_videos WHERE videoId IN (:videos) LIMIT 10;',
	args: { videos: ['--0zLNUmhRI', '--1AEHcLmuk'] },
});

Expected behavior:
Given the table has more than 2 records and the records with videoId '--0zLNUmhRI' and '--1AEHcLmuk' exist, the query should return two rows containing the corresponding videoId.

Actual result - no records are returned:

{
    "columns": [
        "videoId",
        "status"
    ],
    "columnTypes": [
        "varchar(255)",
        "INT",
    ],
    "rows": [],
    "rowsAffected": 0,
    "lastInsertRowid": null
}

I've looked at the code libsql, and it seems that currently there is no support for an array of values as argument, like the above.
https://github.com/tursodatabase/libsql-client-ts/blob/main/packages/libsql-core/src/api.ts#L422

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at packages/libsql-core/src/api.ts around line 422 and inspect how execute arguments are typed and bound. Use the reported SELECT with IN (:videos) as the entry case; done means passing the two-element array returns both matching rows instead of an empty result.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, sqlite, typescript
Domain
api, database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.