Reading Data (Go)
Overview
The Prisma client is based on the operations defined in the GraphQL schema of your Prisma API. For reading data, it basically mirrors the GraphQL queries of your Prisma service.
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.