{"id":22441219,"url":"https://github.com/duchng/dblock","last_synced_at":"2025-10-06T04:26:40.437Z","repository":{"id":266650982,"uuid":"898932613","full_name":"duchng/dblock","owner":"duchng","description":"Zero dependencies, lightweight go library to utilize your database for distributed locking.","archived":false,"fork":false,"pushed_at":"2024-12-05T10:37:59.000Z","size":6,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-10T16:34:00.820Z","etag":null,"topics":["distributed-lock","go","golang","lock","mysql","mysql-lock","postgres"],"latest_commit_sha":null,"homepage":"","language":"Go","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/duchng.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-05T10:05:26.000Z","updated_at":"2025-01-26T15:53:09.000Z","dependencies_parsed_at":"2024-12-05T11:36:30.155Z","dependency_job_id":"516732e2-4782-408f-9b3d-7dfab02f243b","html_url":"https://github.com/duchng/dblock","commit_stats":null,"previous_names":["duchng/dblock"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/duchng/dblock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duchng%2Fdblock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duchng%2Fdblock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duchng%2Fdblock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duchng%2Fdblock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duchng","download_url":"https://codeload.github.com/duchng/dblock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duchng%2Fdblock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278557933,"owners_count":26006404,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["distributed-lock","go","golang","lock","mysql","mysql-lock","postgres"],"created_at":"2024-12-06T02:13:27.227Z","updated_at":"2025-10-06T04:26:40.388Z","avatar_url":"https://github.com/duchng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dblock\n\nZero dependencies, lightweight go library to utilize your database for distributed locking.\n\nExample:\n\n```go\nconn, err := sql.Open(\"postgres\", \"postgres://user:password@localhost:5432/dblock\u0026sslmode=disable\")\nif err != nil {\n    return err\n}\nlocker := dblock.New(conn, postgres_dialect.New())\nreleaseFunc, err := locker.TryLock(context.Background(), \"key\", time.Minute)\nif err != nil {\n    return err\n}\n// your critical section here\nif err := releaseFunc(); err != nil {\n    return err\n}\n```\n\n### Usage\n\n```go\n// New Create a new locker with provided database connection and dialect.\n// The Locker is build with simplicity and proficient in mind, it is designed to be used when you have well established persistent database\n// which you want to leverage for simple locking use cases.\n//\n// For more complex use cases, consider using a dedicated distributed system with proper consensus mechanism like zookeeper, etcd...\n//\n// A locker should be shared across the application with a single database connection for it to work correctly.\n//\n// Available options: WithLogger, WithDefaultTtl\nfunc New(querier Querier, dialect Dialect, opts ...LockerOption) *Locker\n```\n\n```go\n// TryLock tries to acquire a lock on the key. If the lock is already acquired, it returns ErrLockAlreadyAcquired.\n//\n// If ttl equals 0 and the locker's default ttl is 0, the lock is not released automatically unless the database session ends,\n// and the caller is responsible for releasing the lock.\n//\n// Due to the limitation of popular databases lock functions, bigint with postgres and 64 characters with mysql,\n// the provided key is hashed using FNV-1a before persisting, this behavior can be overridden by providing a custom keyFunc.\n//\n// Available options: WithKeyFunc\nfunc (l *Locker) TryLock(ctx context.Context, key string, ttl time.Duration, opts ...LockOption) (releaseFunc ReleaseFunc, err error)\n```\n\n### Contributing\nContributions are welcome!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduchng%2Fdblock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduchng%2Fdblock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduchng%2Fdblock/lists"}