{"id":27283793,"url":"https://github.com/itsdillon/prepare-array-for-prisma","last_synced_at":"2025-04-11T18:43:36.462Z","repository":{"id":57104372,"uuid":"384815231","full_name":"itsdillon/prepare-array-for-prisma","owner":"itsdillon","description":"A utility that will take regular arrays from forms and adapt them to work with prisma. It also works with nested arrays.","archived":false,"fork":false,"pushed_at":"2021-08-11T17:58:04.000Z","size":151,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T20:59:27.553Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itsdillon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-10T23:11:14.000Z","updated_at":"2024-01-22T23:05:58.000Z","dependencies_parsed_at":"2022-08-20T17:10:52.580Z","dependency_job_id":null,"html_url":"https://github.com/itsdillon/prepare-array-for-prisma","commit_stats":null,"previous_names":["creatorsneverdie/prepare-array-for-prisma","itsdillon/prepare-array-for-prisma"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdillon%2Fprepare-array-for-prisma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdillon%2Fprepare-array-for-prisma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdillon%2Fprepare-array-for-prisma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdillon%2Fprepare-array-for-prisma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itsdillon","download_url":"https://codeload.github.com/itsdillon/prepare-array-for-prisma/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248461064,"owners_count":21107599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-11T18:43:35.889Z","updated_at":"2025-04-11T18:43:36.445Z","avatar_url":"https://github.com/itsdillon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prepare Array For Prisma\nA utility that will take regular arrays from forms and adapt them to work with prisma. It also works with nested arrays.\n\n## Get Started\n`yarn add @creatorsneverdie/prepare-array-for-prisma`\n\n`import {prepareArrayField} from \"@creatorsneverdie/prepare-array-for-prisma\"`\n\n## How To\n`prepareArrayField()` takes 4 parameters:\n1. Form values as `any[]`\n2. Initial database data as `any[]`\n3. Mapper as `((item: any, initial?: any) =\u003e any)`\n4. Options as `{ removedItemsMethod: 'disconnect' | 'delete'}`\n\nYou use the function like this:\n```ts\nconst value = [ {name: 1}, {id: 2, name: 3} ]\nconst initial = [ {id: 2, name: 2}, {id: 3} ]\n\nconst mappedArray = prepareArrayField(value, initial, (item) =\u003e ({\n  ...item,\n}))\n```\n\nYou can also set options object for handling removing elements. You can choose to either delete the element from the database completely, or disconnect. By default the option is set to  `disconnect`:\n\n```ts\nconst mappedArray = prepareArrayField(value, initial, (item) =\u003e ({\n  ...item,\n}), {removedItemsMethod: \"delete\" })\n```\n\nThen inside a prisma operation:\n```ts\n  const updateUser = await prisma.project.update({\n    where: {\n      id: 1\n    },\n    data: {\n      title: 'test project update',\n      users: mappedArray\n    }\n  })\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsdillon%2Fprepare-array-for-prisma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsdillon%2Fprepare-array-for-prisma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsdillon%2Fprepare-array-for-prisma/lists"}