drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.54k stars 643 forks source link

[BUG]: libsql error's out while inserting #1049

Closed lightyaer closed 11 months ago

lightyaer commented 1 year ago

What version of drizzle-orm are you using?

^0.28.2

What version of drizzle-kit are you using?

^0.19.12

Describe the Bug

While inserting a row on libsql and calling get() on it, without using the returning(), the function normalizeRow is passed a undefined. This inserts the record but also throws an error, which in the end is caught by API's try catch, and results in 500.

function normalizeRow(obj) {
  // The libSQL node-sqlite3 compatibility wrapper returns rows
  // that can be accessed both as objects and arrays. Let's
  // turn them into objects what's what other SQLite drivers
  // do.
  return Object.keys(obj).reduce((acc, key) => {
    if (Object.prototype.propertyIsEnumerable.call(obj, key)) {
      acc[key] = obj[key];
    }
    return acc;
  }, {});
}
Screenshot 2023-08-15 at 2 13 35 PM

Expected behavior

Inserting rows on libsql should work.

Environment & setup

local development setup, but also tried this on turso.

Angelelz commented 11 months ago

You are supposed to only call get() if you're expecting one result. This error is intended behavior. I think you can use the .run() method if you know nothing is going to be returned.