{"id":38353289,"url":"https://github.com/bgruszka/gorm-loggable","last_synced_at":"2026-01-17T03:12:38.150Z","repository":{"id":57550546,"uuid":"308608582","full_name":"bgruszka/gorm-loggable","owner":"bgruszka","description":"loggable plugin for gorm v2","archived":false,"fork":false,"pushed_at":"2020-10-30T11:59:53.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T16:48:47.948Z","etag":null,"topics":["golang","gorm","gorm-orm","plugin"],"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/bgruszka.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":"2020-10-30T11:19:07.000Z","updated_at":"2022-06-29T18:12:11.000Z","dependencies_parsed_at":"2022-08-29T20:41:28.146Z","dependency_job_id":null,"html_url":"https://github.com/bgruszka/gorm-loggable","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bgruszka/gorm-loggable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgruszka%2Fgorm-loggable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgruszka%2Fgorm-loggable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgruszka%2Fgorm-loggable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgruszka%2Fgorm-loggable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bgruszka","download_url":"https://codeload.github.com/bgruszka/gorm-loggable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgruszka%2Fgorm-loggable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28492616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T02:39:23.645Z","status":"ssl_error","status_checked_at":"2026-01-17T02:34:19.649Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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","gorm","gorm-orm","plugin"],"created_at":"2026-01-17T03:12:38.067Z","updated_at":"2026-01-17T03:12:38.133Z","avatar_url":"https://github.com/bgruszka.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gorm-loggable\nLoggable plugin for gorm v2\n\n## How to use it?\n```\ngo get github.com/bgruszka/gorm-loggable\n```\n\nthen after db init:\n```go\ndb, err = gorm.Open(postgres.Open(databaseURL), \u0026gorm.Config{\n    Logger: logger.Default.LogMode(logger.Info),\n})\n```\n\nregister loggable plugin:\n\n```go\nDB.Use(loggable.New())\n```\n\nIn order to track changes of your model you have to mark a model with `loggable.LoggableModel`.\n\n```go\ntype Order struct {\n    ...\n    loggable.LoggableModel\n}\n```\n\nNext you have to specify which fields should be tracked in inserts and updates.\n\nThere are to options to use:\n* to track creates:\n  ```\n  loggable:\"create\"\n  ```\n\n* to track updates:\n  ```\n  loggable:\"update\"\n  ```\n\nIt's of course possible to track both:\n```\nloggable:\"create,update\"\n```\n\nMore detailed example:\n\n```go\ntype Order struct {\n    ID         uint `gorm:\"primary_key\"`\n    UserID     uint `gorm:\"not null\" loggable:\"create\"`\n    User       User\n    State      OrderState      `gorm:\"not null\" loggable:\"create,update\"`\n    TotalPrice decimal.Decimal `gorm:\"not null\" loggable:\"create\"`\n    Items      []OrderItem\n    CreatedAt  time.Time\n    UpdatedAt  time.Time\n    DeletedAt  *time.Time `sql:\"index\"`\n    loggable.LoggableModel\n}\n```\n\nAll the logs will be stored in `change_logs` table using this model:\n```go\ntype ChangeLog struct {\n    ID         uint      `gorm:\"primaryKey\"`\n    CreatedAt  time.Time `gorm:\"DEFAULT:current_timestamp\"`\n    Action     string    `gorm:\"type:VARCHAR(10)\"`\n    ObjectID   string    `gorm:\"index;type:VARCHAR(30)\"`\n    ObjectType string    `gorm:\"index;type:VARCHAR(50)\"`\n    RawObject  string    `gorm:\"type:JSON\"`\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgruszka%2Fgorm-loggable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbgruszka%2Fgorm-loggable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgruszka%2Fgorm-loggable/lists"}