Skip to content

Fix $onUpdate not handling sql values - #2911

Closed
L-Mario564 wants to merge 11 commits into
drizzle-team:betafrom
L-Mario564:fix-on-update-sql
Closed

L-Mario564 wants to merge 11 commits into
drizzle-team:betafrom
L-Mario564:fix-on-update-sql

Conversation

@L-Mario564

Copy link
Copy Markdown
Contributor

Addresses #2388.

$onUpdate on a column now handles sql values properly.

const table = pgTable('table', {
    ...
    updatedDate: timestamp('updated_date', { mode: 'date' }).$onUpdate(() => sql`CURRENT_TIMESTAMP`) // this now works as expected
});

Comment thread drizzle-orm/src/libsql/session.ts Outdated
@sdarnell

Copy link
Copy Markdown

This change seems to change every type's toDriver()/mapToDriver() to check for SQL values.
So presumably custom types also need to perform the check?

As per #3730 it looks to me like adding the check to buildUpdateSet() (like the check in buildInsertQuery()) for each dialect would possibly be a better solution.

@Sukairo-02

Copy link
Copy Markdown
Collaborator

SQL shouldn't be mapper's concern. Re-implemented in #5002 using test cases from this PR.

renovate Bot added a commit to cigaleapp/beamup that referenced this pull request Sep 21, 2026
##### [v0.45.2](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.2)

- Fixed `sql.identifier()`, `sql.as()` escaping issues. Previously all the values passed to this functions were not properly escaped
  causing a possible SQL Injection (CWE-89) vulnerability

