57 lines
2.1 KiB
Go
57 lines
2.1 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"
|
|
|
|
"go.ipao.vip/gen"
|
|
)
|
|
|
|
const TableNameUserPost = "user_posts"
|
|
|
|
// UserPost mapped from table <user_posts>
|
|
type UserPost struct {
|
|
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp without time zone;not null;default:now()" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp without time zone;not null;default:now()" json:"updated_at"`
|
|
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
|
PostID int64 `gorm:"column:post_id;type:bigint;not null" json:"post_id"`
|
|
Price int64 `gorm:"column:price;type:bigint;not null" json:"price"`
|
|
}
|
|
|
|
// Quick operations without importing query package
|
|
// Update applies changed fields to the database using the default DB.
|
|
func (m *UserPost) Update(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.UserPost.WithContext(ctx).Updates(m)
|
|
}
|
|
|
|
// Save upserts the model using the default DB.
|
|
func (m *UserPost) Save(ctx context.Context) error { return Q.UserPost.WithContext(ctx).Save(m) }
|
|
|
|
// Create inserts the model using the default DB.
|
|
func (m *UserPost) Create(ctx context.Context) error { return Q.UserPost.WithContext(ctx).Create(m) }
|
|
|
|
// Delete removes the row represented by the model using the default DB.
|
|
func (m *UserPost) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.UserPost.WithContext(ctx).Delete(m)
|
|
}
|
|
|
|
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
|
func (m *UserPost) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.UserPost.WithContext(ctx).Unscoped().Delete(m)
|
|
}
|
|
|
|
// Reload reloads the model from database by its primary key and overwrites current fields.
|
|
func (m *UserPost) Reload(ctx context.Context) error {
|
|
fresh, err := Q.UserPost.WithContext(ctx).GetByID(m.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*m = *fresh
|
|
return nil
|
|
}
|