bob/bob.go

54 lines
1.6 KiB
Go
Raw Normal View History

2021-06-24 07:43:28 +00:00
package bob
import "github.com/lann/builder"
// BobBuilderType is the type for BobBuilder
2021-06-24 07:43:28 +00:00
type BobBuilderType builder.Builder
// BobBuilder interface wraps the ToSQL method
2021-06-24 07:43:28 +00:00
type BobBuilder interface {
ToSQL() (string, []interface{}, error)
2021-06-24 07:43:28 +00:00
}
// CreateTable creates a table with CreateBuilder interface
2021-06-24 07:43:28 +00:00
func (b BobBuilderType) CreateTable(table string) CreateBuilder {
return CreateBuilder(b).Name(table)
}
2021-07-09 06:39:30 +00:00
func (b BobBuilderType) CreateTableIfNotExists(table string) CreateBuilder {
return CreateBuilder(b).Name(table).IfNotExists()
}
// HasTable checks if a table exists with HasBuilder interface
2021-06-25 17:04:41 +00:00
func (b BobBuilderType) HasTable(table string) HasBuilder {
return HasBuilder(b).HasTable(table)
}
// HasColumn checks if a column exists with HasBuilder interface
2021-06-25 17:04:41 +00:00
func (b BobBuilderType) HasColumn(column string) HasBuilder {
return HasBuilder(b).HasColumn(column)
}
// BobStmtBuilder is the parent builder for BobBuilderType
2021-06-24 07:43:28 +00:00
var BobStmtBuilder = BobBuilderType(builder.EmptyBuilder)
// CreateTable creates a table with CreateBuilder interface
2021-06-24 07:43:28 +00:00
func CreateTable(table string) CreateBuilder {
return BobStmtBuilder.CreateTable(table)
}
2021-06-25 17:04:41 +00:00
2021-07-09 06:39:30 +00:00
// CreateTableIfNotExists creates a table with CreateBuilder interface, if the table doesn't exists
func CreateTableIfNotExists(table string) CreateBuilder {
return BobStmtBuilder.CreateTableIfNotExists(table)
}
// HasTable checks if a table exists with HasBuilder interface
2021-06-25 17:04:41 +00:00
func HasTable(table string) HasBuilder {
return BobStmtBuilder.HasTable(table)
}
// HasColumn checks if a column exists with HasBuilder interface
2021-06-25 17:04:41 +00:00
func HasColumn(col string) HasBuilder {
return BobStmtBuilder.HasColumn(col)
}