Two helpers at the top of Nakodo 's schema file decide how every row in the database records its own age:
const createdAt = () => timestamp ({ withTimezone : true }). notNull (). defaultNow (); const updatedAt = () => timestamp ({ withTimezone : true }) . notNull () . defaultNow () . $onUpdate (() => new Date ());
Enter fullscreen mode
Exit fullscreen mode
They look like a pair. They are not. defaultNow() compiles into the table definition and is executed by Postgres. $onUpdate compiles into nothing at all: it is a JavaScript callback that Drizzle runs while building an UPDATE , adding updated_at = $n to the statement it sends.
You can see the asymmetry in the generated migration, which is the only SQL that exists for these columns:
"created_at" timestamp with time zone DEFAULT now () NOT NULL , "updated_at" timestamp with time zone DEFAULT now () NOT NULL ,
Enter fullscreen mode
Exit fullscreen mode
$ grep -il "create trigger \| create function" drizzle/ * .sql $ echo $?…