How to save array of key, value from json file? using prisma sqlite

I am unable to save customers, purchased items to my database, I am using sqlite prisma, belwo is my customers.json

[
  {
    "id": 1,
    "firstName": "Emily",
    "lastName": "Davis",
    "username": "emilydavisxyz",
    "password": "password123",
    "role": "Customer",
    "balance": 1000,
      "street": "123 Main St",
      "city": "New York City",
      "country": "United States",
      "zipCode": "10001"
    
  },
  {
    "id": 2,
    "firstName": "Jane",
    "lastName": "Doe",
    "username": "janedoexyz",
    "password": "password123",
    "role": "Customer",
    "balance": 750,
    
      "street": "456 Elm St",
      "city": "London",
      "country": "United Kingdom",
      "zipCode": "32493"
    
  },
  {
    "id": 3,
    "firstName": "David",
    "lastName": "Brown",
    "username": "davidbrownxyz",
    "password": "password123",
    "role": "Customer",
    "balance": 500,
    
      "street": "789 Oak St",
      "city": "Sydney",
      "country": "Australia",
      "zipCode": "20200"
    
  },
  {
    "id": 4,
    "firstName": "Noah",
    "lastName": "Thomas",
    "username": "noahthomasxyz",
    "password": "password123",
    "role": "Customer",
    "balance": 1200,
   
      "street": "101 Pine St",
      "city": "Paris",
      "country": "France",
      "zipCode": "75001"
    
  },
  {
    "id": 5,
    "firstName": "Ava",
    "lastName": "Lee",
    "username": "avaleexyz",
    "password": "password123",
    "role": "Customer",
    "balance": 850,
    
      "street": "111 Cedar St",
      "city": "Tokyo",
      "country": "Japan",
      "zipCode": "45739"
    
  }
]

now this is my purchased-items.json

[
  {
    "purchaseId": 1,
    "userId": 1,
    "itemsPurchased": [
      {
        "isbn": "9780316769488",
        "quantity": 1,
        "imageUrl": "to_kill_a_mockingbird.jpg",
        "title": "To Kill a Mockingbird",
        "price": 10.99
      },
      {
        "isbn": "9781984818653",
        "quantity": 1,
        "imageUrl": "the_silent_patient.jpg",
        "title": "The Silent Patient",
        "price": 12.99
      }
    ]
  },
  {
    "purchaseId": 2,
    "userId": 1,
    "itemsPurchased": [
      {
        "isbn": "9784012345678",
        "quantity": 3,
        "imageUrl": "whispers_in_the_attic.jpg",
        "title": "Whispers in the Attic",
        "price": 14.25
      }
    ]
  },
  {
    "purchaseId": 3,
    "userId": 2,
    "itemsPurchased": [
      {
        "isbn": "9786021978321",
        "quantity": 2,
        "imageUrl": "atomic_habits.jpg",
        "title": "Atomic Habits",
        "price": 14.99
      },
      {
        "isbn": "9782753981642",
        "quantity": 1,
        "imageUrl": "the_power_of_meaning.jpg",
        "title": "The Power of Meaning",
        "price": 13.75
      },
      {
        "isbn": "9781982117801",
        "quantity": 1,
        "imageUrl": "educated.jpg",
        "title": "Educated",
        "price": 15.99
      }
    ]
  },
  {
    "purchaseId": 4,
    "userId": 4,
    "itemsPurchased": [
      {
        "isbn": "9786021978321",
        "quantity": 3,
        "imageUrl": "atomic_habits.jpg",
        "title": "Atomic Habits",
        "price": 14.99
      },
      {
        "isbn": "9781984818653",
        "quantity": 2,
        "imageUrl": "the_silent_patient.jpg",
        "title": "The Silent Patient",
        "price": 12.99
      }
    ]
  }
]

This is the prisma schema I made: in schema.prisma client version

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model Books {
  id                Int     @id @default(autoincrement())
  isbn              String  @unique
  title             String
  author            String
  description       String
  genres            String
  publishedDate     String
  pageCount         Int
  imageUrl          String
  price             Float
  sales             Int
  availableQuantity Int
  sellerID          Int
  Sellers           Sellers @relation(fields: [sellerID], references: [id], onDelete: Cascade, onUpdate: Cascade)
}

model Sellers {
  id          Int     @id @default(autoincrement())
  firstName   String
  lastName    String
  username    String
  password    String
  role        String
  bankAccount String
  companyName String
  books       Books[] //books the seller is selling
}

model Customers {
  id            Int             @id @default(autoincrement())
  firstName     String
  lastName      String
  username      String
  password      String
  role          String
  balance       Int
  street        String
  city          String
  country       String
  zipCode       String
  purchaseditem purchasedItem[]
}

model purchasedItem {
  id     Int @id @default(autoincrement())
  userId Int

  itemsPurchased Item[]

  Customers   Customers? @relation(fields: [userId], references: [id])
  
}

model Item {
  isbn            String        @unique
  quantity        Int
  imageUrl        String
  title           String
  price           Float
  purchasedItemId Int           @unique
  purchasedItem   purchasedItem @relation(fields: [purchasedItemId], references: [id], onDelete: Cascade, onUpdate: Cascade)
}

now finally this is how I am trying to seed in seed.js, but it is not working, what am i doing wrong how to fix?? please helpp

import fs from 'fs-extra'
import path from 'path'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

const bookspath=path.join(process.cwd(),'app/data/books.json')
const sellerpath=path.join(process.cwd(),'app/data/sellers.json')
const customerpath=path.join(process.cwd(),'app/data/customers.json')
const purchasepath=path.join(process.cwd(),'app/data/purchased-items.json')


async function addBooks(b) {
    b.genres=b.genres.join(',');
    await prisma.books.create({data:b})
    //for retreiving as array use b.genres=b.genres.split(',')
}

async function savedata(itemsPurchased){
 try{
    const s=JSON.stringify(itemsPurchased);
    await prisma.purchasedItem.create({data:s});
    console.log("Data saved successfully")

 } catch(error){
    console.error('error saving data',error)
 }

}

async function main(){
 try{
    await prisma.books.deleteMany({});
    await prisma.sellers.deleteMany({});
    await prisma.customers.deleteMany({});
    await prisma.purchasedItem.deleteMany({});
    await prisma.item.deleteMany({});

    
    const seller=await fs.readJSON(sellerpath)
        for(const s of seller)
        await prisma.sellers.create({data:s})
    const book=await fs.readJSON(bookspath)
        for(const b of book)
            await addBooks(b) //this method will read according to data type
        const customer=await fs.readJSON(customerpath)
        for(const c of customer){
        await prisma.customers.create({data:c})

        const purchases=await fs.readJSON(purchasepath)
        for(let p of purchases){
            if(p.itemsPurchased){
                savedata(p.itemsPurchased)

            }
            else{

            }
            

        }
        
    }
        console.log("successfully seeded")
 }

 catch(error){
 console.log(error);
 }
}


await main()

I already added everything above, I want to save this data, so when i type npx prisma studio it shows me there properly, I don’t know how to use postgressql thats why I want to use sqlite to implement this

New contributor

kashaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật