colname

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2016 License: MIT Imports: 3 Imported by: 0

README

colname GoDoc

Package colname is concerned with inferring database table column names from the names of the associated Go struct fields.

There is no backward compatibility guarantee for this package.

Documentation

Overview

Package colname is concerned with inferring database table column names from the names of the associated Go struct fields.

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

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

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