From 9772713589fafd33d8f82139395518ddd4b32c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Mari=C4=87?= <45515666+GocaMaric@users.noreply.github.com> Date: Tue, 5 Dec 2023 20:39:27 +0100 Subject: [PATCH] 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. --- clause/clause.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/clause/clause.go b/clause/clause.go index 1354fc057..4e22627c9 100644 --- a/clause/clause.go +++ b/clause/clause.go @@ -1,21 +1,22 @@ package clause -// Interface clause interface +// Interface is a clause interface. type Interface interface { Name() string Build(Builder) 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) +// Writer is an interface for writing operations. type Writer interface { WriteByte(byte) error WriteString(string) (int, error) } -// Builder builder interface +// Builder is a builder interface. type Builder interface { Writer WriteQuoted(field interface{}) @@ -23,9 +24,9 @@ type Builder interface { AddError(error) error } -// Clause +// Clause represents a query clause. type Clause struct { - Name string // WHERE + Name string BeforeExpression Expression AfterNameExpression Expression AfterExpression Expression @@ -33,7 +34,7 @@ type Clause struct { Builder ClauseBuilder } -// Build build clause +// Build builds the clause. func (c Clause) Build(builder Builder) { if c.Builder != nil { c.Builder(c, builder) @@ -62,18 +63,20 @@ func (c Clause) Build(builder Builder) { } } +// Constants for special names. const ( - PrimaryKey string = "~~~py~~~" // primary key - CurrentTable string = "~~~ct~~~" // current table - Associations string = "~~~as~~~" // associations + PrimaryKey = "~~~py~~~" // Primary key + CurrentTable = "~~~ct~~~" // Current table + Associations = "~~~as~~~" // Associations ) +// Predefined instances. var ( - currentTable = Table{Name: CurrentTable} - PrimaryColumn = Column{Table: CurrentTable, Name: PrimaryKey} + CurrentTableInstance = Table{Name: CurrentTable} + PrimaryColumn = Column{Table: CurrentTable, Name: PrimaryKey} ) -// Column quote with name +// Column represents a column with optional table and alias. type Column struct { Table string Name string @@ -81,7 +84,7 @@ type Column struct { Raw bool } -// Table quote with name +// Table represents a table with optional alias. type Table struct { Name string Alias string