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
23.52k stars 577 forks source link

[BUG]: broken methods for crud operations with libsql #718

Closed vedantnn71 closed 1 year ago

vedantnn71 commented 1 year ago

What version of drizzle-orm are you using?

0.26.5

What version of drizzle-kit are you using?

0.18.1

Describe the Bug

hey, i am using libsql on my local environment with drizzle but i am unable to read, insert, update or delete anything in the database.

all the methods for crud operations seem to be broken. i am on the latest drizzle orm and kit version.

here is the code to reproduce:

await db.insert(anyTable).values({
  foo: "bar",
});

await db.update(anyTable).values({
  foo: "foo",
}).where(eq(fanyRow.foo, "bar"));

await db.delete(anyTable).where(eq(anyRow.foo, "bar"));

await db.select().from(anyTable);

my drizzle client code looks like this:

import { drizzle } from "drizzle-orm/libsql";
import { migrate } from "drizzle-orm/libsql/migrator";
import { createClient } from "@libsql/client";
import { schema } from "./schema";
import { env } from "~/env";

export const client = createClient({
  url: env.DATABASE_URL,
  authToken: env.DATABASE_ACCESS_TOKEN,
});

export const db = drizzle(client, { schema });

migrate(db, { migrationsFolder: "./drizzle" })
  .then(() => console.log(`✅ [drizzle] database migrated`))
  .catch((err) => {
    console.log(`❌ [drizzle] error migrating database:`);
    console.error(err);
  }
);

export type DbClient = typeof db;

and i am basically using websockets with the help of turso for local development.

Expected behavior

To perform crud operations and return promises.

Environment & setup

Linux (pop_os) Node version => 18.6.0 Package manager => pnpm

image

AndriiSherman commented 1 year ago

You need to add .run() after .values() function

vedantnn71 commented 1 year ago

Oh got it!

Thanks for the quick response @AndriiSherman! :D

AndriiSherman commented 1 year ago

I think it was skipped in web docs. We will fix that You can refer to this doc for now https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sqlite-core/README.md#insert

AndriiSherman commented 1 year ago

For select you will need to use .all instead of run

vedantnn71 commented 1 year ago

Got it, thanks @AndriiSherman!