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

Temporary workaround for Union-Types in the distant future #212

Closed
Tracked by #216
medz opened this issue May 4, 2023 · 6 comments
Closed
Tracked by #216

Temporary workaround for Union-Types in the distant future #212

medz opened this issue May 4, 2023 · 6 comments

Comments

@medz
Copy link
Owner

medz commented May 4, 2023

Temporary workaround for Union-Types in the distant future

In the planned full Prisma ORM feature support, we voted to wait for Dart 3 Union-Types support results.

But after months of waiting, the Dart language team is reluctant to announce any news and developments related to union types. My vision:

  1. For multi-type input scenarios such as where, the dynamic type is used, and we add a check method inside the function to check that the input is a supported type.
  2. The returned joint demand will not be processed temporarily.
  3. For incoming parameters, we add temporary docs to describe it.

Disadvantage: It is impossible for users to know what the incoming type is without reading the documentation or source code.
Advantages: Completed ahead of time, when Dart Union-types are supported, we can produce types for them (dynamic is replaced by a specific union type)

@medz
Copy link
Owner Author

medz commented May 4, 2023

Alternatively, we construct a nested view type for nesting:

where = PrismaUnion<A, PrismaUnion<B, C>>

This will obviously increase the complexity of the condition. It is worth noting that this method is adopted by the early version 1.0.

@Linloir
Copy link
Contributor

Linloir commented May 11, 2023

Dart 3 is out alongside Google I/O yesterday! looking forward for updates~

@medz
Copy link
Owner Author

medz commented May 11, 2023

Dart 3 is out alongside Google I/O yesterday! looking forward for updates~

No Union-Types and macros, little pity.

@Linloir
Copy link
Contributor

Linloir commented May 11, 2023

Dart 3 is out alongside Google I/O yesterday! looking forward for updates~

No Union-Types and macros, little pity.

Is it possible to make union structures such as something below?

class UnionNullableStringWhereClause {
  factory string(String val);
  factory null();

  String? value;
  bool isNull;
}

By properly defining factory constructors it's possible to deduce whether the value is a string or a null.

And by using a nullable UnionNullableStringWhereClause type in the where clause it'll be easy to tell whether the user is declaring a null for the string or just left the whole where empty.

@medz
Copy link
Owner Author

medz commented May 11, 2023

I made this structure once, and the code size doubled. It doesn't feel like the best solution. Currently I'm thinking about dynamic or nested Union views. After dynamic, Dart 3 will migrate painlessly after the release of Union, while nested attempts will require a lot of code changes for subsequent upgrades.

dynamic Advantages: Painless upgrades, Disadvantages: Developers must read the comments, otherwise they will not know the specific content that needs to be passed in.

@medz medz mentioned this issue May 18, 2023
7 tasks
@medz
Copy link
Owner Author

medz commented Nov 25, 2023

I haven't waited long for the Dart union types feature. PrismaUnion is built in the new version to implement structure nesting. Please follow #290

@medz medz closed this as completed Nov 25, 2023
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

2 participants