Код

Код


script.ts

Код:

import { PrismaClient } from "@prisma/client";


const prisma = new PrismaClient({

 log: ["query", "info", "warn", "error"],

});


async function main() {

 // create an account

 const accountWithPost = await prisma.account.create({

  data: {

   email: "hello@exmaple.com",

   name: "John Doe",

   meta: {

    firstName: "John",

    lastName: "Doe",

    age: 30,

   },

   isActive: true,

   posts: {

    create: {

     title: "Post #1",

     content: "Hello world",

     published: true,

    },

   },

  },

 });

 console.log(accountWithPost);


 // select active accounts

 const activeAccounts = await prisma.account.findMany({

  where: {

   isActive: true,

  },

 });

 console.group(activeAccounts);

}


main()

 .then(async () => {

  await prisma.$disconnect();

 })

 .catch(async (e) => {

  console.error(e);

  await prisma.$disconnect();

  process.exit(1);

 });


BEGIN;

INSERT

INTO

  cta.Account (id, email, name, meta, isActive, createdAt)

VALUES

  (?, ?, ?, ?, ?, ?);

INSERT

INTO

  cta.Post (id, title, content, published, accountId)

VALUES

  (?, ?, ?, ?, ?);

SELECT

  cta.Account.id,

  cta.Account.parentAccountId,

  cta.Account.email,

  cta.Account.name,

  cta.Account.meta,

  cta.Account.isActive,

  cta.Account.createdAt

FROM

  cta.Account

WHERE

  cta.Account.id = ?

LIMIT ? OFFSET ?;

COMMIT;

Report Page