{"id":42701356,"url":"https://github.com/storage-lock/go-postgresql-storage","last_synced_at":"2026-01-29T14:20:14.849Z","repository":{"id":186476546,"uuid":"674638821","full_name":"storage-lock/go-postgresql-storage","owner":"storage-lock","description":"以PostgreSQL为存储引擎的Storage实现，当前仓库为比较底层的存储层实现，你可以与storage-lock结合使用，或者这个项目PostgreSQL-locks里专门封装提供了一些PostgreSQL锁相关的更易用友好的API。","archived":false,"fork":false,"pushed_at":"2023-09-16T18:49:26.000Z","size":47,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T18:13:03.115Z","etag":null,"topics":["postgresql","sql-based-storage","storage"],"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/storage-lock.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}},"created_at":"2023-08-04T12:38:11.000Z","updated_at":"2023-08-16T02:23:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"d789593b-f80a-48b2-8dd9-cdfbb4b956ff","html_url":"https://github.com/storage-lock/go-postgresql-storage","commit_stats":{"total_commits":20,"total_committers":3,"mean_commits":6.666666666666667,"dds":"0.19999999999999996","last_synced_commit":"6506db239a8077fb8a773bdc431d99bfec80bae9"},"previous_names":["storage-lock/go-postgresql-storage"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/storage-lock/go-postgresql-storage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-postgresql-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-postgresql-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-postgresql-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-postgresql-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/storage-lock","download_url":"https://codeload.github.com/storage-lock/go-postgresql-storage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-postgresql-storage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28879332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T10:31:27.438Z","status":"ssl_error","status_checked_at":"2026-01-29T10:31:01.017Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["postgresql","sql-based-storage","storage"],"created_at":"2026-01-29T14:20:13.955Z","updated_at":"2026-01-29T14:20:14.821Z","avatar_url":"https://github.com/storage-lock.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Postgresql Storage \n\n# 一、这是什么\n以Postgresql为存储引擎的[Storage](https://github.com/storage-lock/go-storage)实现，当前仓库为比较底层的存储层实现，你可以与[storage-lock](https://github.com/storage-lock/go-storage-lock)结合使用，或者这个项目[PostgreSQL-locks](https://github.com/storage-lock/go-postgresql-storage)里专门封装提供了一些PostgreSQL锁相关的更易用友好的API。\n\n\n# 二、安装依赖\n\n```bash\ngo get -u github.com/storage-lock/go-postgresql-storage\n```\n\n# 三、API Examples\n\n## 3.1 从DSN创建PostgresqlStorage\n\n在Golang的世界中连接数据库最常见的就是DSN，下面的例子演示了如何从一个DSN创建PostgresqlStorage： \n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\tpostgresql_storage \"github.com/storage-lock/go-postgresql-storage\"\n)\n\nfunc main() {\n\n\t// 使用一个DSN形式的数据库连接字符串创建ConnectionManager\n\ttestDsn := \"host=127.0.0.1 user=postgres password=UeGqAm8CxYGldMDLoNNt port=5432 dbname=postgres sslmode=disable\"\n\tconnectionManager := postgresql_storage.NewPostgresqlConnectionGetterFromDSN(testDsn)\n\n\t// 然后从这个ConnectionManager创建PostgreSQL Storage\n\toptions := postgresql_storage.NewPostgresqlStorageOptions().SetConnectionManager(connectionManager)\n\tstorage, err := postgresql_storage.NewPostgresqlStorage(context.Background(), options)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(storage.GetName())\n\n}\n```\n\n\n## 3.2 从连接属性（ip、端口、用户名、密码等等）中创建PostgresqlStorage\n\n或者你的配置文件中存放的并不是DSN，而是零散的几个连接属性，下面是一个创建PostgresqlStorage的例子：\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\tpostgresql_storage \"github.com/storage-lock/go-postgresql-storage\"\n)\n\nfunc main() {\n\n\t// 使用一个DSN形式的数据库连接字符串创建ConnectionManager\n\thost := \"127.0.0.1\"\n\tport := uint(5432)\n\tusername := \"postgres\"\n\tpasswd := \"UeGqAm8CxYGldMDLoNNt\"\n\tdatabase := \"postgres\"\n\tconnectionManager := postgresql_storage.NewPostgresqlConnectionManager(host, port, username, passwd, database)\n\n\t// 然后从这个ConnectionManager创建PostgreSQL Storage\n\toptions := postgresql_storage.NewPostgresqlStorageOptions().SetConnectionManager(connectionManager)\n\tstorage, err := postgresql_storage.NewPostgresqlStorage(context.Background(), options)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(storage.GetName())\n\n}\n```\n\n\n## 3.3 从sql.DB创建PostgresqlStorage\n\n或者现在你已经有从其它渠道创建的能够连接到Postgresql的sql.DB，则也可以从这个*sql.DB创建PostgresqlStorage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"database/sql\"\n\t\"fmt\"\n\n\t\"github.com/storage-lock/go-storage\"\n\n\tpostgresql_storage \"github.com/storage-lock/go-postgresql-storage\"\n)\n\nfunc main() {\n\n\t// 使用一个DSN形式的数据库连接字符串创建ConnectionManager\n\ttestDsn := \"host=127.0.0.1 user=postgres password=UeGqAm8CxYGldMDLoNNt port=5432 dbname=postgres sslmode=disable\"\n\tdb, err := sql.Open(\"postgres\", testDsn)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tconnectionManager := storage.NewFixedSqlDBConnectionManager(db)\n\n\t// 然后从这个ConnectionManager创建Postgresql Storage\n\toptions := postgresql_storage.NewPostgresqlStorageOptions().SetConnectionManager(connectionManager)\n\tstorage, err := postgresql_storage.NewPostgresqlStorage(context.Background(), options)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(storage.GetName())\n\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstorage-lock%2Fgo-postgresql-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstorage-lock%2Fgo-postgresql-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstorage-lock%2Fgo-postgresql-storage/lists"}