Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.86k stars 111 forks source link

Working with Prisma Studio #96

Open spicyzboss opened 2 years ago

spicyzboss commented 2 years ago

after run cargo prisma studio it show me error

Prisma schema loaded from prisma/schema.prisma
Prisma Studio is up on http://localhost:5555
Unable to get DMMF from Prisma Client:  AggregateError: 
    Error: Generator at /snapshot/node_modules/prisma/prisma-client/generator-build/index.js could not start:
    node:internal/modules/cjs/loader:936
      throw err;
      ^
    Error: Cannot find module '/Users/spicyzboss/Code/contribute/prisma-client-rust/examples/with-actix/--max-old-space-size=8096'
        at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
        at Function._resolveFilename (pkg/prelude/bootstrap.js:1912:46)
        at Function.Module._load (node:internal/modules/cjs/loader:778:27)
        at Function.runMain (pkg/prelude/bootstrap.js:1940:12)
        at node:internal/main/run_main_module:17:47 {
      code: 'MODULE_NOT_FOUND',
      requireStack: []
    }
        at Timeout._onTimeout (/snapshot/node_modules/prisma/build/index.js:43201:25)
        at listOnTimeout (node:internal/timers:559:17)
        at processTimers (node:internal/timers:502:7)
    at next (/snapshot/node_modules/prisma/build/index.js:17644:25)
    at /snapshot/node_modules/prisma/build/index.js:17665:17

This is my schema.prisma

datasource db {
  provider             = "sqlite"
  url                  = "file:./dev.db"
}

generator client {
  provider = "cargo prisma"
  output   = "../src/prisma.rs"
}

model User {
  id          String @id @default(uuid())
  displayName String
  posts       Post[]
}

model Post {
  id      String @id @default(uuid())
  content String
  user    User   @relation(fields: [userId], references: [id])
  userId  String
}
Brendonovich commented 2 years ago

I'm pretty sure this has something to do with this issue.

Prisma Client Python solved this by showing alternatives to access Prisma Studio, we should probably do something similar.

RobertCraigie commented 2 years ago

@Brendonovich For what it's worth I'm looking into an actual fix for this which would be to avoid using the packaged CLI in the first place and instead downloading node at runtime if it isn't already installed on the user's machine.

This is what the CLI workflow with proposed change would look like for Prisma Client Python:

From my testing this works perfectly well in the Python Client and has no discernible downsides apart from the fact that there is somewhat of a size increase when it comes to downloading node with nodeenv, although that can be mitigated by installing nodejs-bin which ends up being the same size as the packaged CLI. The upside to making this change (apart from fixing this particular bug) is that the Python Client then doesn't have to download the engine binaries and can delegate that to the CLI which will remove a lot of code and maintenance burden.

I don't have enough context about the Rust Client to know if this solution would also work here but I thought it was worth bringing to your attention anyway :)

Brendonovich commented 2 years ago

@RobertCraigie that's an interesting idea. Here in Rust-land I don't know if any package that allows for installing node as a dependency.

I don't like the idea of forcing Rust developers to install node, so I'd probably put it behind a feature flag and require that node is available on the system.

If it works for Python then I'm down to do something similar in Rust, thanks for the idea!

AlaaZorkane commented 1 year ago

Any updates on this? Would love to have prisma studio work directly with the rust client 😄

Brendonovich commented 1 year ago

Nothing atm, seeing as Rust doesn't have an equivalent of nodeenv I'm not quite sure how to go about this. I'll do it at some point though.

numfin commented 1 year ago

@Brendonovich i have nodejs in my system. Why this does not work?

Brendonovich commented 1 year ago

@numfin prisma-client-rust-cli doesn't execute the Prisma CLI via node - it uses the pre-packaged version. Accessing the CLI via npm may work.

ktisakib commented 1 year ago

I am also getting the same error

Brendonovich commented 1 year ago

@ktisakib Please don't comment on issues like this unless you have additional information, a 👍 react is enough and prevents notifying everyone else who is subscribed to this thread.

farukg commented 9 months ago

if you just want studio to run, run npx prisma studio as @Brendonovich mentioned