drizzle-team / drizzle-team/drizzle-orm

[BUG]: prepared statement do not seem to work in batch

Open
#2,197 5 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

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

0.30.6

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

0.20.14

### Describe the Bug

preapred statement like the following
```
const insertUser = db
.insert(users)
.values({
address: sql.placeholder('address'),
name: sql.placeholder('name'),
created: sql.placeholder('created'),
})
.onConflictDoUpdate({
target: users.address,
set: {
name: sql`coalesce(excluded.name,name)`,
},
})
.prepare();
```

cannot be used in batch like this
```
const response = await db.batch([
insertUser.execute({address, name: action.name || null, created: timestampMS}),
```

Note that it works in cloudflare worker :

```
const insertUser = env.DB.prepare(`INSERT INTO Users(address,name,created)
VALUES(?1,?2,?3)
ON CONFLICT(address) DO UPDATE SET name=coalesce(excluded.name,name)
`);
const insertDomainUser = env.DB.prepare(`INSERT INTO DomainUsers(user,domain,domainUsername,publicKey,signature,added,lastPresence)
VALUES(?1,?2,?3,?4,?5,?6,?7)
ON CONFLICT(user,domain) DO UPDATE SET domainUsername=coalesce(excluded.domainUsername,domainUsername), added=excluded.added, lastPresence=excluded.lastPresence
`);
const response = await env.DB.batch([
insertUser.bind(address, action.name || null, timestampMS),
insertDomainUser.bind(address, action.domain, action.domainUsername || null, publicKey, action.signature, timestampMS, timestampMS),
]);

```

### Expected behavior

I expect to be able to execute prepared statement in a batch

### Environment & setup

_No response_

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.