Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model types not returned from findMany #1

Open
Gherdty opened this issue Jul 12, 2023 · 11 comments
Open

Model types not returned from findMany #1

Gherdty opened this issue Jul 12, 2023 · 11 comments

Comments

@Gherdty
Copy link

Gherdty commented Jul 12, 2023

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.

@JoeRoddy
Copy link
Owner

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
Copy link
Owner

JoeRoddy commented Jul 15, 2023

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
Copy link
Owner

JoeRoddy commented Jul 17, 2023

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 😄

@safejace
Copy link

safejace commented Jul 27, 2023

just left a comment here: prisma/prisma#2443 (comment)

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

@JoeRoddy
Copy link
Owner

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
Copy link
Owner

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

@safejace
Copy link

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
Copy link

afaik, pnpx should work the same as npx

but im not super experience with these things

@safejace
Copy link

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

@JoeRoddy
Copy link
Owner

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)

@safejace
Copy link

safejace commented Jul 28, 2023

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 prisma/prisma#2443 (comment)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants