{"id":46178001,"url":"https://github.com/yoockh/dbyoc","last_synced_at":"2026-03-02T19:09:30.258Z","repository":{"id":324403125,"uuid":"1097060134","full_name":"yoockh/dbyoc","owner":"yoockh","description":"DBYOC is a Go module that simplifies database connections by providing a unified interface for both SQL and NoSQL databases. This module comes with flexible configuration, automatic retry mechanisms, connection pooling, migration support, logging, and metrics tracking.","archived":false,"fork":false,"pushed_at":"2025-11-23T20:58:56.000Z","size":497,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-23T22:20:12.451Z","etag":null,"topics":["database","golang","nosql","sql"],"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/yoockh.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-15T13:16:58.000Z","updated_at":"2025-11-23T20:56:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yoockh/dbyoc","commit_stats":null,"previous_names":["yoockh/dbyoc"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/yoockh/dbyoc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoockh%2Fdbyoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoockh%2Fdbyoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoockh%2Fdbyoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoockh%2Fdbyoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoockh","download_url":"https://codeload.github.com/yoockh/dbyoc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoockh%2Fdbyoc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30016507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T17:00:27.440Z","status":"ssl_error","status_checked_at":"2026-03-02T17:00:03.402Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["database","golang","nosql","sql"],"created_at":"2026-03-02T19:09:28.837Z","updated_at":"2026-03-02T19:09:30.244Z","avatar_url":"https://github.com/yoockh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DBYOC - Database Bring Your Own Connection\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Go Version](https://img.shields.io/badge/Go-1.24+-00ADD8?style=flat\u0026logo=go)](https://go.dev/)\n[![Release](https://img.shields.io/badge/release-v1.3.6-blue.svg)]()\n\n![dbyoc logo](assets/dbyoc.png)\n\nDBYOC is a Go module that simplifies database connections by providing a unified interface for both SQL and NoSQL databases. This module comes with flexible configuration, automatic retry mechanisms, connection pooling, migration support, logging, and metrics tracking.\n\n## Features\n\n- **One-Line Setup**: Connect with just environment variable\n- **Unified Interface**: Consistent interface for various database types\n- **Flexible Configuration**: Load configuration from environment variables, JSON, or YAML\n- **Auto Retry \u0026 Reconnect**: Handle transient errors with automatic retry logic\n- **Connection Pooling**: Efficient database connection management\n- **Built-in Migration**: Manage database schema changes easily\n- **Integrated Logging**: Automatic logging for queries and errors using Logrus\n- **Metrics Tracking**: Monitor connection and query performance\n\n## Installation\n\n```bash\ngo get github.com/yoockh/dbyoc\n```\n\n## Super Quick Start (Recommended)\n\n### MongoDB - One Line Setup\n\n```bash\nexport MONGO_URI=\"mongodb://localhost:27017/mydb\"\n```\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log\"\n    \n    \"github.com/yoockh/dbyoc/config\"\n    \"github.com/yoockh/dbyoc/db/nosql\"\n    \"github.com/yoockh/dbyoc/logger\"\n    \"go.mongodb.org/mongo-driver/bson\"\n)\n\nfunc main() {\n    // Load config from MONGO_URI\n    cfg, err := nosql.QuickMongo()\n    if err != nil {\n        log.Fatal(err)\n    }\n    \n    // Validate config\n    if err := cfg.Validate(); err != nil {\n        log.Fatal(\"Config validation error:\", err)\n    }\n    \n    // Initialize logger\n    logger.Init(cfg.Logger.Level)\n    \n    // Connect with database and collection names\n    client, err := nosql.NewMongoDBClient(cfg.MongoDB.URI, \"planetsdb\", \"planet\")\n    if err != nil {\n        log.Fatal(\"Failed to connect to db:\", err)\n    }\n    defer client.Close()\n    \n    // Insert\n    client.Insert(bson.M{\"name\": \"Earth\", \"type\": \"Terrestrial\"})\n    \n    // Find\n    cursor, _ := client.Find(bson.M{})\n    defer cursor.Close(context.Background())\n    \n    for cursor.Next(context.Background()) {\n        var result bson.M\n        cursor.Decode(\u0026result)\n        log.Printf(\"Planet: %+v\", result)\n    }\n}\n```\n\n### PostgreSQL - One Line Setup\n\n```bash\nexport DATABASE_URL=\"postgres://user:pass@localhost:5432/mydb?sslmode=disable\"\n```\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"github.com/yoockh/dbyoc/db/sql\"\n)\n\nfunc main() {\n    // ONE LINE!\n    db, err := sql.QuickPostgres()\n    if err != nil {\n        log.Fatal(err)\n    }\n    defer db.Close()\n    \n    rows, _ := db.Query(\"SELECT id, name FROM users\")\n    defer rows.Close()\n    \n    for rows.Next() {\n        var id int\n        var name string\n        rows.Scan(\u0026id, \u0026name)\n        log.Printf(\"User: %d - %s\", id, name)\n    }\n}\n```\n\n### Redis - One Line Setup\n\n```bash\nexport REDIS_URL=\"redis://:password@localhost:6379/0\"\n```\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log\"\n    \"time\"\n    \n    \"github.com/yoockh/dbyoc/db/nosql\"\n)\n\nfunc main() {\n    // ONE LINE!\n    redis, err := nosql.QuickRedis()\n    if err != nil {\n        log.Fatal(err)\n    }\n    defer redis.Close()\n    \n    ctx := context.Background()\n    redis.Set(ctx, \"key\", \"value\", 5*time.Minute)\n    \n    val, _ := redis.Get(ctx, \"key\")\n    log.Printf(\"Value: %s\", val)\n}\n```\n\n## Environment Variables\n\n### Minimal (Recommended)\n\n```bash\n# MongoDB\nexport MONGO_URI=\"mongodb://localhost:27017/mydb\"\n\n# PostgreSQL\nexport DATABASE_URL=\"postgres://user:pass@localhost:5432/mydb\"\n\n# Redis\nexport REDIS_URL=\"redis://:password@localhost:6379/0\"\n```\n\n### Optional Settings\n\n```bash\n# MongoDB\nexport MONGO_DATABASE=\"mydb\"\nexport MONGO_TIMEOUT=30\n\n# PostgreSQL\nexport DATABASE_MAX_RETRIES=3\nexport DATABASE_MAX_POOL_SIZE=10\n\n# Redis\nexport REDIS_PASSWORD=\"secret\"\nexport REDIS_DB=0\n```\n\n## Advanced Usage (Optional)\n\nIf you need more control, use config file:\n\n```yaml\ndatabase:\n  url: \"postgres://user:pass@localhost:5432/mydb\"\n  max_pool_size: 10\n\nmongodb:\n  uri: mongodb://localhost:27017\n  database: mydb\n\nredis:\n  url: \"redis://:password@localhost:6379/0\"\n```\n\n```go\ncfg, err := config.LoadConfig()\n```\n\n## Project Structure\n\n```\ndbyoc/\n├── config/          # Configuration management\n├── db/             \n│   ├── sql/        # PostgreSQL, MySQL\n│   └── nosql/      # MongoDB, Redis\n├── migration/      # Database migrations\n├── logger/         # Logging\n├── metrics/        # Metrics tracking\n└── utils/          # Utilities\n```\n\n## External Dependencies\n\n| Library | Purpose | Repository |\n|---------|---------|------------|\n| **Logrus** | Structured logging | [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) |\n| **Viper** | Configuration management | [github.com/spf13/viper](https://github.com/spf13/viper) |\n| **Mapstructure** | Map to struct conversion | [github.com/mitchellh/mapstructure](https://github.com/mitchellh/mapstructure) |\n| **PostgreSQL Driver** | PostgreSQL connectivity | [github.com/lib/pq](https://github.com/lib/pq) |\n| **MySQL Driver** | MySQL connectivity | [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) |\n| **MongoDB Driver** | MongoDB connectivity | [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) |\n| **Redis Client** | Redis connectivity | [github.com/go-redis/redis](https://github.com/go-redis/redis) |\n\n## Changelog\n\n### v1.3.7 (Latest)\n- Added Quick Start helpers: `QuickMongo()`, `QuickPostgres()`, `QuickRedis()`\n- MongoDB works with just `MONGO_URI` environment variable\n- PostgreSQL works with just `DATABASE_URL` environment variable\n- Redis works with just `REDIS_URL` environment variable\n- No complex configuration needed for basic usage\n- Backward compatible with existing configuration methods\n\n### v1.3.6\n- Fixed module import resolution issues\n- Improved graceful shutdown flow\n- Corrected timeout handling\n\n## Contributing\n\nContributions are welcome. To contribute:\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n## Author\n\n**Aisiya Qutwatunnada**\n\n---\n\n**Note**: DBYOC is designed to simplify database connections. Just set one environment variable and you're ready to go.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoockh%2Fdbyoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoockh%2Fdbyoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoockh%2Fdbyoc/lists"}