Auto-generated database client (ORM*) for JavaScript/TypeScript based on your DB schema.
Follow Photon on GitHubPhoton is based on modern JavaScript & TypeScript (ES6, ES7). Check out the full API documentation.
The API examples are based on a Prisma data model definition.
Photon is based on modern JavaScript & TypeScript (ES6, ES7). Check out the full API documentation.
// Retrieve all posts
const allPosts: Post[] = await photon.posts.findMany()
[
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Introducing the Analytical Engine'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqcs3hk0a51qfk40z0b',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Building General-Purpose Computers'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13: 31: 14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13: 31: 14.308Z',
title: 'Working at Xerox PARC'
},
{
updatedAt: '2018-11-01T13: 31: 14.308Z',
published: true,
id: 'cjnymow0as3i90a51muoz70zp',
createdAt: '2018-11-01T13: 31: 14.308Z',
title: 'Introduction to VLSI Systems'
}
]
// Retrieve user by ID
const userById: User = await photon.users.findOne({ where: { id : 54394 } })
{
id: 'cjnymovv3s3ht0a516fhmria8',
name: 'Grace',
email: 'grace@prisma.io'
}
// Retrieve user by email
const userByEmail: User = await photon.users.findOne({ where: { email : 'ada@prisma.io' } })
{
id: 'cjnymovq4s3hh0a51ghqhok2f',
name: 'Ada',
email: 'ada@prisma.io'
}
// Retrieve the posts of a user
const postsByUser: Post[] = await photon
.users
.findOne({ where: { email: 'ada@prisma.io' }})
.posts()
[
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Introducing the Analytical Engine'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqcs3hk0a51qfk40z0b',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Building General-Purpose Computers'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Why Algorithms are Awesome'
}
]
// Retrieve the categories of a post
const categoriesOfPost: Category[] = await photon
.posts
.findOne({ where: { id: 1 }})
.categories()
[
{
id: 'cjnymow0cs3ib0a517qntpuyf',
name: 'Random'
},
{
id: 'cjnymow0fs3ie0a51yres9ry8',
name: 'Tech'
}
]
// Retrieve the profile of a user via a specific post
const authorProfile: Category[] = await photon
.posts
.findOne({ where: { id: 1 } })
.author()
.profile()
{
id: 'cjnymovvfs3i00a51q1mgzn6o',
bio: 'Hello World!'
}
// Retrieve all published posts about GraphQL or REST
const posts: Post[] = await photon.posts.findMany({
where: {
OR: [
{ title: { contains: 'GraphQL' } },
{ title: { contains: 'REST' } }
],
published: true,
},
orderBy: { createdAt: 'asc' }
})
[
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'GraphQL - The Query Language of the Future'
}
]
// Retrieve all posts of a particular user
// that start with 'Hello'
const posts: Post[] = await photon.users.findOne({
where: { email: 'ada@prisma.io' },
}).posts({
where: {
title: {
startsWith: 'Hello'
}
}
})
[
{
id: 'cjnymovvfs3i00a51q1mgzn6o',
createdAt: '2018-11-01T13: 31: 14.127Z',
text: 'Great work!'
}
]
// Sort posts alphabetically
const alphabeticPosts: Post[] = await photon.posts.findMany({
orderBy: { title: 'asc' },
})
[{
updatedAt: '2018-11-01T13:31:13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Introducing the Analytical Engine'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqcs3hk0a51qfk40z0b',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Building General-Purpose Computers'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Working at Xerox PARC'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: true,
id: 'cjnymow0as3i90a51muoz70zp',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Introduction to VLSI Systems'
}]
// Retrieve the posts from position 6 to position 10
const paginatedPosts1: Post[] = await photon.posts.findMany({
first: 5,
skip: 5,
})
[{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Working at Xerox PARC'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: true,
id: 'cjnymow0as3i90a51muoz70zp',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Introduction to VLSI Systems'
}]
// Retrieve the last 3 posts after having
// skipped 2 posts from the end of the list
const paginatedPosts2: Post[] = await photon.posts.findMany({
last: 3,
skip: 2,
})
[{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
}]
// Retrieve the first 5 posts after a cursor
const paginatedPosts3: Post[] = await photon.posts.findMany({
first: 5,
after: 43834, // represents an ID value
})
[{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Working at Xerox PARC'
}]
// Retrieve the last 5 posts before a cursor
const paginatedPosts4: Post[] = await photon.posts.findMany({
last: 5,
before: 10423, // represents an ID value
})
[{
updatedAt: '2018-11-01T13:31:13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
}]
// Create a new user
const newUser: User = await photon.users.create({
data: {
name: 'Alice',
email: 'alice@prisma.io',
},
})
{
id: 'cjnyr53gasxe00a51i4p2nx8n',
name: 'Alice',
email: 'alice@prisma.io',
role: 'USER'
}
// Update an existing user
const updatedUser: User = await photon.users.update({
data: { role: 'ADMIN' },
where: { email: 'alice@prisma.io' },
})
{
id: 'cjnyr53gasxe00a51i4p2nx8n',
name: 'Alice',
email: 'alice@prisma.io',
role: 'ADMIN'
}
// Delete an existing user
const deletedUser: User = await photon.users.delete({
where: { email: 'alice@prisma.io' },
})
{
id: 'cjnyr53gasxe00a51i4p2nx8n',
name: 'Alice',
email: 'alice@prisma.io',
role: 'ADMIN'
}
// Create a new user with two posts in a
// single transaction
const newUser: User = await photon.users.create({
data: {
email: 'alice@prisma.io',
posts: {
create: [
{ title: 'Join the Prisma Slack on https://slack.prisma.io' },
{ title: 'Follow Prisma on Twitter' },
],
},
},
})
{
id: 'cjnyrgr97szhf0a51tjyz2e14',
name: null,
email: 'alice@prisma.io'
}
// Change the author of a post in a single transaction
const updatedPost: Post = await photon.posts.update({
where: { id: 5424 },
data: {
author: {
connect: { email: 'alice@prisma.io' },
},
},
})
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: true,
id: 'cjnymow0as3i90a51muoz70zp',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Introduction to VLSI Systems'
}
// Update existing user to grant admin rights
// or create if don't exist yet
const upsertedUser: User = await photon.users.upsert({
update: {
role: 'ADMIN'
},
where: {
email: 'alice@prisma.io'
},
create: {
name: 'Alice',
email: 'alice@prisma.io',
role: 'ADMIN'
}
})
{
id: 'cjnyrfmr9szcj0a51802wzot9',
name: null,
email: 'alice@prisma.io'
}
// Grant admin access to all users
// who have a prisma.io-email
const updatedUsers: BatchPayload = await photon.users.updateMany({
data: { role: 'ADMIN'},
where: { email: { endsWith: '@prisma.io' } }
})
{ count: 3 }
// Delete two users with specific email adresses
// (emails that don't exist are silently ignored)
const deletedUsers: BatchPayload = await photon.users.deleteMany({
where: {
email: { in: ['alice@prisma.io', 'bob@prisma.io'] },
}
})
{ count: 1 }
// The returned post objects will only have the `title` and
// `published` properties
const allPosts: Post[] = await photon.posts.findMany({
select: {
title: true,
published: true
}
})
[
{
title: 'Join the Prisma Slack on https://slack.prisma.io',
published: true
},
{
title: 'Follow Prisma on Twitter',
published: false
}
]
// The returned user object will only have the `id` property
const newUser: User = await photon.users.create({
data: {
email: 'alice@prisma.io',
posts: {
create: [
{ title: 'Join the Prisma Slack on https://slack.prisma.io' },
{ title: 'Follow Prisma on Twitter' },
],
},
},
select: { id: true }
})
{
id: 'cjnyt0bilt9tr0a511751giub'
}
// The returned posts objects will have all scalar fields of the `Post` model and additionally all the categories for each post
const allPosts: Post[] = await photon.posts.findMany({
include: { categories: true }
})
[
{
updatedAt: '2019-04-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2019-11-01T13: 31: 13.948Z',
title: 'Join the Prisma Slack on https://slack.prisma.io',
categories: [{ id: "cjdisnmsp9smabxmcnkl", name: "slack" }]
},
{
updatedAt: '2019-01-01T13: 31: 13.948Z',
published: false,
id: 'cjndncioqqpkdkkmxkkmd8dk',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Welcome to Prisma Day',
categories: [
{
id: "cjyq42xvk000001mrg87vdp1j",
name: "prisma-day"
},
{
id: "cjyq43qau000201mrf8ucfzja",
name: "welcome"
}
]
}
]
// The returned user object will have all scalar fields of the `User` model and additionally all the posts of that user
const newUser: User = await photon.users.create({
data: {
email: 'alice@prisma.io',
posts: {
create: [
{ title: 'Join the Prisma Slack on https://slack.prisma.io' },
{ title: 'Follow Prisma on Twitter' },
],
},
},
include: { posts: true }
})
{
id: 'cjnymovv3s3ht0a516fhmria8',
email: 'alice@prisma.io'
posts: [
{
updatedAt: '2019-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Join the Prisma Slack on https://slack.prisma.io'
},
{
updatedAt: '2019-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovqcs3hk0a51qfk40z0b',
createdAt: '2019-11-01T13: 31: 13.948Z',
title: 'Follow Prisma on Twitter'
}
]
}
// Retrieve all posts
const allPosts: Post[] = await photon.posts.findMany()
[
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Introducing the Analytical Engine'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqcs3hk0a51qfk40z0b',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Building General-Purpose Computers'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13: 31: 14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13: 31: 14.308Z',
title: 'Working at Xerox PARC'
},
{
updatedAt: '2018-11-01T13: 31: 14.308Z',
published: true,
id: 'cjnymow0as3i90a51muoz70zp',
createdAt: '2018-11-01T13: 31: 14.308Z',
title: 'Introduction to VLSI Systems'
}
]
// Retrieve user by ID
const userById: User = await photon.users.findOne({ where: { id : 54394 } })
{
id: 'cjnymovv3s3ht0a516fhmria8',
name: 'Grace',
email: 'grace@prisma.io'
}
// Retrieve user by email
const userByEmail: User = await photon.users.findOne({ where: { email : 'ada@prisma.io' } })
{
id: 'cjnymovq4s3hh0a51ghqhok2f',
name: 'Ada',
email: 'ada@prisma.io'
}
// Retrieve the posts of a user
const postsByUser: Post[] = await photon
.users
.findOne({ where: { email: 'ada@prisma.io' }})
.posts()
[
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Introducing the Analytical Engine'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqcs3hk0a51qfk40z0b',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Building General-Purpose Computers'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13: 31: 13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13: 31: 13.948Z',
title: 'Why Algorithms are Awesome'
}
]
// Retrieve the categories of a post
const categoriesOfPost: Category[] = await photon
.posts
.findOne({ where: { id: 1 }})
.categories()
[
{
id: 'cjnymow0cs3ib0a517qntpuyf',
name: 'Random'
},
{
id: 'cjnymow0fs3ie0a51yres9ry8',
name: 'Tech'
}
]
// Retrieve the profile of a user via a specific post
const authorProfile: Category[] = await photon
.posts
.findOne({ where: { id: 1 } })
.author()
.profile()
{
id: 'cjnymovvfs3i00a51q1mgzn6o',
bio: 'Hello World!'
}
// Retrieve all published posts about GraphQL or REST
const posts: Post[] = await photon.posts.findMany({
where: {
OR: [
{ title: { contains: 'GraphQL' } },
{ title: { contains: 'REST' } }
],
published: true,
},
orderBy: { createdAt: 'asc' }
})
[
{
updatedAt: '2018-11-01T13: 31: 14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13: 31: 14.127Z',
title: 'GraphQL - The Query Language of the Future'
}
]
// Retrieve all posts of a particular user
// that start with 'Hello'
const posts: Post[] = await photon.users.findOne({
where: { email: 'ada@prisma.io' },
}).posts({
where: {
title: {
startsWith: 'Hello'
}
}
})
[
{
id: 'cjnymovvfs3i00a51q1mgzn6o',
createdAt: '2018-11-01T13: 31: 14.127Z',
text: 'Great work!'
}
]
// Sort posts alphabetically
const alphabeticPosts: Post[] = await photon.posts.findMany({
orderBy: { title: 'asc' },
})
[{
updatedAt: '2018-11-01T13:31:13.948Z',
published: false,
id: 'cjnymovq9s3hi0a51oz6rp83k',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Introducing the Analytical Engine'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqcs3hk0a51qfk40z0b',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Building General-Purpose Computers'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Working at Xerox PARC'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: true,
id: 'cjnymow0as3i90a51muoz70zp',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Introduction to VLSI Systems'
}]
// Retrieve the posts from position 6 to position 10
const paginatedPosts1: Post[] = await photon.posts.findMany({
first: 5,
skip: 5,
})
[{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Working at Xerox PARC'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: true,
id: 'cjnymow0as3i90a51muoz70zp',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Introduction to VLSI Systems'
}]
// Retrieve the last 3 posts after having
// skipped 2 posts from the end of the list
const paginatedPosts2: Post[] = await photon.posts.findMany({
last: 3,
skip: 2,
})
[{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
}]
// Retrieve the first 5 posts after a cursor
const paginatedPosts3: Post[] = await photon.posts.findMany({
first: 5,
after: 43834, // represents an ID value
})
[{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
},
{
updatedAt: '2018-11-01T13:31:14.308Z',
published: false,
id: 'cjnymow08s3i70a51akud49tl',
createdAt: '2018-11-01T13:31:14.308Z',
title: 'Working at Xerox PARC'
}]
// Retrieve the last 5 posts before a cursor
const paginatedPosts4: Post[] = await photon.posts.findMany({
last: 5,
before: 10423, // represents an ID value
})
[{
updatedAt: '2018-11-01T13:31:13.948Z',
published: false,
id: 'cjnymovqjs3hm0a51hfdprde6',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'RESTful APIs Considered Harmful'
},
{
updatedAt: '2018-11-01T13:31:13.948Z',
published: true,
id: 'cjnymovqls3ho0a51rhg7h2xv',
createdAt: '2018-11-01T13:31:13.948Z',
title: 'Why Algorithms are Awesome'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: false,
id: 'cjnymovv7s3hu0a51j6he7hhs',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Five Things You Didn't Know About Compilers'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvbs3hw0a51slwjkii7',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'GraphQL - The Query Language of the Future'
},
{
updatedAt: '2018-11-01T13:31:14.127Z',
published: true,
id: 'cjnymovvds3hy0a51xtxyhyh2',
createdAt: '2018-11-01T13:31:14.127Z',
title: 'Progamming with English Words'
}]
Generated code that looks handwritten. Photon saves CRUD boilerplate and keeps your typings in sync with your database schema.
Photon is based on a high performance query engine that optimizes queries and ensures blazing fast database access.
Next to relational databases, Photon will soon support various kinds of data sources such as document and graph databases and even web APIs.
Save the boilerplate you’d have to write connect your API layer to the database. Photon supports GraphQL, REST, gRPC and many other use cases.
Photon challenges the status quo of ORMs with a new approach. Generate a type-safe data access API instead of writing brittle database queries.
When using Photon with an existing database, Photon will introspect the database schema and generate a custom database client for your app.
Connect your database
Prisma analyses your database schema and generates a data model.
Generate the Prisma client for your preferred programming language.
Build your app
$ npx prisma2 init
and follow the interactive prompt to get started from scratch or with your existing database.$ npm install -g prisma2
$ prisma2 init
Created project.prisma
Run $ prisma2 generate to generate your Photon API
$ prisma2 generate
Generated Photon API based on project.prisma
You can import it with:
import { Photon } from '@generated/photon'
debug
option to true
when instanting your Photon
instance. Learn more in the docs.info
object from a resolver of the first GraphQL schema to a resolver of the second GraphQL schema. Schema delegation also is the foundation for GraphQL binding.nexus-prisma
integration. GraphQL Nexus provides a code-first and type-safe way to build GraphQL servers in a scalable way.