refactor: clean up exported funcs

This commit is contained in:
Reinaldy Rafli 2021-07-31 11:17:48 +07:00
parent ecefcdb710
commit 49cf645a9e
6 changed files with 17 additions and 20 deletions

12
bob.go
View File

@ -30,12 +30,12 @@ type BobBuilder interface {
// CreateTable creates a table with CreateBuilder interface // CreateTable creates a table with CreateBuilder interface
func (b BobBuilderType) CreateTable(table string) CreateBuilder { func (b BobBuilderType) CreateTable(table string) CreateBuilder {
return CreateBuilder(b).Name(table) return CreateBuilder(b).name(table)
} }
// CreateTableIfNotExists creates a table with CreateBuilder interface, if the table doesn't exists. // CreateTableIfNotExists creates a table with CreateBuilder interface, if the table doesn't exists.
func (b BobBuilderType) CreateTableIfNotExists(table string) CreateBuilder { func (b BobBuilderType) CreateTableIfNotExists(table string) CreateBuilder {
return CreateBuilder(b).Name(table).IfNotExists() return CreateBuilder(b).name(table).ifNotExists()
} }
// HasTable checks if a table exists with HasBuilder interface // HasTable checks if a table exists with HasBuilder interface
@ -50,22 +50,22 @@ func (b BobBuilderType) HasColumn(column string) HasBuilder {
// DropTable drops (delete contents & remove) a table from the database. // DropTable drops (delete contents & remove) a table from the database.
func (b BobBuilderType) DropTable(table string) DropBuilder { func (b BobBuilderType) DropTable(table string) DropBuilder {
return DropBuilder(b).DropTable(table) return DropBuilder(b).dropTable(table)
} }
// DropTable drops (delete contents & remove) a table from the database if the table exists. // DropTable drops (delete contents & remove) a table from the database if the table exists.
func (b BobBuilderType) DropTableIfExists(table string) DropBuilder { func (b BobBuilderType) DropTableIfExists(table string) DropBuilder {
return DropBuilder(b).DropTable(table).IfExists() return DropBuilder(b).dropTable(table).ifExists()
} }
// RenameTable simply renames an exisisting table. // RenameTable simply renames an exisisting table.
func (b BobBuilderType) RenameTable(from, to string) RenameBuilder { func (b BobBuilderType) RenameTable(from, to string) RenameBuilder {
return RenameBuilder(b).From(from).To(to) return RenameBuilder(b).from(from).to(to)
} }
// Truncate performs TRUNCATE function. It deletes all contents from a table but not deleting the table. // Truncate performs TRUNCATE function. It deletes all contents from a table but not deleting the table.
func (b BobBuilderType) Truncate(table string) TruncateBuilder { func (b BobBuilderType) Truncate(table string) TruncateBuilder {
return TruncateBuilder(b).Truncate(table) return TruncateBuilder(b).truncate(table)
} }
func (b BobBuilderType) Upsert(table string, dialect int) UpsertBuilder { func (b BobBuilderType) Upsert(table string, dialect int) UpsertBuilder {

View File

@ -27,13 +27,13 @@ func init() {
builder.Register(CreateBuilder{}, createData{}) builder.Register(CreateBuilder{}, createData{})
} }
// Name sets the table name // name sets the table name
func (b CreateBuilder) Name(name string) CreateBuilder { func (b CreateBuilder) name(name string) CreateBuilder {
return builder.Set(b, "TableName", name).(CreateBuilder) return builder.Set(b, "TableName", name).(CreateBuilder)
} }
// IfNotExists adds IF NOT EXISTS to the query // ifNotExists adds IF NOT EXISTS to the query
func (b CreateBuilder) IfNotExists() CreateBuilder { func (b CreateBuilder) ifNotExists() CreateBuilder {
return builder.Set(b, "IfNotExists", true).(CreateBuilder) return builder.Set(b, "IfNotExists", true).(CreateBuilder)
} }

View File

@ -19,11 +19,11 @@ func init() {
} }
// DropTable sets which table to be dropped // DropTable sets which table to be dropped
func (b DropBuilder) DropTable(name string) DropBuilder { func (b DropBuilder) dropTable(name string) DropBuilder {
return builder.Set(b, "TableName", name).(DropBuilder) return builder.Set(b, "TableName", name).(DropBuilder)
} }
func (b DropBuilder) IfExists() DropBuilder { func (b DropBuilder) ifExists() DropBuilder {
return builder.Set(b, "IfExists", true).(DropBuilder) return builder.Set(b, "IfExists", true).(DropBuilder)
} }

3
has.go
View File

@ -8,9 +8,6 @@ import (
"github.com/lann/builder" "github.com/lann/builder"
) )
// TODO - The whole file is a todo
// Meant to find two things: HasTable and HasColumn(s)
type HasBuilder builder.Builder type HasBuilder builder.Builder
type hasData struct { type hasData struct {

View File

@ -17,13 +17,13 @@ func init() {
builder.Register(RenameBuilder{}, renameData{}) builder.Register(RenameBuilder{}, renameData{})
} }
// From sets existing table name // from sets existing table name
func (b RenameBuilder) From(name string) RenameBuilder { func (b RenameBuilder) from(name string) RenameBuilder {
return builder.Set(b, "From", name).(RenameBuilder) return builder.Set(b, "From", name).(RenameBuilder)
} }
// To sets desired table name // to sets desired table name
func (b RenameBuilder) To(name string) RenameBuilder { func (b RenameBuilder) to(name string) RenameBuilder {
return builder.Set(b, "To", name).(RenameBuilder) return builder.Set(b, "To", name).(RenameBuilder)
} }

View File

@ -17,7 +17,7 @@ func init() {
} }
// Truncate sets which table to be dropped // Truncate sets which table to be dropped
func (b TruncateBuilder) Truncate(name string) TruncateBuilder { func (b TruncateBuilder) truncate(name string) TruncateBuilder {
return builder.Set(b, "TableName", name).(TruncateBuilder) return builder.Set(b, "TableName", name).(TruncateBuilder)
} }