{"id":16002938,"url":"https://github.com/soreing/easyscan","last_synced_at":"2025-04-05T01:26:25.157Z","repository":{"id":64297279,"uuid":"564228259","full_name":"Soreing/easyscan","owner":"Soreing","description":"Golang generator for sql row scanning with object mapping","archived":false,"fork":false,"pushed_at":"2023-02-11T12:35:20.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T09:43:55.788Z","etag":null,"topics":["generator","go","golang","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Soreing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-11-10T09:16:41.000Z","updated_at":"2023-02-11T14:52:29.000Z","dependencies_parsed_at":"2024-06-20T12:49:22.520Z","dependency_job_id":"d3125f66-d785-4fe7-bfae-5dc012ddb72d","html_url":"https://github.com/Soreing/easyscan","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Feasyscan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Feasyscan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Feasyscan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Feasyscan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soreing","download_url":"https://codeload.github.com/Soreing/easyscan/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247274188,"owners_count":20912063,"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":["generator","go","golang","sql"],"created_at":"2024-10-08T10:05:08.585Z","updated_at":"2025-04-05T01:26:25.137Z","avatar_url":"https://github.com/Soreing.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Easy Scan\nEasy Scan is a code generator that implements functions on structures to map the Rows of an SQL query to the fields of an object or a slice of objects with no reflections.\n\n```\ngo install github.com/Soreing/easyscan/...\n```\n\n## Generation\n\nDefine a structure to generate scan functions for, then run the generator. The default behavior is that fields are scanned in the order they are defined in, but it can be changed with the `-any_order` flag.\n\n`./models/book.go`\n```golang\ntype Book struct {\n\tId          string\n\tTitle       string\n\tDescription string\n\tAuthor      string\n\tYear        int\n\tVersion     int\n}\n```\nYou can either target a single file or an entire directory by providing the relative path from the module root. When targeting a single file, the result is written into `[filename]_easyscan.go`. When targeting a directory, the result is written into `[pkgname]_easyscan.go`. The output file name can also be custom set with flags. \n```\neasyscan -all ./models/book.go\n```\n\nThe `-all` flag processes all defined types, but you can explicitly include or exclude types from the generation. The following example includes `Movie` without the use of the all flag, and excludes `Shape` even with the all flag\n```golang\n//easyscan:explicit\ntype Movie struct {\n    Title string\n    Time  time.Time\n}\n\n//easyscan:skip\ntype Shape struct {\n    Sides int\n    Color string\n}\n```\n\nThe `easyscan` field tag lets you customize how specific fields behave. The first value specifies an alias for the field for parsing rows. You can also use `omit` to exclude the field from scanning.\n```golang\ntype User struct {\n    Id       string `easyscan:\"_Id\"`\n    Name     string\n    Password string `easyscan:\",omit\"`\n}\n```\n\nTo generate scan functions for a slice of objects, you need to define and use a new type that wraps the slice.\n```golang\ntype BookList []Book\n```\n\n## Usage\n\nUse the generated method `ScanRow` to scan a single row into an object. You need to provide sql.Rows structure even if there is only one row.\n```golang \n// Query the database\nrows, err := db.Query(\"SELECT * FROM books WHERE id=$1\", 0)\nif err != nil {\n    panic(err)\n}\n\n// Scan the row into a Book object\nbk := models.Book{}\nif err := bk.ScanRow(rows); err != nil {\n    fmt.Println(\"failed to scan\")\n}\nfmt.Println(\"Book: \", bk)\n```\n\nWhen you have multiple rows to scan, you can iterate over the sql.Rows structure and append into the slice with the `ScanAppendRow` generated method.\n```golang \n// Query the database\nrows, err := db.Query(\"SELECT * FROM books WHERE id=$1\", 0)\nif err != nil {\n    panic(err)\n}\n\n// Scan the rows into a Book List object\nbkl := models.BookList{}\nfor rows.Next() {\n    if err := bkl.ScanAppendRow(rows); err != nil {\n        fmt.Println(\"failed to scan\")\n        break\n    }\n}\nfmt.Println(\"Book List: \", bkl)\n```\n\n## Options\n| Option | Description |\n|--------|-------------|\n| -all             | Processes all defined types in the target path        |\n| -any_order       | Allows scanning fields in any order from rows         |\n| -output_filename | Specify the output file name for the code             |\n| -lower_case      | Transform field names to lower case for parsing rows  |\n| -camel_case      | Transform field names to camel case for parsing rows  |\n| -kebab_case      | Transform field names to kebab case for parsing rows  |\n| -snake_case      | Transform field names to snake case for parsing rows  |\n| -pascal_case     | Transform field names to pascal case for parsing rows |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Feasyscan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoreing%2Feasyscan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Feasyscan/lists"}