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 :: prisma usersWithZeroPosts 
Javascript :: console.log(number++); console.log(++number); console.log(number); 
Javascript :: react mui pagination change text color site:stackoverflow.com 
Javascript :: javascript remove the second to last character of a string 
Javascript :: todo app html css javascript 
Javascript :: onclick readmore and readless react js 
Javascript :: mongodb function example 
Javascript :: camelcase to css variable javascript 
Javascript :: button style when clicked and unclicked react material 
Javascript :: sinha express crud template 
Javascript :: adding number upto n , adding number, fastest number addding 
Javascript :: dockerignore node_modules 
Javascript :: How many options are there to climb a ladder with N 
Javascript :: for-loop-how-to-loop-through-an-array-in-js 
Javascript :: how to run json server 
Javascript :: convert text to number 
Javascript :: number of factors 
Javascript :: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 
Javascript :: calculator program in javascript 
Javascript :: comment field react 
Javascript :: singleton class in js 
Javascript :: req.body showing undefined 
Javascript :: how to sort linesin javascript 
Javascript :: react native android build location 
Javascript :: ternary operator multiple conditions 
Javascript :: javascript Passing Parameter as Default Values 
Javascript :: javascript Working of multiple yield Statements 
Javascript :: disable SerializableStateInvariantMiddleware and ImmutableStateInvariantMiddleware middlewares for large redux stores 
Javascript :: bootstrap on tabs change 
Javascript :: change rotation phaser 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =