gorm

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2022 License: Apache-2.0 Imports: 3 Imported by: 1

README

Gorm Utils

go get github.com/andiwork/gorm-utils

Overview

  • model.go : update base gorm.Model with uuid for ID and set update time to now()

Getting Started

gorm-utils.Model
package hello

import (
	utils "github.com/andiwork/gorm-utils"
)

// User is just a sample type
type Person struct {
	utils.Model
	Name string `json:"name" description:"name of the user" default:"john"`
	Age  int    `json:"age" description:"age of the user" default:"21"`
}

License

© J. K. Gaglo, 2021~time.Now

Released under the Apache License Version 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	gorm.Model
	ID        uuid.UUID `gorm:"type:uuid;primary_key;"`
	OwnedBy   string
	CreatedBy string
	UpdatedBy string
}

Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt It may be embedded into your model or you may build your own model without it

type User struct {
  gorm.Base
}

https://gorm.io/docs/conventions.html

func (*Model) BeforeCreate

func (model *Model) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate will set a UUID rather than numeric ID.

func (*Model) BeforeUpdate

func (model *Model) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate will update UpdatedAt.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL