{"id":39036767,"url":"https://github.com/plopezm/genorm","last_synced_at":"2026-01-17T17:44:45.069Z","repository":{"id":57497138,"uuid":"199213841","full_name":"plopezm/genorm","owner":"plopezm","description":"Simple ORM based on code generation","archived":false,"fork":false,"pushed_at":"2019-07-31T17:11:45.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T12:43:42.049Z","etag":null,"topics":["code-generation","database","godb","golang","orm"],"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/plopezm.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}},"created_at":"2019-07-27T21:12:49.000Z","updated_at":"2024-06-20T12:43:42.050Z","dependencies_parsed_at":"2022-09-03T23:51:35.767Z","dependency_job_id":null,"html_url":"https://github.com/plopezm/genorm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/plopezm/genorm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Fgenorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Fgenorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Fgenorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Fgenorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plopezm","download_url":"https://codeload.github.com/plopezm/genorm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Fgenorm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28513975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: 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":["code-generation","database","godb","golang","orm"],"created_at":"2026-01-17T17:44:44.948Z","updated_at":"2026-01-17T17:44:45.034Z","avatar_url":"https://github.com/plopezm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# genorm\n\nGenorm is a basic orm based on code generator using the query builder [godb](https://github.com/samonzeweb/godb)\n\n### Installing GENORM\n\nTo install genorm download it using golang tools:\n\n```\ngo get github.com/plopezm/genorm\n```\n\n### Supported databases\n\nThis code generation tool uses godb to perform the queries. This means that every adapter used in godb is compatible with this library.\n\nAvailable drivers:\n- sqlite\n- mssql\n- mysql\n- postgresql\n\nYou can check the updated list [here](https://github.com/samonzeweb/godb/tree/master/adapters)\n\n### How to use\n\nUsing genorm is easy, just define your struct like golang db standard.\n\n```\ntype Book struct {\n\tId        int       `db:\"id,key,auto\"`\n\tTitle     string    `db:\"title\"`\n\tAuthor    string    `db:\"author\"`\n\tPublished time.Time `db:\"published\"`\n}\n```\n\nNow we need to add on the top of the file the genorm directive\n\n```\n//go:generate genorm -type=Book -driver=sqlite -url=local.db -tableName=books\n```\n\nThe next step is call golang generate command:\n\n```\ngo generate ./...\n```\n\nA new file will appear with the name \"{structName}-repository.go\". This file is autogenerated, so if you want to add new fearures, the best approach is to create a new file a using the repository struct created add that funcionality there.\n\nComplete example: \n\n```\npackage models\n\nimport \"time\"\n\n//go:generate genorm -type=Book -driver=sqlite -url=local.db -tableName=books\n\ntype Book struct {\n\tId        int       `db:\"id,key,auto\"`\n\tTitle     string    `db:\"title\"`\n\tAuthor    string    `db:\"author\"`\n\tPublished time.Time `db:\"published\"`\n}\n```\n\nGenerated file: book-repository.go\n\n```\npackage models\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/samonzeweb/godb\"\n\t\"github.com/samonzeweb/godb/adapters/sqlite\"\n)\n\ntype BookRepository struct {\n\tdb *godb.DB\n}\n\nfunc (entity *Book) TableName() string {\n\treturn \"books\"\n}\n\nfunc NewBookRepository() *BookRepository {\n\tdb, err := godb.Open(sqlite.Adapter, \"local.db\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn \u0026BookRepository{\n\t\tdb: db,\n\t}\n}\n\nfunc (this *BookRepository) FindAll() (result []Book, err error) {\n\tresult = make([]Book, 0, 0)\n\terr = this.db.Select(\u0026result).Do()\n\treturn\n}\n\nfunc (this *BookRepository) FindByFields(fields []string, values []interface{}) (result []Book, err error) {\n\tresult = make([]Book, 0, 0)\n\tquery := this.db.Select(\u0026result)\n\tfor i, field := range fields {\n\t\tquery.Where(fmt.Sprintf(\"%s = ?\", field), values[i])\n\t}\n\terr = query.Do()\n\treturn\n}\n\nfunc (this *BookRepository) FindAllWithIterator() (result godb.Iterator, err error) {\n\tentity := \u0026Book{}\n\tresult ,err = this.db.SelectFrom(entity.TableName()).DoWithIterator()\n\treturn\n}\n\nfunc (this *BookRepository) FindOneById(idField string, idValue interface{}) (result *Book, err error) {\n\tresult = \u0026Book{}\n\terr = this.db.Select(result).\n\t\tWhere(fmt.Sprintf(\"%s = ?\", idField), idValue).\n\t\tDo()\n\treturn\n}\n\nfunc (this *BookRepository) RawSQL(queryBuffer *godb.SQLBuffer) (result []Book, err error) {\n\tresult = make([]Book, 0, 0)\n\terr = this.db.RawSQL(queryBuffer.SQL(), queryBuffer.Arguments()...).Do(\u0026result)\n\treturn\n}\n\nfunc (this *BookRepository) BeginTx() (err error) {\n\terr = this.db.Begin()\n\treturn\n}\n\nfunc (this *BookRepository) CommitTx() (err error) {\n\terr = this.db.Commit()\n\treturn\n}\n\nfunc (this *BookRepository) RollbackTx() (err error) {\n\terr = this.db.Rollback()\n\treturn\n}\n\nfunc (this *BookRepository) CreateOne(newBook *Book) (err error) {\n\terr = this.db.Insert(newBook).Do()\n\treturn\n}\n\nfunc (this *BookRepository) UpdateOne(newBook *Book) (err error) {\n\terr = this.db.Update(newBook).Do()\n\treturn\n}\n\nfunc (this *BookRepository) DeleteOne(newBook *Book) (err error) {\n\t_ ,err = this.db.Delete(newBook).Do()\n\treturn\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplopezm%2Fgenorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplopezm%2Fgenorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplopezm%2Fgenorm/lists"}