drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: Problem on MacBook - This statement does not return data. Use run() instead

Open hillaliy opened this issue 2 years ago • 14 comments

What version of drizzle-orm are you using?

v0.32.0

What version of drizzle-kit are you using?

v0.23.0

Describe the Bug

Screenshot 2024-07-13 at 13 33 06

When I execute db:push I get en error. It's working on Window but not on my Mac.

Error: yossihillali@Yossis-MacBook-Pro homarr % pnpm db:push

> homarr@ db:push /Users/yossihillali/homarr
> pnpm -F db push:sqlite


> @homarr/[email protected] push:sqlite /Users/yossihillali/homarr/packages/db
> drizzle-kit push --config ./configs/sqlite.config.ts

drizzle-kit: v0.23.0
drizzle-orm: v0.32.0

Custom config path was provided, using './configs/sqlite.config.ts'
Reading config file '/Users/yossihillali/homarr/packages/db/configs/sqlite.config.ts'
[✓] Pulling schema from database...
TypeError: This statement does not return data. Use run() instead
    at Object.query (/Users/yossihillali/homarr/node_modules/drizzle-kit/bin.cjs:121780:54)
    at sqlitePush (/Users/yossihillali/homarr/node_modules/drizzle-kit/bin.cjs:124445:23)
    at async _Command.<anonymous> (/Users/yossihillali/homarr/node_modules/drizzle-kit/bin.cjs:131629:7)

The error happens when I try to push the db schema. Repo: https://github.com/homarr-labs/homarr/tree/dev

Expected behavior

No response

Environment & setup

Node - 20.15.1 pnpm - 9.5.0 No response

hillaliy avatar Jul 13 '24 10:07 hillaliy

To elaborate: I debugged this with OP. You can find the drizzle related code here: https://github.com/homarr-labs/homarr/tree/dev/packages/db. Our versions between Windows & Mac of packages are identical and we never encountered this error on Windows (hence maybe a problem with Mac?). The error does not seem to be thrown in our code and we decided to report this here. We were unable to find existing issues with the same problem / identical error.

manuel-rw avatar Jul 13 '24 10:07 manuel-rw

[✓] Pulling schema from database...
TypeError: This statement does not return data. Use run() instead
    at Object.query (C:\Users\dewin\Documents\Personal\dewin-demo\node_modules\drizzle-kit\bin.cjs:121780:54)
    at sqlitePush (C:\Users\dewin\Documents\Personal\dewin-demo\node_modules\drizzle-kit\bin.cjs:124445:23)
    at async _Command.<anonymous> (C:\Users\dewin\Documents\Personal\dewin-demo\node_modules\drizzle-kit\bin.cjs:131629:7)

