prismany icon indicating copy to clipboard operation
prismany copied to clipboard

Model types not returned from findMany

Open Gherdty opened this issue 2 years ago • 11 comments

Very excited at the prospect of this CLI. I am finding that the findMany function is not returning the model types from my schema.

In the example project I have changed findFirst to findMany: const sqliteRes = await sqlite.sqliteModel.findMany();

The type for the variable thats returned then becomes: const sqliteRes: runtime.Types.Public.PrismaPromise<T>

It looks like all other functions are working besides findMany.

Gherdty avatar Jul 12 '23 02:07 Gherdty

Thanks for the heads up @Gherdty !

Will take a look when I get a chance, hoping to play around with this project this weekend to see if it works with Prisma 5 as well, so hopefully I can get this fixed when I do that.

JoeRoddy avatar Jul 13 '23 15:07 JoeRoddy

Seeing the same issue on my end. Temporarily, if anyone else is running into this, you can cast the type as a workaround:

import {  PrismaClientPostgres } from '@prismany/client';
import { type PostgresModel } from '@prismany/client/postgres';

  const manyWithType = (await postgres.postgresModel.findMany()) as PostgresModel[];

Definitely not an acceptable solution, but it's an option temporarily while I work on getting this fixed. Thanks again for catching this!

JoeRoddy avatar Jul 15 '23 20:07 JoeRoddy

Should be fixed with version 1.0.2.

Let me know if you get a chance to try it out @Gherdty

Tested with Prisma 5 and that seems to be working for me as well 😄

JoeRoddy avatar Jul 17 '23 13:07 JoeRoddy

just left a comment here: https://github.com/prisma/prisma/issues/2443#issuecomment-1654582157

then saw this issue lol,

how do i force using the latest version when running with npx?

edit: Actually i am using pnpx, dunno if that's technically supported

but running pnpx prismany --version gets this output:

$ pnpx prismany --version
.../share/pnpm/store/v3/tmp/dlx-329510   |   +2 +
.../share/pnpm/store/v3/tmp/dlx-329510   | Progress: resolved 1, reused 0, downloaded 0, added 0
.../share/pnpm/store/v3/tmp/dlx-329510   | Progress: resolved 2, reused 2, downloaded 0, added 2, done

edit 2:

using pnpx prismany@latest generate seemed to work, but now when loading up my nuxt3 site, it seems to fail to find some files:

ERROR  [worker reload] [worker init] Cannot find module '/path/to/site/.nuxt/dev/CBAR/index.js' imported from /path/to/site/.nuxt/dev/index.mjs

safejace avatar Jul 27 '23 21:07 safejace

Thanks for bringing this up @safejace !

Hmm, I don't usually use pnpm, and I've never used pnpx.

Can you try adding the the package to your dev dependencies? npx looks in node_modules/ first, I would think pnpx works the same way 🤞 .

npm i -D prismany@latest

Should be 1.0.2

JoeRoddy avatar Jul 27 '23 21:07 JoeRoddy

I guess it's possible the second error could be a totally new, unrelated bug with prismany. Do you not get those missing files with [email protected]?

JoeRoddy avatar Jul 27 '23 21:07 JoeRoddy

hmmm. ya i seem to be getting the same errors now with 1.0.0

though in the readme, it makes no metion of installing prismany as a dev dependancy. is that expected?

i know nuxt does a lot of magic with autoimports. so it's possible that it's a nuxt issue.

i just don't know how to override/fix it

safejace avatar Jul 27 '23 21:07 safejace

afaik, pnpx should work the same as npx

but im not super experience with these things

safejace avatar Jul 27 '23 21:07 safejace

it's entirely possible that it was never working. i was just looking in the ide for the type checking before even running the site.

but when i run pnpm dev to spin up the nuxt site. nuxt makes\rebuilds the .nuxt folder. and in the .nuxt/dev/index.mjs file i see:

import { PrismaClientCBAR } from './CBAR/index.js';
import { PrismaClientRelease } from './release/index.js';

which is vastly different form other import of other packages. eg:

import { defineEventHandler, handleCacheHeaders, createEvent, eventHandler, setHeaders, sendRedirect, proxyRequest, setResponseStatus, getRequestHeader, setResponseHeader, getRequestHeaders, getCookie, createApp, createRouter as createRouter$1, toNodeListener, fetchWithEvent, lazyEventHandler, readBody, setCookie, deleteCookie, getQuery as getQuery$1, createError } from 'file:///path/to/app/node_modules/.pnpm/[email protected]/node_modules/h3/dist/index.mjs';
...
import { createCall, createFetch } from 'file:////path/to/app/node_modules/.pnpm/[email protected]/node_modules/unenv/runtime/fetch/index.mjs';

...

import { parseURL, withoutBase, joinURL, getQuery, withQuery } from 'file:///path/to app/node_modules/.pnpm/[email protected]/node_modules/ufo/dist/index.mjs';

etc

safejace avatar Jul 27 '23 22:07 safejace

Hm, yeah it sounds like an issue with how it's getting bundled with Nuxt specifically.

If you just do pnpx prisma generate, are you able to import the regular PrismaClient? Or does that have the same problem?

Did you try deleting .nuxt/ and restarting? (I don't have any nuxt experience beyond a tutorial or two)

JoeRoddy avatar Jul 27 '23 22:07 JoeRoddy

deleting .nuxt and restarting doesnt fix anything. it gets overidden every time i start the server

yes, using prisma works

the function is imported as expected:

import { PrismaClient } from 'file:///path/to/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/index.js';

so i just followed the steps from https://github.com/prisma/prisma/issues/2443#issuecomment-1599411256

and it worked. so im not sure what your package is doing, but its slighty different than prisma

regardless, its working for me now. your package would be more convenient ofc

something you could look into, i can help where i can, if you would like to try to support it :D

edit: and most importantly, the type hinting works

safejace avatar Jul 28 '23 05:07 safejace