parse

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parse implements parsing of Go structs in files and runtime.

This package, despite containing exported types, methods and functions, is an internal part of implementation of 'reform' command, also used by generated files, and not a part of public stable API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertUpToDate

func AssertUpToDate(si *StructInfo, obj interface{})

AssertUpToDate checks that given StructInfo matches given object. It is used during program initialization to check that generated files are up-to-date.

Types

type FieldInfo

type FieldInfo struct {
	Name   string // field name as defined in source file, e.g. Name
	Type   string // field type as defined in source file, e.g. string; always present for primary key, may be absent otherwise
	Column string // SQL database column name from "reform:" struct field tag, e.g. name
}

FieldInfo represents information about struct field.

type StructInfo

type StructInfo struct {
	Type         string      // struct type as defined in source file, e.g. User
	SQLSchema    string      // SQL database schema name from magic "reform:" comment, e.g. public
	SQLName      string      // SQL database view or table name from magic "reform:" comment, e.g. users
	Fields       []FieldInfo // fields info
	PKFieldIndex int         // index of primary key field in Fields, -1 if none
}

StructInfo represents information about struct.

func File

func File(path string) ([]StructInfo, error)

File parses given file and returns found structs information.

func Object

func Object(obj interface{}, schema, table string) (res *StructInfo, err error)

Object extracts struct information from given object.

func (*StructInfo) Columns

func (s *StructInfo) Columns() []string

Columns returns a new slice of column names.

func (*StructInfo) IsTable

func (s *StructInfo) IsTable() bool

IsTable returns true if this object represent information for table, false for view.

func (*StructInfo) PKField

func (s *StructInfo) PKField() FieldInfo

PKField returns a primary key field, panics for views.

Jump to

Keyboard shortcuts

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