# Prisma Client (Preview): Simplified & Type-safe Database Access
URL: https://www.prisma.io/blog/prisma-client-preview-ahph4o1umail
Published: 2018-09-11
Authors: Nikolas Burk
Description: Prisma Client introduced type-safe, auto-generated database access for application code and marked an important step toward Prisma's modern developer workflow.
The Prisma client is an auto-generated library that can be used as an alternative to Prisma bindings to access data in
your applications. It is available in JavaScript, TypeScript, Flow and Go.
> ⚠️ **This article is outdated** as it relates to [Prisma 1](https://github.com/prisma/prisma1) which is now [deprecated](https://github.com/prisma/prisma1/issues/5208). To learn more about the most recent version of Prisma, read the [documentation](https://www.prisma.io/docs). ⚠️
## Prisma client: The next evolution of Prisma bindings [#prisma-client-the-next-evolution-of-prisma-bindings]
Prisma turns your database into a GraphQL API. This GraphQL API is usually not consumed directly by frontend applications, but is used as a *database abstraction* to simplify data access in application servers (similar to an ORM).
When implementing a GraphQL server with Prisma, the resolvers of your GraphQL servers connect to the Prisma API using [Prisma bindings](https://github.com/prisma/prisma1/tree/master/docs/1.14) and [schema delegation](https://www.prisma.io/blog/graphql-schema-stitching-explained-schema-delegation-4c6caf468405).
> **Schema delegation** is an advanced way to implement resolvers by forwarding incoming requests (using the [`info`](https://www.prisma.io/blog/graphql-server-basics-demystifying-the-info-argument-in-graphql-resolvers-6f26249f613a) object) to another GraphQL API.
While schema delegation is a powerful and elegant concept, it is best suited for advanced use cases. Striving to make Prisma more flexible and easier to use, we are introducing a new way to consume Prisma's API in your application: **The Prisma client**.

### More use cases: Build GraphQL servers, REST APIs & more [#more-use-cases-build-graphql-servers-rest-apis--more]
The new Prisma client serves a similar purpose as Prisma bindings with three major differences:
* While Prisma bindings are designed for GraphQL servers, Prisma client is **more flexible and can be used for more use cases such as REST APIs, CLIs, scripting, etc.**
* Prisma client is an integral part of the Prisma toolchain: It is **configured in `prisma.yml` and generated with the Prisma CLI**.
* Prisma client is **available in various languages**. Today's preview release makes it available in JavaScript, TypeScript, Flow and Go!
### Can I still use Prisma bindings for my GraphQL server? [#can-i-still-use-prisma-bindings-for-my-graphql-server]
Prisma bindings remain a powerful way to implement GraphQL resolvers by delegating to the underlying Prisma API. If Prisma bindings work well for your current use case, there is no need to change your implementation to use the new Prisma client.
***
## Generating the Prisma client [#generating-the-prisma-client]
Prisma client is a library that connects to your Prisma API. It is auto-generated based on your Prisma datamodel and thus aware of all API operations and data structures.
To generate a Prisma client, you need to do two things:
1. Specify the new `generate` property in your `prisma.yml`, e.g.:
```yml
generate:
- generator: typescript-client
output: ./prisma-client/
```
2. Run the new `prisma generate` command in the Prisma CLI. It reads information from `prisma.yml` and your datamodel to generate the Prisma client. **Note that this only works with Prisma 1.17-beta or higher.**
The code above demonstrates how to generate the client in TypeScript; for JavaScript, Flow and Go you can use the following values for `generator`: `javascript-client`, `flow-client` and `go-client`.
## Using the Prisma client API [#using-the-prisma-client-api]
The Prisma client API is generated based on your datamodel and exposes CRUD operations for each model.
All following code examples are based on the datamodel below:
```graphql
type Post {
id: ID! @unique
title: String!
author: User!
}
type User {
id: ID! @unique
email: String! @unique
name: String!
posts: [Post!]!
}
```
> You can check out the full documentation for the new Prisma client API [here](https://v1.prisma.io/docs/1.34/prisma-client/).
### Importing the Prisma client instance [#importing-the-prisma-client-instance]
Once generated, you can import the Prisma client instance into your code:
```js
const { prisma } = require('./prisma-client')
```
```ts
const { prisma } = require('./prisma-client')
```
```go
import "github.com/you/repo/prisma-client"
client := prisma.New(nil)
```
### Reading data [#reading-data]
While Prisma bindings expose all queries via the `query` field, queries can be invoked directly on the generated Prisma client:
```js
const allUsers = await prisma.users()
```
```ts
const allUsers: User[] = await prisma.users()
```
```go
users := client.Users(nil).Exec()
```
This returns all *scalar* fields of the returned `User` objects. Relations can be queried elegantly using method chaining (also referred to as a [fluent API](https://www.sitepoint.com/javascript-like-boss-understanding-fluent-apis/)):
```js
const postsByUser = await prisma.user({ email: 'alice@prisma.io' }).posts()
```
```ts
const postsByUser: Post[] = await prisma.user({ email: 'alice@prisma.io' }).posts()
```
```go
email := "alice@prisma.io"
postsByUser := client.
User(&prisma.UserWhereUniqueInput{Email: &email}).
Posts(nil).
Exec()
```
Note that the snippet above still results in a single request to the Prisma API which is then resolved against the database by Prisma's powerful query engine.
It is also still possible to use GraphQL to query nested data or use schema delegation for advanced use cases with the new Prisma client API.
> See more examples in the [documentation](https://v1.prisma.io/docs/1.34/prisma-client/basic-data-access/reading-data-JAVASCRIPT-rsc2/).
### Writing data [#writing-data]
Just like queries, mutations are also exposed on the top-level on your Prisma client:
```js
const newUser = await prisma.createUser({
name: 'Alice',
email: 'alice@prisma.io',
})
```
```ts
const newUser: User = await prisma.createUser({
name: 'Alice',
email: 'alice@prisma.io',
})
```
```go
client.CreateUser(&prisma.UserCreateInput{
Name: "Alice",
Email: "alice@prisma.io",
})
```
You can also perform several write operations in a single transaction:
```js
const newUserWithPosts = await prisma.createUser({
name: 'Bob',
email: 'bob@prisma.io',
posts: {
create: [
{
title: 'Hello World',
},
{
title: 'I ❤️ Prisma',
},
],
},
})
```
```ts
const newUserWithPosts: User = await prisma.createUser({
name: 'Bob',
email: 'bob@prisma.io',
posts: {
create: [
{
title: 'Hello World',
},
{
title: 'I ❤️ Prisma',
},
],
},
})
```
```go
client.CreateUser(&prisma.UserCreateInput{
Name: "Bob",
Email: "bob@prisma.io",
Posts: &prisma.PostCreateManyWithoutAuthorInput{
Create: &prisma.PostCreateWithoutAuthorInput{
Title: "Hello World",
},
},
})
```
> See more examples in the [documentation](https://v1.prisma.io/docs/1.34/prisma-client/basic-data-access/writing-data-JAVASCRIPT-rsc6/).
### No boilerplate: Type-safety through code generation [#no-boilerplate-type-safety-through-code-generation]
One core benefit of the Prisma client is [type-safety](https://en.wikipedia.org/wiki/Type_safety). Type-safety fosters productivity, better maintainability, easier refactoring and makes for a great developer experience.
Type-safe data access requires a lot of manual work, writing boilerplate code and redundant type definitions. The Prisma client leverages code generation in order to provide custom typings for data models and queries.
***
## Try out Prisma client [#try-out-prisma-client]
To learn more about the Prisma client, check out the new [examples](https://github.com/prisma/prisma-examples) repository or follow the "Get Started" tutorial. Please let us know what you think on [Slack](https://slack.prisma.io) 🙌
[Get started](https://v1.prisma.io/docs/1.34/get-started/01-setting-up-prisma-new-database-JAVASCRIPT-a002/)