Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

prisma database example

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String   @db.VarChar(255)
  content   String?
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id])
  authorId  Int
}

model Profile {
  id     Int     @id @default(autoincrement())
  bio    String?
  user   User    @relation(fields: [userId], references: [id])
  userId Int     @unique
}

model User {
  id      Int      @id @default(autoincrement())
  email   String   @unique
  name    String?
  posts   Post[]
  profile Profile?
}
Comment

prisma write database

async function main() {
  await prisma.user.create({
    data: {
      name: 'Alice',
      email: 'alice@prisma.io',
      posts: {
        create: { title: 'Hello World' },
      },
      profile: {
        create: { bio: 'I like turtles' },
      },
    },
  })

  const allUsers = await prisma.user.findMany({
    include: {
      posts: true,
      profile: true,
    },
  })
  console.dir(allUsers, { depth: null })
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jsonl parser 
Javascript :: remove last character from string javascript 
Javascript :: javascript add method to a class 
Javascript :: javascript access map elements 
Javascript :: read and save excel with react 
Javascript :: how to detect if javascript is disabled with javascript 
Javascript :: open window in same tab 
Javascript :: how to change textContent in js 
Javascript :: react throttle render 
Javascript :: event handler 
Javascript :: get item in array from index 
Javascript :: metadata object ANGULAR 
Javascript :: example custom theme material ui 
Javascript :: delete value from an array javascript 
Javascript :: javascript Insert Item to Map 
Javascript :: react animations 
Javascript :: what is process.env.NODE_ENV 
Javascript :: Promise.all() with async and await to run in console 
Javascript :: Graph pie 
Javascript :: Ternary Expressions in JavaScript 
Javascript :: array count in mongoose query 
Javascript :: copy an array 
Javascript :: javascript syntax of throw statement 
Javascript :: assertion error in jest 
Javascript :: call node js function from javascript 
Javascript :: regular expression escape character 
Javascript :: object model javascript 
Javascript :: npm ERR! missing script: build:dev 
Javascript :: passing ref to child component 
Javascript :: router 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =