Skip to content

Instantly share code, notes, and snippets.

Avatar
😑

Nikolas nikolasburk

😑
View GitHub Profile
View relations-prisma-1.md

In Prisma 1, it wasn't necessary to specify both sides of a relation, this means this was allowed:

type User {
  id: ID! @unique @id
  questions: [Question]
}

type Question {
  id: ID! @unique @id
View prisma-stickers.md

Get Prisma Stickers 🚢

We're shipping Prisma stickers for your favorite framework to your home address!

  1. Learn about Prisma and your favorite framework by following the link below 👇
  2. Scroll to the bottom of the page and click Get Stickers
  3. Fill out the form so we can ship the stickers to you 🚢

Prisma ❤️ Your Favorite Framework

@nikolasburk
nikolasburk / nextjs-and-prisma.md
Last active Jul 2, 2021
Fullstack Apps with Next.js and Prisma (PostgreSQL, MySQL & SQLite)
View nextjs-and-prisma.md

🚀 Fullstack Apps with Next.js and Prisma

Next.js blurs the lines between client and server. It supports pre-rendering pages at build time (SSG) or request time (SSR). Prisma is the perfect companion if you need to work with a database in a Next.js app.

Here is a list of example apps that are based on Next.js and use Prisma on the server to access data from a database:

✍️ Language 🤖 Server 🔐 Authentication 🔗 URL
TypeScript API Routes Yes (via NextAuth.js) URL
TypeScript API Routes No
View prisma2.md

Addressing feedback from this Gist.

Pagination. Looks like limited to paginate by id. I wanted to paginate by a date field and felt impossible

In the most recent Preview version, (cursor-)pagination can be done by any unique field or combination of fields. For example:

model Post {
  id        Int     @id @default(autoincrement())
  title     String
View schema.prisma
datasource sqlite {
url = "file:data.db"
provider = "sqlite"
}
generator photonjs {
provider = "photonjs"
}
model User {
View tutorial.md

I'm using these prisma2 versions:

{
  "dependencies": {
    "@prisma/photon": "alpha"
  },
  "devDependencies": {
    "prisma2": "alpha",
    "ts-node-dev": "^1.0.0-pre.44",
View challenge-test.md

Test

Challenge 1

Setup instructions:

git clone https://github.com/prisma/support-challenges
cd support-challenges/challenge-1
# Create local Postgres DB called "test1"
View index.d.ts
import { DMMF, DMMFClass, Engine } from './runtime';
/**
* Utility Types
*/
export declare type Enumerable<T> = T | Array<T>;
export declare type MergeTruthyValues<R extends object, S extends object> = {
[key in keyof S | keyof R]: key extends false ? never : key extends keyof S ? S[key] extends false ? never : S[key] : key extends keyof R ? R[key] : never;
};
export declare type CleanupNever<T> = {
[key in keyof T]: T[key] extends never ? never : key;
View schema.graphql
type User {
id: ID!
name: String
}
type Query {
user(id: ID!): User
}
View express-graphql.js
// express-graphql
const app = express()
app.use('/graphql', graphqlHTTP({ schema }))
app.listen(4000, () => {
console.log(`Server ready at http://localhost:4000`)
})