Exemple #1
0
func NewTable(any interface{}) (*Table, error) {
	if meta.IsSlice(any) {
		any = meta.CreateElement(any).Interface()
	}

	fields, err := GetFieldsOf(any)
	if err != nil {
		return nil, err
	}

	SetDefaultPK(fields)

	name := meta.TypeNameOf(any)

	return &Table{
		Name:    name,
		SQLName: snakecase.SnakeCase(name),
		Fields:  fields,
	}, nil
}
Exemple #2
0
func (iteration *FieldIteration) SQLOptions() (*sql.Options, error) {
	result, err := sql.NewOptions(iteration.TypeField().Tag.Get("sql"))
	if err != nil {
		return nil, err
	}

	if len(result.Name) == 0 {
		result.Name = snakecase.SnakeCase(iteration.Name())
	}

	if len(result.Type) == 0 {
		sqlType, err := sql.MatchType(iteration.TypeField().Type.String())
		if err != nil {
			return nil, err
		}

		result.Type = sqlType
		result.Length = sql.Types[result.Type]
	}

	return result, nil
}
Exemple #3
0
func SQLTableNameOf(st interface{}) string {
	return snakecase.SnakeCase(meta.TypeNameOf(st))
}
Exemple #4
0
// transform from filterCamelCase to camel_case
func filterName(name string) string {
	return snakecase.SnakeCase(strings.TrimPrefix(name, filterPrefix))
}