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

[FEATURE]: `CREATE TRIGGER` functions

Open MatanYadaev opened this issue 2 years ago • 4 comments
trafficstars

Describe what you want

Expected behavior:

export const users = pgTable('users', {
  updatedAt: timestamp('updated_at')
    .defaultNow()
    .notNull()
    // Feature request:
    .triggerBeforeUpdate('set_updated_at', sql`set_updated_at()`),
});
-- Inserted manually in a previous migration file
CREATE OR REPLACE FUNCTION set_updated_at()
    RETURNS TRIGGER AS
$$
BEGIN
    NEW.updated_at = NOW();
    RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
CREATE TABLE IF NOT EXISTS "users" (
  "updated_at" timestamp DEFAULT now() NOT NULL,
);

CREATE TRIGGER set_updated_at
BEFORE UPDATE ON "users"
FOR EACH ROW
EXECUTE PROCEDURE set_updated_at();

MatanYadaev avatar Jul 02 '23 10:07 MatanYadaev

It seems to be a priority ! Indeed, it's a very important feature

strength to you and thank you :)

mattaiod avatar Dec 13 '23 10:12 mattaiod

is there an update on the timeline/prioritization for arbitrarily defining triggers within the schema?

strength to you and thank you :)

ItayTamary avatar Jan 10 '24 21:01 ItayTamary

any updates here ?

ghyath5 avatar Mar 05 '24 20:03 ghyath5

Bump

Khosraw avatar May 15 '24 20:05 Khosraw

+1

mianala avatar Jun 14 '24 09:06 mianala

+1

Raveen2001 avatar Jun 15 '24 12:06 Raveen2001

+1

adfdev avatar Jun 18 '24 08:06 adfdev

+1

sh-k-l avatar Jun 19 '24 21:06 sh-k-l

+1

1mono2 avatar Jul 11 '24 11:07 1mono2

@1mono2 @dudubernardino @sh-k-l @adfdev @Raveen2001 @mianala @Khosraw @ghyath5 Your messages are counterproductive. If you're interested and want to share the sentiment, add a reaction to this comment: https://github.com/drizzle-team/drizzle-orm/issues/843#issuecomment-1885771513

That said, I'm also sorry for contributing to the noise since everyone here will get a notification for my comment.

millette avatar Jul 11 '24 14:07 millette

Bump

zackwalton avatar Mar 28 '25 11:03 zackwalton