{"id":22941494,"url":"https://github.com/sanda0/gormdt","last_synced_at":"2026-02-03T22:06:02.745Z","repository":{"id":255112336,"uuid":"848577122","full_name":"sanda0/gormdt","owner":"sanda0","description":"gormdt is a Golang package that simplifies data filtering and pagination when working with GORM","archived":false,"fork":false,"pushed_at":"2024-08-28T03:35:08.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T21:46:31.944Z","etag":null,"topics":["datatable","golang","gorm"],"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/sanda0.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}},"created_at":"2024-08-28T02:41:05.000Z","updated_at":"2024-08-29T18:04:59.000Z","dependencies_parsed_at":"2024-08-28T03:50:14.481Z","dependency_job_id":"2a71e2d6-59b1-4e64-8c33-53e3e3046b4c","html_url":"https://github.com/sanda0/gormdt","commit_stats":null,"previous_names":["sanda0/gormdt"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sanda0/gormdt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanda0%2Fgormdt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanda0%2Fgormdt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanda0%2Fgormdt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanda0%2Fgormdt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanda0","download_url":"https://codeload.github.com/sanda0/gormdt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanda0%2Fgormdt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29059072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T20:13:53.544Z","status":"ssl_error","status_checked_at":"2026-02-03T20:13:40.507Z","response_time":96,"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":["datatable","golang","gorm"],"created_at":"2024-12-14T13:44:04.697Z","updated_at":"2026-02-03T22:06:02.722Z","avatar_url":"https://github.com/sanda0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gormdt\n\n`gormdt` is a Golang package that simplifies data filtering and pagination when working with GORM. It provides two main functions, `FilterAndPaginate` and `FilterAndPaginateCustomQuery`, which allow you to easily filter, search, and paginate database records.\n\n## jQuery DataTables Support\n\nThe responses generated by the FilterAndPaginate and FilterAndPaginateCustomQuery functions are designed to be compatible with the jQuery DataTables plugin. This means you can directly use the output from these functions in your frontend application where you are using jQuery DataTables, making it easy to implement server-side processing.\n\n## Installation\n\nTo install `gormdt`, run:\n\n```bash\ngo get github.com/sanda0/gormdt\n```\n\n## Usage\n\n### Basic Usage: `FilterAndPaginate`\n\nThis function filters and paginates data from a specific table based on the search criteria provided. \n\n#### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/yourusername/gormdt\"\n\t\"gorm.io/driver/sqlite\"\n\t\"gorm.io/gorm\"\n)\n\nfunc main() {\n\t// Initialize GORM DB connection\n\tdb, err := gorm.Open(sqlite.Open(\"test.db\"), \u0026gorm.Config{})\n\tif err != nil {\n\t\tpanic(\"failed to connect to database\")\n\t}\n\n\t// Define the filter and paginate parameters\n\tparams := gormdt.FilterAndPaginateParam{\n\t\tDB:        db,\n\t\tTableName: \"users\",\n\t\tFields:    []string{\"name\", \"email\"},\n\t\tRequest: gormdt.DataTableRequest{\n\t\t\tDraw:   1,\n\t\t\tStart:  0,\n\t\t\tLength: 10,\n\t\t\tSearch: \"john\",\n\t\t},\n\t}\n\n\t// Call the FilterAndPaginate function\n\tresponse, err := gormdt.FilterAndPaginate(params)\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t\treturn\n\t}\n\n\t// Output the results\n\tfmt.Printf(\"Total Records: %d\\n\", response.RecordsTotal)\n\tfmt.Printf(\"Filtered Records: %d\\n\", response.RecordsFiltered)\n\tfmt.Printf(\"Data: %+v\\n\", response.Data)\n}\n```\n\n### Advanced Usage: `FilterAndPaginateCustomQuery`\n\nThis function allows for more advanced filtering and pagination using a custom SQL query.\n\n#### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/yourusername/gormdt\"\n\t\"gorm.io/driver/sqlite\"\n\t\"gorm.io/gorm\"\n)\n\nfunc main() {\n\t// Initialize GORM DB connection\n\tdb, err := gorm.Open(sqlite.Open(\"test.db\"), \u0026gorm.Config{})\n\tif err != nil {\n\t\tpanic(\"failed to connect to database\")\n\t}\n\n\t// Define the custom filter and paginate parameters with GROUP BY and HAVING\n\tparams := gormdt.FilterAndPaginateCustomQueryParam{\n\t\tDB:        db,\n\t\tBaseQuery: \"SELECT name, email, COUNT(*) as email_count FROM users\",\n\t\tWhere:     \"status = 'active'\",\n\t\tGroupBy:   \"name, email\",\n\t\tHaving:    \"COUNT(email) \u003e 1\", // Example HAVING condition\n\t\tFields:    []string{\"name\", \"email\"},\n\t\tRequest: gormdt.DataTableRequest{\n\t\t\tDraw:   1,\n\t\t\tStart:  0,\n\t\t\tLength: 10,\n\t\t\tSearch: \"john\",\n\t\t},\n\t}\n\n\t// Call the FilterAndPaginateCustomQuery function\n\tresponse, err := gormdt.FilterAndPaginateCustomQuery(params)\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t\treturn\n\t}\n\n\t// Output the results\n\tfmt.Printf(\"Total Records: %d\\n\", response.RecordsTotal)\n\tfmt.Printf(\"Filtered Records: %d\\n\", response.RecordsFiltered)\n\tfmt.Printf(\"Data: %+v\\n\", response.Data)\n}\n\n```\n\n## Data Structures\n\n### `DataTableRequest`\n\nThis struct represents the request for data filtering and pagination.\n\n```go\ntype DataTableRequest struct {\n\tDraw   int    `json:\"draw\" form:\"draw\"`\n\tStart  int    `json:\"start\" form:\"start\"`\n\tLength int    `json:\"length\" form:\"length\"`\n\tSearch string `json:\"search\" form:\"search[value]\"`\n}\n```\n\n### `DataTableResponse`\n\nThis struct represents the response after filtering and pagination.\n\n```go\ntype DataTableResponse struct {\n\tDraw            int         `json:\"draw\"`\n\tRecordsTotal    int         `json:\"recordsTotal\"`\n\tRecordsFiltered int         `json:\"recordsFiltered\"`\n\tData            interface{} `json:\"data\"`\n}\n```\n\n### Parameters\n\n#### `FilterAndPaginateParam`\n\nParameters for the `FilterAndPaginate` function.\n\n```go\ntype FilterAndPaginateParam struct {\n\tDB        *gorm.DB\n\tTableName string\n\tFields    []string\n\tRequest   DataTableRequest\n}\n```\n\n#### `FilterAndPaginateCustomQueryParam`\n\nParameters for the `FilterAndPaginateCustomQuery` function.\n\n```go\ntype FilterAndPaginateCustomQueryParam struct {\n\tDB        *gorm.DB\n\tBaseQuery string\n\tWhere     string\n\tGroupBy   string\n\tHaving    string\n\tFields    []string\n\tRequest   DataTableRequest\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanda0%2Fgormdt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanda0%2Fgormdt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanda0%2Fgormdt/lists"}