dbutil

package
v0.0.0-...-d0e669d Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPageSize    = 20
	MaxDefaultPageSize = 100
)

Functions

func NewTestDB

func NewTestDB(t *testing.T, migrationTables ...interface{}) (testDB *gorm.DB, cleanup func(...string) error)

func Now

func Now() time.Time

func QuoteIdentifier

func QuoteIdentifier(s string) string

QuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be used as part of an SQL statement.

Types

type Cursor

type Cursor struct {
	Value    interface{}
	PageSize int
}

func (Cursor) Limit

func (p Cursor) Limit() int

type Model

type Model struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

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.Model
}

type Pagination

type Pagination struct {
	Page     int
	PageSize int
}

func (Pagination) LimitOffset

func (p Pagination) LimitOffset() (limit, offset int)

LimitOffset returns LIMIT and OFFSET parameter for SQL. The first page is page 0.

Jump to

Keyboard shortcuts

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