{"id":19793591,"url":"https://github.com/darky/typeorm-optimistic-lock","last_synced_at":"2025-11-09T02:03:33.144Z","repository":{"id":152776273,"uuid":"627112208","full_name":"darky/typeorm-optimistic-lock","owner":"darky","description":"TypeORM helper for optimistic lock persistance","archived":false,"fork":false,"pushed_at":"2023-04-12T21:09:10.000Z","size":24,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-23T20:47:20.356Z","etag":null,"topics":["lock","optimistic","typeorm"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-12T20:07:31.000Z","updated_at":"2023-09-06T00:21:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"f11a1553-6bee-42d8-907e-5972306a6a13","html_url":"https://github.com/darky/typeorm-optimistic-lock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Ftypeorm-optimistic-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Ftypeorm-optimistic-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Ftypeorm-optimistic-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Ftypeorm-optimistic-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darky","download_url":"https://codeload.github.com/darky/typeorm-optimistic-lock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241133152,"owners_count":19915348,"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":["lock","optimistic","typeorm"],"created_at":"2024-11-12T07:10:28.969Z","updated_at":"2025-11-09T02:03:28.114Z","avatar_url":"https://github.com/darky.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typeorm-optimistic-lock\n\nTypeORM helper for optimistic lock persistance\n\n## Notes\n\n* This library tested only for Postgres, but potentially can be improved for any database\n* You should manually detect type of persistance: insert or update. Detected by entity existance while fetching as usual\n* Entity should have required integer property `version`\n* On inserting need to set `version: 1`\n* On updating in `whereUpdate` need to use current `version`, in `forUpdate` need to set current `version` + 1\n\n## Insert example\n\n```ts\nimport { typeormOptimisticLockSave } from \"typeorm-optimistic-lock\";\n\nawait typeormOptimisticLockSave({\n  repository: connection.getRepository(Test),\n  conflictError: new Error(\"conflict happens\"),\n  forInsert: { id: 1, text: \"foo bar\", version: 1 },\n});\n```\n\n## Update example\n\n```ts\nimport { typeormOptimisticLockSave } from \"typeorm-optimistic-lock\";\n\nawait typeormOptimisticLockSave({\n  repository: connection.getRepository(Test),\n  conflictError: new Error(\"conflict happens\"),\n  forUpdate: { id: 1, text: \"test\", version: 2 },\n  whereUpdate: { id: 1, version: 1 },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Ftypeorm-optimistic-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarky%2Ftypeorm-optimistic-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Ftypeorm-optimistic-lock/lists"}