naming

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 3 Imported by: 0

README

naming GoDoc

Package naming is concerned with naming database tables and column names.

There is no backward compatibility guarantee for this package.

Documentation

Overview

Package naming provides naming conventions used to convert Go struct field names to database columns.

Example
type convention interface {
	Convert(string) string
	Join([]string) string
}
conventions := []convention{SnakeCase, SameCase, LowerCase}
names := []string{"snake case", "same case", "lower case"}

for i, convention := range conventions {
	fmt.Printf("\n%s:\n\n", names[i])
	fmt.Println(convention.Convert("UserID"))
	fmt.Println(convention.Convert("HomeAddress"))
	fmt.Println(convention.Convert("StreetName"))
	fmt.Println(convention.Join([]string{
		convention.Convert("HomeAddress"),
		convention.Convert("StreetName"),
	}))
	fmt.Println(convention.Convert("HTMLElement"))
}
Output:


snake case:

user_id
home_address
street_name
home_address_street_name
html_element

same case:

UserID
HomeAddress
StreetName
HomeAddressStreetName
HTMLElement

lower case:

userid
homeaddress
streetname
homeaddressstreetname
htmlelement

Index

Examples

Constants

This section is empty.

Variables

Instances of the different naming conventions

Functions

This section is empty.

Types

type LowerCaseConvention

type LowerCaseConvention struct{}

LowerCaseConvention implements NamingConvention, by converting to lower case.

func (LowerCaseConvention) Convert

func (lc LowerCaseConvention) Convert(fieldName string) string

Convert converts the field name to lower case.

func (LowerCaseConvention) Join

func (lc LowerCaseConvention) Join(names []string) string

Join joins together the names with no separating characters between them.

func (LowerCaseConvention) TableName added in v0.6.0

func (lc LowerCaseConvention) TableName(typeName string) string

TableName converts a type name into a table name.

type SameCaseConvention

type SameCaseConvention struct{}

SameCaseConvention implements NamingConvention. It does not alter field names.

func (SameCaseConvention) Convert

func (sc SameCaseConvention) Convert(fieldName string) string

Convert returns fieldName unchanged.

func (SameCaseConvention) Join

func (sc SameCaseConvention) Join(names []string) string

Join joins together the names with no separating characters between them.

func (SameCaseConvention) TableName added in v0.6.0

func (sc SameCaseConvention) TableName(typeName string) string

TableName converts a type name into a table name.

type SnakeCaseConvention

type SnakeCaseConvention struct{}

SnakeCaseConvention converts Go struct fields into "snake_case". So the field name "UserID" would be converted to "user_id".

func (SnakeCaseConvention) Convert

func (sc SnakeCaseConvention) Convert(name string) string

Convert converts fieldName into snake_case.

func (SnakeCaseConvention) Join

func (sc SnakeCaseConvention) Join(names []string) string

Join joins together the names with underscores.

func (SnakeCaseConvention) TableName added in v0.6.0

func (sc SnakeCaseConvention) TableName(typeName string) string

TableName converts a type name into a table name.

Jump to

Keyboard shortcuts

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