{"id":13366930,"url":"https://github.com/Go-reform/reform","last_synced_at":"2025-03-12T18:31:40.912Z","repository":{"id":8544452,"uuid":"52513524","full_name":"go-reform/reform","owner":"go-reform","description":"A better ORM for Go, based on non-empty interfaces and code generation.","archived":false,"fork":false,"pushed_at":"2023-03-13T13:56:56.000Z","size":1143,"stargazers_count":1445,"open_issues_count":86,"forks_count":73,"subscribers_count":22,"default_branch":"main","last_synced_at":"2025-03-09T04:16:28.442Z","etag":null,"topics":["go","golang","hacktoberfest","orm","sql","sql-orm"],"latest_commit_sha":null,"homepage":"https://gopkg.in/reform.v1","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/go-reform.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2016-02-25T09:41:09.000Z","updated_at":"2025-02-19T03:06:57.000Z","dependencies_parsed_at":"2024-06-18T12:21:26.423Z","dependency_job_id":"659987b0-03df-426c-a3d0-4c60af9d0157","html_url":"https://github.com/go-reform/reform","commit_stats":{"total_commits":322,"total_committers":15,"mean_commits":"21.466666666666665","dds":"0.16770186335403725","last_synced_commit":"db2c976d4b2fa1df1f9e16b4c314e18c5b475969"},"previous_names":["aleksi/reform"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-reform%2Freform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-reform%2Freform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-reform%2Freform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-reform%2Freform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-reform","download_url":"https://codeload.github.com/go-reform/reform/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243271345,"owners_count":20264441,"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":["go","golang","hacktoberfest","orm","sql","sql-orm"],"created_at":"2024-07-30T00:01:34.415Z","updated_at":"2025-03-12T18:31:40.615Z","avatar_url":"https://github.com/go-reform.png","language":"Go","readme":"# reform\n\n[![Release](https://img.shields.io/github/release/go-reform/reform.svg)](https://github.com/go-reform/reform/releases/latest)\n[![PkgGoDev](https://pkg.go.dev/badge/gopkg.in/reform.v1)](https://pkg.go.dev/gopkg.in/reform.v1)\n[![CI](https://github.com/go-reform/reform/workflows/CI/badge.svg?branch=main\u0026event=push)](https://github.com/go-reform/reform/actions)\n[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/srwa0cuwf91qpjge/branch/main?svg=true)](https://ci.appveyor.com/project/AlekSi/reform/branch/main)\n[![Coverage Report](https://codecov.io/gh/go-reform/reform/branch/main/graph/badge.svg)](https://codecov.io/gh/go-reform/reform)\n[![Go Report Card](https://goreportcard.com/badge/gopkg.in/reform.v1)](https://goreportcard.com/report/gopkg.in/reform.v1)\n\n\u003ca href=\"https://en.wikipedia.org/wiki/Peter_the_Great\"\u003e\u003cimg align=\"right\" alt=\"Reform gopher logo\" title=\"Peter the Reformer\" src=\".github/reform.png\"\u003e\u003c/a\u003e\n\nA better ORM for Go and `database/sql`.\n\nIt uses non-empty interfaces, code generation (`go generate`), and initialization-time reflection\nas opposed to `interface{}`, type system sidestepping, and runtime reflection. It will be kept simple.\n\nSupported SQL dialects:\n\n| RDBMS                | Library and drivers                                                                                 | Status\n| -----                | -------------------                                                                                 | ------\n| PostgreSQL           | [github.com/lib/pq](https://github.com/lib/pq) (`postgres`)                                         | Stable. Tested with all [supported](https://www.postgresql.org/support/versioning/) versions.\n|                      | [github.com/jackc/pgx/stdlib](https://github.com/jackc/pgx) (`pgx` v3)                              | Stable. Tested with all [supported](https://www.postgresql.org/support/versioning/) versions.\n| MySQL                | [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) (`mysql`)                  | Stable. Tested with all [supported](https://www.mysql.com/support/supportedplatforms/database.html) versions.\n| SQLite3              | [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) (`sqlite3`)                      | Stable.\n| Microsoft SQL Server | [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb) (`sqlserver`, `mssql`) | Stable.\u003cbr/\u003eTested on Windows with: SQL2008R2SP2, SQL2012SP1, SQL2014, SQL2016.\u003cbr/\u003eOn Linux with: `mcr.microsoft.com/mssql/server:2017-latest` and `mcr.microsoft.com/mssql/server:2019-latest` [Docker images](https://hub.docker.com/_/microsoft-mssql-server).\n\nNotes:\n* [`clientFoundRows=true` flag](https://github.com/go-sql-driver/mysql#clientfoundrows) is required for `mysql` driver.\n* `mssql` driver is [deprecated](https://github.com/denisenkom/go-mssqldb#deprecated) (but not `sqlserver` driver).\n\n\n## Quickstart\n\n1. Make sure you are using Go 1.17+, and Go modules support is enabled.\n   Install or update `reform` package, `reform` and `reform-db` commands with:\n    ```\n    go get -v gopkg.in/reform.v1/...\n    ```\n\n   If you are not using Go modules yet, you can use dep to vendor desired version of reform,\n   and then install commands with:\n    ```\n    go install -v ./vendor/gopkg.in/reform.v1/...\n    ```\n\n   You can also install the latest stable version of reform without using Go modules thanks to\n   [gopkg.in redirection](https://gopkg.in/reform.v1), but please note that this will not use the stable\n   versions of the database drivers:\n    ```\n    env GO111MODULE=off go get -u -v gopkg.in/reform.v1/...\n    ```\n\n   Canonical import path is `gopkg.in/reform.v1`; using `github.com/go-reform/reform` will not work.\n\n   See note about versioning and branches below.\n\n2. Use `reform-db` command to generate models for your existing database schema. For example:\n    ```\n    reform-db -db-driver=sqlite3 -db-source=example.sqlite3 init\n    ```\n\n3. Update generated models or write your own – `struct` representing a table or view row. For example,\n   store this in file `person.go`:\n    ```go\n    //go:generate reform\n\n    //reform:people\n\ttype Person struct {\n\t\tID        int32      `reform:\"id,pk\"`\n\t\tName      string     `reform:\"name\"`\n\t\tEmail     *string    `reform:\"email\"`\n\t\tCreatedAt time.Time  `reform:\"created_at\"`\n\t\tUpdatedAt *time.Time `reform:\"updated_at\"`\n\t}\n    ```\n\n    Magic comment `//reform:people` links this model to `people` table or view in SQL database.\n    The first value in field's `reform` tag is a column name. `pk` marks primary key.\n    Use value `-` or omit tag completely to skip a field.\n    Use pointers (recommended) or `sql.NullXXX` types for nullable fields.\n\n4. Run `reform [package or directory]` or `go generate [package or file]`. This will create `person_reform.go`\n   in the same package with type `PersonTable` and methods on `Person`.\n\n5. See [documentation](https://godoc.org/gopkg.in/reform.v1) how to use it. Simple example:\n\n    ```go\n\t// Get *sql.DB as usual. PostgreSQL example:\n\tsqlDB, err := sql.Open(\"postgres\", \"postgres://127.0.0.1:5432/database\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer sqlDB.Close()\n\n\t// Use new *log.Logger for logging.\n\tlogger := log.New(os.Stderr, \"SQL: \", log.Flags())\n\n\t// Create *reform.DB instance with simple logger.\n\t// Any Printf-like function (fmt.Printf, log.Printf, testing.T.Logf, etc) can be used with NewPrintfLogger.\n\t// Change dialect for other databases.\n\tdb := reform.NewDB(sqlDB, postgresql.Dialect, reform.NewPrintfLogger(logger.Printf))\n\n\t// Save record (performs INSERT or UPDATE).\n\tperson := \u0026Person{\n\t\tName:  \"Alexey Palazhchenko\",\n\t\tEmail: pointer.ToString(\"alexey.palazhchenko@gmail.com\"),\n\t}\n\tif err := db.Save(person); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// ID is filled by Save.\n\tperson2, err := db.FindByPrimaryKeyFrom(PersonTable, person.ID)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Println(person2.(*Person).Name)\n\n\t// Delete record.\n\tif err = db.Delete(person); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Find records by IDs.\n\tpersons, err := db.FindAllFrom(PersonTable, \"id\", 1, 2)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfor _, p := range persons {\n\t\tfmt.Println(p)\n\t}\n    ```\n\n\n## Background\n\nreform was born during summer 2014 out of frustrations with existing Go ORMs. All of them have a method\n`Save(record interface{})` which can be used like this:\n\n```go\norm.Save(User{Name: \"gopher\"})\norm.Save(\u0026User{Name: \"gopher\"})\norm.Save(nil)\norm.Save(\"Batman!!\")\n```\n\nNow you can say that last invocation is obviously invalid, and that it's not hard to make an ORM to accept both\nfirst and second versions. But there are two problems:\n\n1. Compiler can't check it. Method's signature in `godoc` will not tell us how to use it.\n   We are essentially working against those tools by sidestepping type system.\n2. First version is still invalid, since one would expect `Save()` method to set record's primary key after `INSERT`,\n   but this change will be lost due to passing by value.\n\nFirst proprietary version of reform was used in production even before `go generate` announcement.\nThis free and open-source version is the fourth milestone on the road to better and idiomatic API.\n\n\n## Versioning and branching policy\n\nWe are following [Semantic Versioning](http://semver.org/spec/v2.0.0.html),\nusing [gopkg.in](https://gopkg.in) and filling a [changelog](CHANGELOG.md).\nAll v1 releases are SemVer-compatible; breaking changes will not be applied.\n\nWe use tags `v1.M.m` for releases, branch `main` (default on GitHub) for the next minor release development,\nand `release/1.M` branches for patch release development. (It was more complicated before 1.4.0 release.)\n\nMajor version 2 is currently not planned.\n\n\n## Additional packages\n\n* [github.com/AlekSi/pointer](https://github.com/AlekSi/pointer) is very useful for working with reform structs with pointers.\n\n\n## Caveats and limitations\n\n* There should be zero `pk` fields for Struct and exactly one `pk` field for Record.\n  Composite primary keys are not supported ([#114](https://github.com/go-reform/reform/issues/114)).\n* `pk` field can't be a pointer (`== nil` [doesn't work](https://golang.org/doc/faq#nil_error)).\n* Database row can't have a Go's zero value (0, empty string, etc.) in primary key column.\n\n\n## License\n\nCode is covered by standard MIT-style license. Copyright (c) 2016-2020 Alexey Palazhchenko.\nSee [LICENSE](LICENSE) for details. Note that generated code is covered by the terms of your choice.\n\nThe reform gopher was drawn by Natalya Glebova. Please use it only as reform logo.\nIt is based on the original design by Renée French, released under [Creative Commons Attribution 3.0 USA license](https://creativecommons.org/licenses/by/3.0/).\n\n\n## Contributing\n\nSee [Contributing Guidelines](.github/CONTRIBUTING.md).\n","funding_links":[],"categories":["ORM"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGo-reform%2Freform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGo-reform%2Freform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGo-reform%2Freform/lists"}