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 ¶
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.