Skip to content
\n
\n
    \n
  1. UUIDs are generated as strings, and createdAt fields with @default(now()) are also generated (as mentioned in the original README).
  2. \n
\n
\n

Yes, prisma-factory currently does not support generating default values based on native database type attributes because DMMF, used in prisma-factory, does not support passing native types (ref: prisma/prisma#10252). Therefore, one simple way is to override the id property yourself, as you already described.

\n
\n
    \n
  1. No sequence number accessor.
  2. \n
\n
\n

Could you please tell me more about the sequence number accessor? Is it similar to sequences in factory_bot?

","upvoteCount":1,"url":"https://github.com/orgs/factory-js/discussions/28#discussioncomment-9555555"}}}

How to use sequence, or custom vars on Prisma? #28

Closed Answered by ktmouk
darr1s asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @darr1s. 👋

  1. Prisma generated factories cannot create custom variables.

It is impossible to add new variables to the defined factory because of TypeScript limitation, but you can create a new factory with the defined factory by using .def, like below:

const baseUserFactory = defineUserFactory(db)
const { props, vars } = baseUserFactory.def

export const userFactory = await factory
  .define({
    props: {
      ...props,
      foo: () => "foo", // add 'foo' prop
    },
    vars: {
      ...vars,
      bar: () => "bar", // add 'bar' var
    },
  })
  1. UUIDs are generated as strings, and createdAt fields with @default(now()) are also generated (as mentioned in the original README).

Y…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@darr1s
Comment options

@ktmouk
Comment options

Answer selected by ktmouk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants