schema

package
v0.0.0-...-d6a6539 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name string // Name is the name of the field.
	Type string // Type is the type of the field.
	Tag  string // Tag is the tag associated with the field.
}

Field represents a column of database

type Schema

type Schema struct {
	Model      interface{} // Model is the model of the schema.
	Name       string      // Name is the name of the schema.
	Fields     []*Field    // Fields is a slice of pointers to the fields in the schema.
	FieldNames []string    // FieldNames is a slice of the names of the fields in the schema.
	// contains filtered or unexported fields
}

Schema represents a table of database

func Parse

func Parse(dest interface{}, d dialect.Dialect) *Schema

Parse is a function that takes a destination interface and a dialect, and returns a pointer to a Schema. It first gets the type of the model from the destination interface, and initializes a new Schema with the model, its name, and an empty fieldMap. Then, it iterates over the fields of the model. If a field is not anonymous and is exported, it creates a new Field with the name of the model field and its type, as determined by the dialect. If the model field has a tag "orm", it also sets the Tag of the Field to the value of this tag. Finally, it adds the new Field to the Fields slice of the Schema, its name to the FieldNames slice, and a mapping from its name to the Field itself to the fieldMap. After all fields have been processed, it returns the pointer to the Schema.

func (*Schema) GetField

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

GetField returns a pointer to the field with the given name in the schema.

Jump to

Keyboard shortcuts

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