{"id":37122753,"url":"https://github.com/samueltissot/sqltime","last_synced_at":"2026-01-14T14:11:09.529Z","repository":{"id":49817421,"uuid":"217399021","full_name":"SamuelTissot/sqltime","owner":"SamuelTissot","description":"a timestamp type that works with RDBMS.","archived":false,"fork":false,"pushed_at":"2020-01-15T16:29:06.000Z","size":15,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T14:10:07.430Z","etag":null,"topics":["database","deepequal","go","golang","gorm","mysql","postgres","postgresql","testing","timestamp"],"latest_commit_sha":null,"homepage":null,"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/SamuelTissot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-24T21:32:50.000Z","updated_at":"2023-02-28T19:58:45.000Z","dependencies_parsed_at":"2022-09-21T13:40:44.388Z","dependency_job_id":null,"html_url":"https://github.com/SamuelTissot/sqltime","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/SamuelTissot/sqltime","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelTissot%2Fsqltime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelTissot%2Fsqltime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelTissot%2Fsqltime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelTissot%2Fsqltime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamuelTissot","download_url":"https://codeload.github.com/SamuelTissot/sqltime/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelTissot%2Fsqltime/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28422408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"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":["database","deepequal","go","golang","gorm","mysql","postgres","postgresql","testing","timestamp"],"created_at":"2026-01-14T14:11:08.818Z","updated_at":"2026-01-14T14:11:09.522Z","avatar_url":"https://github.com/SamuelTissot.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"sqltime\n===\n\nA `time.Time` wrapper compatible with databases `timestamp` type.\n\nIssue \n-----\nMost database `timestamp`  have a resolution of microseconds while Go `time.Time` has a resolution of nanoseconds.\n\n[postgres](https://www.postgresql.org/docs/9.1/datatype-datetime.html)\n[mysql](https://dev.mysql.com/doc/refman/8.0/en/fractional-seconds.html)\n\nThe resolution difference causes a data loss, so when a record is inserted into the database and retrieve the timestamp differs.\n\nFor testing, it gets quite annoying since you can't use `reflect.DeepEqual` to compare the two record ( original and the one fetch from the database)\n\nMoreover,  most of the time, there is the issue of Location. `sqltime` will set the `timestamp` to the right database location. The default database location is `UTC,` but it can easily be changed with:\n\n```go\nsqltime.DatabaseLocation, _ = time.LoadLocation([YOUR_LOCATION])\n```\n\nSolution \n---\nWrapping the `time.Time` type to truncate the time to database resolution. By default, it will truncate the nanoseconds\n\nThe resolution can be changed with:\n\n```go\nsqltime.Truncate = time.Microsecond\n```\n\n---\n\nexample\n----\n\nsee a full example [here](/example/). The example assumes that the database is set\n to the default timezone of `UTC` if not please update the `sqltime.DatabaseLocation`.\n\n\n\n\nUsage with with GORM\n---\n\nIt is particularly useful with ORM's like [GORM](https://github.com/jinzhu/gorm)\n\nBut instead of extending the `gorm.Model` you declare your base.\n\n```go\npackage Model\n\nimport \"github.com/SamuelTissot/sqltime\"\n\n// define the model\ntype Model struct {\n\tID         uint `gorm:\"primary_key\"`\n\tCreatedAt sqltime.Time  `gorm:\"type:timestamp\"`\n\tUpdatedAt sqltime.Time  `gorm:\"type:timestamp\"`\n\tDeletedAt *sqltime.Time `gorm:\"type:timestamp\"`\n}\n\n// and use it like this\ntype MyModel struct {\n\tBaseModel\n\tData string\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamueltissot%2Fsqltime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamueltissot%2Fsqltime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamueltissot%2Fsqltime/lists"}