schema

package
v0.0.0-...-e0aaadd Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TAG_BASE = "orm"

	TAG_PK      = "pk"
	TAG_AUTO    = "auto"
	TAG_TYPE    = "type"
	TAG_SIZE    = "size"
	TAG_VALID   = "valid"
	TAG_COLUMN  = "column"
	TAG_DEFAULT = "default"
	TAG_COMMENT = "comment"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name string // expresses the name of a column
	Type string // expresses the datatype of a column
	Tags *Tag   // expresses the tags of a colum in Go
}

Field represents a column of database

type Schema

type Schema struct {
	Name                  string       // the table name
	Model                 any          // the model of a data object in Go (it's a Go struct).
	ModelName             string       // the name of the data model in Go.
	ModelType             reflect.Type // the type of the data model in Go.
	Fields                []*Field     // table fields
	FieldNames            []string     // the field names in Go.
	ColumnNames           []any        // the column names in DB.
	InsertableColumnNames []any        // the insertable column names in DB (remove automatically generated fields).
	// contains filtered or unexported fields
}

Schema represents a table of database

func Parse

func Parse(model any, dial dialect.Dialect) *Schema

Parse a struct to a Schema instance. QEMU Virtual CPU version 2.5+ Benchmark-1 254864 4565 ns/op 2440 B/op 54 allocs/op Benchmark-2 279913 4076 ns/op 2440 B/op 54 allocs/op

func (*Schema) ExtractValues

func (own *Schema) ExtractValues(object any) []any

ExtractValues return the values of object's member variables. QEMU Virtual CPU version 2.5+ Benchmark-1 1606934 746.9 ns/op 184 B/op 11 allocs/op Benchmark-2 1727646 686.2 ns/op 184 B/op 11 allocs/op

func (*Schema) GetField

func (own *Schema) GetField(name string) *Field

GetField returns a field by the column name

type TableNameGetter

type TableNameGetter interface {
	GetTableName() string
}

type Tag

type Tag struct {
	PK      bool
	Auto    bool
	Type    string
	Size    string
	Valid   string
	Column  string
	Default string
	Comment string
}

func NewTag

func NewTag(tag string) *Tag

NewTag parses orm tag to the *Tag. QEMU Virtual CPU version 2.5+ Benchmark-1 1991818 602.9 ns/op 360 B/op 8 allocs/op Benchmark-2 2227740 540.0 ns/op 360 B/op 8 allocs/op

func (*Tag) IsAutoInsertField

func (own *Tag) IsAutoInsertField() bool

IsAutoInsertField checks if the field are automatically generated data

Jump to

Keyboard shortcuts

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