naming

package
v0.0.0-...-9522951 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 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 is concerned with naming database tables and columns.

Example
conventions := []Convention{Snake, Same, Lower}

for _, convention := range conventions {
	fmt.Printf("\n%s convention:\n\n", convention.Name())
	fmt.Println(convention.ColumnName("UserID"))
	fmt.Println(convention.ColumnName("HomeAddress"))
	fmt.Println(convention.ColumnName("StreetName"))
	fmt.Println(convention.Join(
		convention.ColumnName("HomeAddress"),
		convention.ColumnName("StreetName")))
	fmt.Println(convention.ColumnName("HTMLElement"))
}
Output:


snake convention:

user_id
home_address
street_name
home_address_street_name
html_element

same convention:

UserID
HomeAddress
StreetName
HomeAddressStreetName
HTMLElement

lower convention:

userid
homeaddress
streetname
homeaddressstreetname
htmlelement

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Convention

type Convention struct {
	// contains filtered or unexported fields
}

A Convention provides a naming convention for inferring database column names from Go struct field names.

var Lower Convention

Lower is an alternative convention, where the database column name is the lower case of the field name. This convention is useful with PostgreSQL.

var Same Convention

Same is an alternative convention, where the database column name is identical to the field name.

var Snake Convention

Snake is the default convention, converting Go struct field names into "snake case". So the field name "UserID" would be converted to "user_id".

func (Convention) ColumnName

func (c Convention) ColumnName(fieldName string) string

ColumnName converts a Go struct field name to a database column name.

func (Convention) Join

func (c Convention) Join(prefix, name string) string

Join the prefix string to the name to form a column name. Used for inferring the database column name for fields within embedded structs.

func (Convention) Name

func (c Convention) Name() string

Name returns the name of the convention.

Jump to

Keyboard shortcuts

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