Prisma: Use classes & decorators for a code-first Prisma Schema SDK

Created on 25 Sep 2019  Ā·  1Comment  Ā·  Source: prisma/prisma

Description

We've explored this area in the past and came to the conclusion that classes aren't a great fit to do data-modeling in general, and more especially in Javascript for the following reasons:

  • (JS specific) Poor support for classes (eg: lack of multi-inheritance) + poor type-safety with TS
  • (JS specific) Decorators are still experimental, so is reflection
  • Database types can’t all be expressed by the language primitives. Meaning types need to be defined twice (eg: like TypeORM)
  • OO encourages to mix two different abstractions in one: Data-modeling and domain model concepts. Lots of ORMs mixes them/allow to mix them for convenience under the concept of ā€œEntitiesā€ or ā€œModelsā€ classes. We think this only works for small/simple applications, and we should encourage for better modularity from the start.

    • ā€œBut gluing data persistence and model logic together comes at a cost. When it comes to managing the growth of Rails applications, particularly those that have intricate business logic spread over a large set of features and capabilities, the framework defaults suffer from a kind of metaphor shear where the concept of ā€˜models’ directly mapping to database tables is overshadowed by the variety and complexity of business logic and domain model concepts.ā€ - Rise and fall of ORM

  • (JS specific) Pure objects are more idiomatic to JS + functional paradigm is becoming more popular (eg: react-hooks)
  • (JS specific) Easier API for higher level frameworks: Building dynamic objects is simpler than classes

If you still think classes and decorators are a great fit, feel free to leave your opinion here šŸ™Œ

Most helpful comment

(JS specific) Decorators are still experimental, so is reflection

That's why Angular 2+ uses them for over 3 years, as well as many apps deployed to productions :confused:

Database types can’t all be expressed by the language primitives. Meaning types need to be defined twice (eg: like TypeORM)

Fixable by simple transform plugin:
https://github.com/MichalLytek/typegraphql-reflection-poc

lack of multi-inheritance

Use class mixins and prefer composition over inheritance?
https://github.com/MichalLytek/type-graphql/tree/9af3077c94f11723615973838320285272634c2f/examples/mixin-classes

poor type-safety with TS

What do you mean?

We think this only works for small/simple applications, and we should encourage for better modularity from the start.

So Prisma2 is designed only for large teams with big enterprise apps? If there are people and teams that uses the TypeORM and TypeGraphQL pattern sucesfully, we should just skip them because they can't be right?

Pure objects are more idiomatic to JS + functional paradigm is becoming more popular

So why Photon is returning Promises instead of RXJS observables? :P

Easier API for higher level frameworks: Building dynamic objects is simpler than classes

Why not both? Have a simple API for building prisma2 from object and then allow for creating decorator API on top of that?

>All comments

(JS specific) Decorators are still experimental, so is reflection

That's why Angular 2+ uses them for over 3 years, as well as many apps deployed to productions :confused:

Database types can’t all be expressed by the language primitives. Meaning types need to be defined twice (eg: like TypeORM)

Fixable by simple transform plugin:
https://github.com/MichalLytek/typegraphql-reflection-poc

lack of multi-inheritance

Use class mixins and prefer composition over inheritance?
https://github.com/MichalLytek/type-graphql/tree/9af3077c94f11723615973838320285272634c2f/examples/mixin-classes

poor type-safety with TS

What do you mean?

We think this only works for small/simple applications, and we should encourage for better modularity from the start.

So Prisma2 is designed only for large teams with big enterprise apps? If there are people and teams that uses the TypeORM and TypeGraphQL pattern sucesfully, we should just skip them because they can't be right?

Pure objects are more idiomatic to JS + functional paradigm is becoming more popular

So why Photon is returning Promises instead of RXJS observables? :P

Easier API for higher level frameworks: Building dynamic objects is simpler than classes

Why not both? Have a simple API for building prisma2 from object and then allow for creating decorator API on top of that?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

divyenduz picture divyenduz  Ā·  3Comments

janpio picture janpio  Ā·  3Comments

janpio picture janpio  Ā·  3Comments

SameerChorge94 picture SameerChorge94  Ā·  3Comments

steebchen picture steebchen  Ā·  3Comments