Hi there, I'd really appreciate it if someone coul...
# orm-help
d
Hi there, I'd really appreciate it if someone could give me some pointers. I have a field I'd like to be autogenerated using a custom function. The closest thing I found in the docs is
Copy code
id   String  @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
is there a way to use a function made by me instead of postgresql default one? For reference, my use case would be something like
Copy code
orderNumber BigInt @default(dbgenerated("random_between(99999, 1000000)"))
r
@dfau 👋 I think that should be possible. Have you faced an error when trying this out?
d
yeah when I try to create the entity it complains that the field is null and that violates the constraint, so I'm guessing it doesnt know how to generate it. I'm not sure how to make sure it finds the function. I just created the function in a migration like
Copy code
CREATE OR REPLACE FUNCTION random_between(low BIGINT ,high BIGINT)
    RETURNS BIGINT AS
$$
BEGIN
    RETURN floor(random()* (high-low + 1) + low);
END;
$$ language 'plpgsql' STRICT;
is that the way to do it to reference it in the schema?
got it working btw, I was being dumb
r
Great!