Giter Club home page Giter Club logo

prisma-generator-fake-data's People

Contributors

agustif avatar brynedwards avatar dustin-engstrom avatar luisrudge avatar ssmietana avatar unclejustin avatar valetek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

prisma-generator-fake-data's Issues

@default(@dbgenerated(...)) generates [object Object]; fails

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

Incorrect data when array has a default value

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.

Support Prettier or a post-generate script

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.

`npx prisma generate` doesn't terminate

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:

  1. Set up a new project with try-prisma:
npx try-prisma@latest --template typescript/script -i npm -p . -n demo-test-data
cd demo-test-data
npx prisma migrate dev
  1. Add 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?
}
  1. Generate fake data
$ 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!

Option to not overwrite existing data

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.

Not working on unsupported types (sqlite)

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?
}

The automated release is failing 🚨

🚨 The automated release from the 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.


Cannot push to the Git repository.

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 πŸ“¦πŸš€

How to override what faker.js generates for a specific fields

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.

Option to default to null instead of undefined?

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!

Invalid import paths for generated imports on Windows

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.