tursodatabase / tursodatabase/libsql-client-ts

columnTypes behavior is confusing

Open
#93 2 comments 0 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

This might be a sqld/hrana issue, but I'm reporting this from the observations from the TS client as seen in https://github.com/libsql/libsql-client-ts/pull/87

The values incolumnTypes have inconsistent (and, in my opinion, not very useful) behavior. The values are be based on the underlying table types given at the time of creation, but follow strange rules.

  • Given type cloB becomes columnType cloB (note the exact reproduction of case)
  • Given type text becomes columnType TEXT

As far as I can tell, the rules for deriving columnTypes are like this:

  • If one of the main SQLite types in any case (TEXT, BLOB, INTEGER, REAL), convert to uppercase
  • Otherwise, give back verbatim what was specified when creating the table, including any size limit (e.g. "VaRcHaR(255)" is also reported verbatim)

Additionally, the affinity "NUMERIC" can't be discerned at all by looking at columnTypes. When a column has numeric affinity, the columnType won't tell you what kind of value is actually in each row (it could be a JS string or number - you still have to examine each value itself to know for sure what you've got).

I'm not sure how useful all this is. Client code can break if the type simply changes case in the table and can't easily discern affinity. It would be more useful if the type was always provided in SQLite type affinity form in as a constant string (regardless how it was provided when creating the table). That would give a more reliable indicator of what's in each row value, and easy to switch on.

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 by reviewing the observations in pull request #87 and tracing how the TypeScript client obtains and exposes columnTypes, including whether the behavior comes from sqld or hrana. Reproduce the TEXT, BLOB, and NUMERIC-affinity examples from this issue; done means columnTypes consistently reports the intended SQLite affinity without depending on declaration casing or spelling.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
api, databases
Issue type
Bug
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.