This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: `) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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",
NewerOlder