Files
lndhub.go/db/models/user.go
Roman Useinov 628071160c Cleanup (#25)
* remove cmd folder as we are going to have only one entrypoint

* get rid of pkg directory

* rename test -> integration_tests as unit tests should reside next to the actual files they are testing

* database migration WIP

* reinstate gorm boilerplate in the addinvoice for now to make it compile

* introduce migrations

* add Makefile

* don't use unsigned types for database mappings

* migrations work now

* add build target

* use echo groups

* gorm removed

* add envconfig

* fix comments
2022-01-16 00:49:19 +01:00

30 lines
660 B
Go

package models
import (
"context"
"database/sql"
"time"
"github.com/uptrace/bun"
)
// User : User Model
type User struct {
ID int64 `bun:",pk,autoincrement"`
Email sql.NullString `bun:",unique"`
Login string `bun:",unique,notnull"`
Password string `bun:",notnull"`
CreatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp"`
UpdatedAt bun.NullTime
}
func (u *User) BeforeAppendModel(ctx context.Context, query bun.Query) error {
switch query.(type) {
case *bun.UpdateQuery:
u.UpdatedAt = bun.NullTime{Time: time.Now()}
}
return nil
}
var _ bun.BeforeAppendModelHook = (*User)(nil)