65 lines
2.7 KiB
Go
65 lines
2.7 KiB
Go
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"quyun/v2/pkg/consts"
|
|
|
|
"go.ipao.vip/gen"
|
|
"go.ipao.vip/gen/types"
|
|
)
|
|
|
|
const TableNameTenant = "tenants"
|
|
|
|
// Tenant mapped from table <tenants>
|
|
type Tenant struct {
|
|
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
|
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
|
Code string `gorm:"column:code;type:character varying(64);not null" json:"code"`
|
|
UUID types.UUID `gorm:"column:uuid;type:uuid;not null" json:"uuid"`
|
|
Name string `gorm:"column:name;type:character varying(128);not null" json:"name"`
|
|
Status consts.TenantStatus `gorm:"column:status;type:character varying(64);not null" json:"status"`
|
|
Config types.JSON `gorm:"column:config;type:jsonb;not null;default:{}" json:"config"`
|
|
ExpiredAt time.Time `gorm:"column:expired_at;type:timestamp with time zone" json:"expired_at"`
|
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
|
Users []*User `gorm:"joinForeignKey:TenantID;joinReferences:UserID;many2many:tenant_users" json:"users,omitempty"`
|
|
}
|
|
|
|
// Quick operations without importing query package
|
|
// Update applies changed fields to the database using the default DB.
|
|
func (m *Tenant) Update(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.Tenant.WithContext(ctx).Updates(m)
|
|
}
|
|
|
|
// Save upserts the model using the default DB.
|
|
func (m *Tenant) Save(ctx context.Context) error { return Q.Tenant.WithContext(ctx).Save(m) }
|
|
|
|
// Create inserts the model using the default DB.
|
|
func (m *Tenant) Create(ctx context.Context) error { return Q.Tenant.WithContext(ctx).Create(m) }
|
|
|
|
// Delete removes the row represented by the model using the default DB.
|
|
func (m *Tenant) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.Tenant.WithContext(ctx).Delete(m)
|
|
}
|
|
|
|
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
|
func (m *Tenant) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.Tenant.WithContext(ctx).Unscoped().Delete(m)
|
|
}
|
|
|
|
// Reload reloads the model from database by its primary key and overwrites current fields.
|
|
func (m *Tenant) Reload(ctx context.Context) error {
|
|
fresh, err := Q.Tenant.WithContext(ctx).GetByID(m.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*m = *fresh
|
|
return nil
|
|
}
|