{"id":16534517,"url":"https://github.com/iamolegga/gokvpgx","last_synced_at":"2025-03-03T14:11:27.329Z","repository":{"id":255330594,"uuid":"849226242","full_name":"iamolegga/gokvpgx","owner":"iamolegga","description":"pgx adapter for https://github.com/philippgille/gokv","archived":false,"fork":false,"pushed_at":"2024-12-23T21:07:22.000Z","size":22,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T00:32:35.812Z","etag":null,"topics":["gokv","pgx"],"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/iamolegga.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-08-29T07:57:08.000Z","updated_at":"2024-09-17T05:41:21.000Z","dependencies_parsed_at":"2024-09-17T08:11:46.438Z","dependency_job_id":"40adc7b1-aef9-4c4f-ba78-fe047e90708c","html_url":"https://github.com/iamolegga/gokvpgx","commit_stats":null,"previous_names":["iamolegga/gokvpgx"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fgokvpgx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fgokvpgx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fgokvpgx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fgokvpgx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamolegga","download_url":"https://codeload.github.com/iamolegga/gokvpgx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241678157,"owners_count":20001682,"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":["gokv","pgx"],"created_at":"2024-10-11T18:24:26.442Z","updated_at":"2025-03-03T14:11:27.312Z","avatar_url":"https://github.com/iamolegga.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gokvpgx\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/iamolegga/gokvpgx)](https://pkg.go.dev/github.com/iamolegga/gokvpgx)\n\n`gokvpgx` is a PostgreSQL client for the `gokv` key-value store interface, implemented using the `pgx` library. This package allows you to use PostgreSQL as a key-value store with efficient prepared statements, ensuring optimal performance and security.\n\n## Features\n\n- **pgx-based Implementation**: Utilizes the `pgx` library for efficient PostgreSQL interactions.\n- **Efficient Prepared Statements**: SQL statements are prepared at the database level for faster execution, thanks to `pgx`.\n- **Flexible Serialization**: Supports different encoding formats like JSON and gob through the `gokv` interface.\n- **Connection Pooling**: Leverages `pgxpool.Pool` for efficient database connection management.\n- **Autocreation of Table**: Automatically creates the key-value store table if it does not exist.\n\n## Installation\n\nTo use `gokvpgx`, you need to have a Go environment set up. Then, you can get the package using:\n\n```bash\ngo get github.com/iamolegga/gokvpgx\n```\n\n## Usage\n\nHere is an example of how to use the gokvpgx package to store, retrieve, and delete key-value pairs in PostgreSQL:\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log\"\n\n    \"github.com/iamolegga/gokvpgx\"\n    \"github.com/jackc/pgx/v5/pgxpool\"\n    \"github.com/philippgille/gokv/encoding\"\n)\n\nfunc main() {\n    // Create a connection pool\n    pool, err := pgxpool.New(context.Background(), \"postgres://postgres:secret@localhost:5432/gokv?sslmode=disable\")\n    if err != nil {\n        log.Fatalf(\"Unable to connect to database: %v\", err)\n    }\n    defer pool.Close()\n\n    // Create a new client\n    options := gokvpgx.Options{\n        Pool:      pool,\n        Codec:     encoding.JSON,\n        TableName: \"kv_store\",\n    }\n    client, err := gokvpgx.NewClient(options)\n    if err != nil {\n        log.Fatalf(\"Failed to create client: %v\", err)\n    }\n    defer client.Close()\n\n    // Set a value\n    err = client.Set(\"my_key\", \"my_value\")\n    if err != nil {\n        log.Fatalf(\"Failed to set value: %v\", err)\n    }\n\n    // Get the value\n    var value string\n    found, err := client.Get(\"my_key\", \u0026value)\n    if err != nil {\n        log.Fatalf(\"Failed to get value: %v\", err)\n    }\n    if found {\n        log.Printf(\"Found value: %s\", value)\n    } else {\n        log.Println(\"Value not found\")\n    }\n\n    // Delete the value\n    err = client.Delete(\"my_key\")\n    if err != nil {\n        log.Fatalf(\"Failed to delete value: %v\", err)\n    }\n}\n```\n\n## Options\n\n### Options Struct\n\n- Pool: *pgxpool.Pool - The PostgreSQL connection pool to use.\n- TableName: string - The name of the table where key-value pairs are stored. Default is \"Item\".\n- Codec: encoding.Codec - The codec used for serializing and deserializing values. Default is encoding.JSON.\n\n### DefaultOptions\n\n- TableName: \"Item\"\n- Codec: encoding.JSON\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](https://github.com/iamolegga/gokvpgx/blob/main/LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Feel free to open an issue or submit a pull request if you find a bug or want to add a new feature.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamolegga%2Fgokvpgx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamolegga%2Fgokvpgx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamolegga%2Fgokvpgx/lists"}