CreatedAt set to current date if empty when Update
- Dominant language
- Go
- Stars
- 786
- Forks
- 61
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 2
Description
```
var e = employee{Name: "Wael"}
if err = repo.Insert(context.Background(), &e); err != nil {
panic(err)
}
fmt.Println("employee ", e, "created")
var e2 = employee{Name: "Abbas"}
e2.ID = e.ID
time.Sleep(60 * time.Second)
if err = repo.Update(context.Background(), &e2); err != nil {
panic(err)
}
fmt.Println("employee ", e2, "updated")
```
**Found:**
e2.CreatedAt gets updated:
```
2020/09/24 23:43:53 [duration: 73.43047ms op: adapter-query] INSERT INTO "employees" ("created_at","updated_at","name") VALUES ($1,$2,$3) RETURNING "id";
employee {4 Wael 2020-09-24 23:43:53 +0300 +03 2020-09-24 23:43:53 +0300 +03} created
employee {4 Abbas 2020-09-24 23:44:53 +0300 +03 2020-09-24 23:44:53 +0300 +03} updated
2020/09/24 23:44:53 [duration: 14.41539ms op: adapter-exec] UPDATE "employees" SET "id"=$1,"name"=$2,"created_at"=$3,"updated_at"=$4 WHERE "id"=$5;
```
**Expected:**
e2.CreatedAt should kept unchanged (`2020-09-24 23:43:53 +0300`)
full source code: https://gist.github.com/mhewedy/a90cd7946907e9aabd04c873cb326c34
**Suggestion:**
I would suggest to check for the statement type here:
https://github.com/Fs02/rel/blob/c7b126f33cb90e773956ad66ee10a4fa5cdc6660/structset.go#L31
If it is insert then execute the `CreatedAt` logic, otherwise skip.
What do you think?
Contributor guide
Assessment
This issue has not been assessed yet.