drizzle-team / drizzle-team/drizzle-orm

[BUG]: bun-sql adapter silently exits with code 0 when using Core Query Builder in standalone scripts

Open
#5,451 10 comments 0 reactions 0 assignees View on GitHub
1.0.0-beta.* bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

1.0.0-beta.16-ea816b6

### What version of `drizzle-kit` are you using?

1.0.0-beta.16-ea816b6

### Other packages

_No response_

### Describe the Bug

### Description
When using `drizzle-orm/bun-sql` (currently testing on `@beta`) in a standalone/short-lived script (like a database seeder), the execution silently stops when calling specific `db.select()` queries.

The script exits with code `0`, no errors are thrown, `catch` blocks are not triggered, and subsequent `console.log` statements are never reached.

**Crucial detail:** This issue is highly specific to the Drizzle API method being used and the execution context.

### Reproduction / Investigation Details

I have spent some time isolating the exact triggers. Here are the facts:

1. **Execution Context:**
- Long-running server application: **Works perfectly** (returns data as expected) (Or at least I haven't noticed).
- Standalone script (e.g., seeding script): **Silently exits**.

2. **Database State:**
- The issue occurs regardless of whether the database is empty or populated.

3. **API Methods (in the standalone script context):**
I tested multiple ways to query the same data in the exact same script. The bug only occurs with the Core Query Builder.

❌ **Fails (Silently exits script with code 0):**
```ts
// Example 1: Core Query Builder count
const [userCount] = await db.select({ count: count() }).from(users);

// Example 2: Core Query Builder select
const postsList = await db.select({
id: posts.id,
userId: posts.userId,
dateCreated: posts.dateCreated,
}).from(posts);
```

✅ **Works perfectly (executes and returns data):**
```ts
// Raw SQL
const userCount = await db.execute(sql`SELECT COUNT(*) as count FROM ${users}`)
.then((res) => res[0].count as number);

// New $count API
const userCount = await db.$count(users);

// Relational API
const postsList = await db.query.posts.findMany({
columns: {
id: true,
userId: true,
dateCreated: true,
},
});
```

### Expected behavior
`await db.select().from()` should return the queried data in standalone scripts, exactly as it does in a server context, or at least throw an error if something fails internally. It should not abruptly exit the process with code 0.

### Environment & Setup
- Drizzle ORM version: `1.0.0-beta.16-ea816b6`
- Database driver: `drizzle-orm/bun-sql`
- Bun version: `1.3.10`
- OS: `Windows 10.0.26200` (Script running in `oven/bun` docker container)
- CPU: `11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz (16 cores)`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.