Thanks to [@EthanKim88](https://github.com/EthanKim88), [@0x90sh](https://github.com/0x90sh) and [@wgoodall01](https://github.com/wgoodall01) for reaching out to us with a reproduction and suggested fix
##### [v0.45.1](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.1)

- Fixed pg-native Pool detection in node-postgres transactions breaking in environments with forbidden `require()` ([#5107](drizzle-team/drizzle-orm#5107))
##### [v0.45.0](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.0)

- Fixed pg-native Pool detection in node-postgres transactions
- Allowed subqueries in select fields
- Updated typo algorythm => algorithm
- Fixed `$onUpdate` not handling `SQL` values (fixes [#2388](drizzle-team/drizzle-orm#2388), tests implemented by [L-Mario564](https://github.com/L-Mario564) in [#2911](drizzle-team/drizzle-orm#2911))
- Fixed `pg` mappers not handling `Date` instances in `bun-sql:postgresql` driver responses for `date`, `timestamp` types (fixes [#4493](drizzle-team/drizzle-orm#4493))
##### [v0.44.7](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.44.7)

- fix durable sqlite transaction return value [#3746](drizzle-team/drizzle-orm#3746) - thanks [@joaocstro](https://github.com/joaocstro)
##### [v0.44.6](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.44.6)

- feat: add $replicas reference [#4874](drizzle-team/drizzle-orm#4874)
renovate Bot added a commit to cigaleapp/beamup that referenced this pull request Sep 28, 2026
##### [v0.45.3](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.3)

#### New Netlify DB Driver

> Note: The Netlify DB driver is developed and maintained by the Netlify team.

**Installation:**

```bash
npm i @netlify/db
```

**Usage example:**

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

// reads NETLIFY_DB_URL and NETLIFY_DB_DRIVER env vars
const db = drizzle();

const result = await db.execute('select 1');
```

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

const db = drizzle(process.env.DATABASE_URL);

const result = await db.execute('select 1');
```

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

// Explicit client — consumer controls the driver
const db = drizzle({ client: netlifyDbClient });

const result = await db.execute('select 1');
```
##### [v0.45.2](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.2)

- Fixed `sql.identifier()`, `sql.as()` escaping issues. Previously all the values passed to this functions were not properly escaped
  causing a possible SQL Injection (CWE-89) vulnerability

Thanks to [@EthanKim88](https://github.com/EthanKim88), [@0x90sh](https://github.com/0x90sh) and [@wgoodall01](https://github.com/wgoodall01) for reaching out to us with a reproduction and suggested fix
##### [v0.45.1](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.1)

- Fixed pg-native Pool detection in node-postgres transactions breaking in environments with forbidden `require()` ([#5107](drizzle-team/drizzle-orm#5107))
##### [v0.45.0](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.0)

- Fixed pg-native Pool detection in node-postgres transactions
- Allowed subqueries in select fields
- Updated typo algorythm => algorithm
- Fixed `$onUpdate` not handling `SQL` values (fixes [#2388](drizzle-team/drizzle-orm#2388), tests implemented by [L-Mario564](https://github.com/L-Mario564) in [#2911](drizzle-team/drizzle-orm#2911))
- Fixed `pg` mappers not handling `Date` instances in `bun-sql:postgresql` driver responses for `date`, `timestamp` types (fixes [#4493](drizzle-team/drizzle-orm#4493))
##### [v0.44.7](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.44.7)

- fix durable sqlite transaction return value [#3746](drizzle-team/drizzle-orm#3746) - thanks [@joaocstro](https://github.com/joaocstro)
##### [v0.44.6](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.44.6)

- feat: add $replicas reference [#4874](drizzle-team/drizzle-orm#4874)
renovate Bot added a commit to cigaleapp/beamup that referenced this pull request Oct 15, 2026
##### [v0.45.4](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.4)

- Fixed `postgres-js` not using prepared queries on explicit `.prepare(name)`
##### [v0.45.3](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.3)

#### New Netlify DB Driver

> Note: The Netlify DB driver is developed and maintained by the Netlify team.

**Installation:**

```bash
npm i @netlify/db
```

**Usage example:**

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

// reads NETLIFY_DB_URL and NETLIFY_DB_DRIVER env vars
const db = drizzle();

const result = await db.execute('select 1');
```

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

const db = drizzle(process.env.DATABASE_URL);

const result = await db.execute('select 1');
```

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

// Explicit client — consumer controls the driver
const db = drizzle({ client: netlifyDbClient });

const result = await db.execute('select 1');
```
##### [v0.45.2](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.2)

- Fixed `sql.identifier()`, `sql.as()` escaping issues. Previously all the values passed to this functions were not properly escaped
  causing a possible SQL Injection (CWE-89) vulnerability

Thanks to [@EthanKim88](https://github.com/EthanKim88), [@0x90sh](https://github.com/0x90sh) and [@wgoodall01](https://github.com/wgoodall01) for reaching out to us with a reproduction and suggested fix
##### [v0.45.1](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.1)

- Fixed pg-native Pool detection in node-postgres transactions breaking in environments with forbidden `require()` ([#5107](drizzle-team/drizzle-orm#5107))
##### [v0.45.0](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.0)

- Fixed pg-native Pool detection in node-postgres transactions
- Allowed subqueries in select fields
- Updated typo algorythm => algorithm
- Fixed `$onUpdate` not handling `SQL` values (fixes [#2388](drizzle-team/drizzle-orm#2388), tests implemented by [L-Mario564](https://github.com/L-Mario564) in [#2911](drizzle-team/drizzle-orm#2911))
- Fixed `pg` mappers not handling `Date` instances in `bun-sql:postgresql` driver responses for `date`, `timestamp` types (fixes [#4493](drizzle-team/drizzle-orm#4493))
##### [v0.44.7](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.44.7)

- fix durable sqlite transaction return value [#3746](drizzle-team/drizzle-orm#3746) - thanks [@joaocstro](https://github.com/joaocstro)
##### [v0.44.6](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.44.6)

- feat: add $replicas reference [#4874](drizzle-team/drizzle-orm#4874)
renovate Bot added a commit to cigaleapp/beamup that referenced this pull request Oct 16, 2026
##### [v0.45.4](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.4)

- Fixed `postgres-js` not using prepared queries on explicit `.prepare(name)`
##### [v0.45.3](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.3)

##### New Netlify DB Driver

> Note: The Netlify DB driver is developed and maintained by the Netlify team.

**Installation:**

```bash
npm i @netlify/db
```

**Usage example:**

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

// reads NETLIFY_DB_URL and NETLIFY_DB_DRIVER env vars
const db = drizzle();

const result = await db.execute('select 1');
```

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

const db = drizzle(process.env.DATABASE_URL);

const result = await db.execute('select 1');
```

```typescript
import { drizzle } from 'drizzle-orm/netlify-db';

// Explicit client — consumer controls the driver
const db = drizzle({ client: netlifyDbClient });

const result = await db.execute('select 1');
```
##### [v0.45.2](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.2)

- Fixed `sql.identifier()`, `sql.as()` escaping issues. Previously all the values passed to this functions were not properly escaped
  causing a possible SQL Injection (CWE-89) vulnerability

Thanks to [@EthanKim88](https://github.com/EthanKim88), [@0x90sh](https://github.com/0x90sh) and [@wgoodall01](https://github.com/wgoodall01) for reaching out to us with a reproduction and suggested fix
##### [v0.45.1](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.1)

- Fixed pg-native Pool detection in node-postgres transactions breaking in environments with forbidden `require()` ([#5107](drizzle-team/drizzle-orm#5107))
##### [v0.45.0](https://github.com/drizzle-team/drizzle-orm/releases/tag/0.45.0)

- Fixed pg-native Pool detection in node-postgres transactions
- Allowed subqueries in select fields
- Updated typo algorythm => algorithm
- Fixed `$onUpdate` not handling `SQL` values (fixes [#2388](drizzle-team/drizzle-orm#2388), tests implemented by [L-Mario564](https://github.com/L-Mario564) in [#2911](drizzle-team/drizzle-orm#2911))
- Fixed `pg` mappers not handling `Date` instances in `bun-sql:postgresql` driver responses for `date`, `timestamp` types (fixes [#4493](drizzle-team/drizzle-orm#4493))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants