{"id":15066684,"url":"https://github.com/sphireinc/hydra","last_synced_at":"2025-08-18T19:31:33.931Z","repository":{"id":257241206,"uuid":"857706220","full_name":"sphireinc/Hydra","owner":"sphireinc","description":"A Go library that dynamically hydrates structs with data from multiple databases, offering flexibility and ease for database integration in software development.","archived":false,"fork":false,"pushed_at":"2024-09-24T15:09:25.000Z","size":801,"stargazers_count":37,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-18T12:12:41.294Z","etag":null,"topics":["database","hydration","orm"],"latest_commit_sha":null,"homepage":"https://sphireinc.github.io/Hydra/","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/sphireinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-15T11:48:45.000Z","updated_at":"2024-09-25T02:00:28.000Z","dependencies_parsed_at":"2024-09-15T13:45:31.422Z","dependency_job_id":"ee4b9eab-6664-477f-a15e-5f5c6f3ffb7a","html_url":"https://github.com/sphireinc/Hydra","commit_stats":null,"previous_names":["sphireinc/hydra"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphireinc%2FHydra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphireinc%2FHydra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphireinc%2FHydra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sphireinc%2FHydra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sphireinc","download_url":"https://codeload.github.com/sphireinc/Hydra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230268748,"owners_count":18199806,"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":["database","hydration","orm"],"created_at":"2024-09-25T01:10:48.115Z","updated_at":"2024-12-18T12:12:45.170Z","avatar_url":"https://github.com/sphireinc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sphire Hydra\n\n[![Build](https://github.com/sphireinc/Hydra/actions/workflows/build.yml/badge.svg)](https://github.com/sphireinc/Hydra/actions/workflows/build.yml)\n[![Documentation](https://img.shields.io/badge/Pages-passing-green)](https://sphireinc.github.io/Hydra/)\n[![License](https://img.shields.io/github/license/sphireinc/hydra)](https://github.com/sphireinc/Hydra/releases/latest)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/sphireinc/hydra)](https://github.com/sphireinc/Hydra/releases/latest)\n[![Release Version](https://img.shields.io/github/v/release/sphireinc/hydra)](https://github.com/sphireinc/Hydra/releases/latest)\n[![Release Date](https://img.shields.io/github/release-date/sphireinc/hydra)](https://github.com/sphireinc/Hydra/releases/latest)\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"logo.jpg\" width=\"400px\"  alt=\"logo\" /\u003e\n\u003c/div\u003e\n\nSphire Hydra is a Go library designed to dynamically hydrate Go structs with data from a variety of databases.\nThe library supports multiple databases, including MySQL, PostgreSQL, SQLite, \nMicrosoft SQL Server, Oracle, MariaDB, and CockroachDB. Using reflection and `hydra` tags, \nit automatically fills struct fields with data fetched from database queries.\n\n\u003e [!WARNING]  \n\u003e Hydra went from idea to fruition in the span of 4 hours. It is still a very immature project, use it at your own risk. I welcome all opinions, contributions, and ideas on how to make this a better project. \n\n## Features\n\n- **Automatic Hydration**: Automatically populates Go structs with data fetched from databases using reflection.\n- **Multiple Database Support**: Supports MySQL, PostgreSQL, SQLite, Microsoft SQL Server, Oracle, MariaDB, and CockroachDB.\n- **Flexible Queries**: Allows dynamic construction of SQL `WHERE` clauses.\n- **Type Safety**: Ensures proper type conversions between database values and Go struct fields.\n- **Easily Extendable**: Easily extendable to support more databases in the future.\n\n## Installation\n\nTo install Sphire Hydra, use `go get`:\n\n```bash\ngo get github.com/sphireinc/Hydra\n```\n\n## Supported Databases\n\n- MySQL \n- PostgreSQL \n- SQLite\n- Microsoft SQL Server\n- Oracle\n- MariaDB\n- CockroachDB\n\n## Usage\n\n### Struct Definition\n\nDefine your structs with hydra tags to map the struct fields to the corresponding database columns, annd \nembed the hydra.Hydratable struct:\n\n```go\ntype Person struct {\n    Name        string `json:\"name\" hydra:\"name\"`\n    Age         int    `json:\"age\" hydra:\"age\"`\n    Email       string `json:\"email\" hydra:\"email\"`\n    hydra.Hydratable\n}\n```\n\n### Hydration\n\nTo hydrate a struct, initialize the struct and then call the Hydrate method, which automatically fetches the\ndata from the database and populates the fields:\n\n```go\npackage main\n\nimport (\n    \"database/sql\"\n    \"github.com/sphireinc/Hydra\"\n    _ \"github.com/go-sql-driver/mysql\"\n)\n\ntype Person struct {\n    Name        string `json:\"name\" hydra:\"name\"`\n    Age         int    `json:\"age\" hydra:\"age\"`\n    Email       string `json:\"email\" hydra:\"email\"`\n    hydra.Hydratable\n}\n\nfunc createDBConnection() *sql.DB {\n\tdb, _ := sql.Open(\"mysql\", \"user:password@/dbname\")\n\treturn db\n}\n\nfunc main() {\n    // Create a database connection\n    db := createDBConnection() \n\n    // Create an addressable Person instance and initialize the hydra.Hydratable struct\n    p := \u0026Person{} \n    p.Init(p)\n\n    // Create a map of where clauses\n    whereClause := map[string]interface{}{\"id\": \"U6\"} \n\n    // Call Hydrate to populate the struct with data from the database\n    p.Hydrate(db, whereClause)\n\n    // Print the hydrated struct\n    fmt.Printf(\"Hydrated person: %+v\\n\", p)\n}\n```\n\n# Extensibility\n\nSphire Hydra is designed to be easily extensible. You can add support for additional databases by implementing a \nfetch function specific to the database’s query syntax and integrating it with the existing hydration process.\n\n# Contributing\n\nWe welcome contributions! Feel free to open an issue or submit a pull request to improve the library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsphireinc%2Fhydra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsphireinc%2Fhydra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsphireinc%2Fhydra/lists"}