{"id":40719356,"url":"https://github.com/arjendevos/gosql","last_synced_at":"2026-01-21T13:35:22.302Z","repository":{"id":65965021,"uuid":"593210986","full_name":"arjendevos/gosql","owner":"arjendevos","description":"SQL generator \u0026 REST api generator based on SQLboiler","archived":false,"fork":false,"pushed_at":"2024-01-18T12:50:54.000Z","size":269,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T08:08:47.251Z","etag":null,"topics":["golang","rest-api","sql-generator"],"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/arjendevos.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":"2023-01-25T13:53:33.000Z","updated_at":"2024-01-25T18:27:41.000Z","dependencies_parsed_at":"2024-01-18T15:03:37.344Z","dependency_job_id":null,"html_url":"https://github.com/arjendevos/gosql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arjendevos/gosql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjendevos%2Fgosql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjendevos%2Fgosql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjendevos%2Fgosql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjendevos%2Fgosql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arjendevos","download_url":"https://codeload.github.com/arjendevos/gosql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjendevos%2Fgosql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28633774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["golang","rest-api","sql-generator"],"created_at":"2026-01-21T13:35:22.238Z","updated_at":"2026-01-21T13:35:22.288Z","avatar_url":"https://github.com/arjendevos.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL generator \u0026 REST api generator based on SQLboiler\n\nCurrent implementation is only done for postgresql, though other sql databases like mysql should be easy to implement due to simular features. REST api is build on [gin-gonic](github.com/gin-gonic/gin).\n\n## Installation\n\n1. Create a new go project (`go mod new myproject`)\n2. Create a new folder called `convert` in your project, add your `.env` file with `POSTGRESQL_URL` \u0026 add your `sqlboiler.toml` config file\n3. Create a new file called `convert.go` in your `convert` folder\n4. Copy the following code into your `convert.go` file:\n\n```go\npackage main\n\nimport (\n\t\"os\"\n\t\"strings\"\n\n\t\"github.com/arjendevos/gosql\"\n)\n\nfunc main() {\n\tnewDir, _ := os.Getwd()\n\tos.Chdir(strings.TrimSuffix(newDir, \"/convert\"))\n\n\tgosql.Convert(\u0026gosql.GoSQLConfig{\n\t\tSchemeDir:           \"schemes\",\n\t\tMigrationDir:        \"database/migrations\",\n\t\tModelOutputDir:      \"models\",\n\t\tControllerOutputDir: \"generated\",\n\t\tSetupProject:        true,\n\t})\n}\n```\n\n5. Run `go mod tidy` inside the `convert` folder\n6. Create a new folder called `schemes` in your project\n7. Create a new file called `1_migration.gosql` in your `schemes` folder (you can name it whatever you want, but the number is important)\n8. Add your models into the `1_migration.gosql` file. Make sure to put `@postgresql` at the top (only needed for the first migration).\n9. Run `(cd convert \u0026\u0026 go run convert.go)` in your project folder\n10. Everything should be setup now, you can run `go run main.go` to start your server\n\n## Possibilities\n\n### Models\n\nExample model:\n\n```gosql\nUser {\n  id uuid @unique @default(uuid_generate_v4()) @index\n  name string\n  email string @unique\n  password string @hide\n  organization Organization\n  createdAt dateTime @default(now)\n  updatedAt dateTime @default(now)\n  deletedAt dateTime\n}\n```\n\n### Authentication\n\nAdd `authUser` after your model to make it the main table for your user authentication. It will automatically add their relation to all tables. These columns are required:\n\n- `email string @unique`\n- `password string`\n\nUse `@hide` to hide entire table from outside world.\n\n`@protected` has the following options (`@protected(LIST, BYID, CREATE, UPDATE, DELETE)`):\n\n- `LIST` - To protect the list endpoint\n- `BYID` - To protect the by id endpoint\n- `CREATE` - To protect the create endpoint\n- `UPDATE` - To protect the update endpoint\n- `DELETE` - To protect the delete endpoint\n\n### Data types\n\n| Type                    | PSQL Generator     | API Generator        |\n| ----------------------- | ------------------ | -------------------- |\n| `string`, `string(255)` | :white_check_mark: | :white_check_mark:   |\n| `bool`                  | :white_check_mark: | :white_check_mark:   |\n| `text`                  | :white_check_mark: | :white_check_mark:   |\n| `dateTime`              | :white_check_mark: | :white_check_mark:   |\n| `int`                   | :white_check_mark: | :white_check_mark:   |\n| `any`                   | :white_check_mark: | :white_large_square: |\n\n### Attributes\n\n| Type                             | Meaning                                     |\n| -------------------------------- | ------------------------------------------- |\n| `?` after type                   | Is nullable                                 |\n| `@uniue`                         | Is unique                                   |\n| `@default(autoincrement)`        | Auto increment                              |\n| `@default(uuid_generate_v4())`   | Auto Generate uuid                          |\n| `@default(now)`                  | Auto generate current time                  |\n| `@default(\"your default value\")` | Default string value                        |\n| `@default(false)`                | Default boolean value                       |\n| `@default(1)`                    | Default int value                           |\n| `@index`                         | Index on that column                        |\n| `@hide`                          | Hide from outside world in the api          |\n| `@regexp(\"your regexp\")`         | Regexp validation for creating and updating |\n\n### Relations\n\nYou can create a relation by adding a column name (this should be the table name with lowercase), like: `account` and you add as type the table name: `Account` with the first letter as capital. Don't refer both tables to each other, only one of them. Without `@unique` it is automatically a one to many relation. Optimize it by adding `@index` to the column.\n\n- Add `?` to make it nullable.\n- Add `@unique` to make it a one to one relation.\n\n### Query parameters\n\n- [x] limit=3\n- [x] page=4\n- [x] filter={\"column\": {\"equals\":\"true\"}}\n- [x] filter={\"column\":{\"equals\":true, \"or\": {\"lessThan\": 4}}}\n- [x] filter={\"column\":{\"equals\":true, \"or\": {\"lessThan\": 4, \"isNotIn\": [\"d\"]}}\n- [x] filter={\"relationTable\": {\"column\": {\"equals\":true}}} (filter on relation)\n- [x] rels={\"relationTable\":{}}\n- [x] rels={\"relationTable\":{\"deeperRelation\":{ etc... }}} (you can't call the parent relation in the child relation)\n- [x] rels={\"relationTable\":{\"\\_limit\":4, \"\\_page\":1}} (only for nToMany relations\n- [x] order={\"column\": \"desc\", \"column\":\"asc\"}\n- [x] from=organization | from=user | no parameter (organization = get by organization id, get = fetch by user id, no parameter = get by organization id \u0026 user id)\n- [x] select=[\"column\"] (omitempty fixes this on the json side)\n- [x] select relation columns. {\"\\_select\":[\"id\", \"created_at\"]\"}\n- [ ] Add permissions to a role or user\n\n### IDs\n\n- [x] id uuid @unique @default(uuid_generate_v4()) @index\n- [x] id int @unique @default(autoincrement) @index\n\n## Todo\n\n### Current implementations \u0026 future plans:\n\n- [x] Add order by possibility\n- [x] Add rest of the endpoints with bodies etc\n- [x] Add or possibility in filter\n- [x] Export to typescript types\n- [x] Generate postgresql database setup files (client \u0026 migrations)\n- [x] Auto install deps\n- [x] Add authorization on User \u0026 Organization\n- [x] User authentication\n- [x] fetch items based on user_id or organization_id\n- [x] expose relation ids in api\n- [x] fetch relations for every request except create\n- [x] change relations to include relations of relation\n- [x] add pagination to relations\n- [x] can filter on relation id's\n- [x] can filter on if null\n- [x] filter in relations in filter\n- [x] fix if filter does not exists sql will output: WHERE ()\n- [x] limit queries to relations for x role\n- [x] setup entire project\n- [x] Test all endpoints (high priority)\n- [x] middelware is somehow called 3 times (high priority)\n- [ ] add enum for role (low priority)\n- ~~ [ ] add filter to relation (low priority)~~\n- [x] Add select columns on relation (\\_select:[\"id\", \"name\"])\n- [x] Add select columns (normal not on relations)\n- [x] Add oauth2 login option\n- [x] Add oauth2 google login endpoints\n- [x] Add custom marshaller for time.Time (high priority)\n- [x] Make oauth2 google endpoints better based on scheme (org etc) (high priority)\n- [x] Select columns fix created_at and updated_at omitempty problem (low priority)\n- [x] Change From Query in Filter to InnerJoin for better performance (low priority)\n- [ ] Find a way to pass in args with var names instead of raw sql (medium priority)\n- [ ] Add oauth2 facebook login endpoints (low priority)\n- [ ] Add oauth2 apple login endpoints (lowest priority)\n- [ ] add email option (smtp with default templates) (low priority)\n- [ ] add password forget endpoints (very low priority) (should implement with email)\n\n## Custom options\n\nThere is an option to add extra middleware in the auth middleware to handle role access. This will be generated automatically if you turn on `SetupProject`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjendevos%2Fgosql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farjendevos%2Fgosql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjendevos%2Fgosql/lists"}