util

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Id is camelCased Id
	Id = "Id"
	// Ids is camelCased Ids
	Ids = "Ids"
	// ID is golang ID
	ID = "ID"
	// IDs is golang IDs
	IDs = "IDs"
	// Rel if suffix for Relation
	Rel = "Rel"
)
View Source
const (
	// PublicSchema is a default postgresql schema
	PublicSchema = "public"

	// DefaultPackage is a default package name
	DefaultPackage = "model"

	// DefaultAlias is a default alias for model
	DefaultAlias = "t"
)

Variables

This section is empty.

Functions

func CamelCased

func CamelCased(s string) string

CamelCased converts string to camelCase from https://github.com/uptrace/bun/blob/master/internal/underscore.go#L37

func ColumnName

func ColumnName(s string) string

ColumnName gets string usable as struct field name

func EntityName

func EntityName(s string) string

EntityName gets string usable as struct name

func File

func File(filename string) (*os.File, error)

File creates file

func FmtAndSave

func FmtAndSave(unformatted []byte, filename string) (bool, error)

FmtAndSave formats go code and saves file if formatting failed it still saves file but return error also

func HasUpper

func HasUpper(s string) bool

HasUpper checks if string contains upper case

func IsLower

func IsLower(c byte) bool

IsLower check rune for lower case

func IsUpper

func IsUpper(c byte) bool

IsUpper check rune for upper case

func Join

func Join(schema, table string) string

Join joins table name and schema to full name

func JoinF

func JoinF(schema, table string) string

JoinF joins table name and schema to full name filtering public

func LowerFirst

func LowerFirst(s string) string

LowerFirst lowers the first letter

func PackageName

func PackageName(s string) string

PackageName gets string usable as package name

func Quoted

func Quoted(fullName string, escape bool) string

Quoted quotes entity name if needed

func ReplaceSuffix

func ReplaceSuffix(in, suffix, replace string) string

ReplaceSuffix replaces substring on the end of string

func Sanitize

func Sanitize(s string) string

Sanitize makes string suitable for golang var, const, field, type name

func Schemas

func Schemas(tables []string) (schemas []string)

Schemas get schemas from table names

func Singular

func Singular(s string) string

Singular makes singular of plural english word

func Split

func Split(s string) (string, string)

Split splits full table name in schema and table name

func ToLower

func ToLower(c byte) byte

ToLower converts rune to lower

func ToUpper

func ToUpper(c byte) byte

ToUpper converts rune to upper

func Underscore

func Underscore(s string) string

Underscore converts string to under_scored from https://github.com/uptrace/bun/blob/master/internal/underscore.go#L19

Types

type Annotation

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

Annotation is a simple helper used to build tags for structs

func NewAnnotation

func NewAnnotation() *Annotation

NewAnnotation creates annotation

func (*Annotation) AddTag

func (a *Annotation) AddTag(name string, value string) *Annotation

AddTag ads a tag if not exists, appends a value otherwise

func (*Annotation) Len

func (a *Annotation) Len() int

func (*Annotation) String

func (a *Annotation) String() string

String prints valid tag

type Index

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

Index stores unique strings

func NewIndex

func NewIndex() Index

NewIndex creates Index

func (*Index) Add

func (i *Index) Add(s string)

Add ads string to index

func (*Index) Available

func (i *Index) Available(s string) bool

Available checks if string already exists

func (*Index) GetNext

func (i *Index) GetNext(s string) string

GetNext get next available string if given already exists

type Set

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

Set stores only unique strings

func NewSet

func NewSet() Set

NewSet creates Set

func (*Set) Add

func (s *Set) Add(element string) bool

Add adds element to set return false if element already exists

func (*Set) Elements

func (s *Set) Elements() []string

Elements return all elements from set

func (*Set) Exists

func (s *Set) Exists(element string) bool

Exists checks if element exists

func (*Set) Len

func (s *Set) Len() int

Len gets elements count

Jump to

Keyboard shortcuts

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