does anyone know if its possible to use prisma imp...
# orm-help
t
does anyone know if its possible to use prisma import in a way that it generates the id's? atm im importing a json file without id's and it trhows an error
h
you can use the client to input the data and use something like uuid or shortid to generate the id on the go
t
so you are pretty much saying to structure the json already with the id's right @Harshit?
h
you can also add the data using the prisma client. I don't think that your data will be formatted for prisma import to work
If you want personal assistance, DM me
t
Copy code
type Country {
  id: ID! @unique
  code: String! @unique
  name: String!
}
this is how the schema is strutured
the data I wont to import is similiar to this
Copy code
[
    {
        "code": "AF",
        "name": "Afghanistan"
    },
    {
        "code": "AX",
        "name": "ร…land Islands"
    }
]
how would you do it?
h
you need to write an import script
I will msg you a script in a while
t
thanks ๐Ÿ™‚
h
Copy code
import json from '/path/to/your/json/file'
import { prisma } from './generated/prisma-client'
async function nodeDoesntHaveTopLevelAwaitYet(){
  json.forEach(el => {
    await prisma.createCountry({
      code: el.code,
      name: el.name
    })
  });
}
nodeDoesntHaveTopLevelAwaitYet();
1. you need to generate the js client for this using
prisma generate
2. replace the things with corrent path 3. run this with node
DM me if you have any problems ๐Ÿ™‚
t
oh ok, I was trying to figure out if there was another way without plug atual code into it, but if its the best way of doing it I will take care of it, thank you so much for your time ๐Ÿ™‚