drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.29k stars 625 forks source link

[FEATURE]: `CREATE TRIGGER` functions #843

Open MatanYadaev opened 1 year ago

MatanYadaev commented 1 year ago

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();
mattaiod commented 11 months ago

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

strength to you and thank you :)

ItayTamary commented 10 months ago

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

strength to you and thank you :)

ghyath5 commented 8 months ago

any updates here ?

Khosraw commented 5 months ago

Bump

mianala commented 4 months ago

+1

Raveen2001 commented 4 months ago

+1

adfdev commented 4 months ago

+1

sh-k-l commented 4 months ago

+1

1mono2 commented 3 months ago

+1

millette commented 3 months ago

@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.