luisrudge / prisma-generator-fake-data Goto Github PK
View Code? Open in Web Editor NEWGenerate mock data based on your Prisma models
License: MIT License
Generate mock data based on your Prisma models
License: MIT License
model Example {
someId Int @default(dbgenerated("(current_setting('app.clinic_id'::text)::integer)"))
generates into fake-data.ts:
someId: [object Object]
which errors out:
fake-data.ts:210:16 - error TS2552: Cannot find name 'object'. Did you mean 'Object'?
210 someId: [object Object],
~~~~~~
node_modules/typescript/lib/lib.es5.d.ts:270:13
270 declare var Object: ObjectConstructor;
~~~~~~
'Object' is declared here.
Adding @db.Integer to the prisma schema line has no effect.
I also see an example of a String attribute with @dbgenerated that generates:
someId: '[object Object']
which does not error but is not helpful.
I think the issue is in createMethod.js:37 and :40, where $field.default is returning [object Object]. No handling for dbgenerated inside default?
Thanks
The problem with this schema is not supported by sqlite so the sandbox does not work.
Sample schema with problem:
model User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
roles UserRole[] @default([USER])
}
enum UserRole {
ADMIN
USER
}
This produces the following fake data:
export function fakeUserComplete() {
return {
id: faker.string.uuid(),
roles: USER,
};
}
It should produce:
export function fakeUserComplete() {
return {
id: faker.string.uuid(),
roles: faker.helpers.arrayElement([
UserRole.USER,
] as const),
};
}
This actually breaks our build π’
Using "prisma-generator-fake-data": "^0.11.1" with postgresql provider.
Would it be possible to have an option to run Prettier on the generated file, or at least run an arbitrary script, so that I can run Prettier on it?
Right now the file keeps changing format back and forth and it's not a great experience.
First off: I love this project. I've been thinking that someone should build something like this forever and am happy that it has finally happened π
As I was trying it out though, I ran into an issue. Here's what I did:
try-prisma
:npx try-prisma@latest --template typescript/script -i npm -p . -n demo-test-data
cd demo-test-data
npx prisma migrate dev
prisma-generator-fake-data
npm install -D prisma-generator-fake-data
and in the Prisma schema:
generator client {
provider = "prisma-client-js"
}
generator custom_generator {
provider = "prisma-generator-fake-data"
output = "./fake-data.ts"
}
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
$ npx prisma generate
Prisma schema loaded from prisma/schema.prisma
Here is where I now wait indefinitely for the CLI command to terminate but nothing happens and no fake data appears in my project.
Thanks again for putting in the work for this project, I think it can be incredibly useful in the Prisma community!
Great generator, thanks for putting this together. Was wondering if it would be possible to add a flag that would instruct the generator not to overwrite existing fakes. We'd like to keep this in our schema and generate from our schema often, but also use snapshots in our tests, so we need to assert the same data exists between generate
operations.
Progressive generation would also be cool, where the fake data generator would only generate data for types/methods that don't already exists, but that's probably a big ask.
In case of sqlite
the generator won't create faker objects despite the annotations because it's listed as string.
But there are extensions for sqlite that would allow this also there could be manual serialization.
Would be great if that's supported.
model users {
id String @id @default(cuid())
email String @unique
name String
///FAKE:fakeSettings()
settings String? @default("{}") /// <- This doesn't work
///FAKE:{notificationsEnabled: faker.datatype.boolean(), preferredColor: faker.color.rgb()}
ui_settings Unsupported("json") /// <- This doesn't work either
profile profiles?
}
main
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can fix this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here are some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
semantic-release cannot push the version tag to the branch main
on the remote Git repository with URL https://x-access-token:[secure]@github.com/luisrudge/prisma-generator-fake-data.git
.
This can be caused by:
Good luck with your project β¨
Your semantic-release bot π¦π
Trying to achieve this
/// FAKE: faker.database.mongodbObjectId()
user_id String @db.ObjectId
It still generates a fake string user_id: faker.lorem.words(5)
I know its already possible to generate cusom JSONs and that works! But this wouldve been a nice addition.
I'm not sure if it already exist.
I just stumbled upon this repo and it's awesome! I was wondering if we could get an option to default empty output to null
instead of undefined
as it is currently not the correct type for my outputs. Thanks!
the generated fake-data.ts file starts with an invalid import for me.
It looks like this:
import { MyTestModel } from 'C:\Users\A92615470\IdeaProjects\frontend-privat\node_modules\.pnpm\@[email protected][email protected]\node_modules\@prisma\client';
but should look like this:
import { MyTestModel } from '@prisma/client';
Any Idea what could be the reason for that?
I'm on windows and use pnpm btw.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.