Prisma ClientBasic Data Access

Reading Data (Go)

Overview

The Prisma client is generated from your datamodel. Its API exposes CRUD and other operations for the models defined in the datamodel.

For this page, we'll assume your Prisma API is based on the following datamodel:

type Link {
  id: ID! @unique
  createdAt: DateTime!
  description: String!
  url: String!
  postedBy: User
  votes: [Vote!]!
}

type User {
  id: ID! @unique
  name: String!
  email: String! @unique
  password: String!
  links: [Link!]!
  votes: [Vote!]!
}

type Vote {
  id: ID! @unique
  link: Link!
  user: User!
}

Whenever a model is queried using the Prisma client, all scalar fields of that model are fetched. This is true no matter if a single object or a list of objects is queried.

For example, the following query returns all scalar fields of a single User:

user := client.User(&prisma.UserWhereInput{ "email": "bob@prisma.io" })

In this case, the returned user object will have four properties (that correspond to the scalar fields of the User model): id, name, email and password.

The links and votes fields are both relation fields and are therefore not included in the query.

Here is an example of fetching a list of User objects:

users := client.Users(nil).Exec()

Similar to the previous query, each object inside the users array only has the scalar and no relation fields.

Content
Overview