in ,

Prisma 2.0 is Now in Beta: Type-safe Database Access with Prisma Client | Prisma, Hacker News

Prisma 2.0 is Now in Beta: Type-safe Database Access with Prisma Client | Prisma, Hacker News

Contents Modern database access with Prisma Client 2.0 What’s in this release? Renaming the prisma2 (repository to prisma) Renaming the prisma2 CLI

    )

An abstraction that make the right thing easy (“pit of success”) Queries not classes to avoid complex model objects (Less boilerplate) so developers can focus on the important parts of their app Learn more about how Prisma makes developers productive in the (Introduction or get a taste of the Prisma Client API by checking out the code examples on the (website) .


The @ prisma / client module is different from “conventional” node modules. With conventional node modules (eg lodash ), the entire package is downloaded into your node_modules (directory and only gets updated when you re-install the package. (The @ prisma / client node module is different. It is a "facade package" (basically a stub that does not contain any functional code. While you do need to install it (once


with npm install @ prisma / client , it is likely that the code inside the node_modules / @ prisma / client directory changes more often as you're evolving your application. That's because whenever you make changes to the Prisma schema, you need to re-generate Prisma Client which updates the code in the @ prisma / client (node ​​module.)

because the (node_modules / @ prisma / client directory contains some code that is (tailored to your project, it is sometimes called a "smart node module":

Auto-comple representation and type-safety benefits even in plain JavaScript Auto-completion is an extremely powerful tool for developers. It allows them to explore an API directly in their editor instead of referring to documentation. Prisma Client brings auto-completion to your database queries!

Thanks to Prisma Client’s generated types which are included in the (index.d.ts) of the @ prisma / client module, this feature is available not only to TypeScript developers, but also when developing an application in plain JavaScript.

Type-safety for partial database queries A major benefit of Prisma Client compared to other ORMs and database tools is that it provides full type safety - even for "partial" database queris (ie when you query only the subset of a model's field or include a (relation ). As an example, consider this Prisma Client query (you can swith the tab to view the corresponding (Prisma models) ): (const) usersWithPartialPosts =(await) prisma

 . 
 user .  findMany   
    {{   include : {{     posts
:  {{       select :  {{         title :  (true)  , 
         published :  (true)        }      }    }  }  )    (Note that the resulting  usersWithPartialPosts  will be  statically typed  to:    (export)  

type User={{   id

: (number)   email : (string)   name : (string) |

  
 }  const  usersWithPartialPosts :   (
 User 

& ({    posts

:  {{         title :  (string)  ; 
         published :  (boolean)  ; 
     }  []  ;  }  )  

[

]

This means that TypeScript will catch any errors when you make a typo or accidentally access a property that was not requested from the database! Getting started The best way to get started with Prisma Client is by following the (Quickstart) (in the docs:) Quickstart (5 min)

Alternatively you can:

    Setup a new project with Prisma from scratch

  • (Add Prisma to an existing project

    What's in this release?

    Because Prisma 2.0 is now the default for developers getting started with Prisma, the Prisma repositories have been renamed as follows:

    What do you think?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    GIPHY App Key not set. Please check settings

    Half-Life: Alyx Is Officially the Best-Rated VR Game Ever, Crypto Coins News

    Half-Life: Alyx Is Officially the Best-Rated VR Game Ever, Crypto Coins News

    Amazon: Walkout leader’s firing wasn’t due to his organizing efforts, Ars Technica

    Amazon: Walkout leader’s firing wasn’t due to his organizing efforts, Ars Technica