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

List enum values should be typed as strings #108

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Conversation

alii
Copy link
Collaborator

@alii alii commented Sep 28, 2024

This PR introduces a fix where enum list values are typed as MyEnum[] but Prisma's migrations actually store them as a string format.

Since kysely is just a query builder, we couldn't expect it to parse this string format into an array, so I think it makes the most sense to have it typed like this.

If you would like to merge this, please could I ask you throughly check the PR, it's very possible I've missed something as I only spent a few minutes looking around the codebase for supporting this feature.

Thanks for prisma-kysely, it's a wonderful tool!

fixes #107

@alii alii requested a review from valtyr as a code owner September 28, 2024 14:17
@alii
Copy link
Collaborator Author

alii commented Oct 4, 2024

Hi @valtyr are you still working on prisma-kysely? Appreciate your time is precious especially in open source, so thank you for your hard work. Would you be looking for maintainers to help out manage prisma-kysely? Would love to see this PR merged and released if you think it's a good addition. Cheers

@valtyr
Copy link
Owner

valtyr commented Oct 11, 2024

Hey @alii, I'm sorry for the late reply. Nice work on this PR! Sadly, prisma-kysely has been on the backburner recently cause of work stuff... but thankfully there's not a lot of maintenance that needs to happen here in general. Seems to me like the code all makes sense. Would be be so kind as to adding a changeset with a minor version bump, that explains that this version includes breaking changes to the way we handle arrays of enums in Postgres. That way we can get this merged and deployed ASAP.

I'm open to having a co-maintainer on the project. Is that something that you would be interested in? If so we could have a chat about things on Discord, just let me know.

Copy link
Owner

@valtyr valtyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks great. I have a few minor comments and there are a few things that seem to have slipped in by accident. Check them out and let me know.

"prisma-kysely": minor
---

Make enum array values actually be strings
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, please update this so it mentions that this might have breaking behavior for people that have added their own array parsers etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Will do

provider = "sqlite"
url = "file:./dev.db"
provider = "postgresql"
url = "env(DATABASE_URL)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't actually work in CI since we're not running a PG server there. Either we skip this in the e2e test or we need to set up a PG server to test against. The server URL should be hard-coded in the test as well so it's deterministic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it - the reason I changed it is because enum arrays are not supported in SQLite so prisma wouldn't generate the schema during the test run. Will have more of a think about this. Perhaps skipping it would be ok

@@ -63,5 +63,6 @@
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
},
"packageManager": "[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove, was added automatically by corepack. Worth noting though that locking down the package manager (and subsequently having corepack automatically use the right package manager version) is not a bad idea - perhaps we can re-add in another PR?

@alii
Copy link
Collaborator Author

alii commented Oct 11, 2024

Hey @alii, I'm sorry for the late reply. Nice work on this PR! Sadly, prisma-kysely has been on the backburner recently cause of work stuff... but thankfully there's not a lot of maintenance that needs to happen here in general. Seems to me like the code all makes sense. Would be be so kind as to adding a changeset with a minor version bump, that explains that this version includes breaking changes to the way we handle arrays of enums in Postgres. That way we can get this merged and deployed ASAP.

I'm open to having a co-maintainer on the project. Is that something that you would be interested in? If so we could have a chat about things on Discord, just let me know.

No worries, must reiterate how amazing the work is you've done so far, so really a big thanks.

Regards to co-maintaining, I would be happy to do that! What's your Discord?

Will get to making these adjustments asap, thanks again.

@valtyr
Copy link
Owner

valtyr commented Oct 11, 2024

Hey @alii, I'm sorry for the late reply. Nice work on this PR! Sadly, prisma-kysely has been on the backburner recently cause of work stuff... but thankfully there's not a lot of maintenance that needs to happen here in general. Seems to me like the code all makes sense. Would be be so kind as to adding a changeset with a minor version bump, that explains that this version includes breaking changes to the way we handle arrays of enums in Postgres. That way we can get this merged and deployed ASAP.
I'm open to having a co-maintainer on the project. Is that something that you would be interested in? If so we could have a chat about things on Discord, just let me know.

No worries, must reiterate how amazing the work is you've done so far, so really a big thanks.

Regards to co-maintaining, I would be happy to do that! What's your Discord?

Will get to making these adjustments asap, thanks again.

Haha thanks, I'm just happy that my code can be useful to others.

It would be awesome if you'd be willing to consider joining as a co-maintainer. Let's find time to chat. My username is valtyrorn on Discord, you can message me there.

),
]
)
: ts.factory.createTypeReferenceNode(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ts.factory.createTypeReferenceNode( can also be reused above to improve readability.

export type Timestamp = ColumnType<Date, Date | string, Date | string>;`;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
export type EnumArrayInner<T extends string, All extends string> = T extends infer Single extends string ? T | \`\${Single},\${Exclude<All, Single>}\` : never
export type EnumArray<T extends string> = '{}' | \`{\${EnumArrayInner<T, T>}}\`;`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having this always would throw ts error for unused variable, maybe would be good to add this conditionaly.

@alii alii marked this pull request as draft October 13, 2024 15:31
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

Successfully merging this pull request may close these issues.

Type for an enum array is incorrectly generated
3 participants