model

package
v0.0.0-...-70569e3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypePGInt2 is a postgres type
	TypePGInt2 = "int2"
	// TypePGInt4 is a postgres type
	TypePGInt4 = "int4"
	// TypePGInt8 is a postgres type
	TypePGInt8 = "int8"
	// TypePGNumeric is a postgres type
	TypePGNumeric = "numeric"
	// TypePGFloat4 is a postgres type
	TypePGFloat4 = "float4"
	// TypePGFloat8 is a postgres type
	TypePGFloat8 = "float8"
	// TypePGText is a postgres type
	TypePGText = "text"
	// TypePGVarchar is a postgres type
	TypePGVarchar = "varchar"
	// TypePGUuid is a postgres type
	TypePGUuid = "uuid"
	// TypePGBpchar is a postgres type
	TypePGBpchar = "bpchar"
	// TypePGBytea is a postgres type
	TypePGBytea = "bytea"
	// TypePGBool is a postgres type
	TypePGBool = "bool"
	// TypePGTimestamp is a postgres type
	TypePGTimestamp = "timestamp"
	// TypePGTimestamptz is a postgres type
	TypePGTimestamptz = "timestamptz"
	// TypePGDate is a postgres type
	TypePGDate = "date"
	// TypePGTime is a postgres type
	TypePGTime = "time"
	// TypePGTimetz is a postgres type
	TypePGTimetz = "timetz"
	// TypePGInterval is a postgres type
	TypePGInterval = "interval"
	// TypePGJSONB is a postgres type
	TypePGJSONB = "jsonb"
	// TypePGJSON is a postgres type
	TypePGJSON = "json"
	// TypePGHstore is a postgres type
	TypePGHstore = "hstore"
	// TypePGInet is a postgres type
	TypePGInet = "inet"
	// TypePGCidr is a postgres type
	TypePGCidr = "cidr"
	// TypePGPoint is a postgres type
	TypePGPoint = "point"

	// TypeInt is a go type
	TypeInt = "int"
	// TypeInt32 is a go type
	TypeInt32 = "int32"
	// TypeInt64 is a go type
	TypeInt64 = "int64"
	// TypeFloat32 is a go type
	TypeFloat32 = "float32"
	// TypeFloat64 is a go type
	TypeFloat64 = "float64"
	// TypeString is a go type
	TypeString = "string"
	// TypeByteSlice is a go type
	TypeByteSlice = "[]byte"
	// TypeBool is a go type
	TypeBool = "bool"
	// TypeTime is a go type
	TypeTime = "time.Time"
	// TypeDuration is a go type
	TypeDuration = "time.Duration"
	// TypeMapInterface is a go type
	TypeMapInterface = "map[string]interface{}"
	// TypeMapString is a go type
	TypeMapString = "map[string]string"
	// TypeIP is a go type
	TypeIP = "net.IP"
	// TypeIPNet is a go type
	TypeIPNet = "net.IPNet"

	// TypeInterface is a go type
	TypeInterface = "interface{}"
)

Variables

This section is empty.

Functions

func GoImport

func GoImport(pgType string, nullable, useSQLNull bool) string

GoImport generates import from go type

func GoNullable

func GoNullable(pgType string, useSQLNull bool, customTypes CustomTypeMapping) (string, error)

GoNullable generates all go types from Postgres type with pointer

func GoSlice

func GoSlice(pgType string, dimensions int) (string, error)

GoSlice generates go slice type from Postgres array

func GoType

func GoType(pgType string) (string, error)

GoType generates simple go type from Postgres type

Types

type Column

type Column struct {
	GoName string
	PGName string

	Type       string
	SearchType string

	GoType string
	PGType string

	Nullable bool

	IsArray    bool
	Dimensions int

	IsPK bool
	IsFK bool
	// Relation *Relation
	Relation *columnRelWrap

	Import string

	MaxLen int
	Values []string
}

Column stores information about column

func NewColumn

func NewColumn(pgName string, pgType string, nullable, sqlNulls, array bool, dims int, pk, fk bool, len int, values []string, customTypes CustomTypeMapping) Column

NewColumn creates Column from Postgres info

func (*Column) AddRelation

func (c *Column) AddRelation(relation *Relation, relPK string)

AddRelation adds relation to column. Should be used if FK

type CustomType

type CustomType struct {
	PGType string

	GoType   string
	GoImport string
}

type CustomTypeMapping

type CustomTypeMapping map[string]CustomType

func ParseCustomTypes

func ParseCustomTypes(raw []string) (CustomTypeMapping, error)

func (CustomTypeMapping) Add

func (c CustomTypeMapping) Add(pgType, goType, goImport string)

func (CustomTypeMapping) GoImport

func (c CustomTypeMapping) GoImport(pgType string) (string, bool)

func (CustomTypeMapping) GoType

func (c CustomTypeMapping) GoType(pgType string) (string, bool)

func (CustomTypeMapping) Has

func (c CustomTypeMapping) Has(pgType string) bool

func (CustomTypeMapping) Imports

func (c CustomTypeMapping) Imports() []string

type Entity

type Entity struct {
	GoName       string
	GoNamePlural string
	PGName       string
	PGSchema     string
	PGFullName   string

	ViewName string

	Columns   []Column
	Relations []Relation

	Imports []string
	// contains filtered or unexported fields
}

Entity stores information about table

func NewEntity

func NewEntity(schema, pgName string, columns []Column, relations []Relation) Entity

NewEntity creates new Entity from Postgres info

func (*Entity) AddColumn

func (e *Entity) AddColumn(column Column)

AddColumn adds column to entity

func (*Entity) AddRelation

func (e *Entity) AddRelation(relation Relation)

AddRelation adds relation to entity

func (*Entity) GetPKs

func (e *Entity) GetPKs() []Column

GetPKs returns columns which are marked as primary keys

func (*Entity) HasMultiplePKs

func (e *Entity) HasMultiplePKs() bool

HasMultiplePKs checks if entity has many primary keys

type Relation

type Relation struct {
	PKFields []string
	FKFields []string
	GoName   string

	TargetPGName     string
	TargetPGSchema   string
	TargetPGFullName string

	TargetEntity *Entity

	GoType string
}

Relation stores relation

func NewRelation

func NewRelation(sourceColumns []string, targetSchema, targetTable string, targetColumns []string) Relation

NewRelation creates relation from Postgres info

func (*Relation) AddEntity

func (r *Relation) AddEntity(entity *Entity)

Jump to

Keyboard shortcuts

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