Update clause.go
Exported constants and variables for special names. Updated comments to be more descriptive. I followed common Go naming conventions for exported names. I used more descriptive names for variables where appropriate. We grouped related constants and variables. Added comments for exported methods and types.
This commit is contained in:
parent
f0af94cd16
commit
9772713589
@ -1,21 +1,22 @@
|
|||||||
package clause
|
package clause
|
||||||
|
|
||||||
// Interface clause interface
|
// Interface is a clause interface.
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
Name() string
|
Name() string
|
||||||
Build(Builder)
|
Build(Builder)
|
||||||
MergeClause(*Clause)
|
MergeClause(*Clause)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClauseBuilder clause builder, allows to customize how to build clause
|
// ClauseBuilder is a clause builder that allows customization of how to build a clause.
|
||||||
type ClauseBuilder func(Clause, Builder)
|
type ClauseBuilder func(Clause, Builder)
|
||||||
|
|
||||||
|
// Writer is an interface for writing operations.
|
||||||
type Writer interface {
|
type Writer interface {
|
||||||
WriteByte(byte) error
|
WriteByte(byte) error
|
||||||
WriteString(string) (int, error)
|
WriteString(string) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builder builder interface
|
// Builder is a builder interface.
|
||||||
type Builder interface {
|
type Builder interface {
|
||||||
Writer
|
Writer
|
||||||
WriteQuoted(field interface{})
|
WriteQuoted(field interface{})
|
||||||
@ -23,9 +24,9 @@ type Builder interface {
|
|||||||
AddError(error) error
|
AddError(error) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clause
|
// Clause represents a query clause.
|
||||||
type Clause struct {
|
type Clause struct {
|
||||||
Name string // WHERE
|
Name string
|
||||||
BeforeExpression Expression
|
BeforeExpression Expression
|
||||||
AfterNameExpression Expression
|
AfterNameExpression Expression
|
||||||
AfterExpression Expression
|
AfterExpression Expression
|
||||||
@ -33,7 +34,7 @@ type Clause struct {
|
|||||||
Builder ClauseBuilder
|
Builder ClauseBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build build clause
|
// Build builds the clause.
|
||||||
func (c Clause) Build(builder Builder) {
|
func (c Clause) Build(builder Builder) {
|
||||||
if c.Builder != nil {
|
if c.Builder != nil {
|
||||||
c.Builder(c, builder)
|
c.Builder(c, builder)
|
||||||
@ -62,18 +63,20 @@ func (c Clause) Build(builder Builder) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constants for special names.
|
||||||
const (
|
const (
|
||||||
PrimaryKey string = "~~~py~~~" // primary key
|
PrimaryKey = "~~~py~~~" // Primary key
|
||||||
CurrentTable string = "~~~ct~~~" // current table
|
CurrentTable = "~~~ct~~~" // Current table
|
||||||
Associations string = "~~~as~~~" // associations
|
Associations = "~~~as~~~" // Associations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Predefined instances.
|
||||||
var (
|
var (
|
||||||
currentTable = Table{Name: CurrentTable}
|
CurrentTableInstance = Table{Name: CurrentTable}
|
||||||
PrimaryColumn = Column{Table: CurrentTable, Name: PrimaryKey}
|
PrimaryColumn = Column{Table: CurrentTable, Name: PrimaryKey}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Column quote with name
|
// Column represents a column with optional table and alias.
|
||||||
type Column struct {
|
type Column struct {
|
||||||
Table string
|
Table string
|
||||||
Name string
|
Name string
|
||||||
@ -81,7 +84,7 @@ type Column struct {
|
|||||||
Raw bool
|
Raw bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Table quote with name
|
// Table represents a table with optional alias.
|
||||||
type Table struct {
|
type Table struct {
|
||||||
Name string
|
Name string
|
||||||
Alias string
|
Alias string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user