Skip to content

Instantly share code, notes, and snippets.

View nikolasburk's full-sized avatar
😑

Nikolas nikolasburk

😑
View GitHub Profile
// VERSION 1
// subscribe to all changes on the `User` table
const s = await prisma.user.subscribe()
// wait for new events to arrive
for await (let event of s) {
// log the details about an event to the terminal
console.log(`Something happened in the database: `)
import "isomorphic-fetch";
console.log("Start ...");
const numberOfRequests = 100;
async function main() {
// 1. Create x requests (as unresolved promises)
console.log(`Creating ${numberOfRequests} requests ...`);
const requests = [];
grant usage on schema public to supabase_auth_admin;
grant all on public."Profile" to supabase_auth_admin;
create or replace function create_profile_on_user_creation() returns trigger as
$$
begin
insert into
public."Profile"(id, "modifiedAt")
values(new.id, current_timestamp);

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
@nikolasburk
nikolasburk / nextjs-and-prisma.md
Last active July 1, 2023 22:59
Fullstack Apps with Next.js and Prisma (PostgreSQL, MySQL & SQLite)

🚀 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

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
datasource sqlite {
url = "file:data.db"
provider = "sqlite"
}
generator photonjs {
provider = "photonjs"
}
model User {

I'm using these prisma2 versions:

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

Test

Challenge 1

Setup instructions:

git clone https://github.com/prisma/support-challenges
cd support-challenges/challenge-1
# Create local Postgres DB called "test1"