Having the same issue here, both on windows and linux, figure a "workaround" changing query to run directly in the package

 if (statementsToExecute.length === 0) {
          (0, import_hanji11.render)(`
[${source_default.blue("i")}] No changes detected`);
        } else {
          if (!("driver" in credentials2)) {
            await db2.query("begin");  //db2.run("begin")
            try {
              for (const dStmnt of statementsToExecute) {
                await db2.query(dStmnt); //db2.run(dStmnt)
              }
              await db2.query("commit"); //db2.run("commit"))
            } catch (e2) {
              console.error(e2);
              await db2.query("rollback"); //db2.run("rollback")
              process.exit(1);
            }
          } else if (credentials2.driver === "turso") {
            await db2.batch(statementsToExecute.map((it) => ({ query: it })));
          }
          (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
        }

Working as expected on Drizzle-Kit 0.22.8, guessing is because they are using run() instead of query()

if (statementsToExecute.length === 0) {
          (0, import_hanji11.render)(`
[${source_default.blue("i")}] No changes detected`);
        } else {
          for (const dStmnt of statementsToExecute) {
            await db2.run(dStmnt);
          }
          (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
        }
      }

DewinU avatar Jul 16 '24 01:07 DewinU

"drizzle-orm": "^0.32.0",
"drizzle-kit": "^0.23.0",
node : v22.4.0

I have same issues and DewinU workaround solve my problem.

if (!("driver" in credentials2)) {
  await db2.query("begin");  //db2.run("begin")
  try {
    for (const dStmnt of statementsToExecute) {
      await db2.query(dStmnt); //db2.run(dStmnt)
    }
    await db2.query("commit"); //db2.run("commit"))
  } catch (e2) {
    console.error(e2);
    await db2.query("rollback"); //db2.run("rollback")
    process.exit(1);
  }
}

tz182736 avatar Jul 16 '24 23:07 tz182736

I have the same issue (on MacBook Pro 2021 Apple M1 Pro) and the workaround provided by @DewinU works for me.

[✓] Pulling schema from database...
TypeError: This statement does not return data. Use run() instead
    at Object.query (C:\Users\dewin\Documents\Personal\dewin-demo\node_modules\drizzle-kit\bin.cjs:121780:54)
    at sqlitePush (C:\Users\dewin\Documents\Personal\dewin-demo\node_modules\drizzle-kit\bin.cjs:124445:23)
    at async _Command.<anonymous> (C:\Users\dewin\Documents\Personal\dewin-demo\node_modules\drizzle-kit\bin.cjs:131629:7)

Having the same issue here, both on windows and linux, figure a "workaround" changing query to run directly in the package

 if (statementsToExecute.length === 0) {
          (0, import_hanji11.render)(`
[${source_default.blue("i")}] No changes detected`);
        } else {
          if (!("driver" in credentials2)) {
            await db2.query("begin");  //db2.run("begin")
            try {
              for (const dStmnt of statementsToExecute) {
                await db2.query(dStmnt); //db2.run(dStmnt)
              }
              await db2.query("commit"); //db2.run("commit"))
            } catch (e2) {
              console.error(e2);
              await db2.query("rollback"); //db2.run("rollback")
              process.exit(1);
            }
          } else if (credentials2.driver === "turso") {
            await db2.batch(statementsToExecute.map((it) => ({ query: it })));
          }
          (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
        }

Working as expected on Drizzle-Kit 0.22.8, guessing is because they are using run() instead of query()

if (statementsToExecute.length === 0) {
          (0, import_hanji11.render)(`
[${source_default.blue("i")}] No changes detected`);
        } else {
          for (const dStmnt of statementsToExecute) {
            await db2.run(dStmnt);
          }
          (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
        }
      }

K1NXZ avatar Jul 17 '24 18:07 K1NXZ

See https://github.com/drizzle-team/drizzle-kit-mirror/issues/500#issuecomment-2239083475

Bouchtaoui avatar Jul 19 '24 13:07 Bouchtaoui

The issue is still happening to me

I'm running arch linux

ChoaibMouhrach avatar Aug 07 '24 08:08 ChoaibMouhrach

The error is prompting with the pushing commands, migrations are fine. Idk why @hillaliy close this, is still happening

The other fix besides my workaround is using another version before 0.23 like 0.22.8

EDIT: Still having the same error with 0.24, think i will stay in 0.22.8 for now.

DewinU avatar Aug 15 '24 01:08 DewinU

The error is prompting with the pushing commands, migrations are fine. Idk why @hillaliy close this, is still happening

The other fix besides my workaround is using another version before 0.23 like 0.22.8

EDIT: Still having the same error with 0.24, think i will stay in 0.22.8 for now.

drizzle-kit fallback to 0.22.8, which is indeed a workaround!

gandli avatar Aug 26 '24 02:08 gandli

Still having this issue, I downgraded to 0.22.8 and it works...

camdenvaughan avatar Aug 27 '24 20:08 camdenvaughan

Having the same issue on Mac M1

jimzer avatar Sep 05 '24 09:09 jimzer

aww man I would love for this PR to be merged D:

justinechang39 avatar Oct 31 '24 14:10 justinechang39

Hi currrently i have

//drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
	schema: './src/lib/server/db/schema.ts',

	dbCredentials: {
		url: process.env.DATABASE_URL
	},

	verbose: true,
	strict: true,
	dialect: 'sqlite'
});


// src/lib/server/db/index.ts
import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";
import { env } from "$env/dynamic/private";
const client = new Database(env.DATABASE_URL);
export const db = drizzle(client);

When i run

pnpm run db:push                                                             

> [email protected] db:push /Users/fb/Documents/Github/vido/vido
> drizzle-kit push

No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/fb/Documents/Github/vido/vido/drizzle.config.ts'
[✓] Pulling schema from database...

 Warning  You are about to execute current statements:

CREATE TABLE `films_import` (...
.....
<confirm execution>

TypeError: This statement does not return data. Use run() instead
    at Object.query (/Users/fb/Documents/Github/vido/vido/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:65739:53)
    at sqlitePush (/Users/fb/Documents/Github/vido/vido/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:83176:22)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.handler (/Users/fb/Documents/Github/vido/vido/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:88632:9)
    at async run (/Users/fb/Documents/Github/vido/vido/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:86944:7)

my env

better-sqlite3 11.5.0
drizzle-kit 0.27.0
drizzle-orm 0.36.0
node v22.6.0

fbehrens avatar Oct 31 '24 19:10 fbehrens

Worked for me. Copied from vim. Thought line numbers would be helpful. vi node_modules/drizzle-kit/bin.cjs

drizzle-kit 0.27.1

83171         if (statementsToExecute.length === 0) {
83172           (0, import_hanji11.render)(`
83173 [${source_default.blue("i")}] No changes detected`);
83174         } else {
83175           if (!("driver" in credentials2)) {
83176             await db.run("begin");
83177             try {
83178               for (const dStmnt of statementsToExecute) {
83179                 await db.run(dStmnt);
83180               }
83181               await db.run("commit");
83182             } catch (e2) {
83183               console.error(e2);
83184               await db.run("rollback");
83185               process.exit(1);
83186             }
83187           }
83188           (0, import_hanji11.render)(`[${source_default.green("\u2713")}] Changes applied`);
83189         }

bauchdj avatar Nov 06 '24 07:11 bauchdj

Was fixed in [email protected]

AndriiSherman avatar Nov 06 '24 19:11 AndriiSherman