tursodatabase / libsql-client-ts

TypeScript/JavaScript client API for libSQL
https://docs.turso.tech/sdk/ts/quickstart
MIT License
226 stars 32 forks source link

'length' keyword is not supported as an alias name on the client #234

Open giovannibenussi opened 3 months ago

giovannibenussi commented 3 months ago

As mentioned in this discord thread, using length as an alias name doesn't return any results:

// query: select count(*) as 'length' from my_table
ResultSetImpl {
  columns: [ "length" ],
  columnTypes: [ "" ],
  rows: [ {} ],
  rowsAffected: 0,
  lastInsertRowid: undefined
}

// query: select url as 'length' from my_table
ResultSetImpl {
  columns: [ "length" ],
  columnTypes: [ "TEXT" ],
  rows: [ {}, {} ],
  rowsAffected: 0,
  lastInsertRowid: undefined
}

However, the code works when using an alias name other than length:

// query: select count(*) as 'test' from my_table
ResultSetImpl {
  columns: [ "test" ],
  columnTypes: [ "" ],
  rows: [ { test: 2 } ],
  rowsAffected: 0,
  lastInsertRowid: undefined
}

// query: select url as 'test' from my_table
ResultSetImpl {
  columns: [ "test" ],
  columnTypes: [ "TEXT" ],
  rows: [ { test: "https://example.com" }, { test: "https://example.org" } ],
  rowsAffected: 0,
  lastInsertRowid: undefined
}

Using the length name as an alias works on the Turso shell.