refactor: unexported function & documentation

This commit is contained in:
Reinaldy Rafli 2021-07-31 11:27:31 +07:00
parent 49cf645a9e
commit 0f060565d6
2 changed files with 9 additions and 3 deletions

2
bob.go
View File

@ -69,7 +69,7 @@ func (b BobBuilderType) Truncate(table string) TruncateBuilder {
} }
func (b BobBuilderType) Upsert(table string, dialect int) UpsertBuilder { func (b BobBuilderType) Upsert(table string, dialect int) UpsertBuilder {
return UpsertBuilder(b).dialect(dialect).Into(table) return UpsertBuilder(b).dialect(dialect).into(table)
} }
// BobStmtBuilder is the parent builder for BobBuilderType // BobStmtBuilder is the parent builder for BobBuilderType

View File

@ -24,15 +24,17 @@ func init() {
builder.Register(UpsertBuilder{}, upsertData{}) builder.Register(UpsertBuilder{}, upsertData{})
} }
// dialect specifies database dialect used.
func (u UpsertBuilder) dialect(db int) UpsertBuilder { func (u UpsertBuilder) dialect(db int) UpsertBuilder {
return builder.Set(u, "Dialect", db).(UpsertBuilder) return builder.Set(u, "Dialect", db).(UpsertBuilder)
} }
// Table sets which table to be dropped // Table sets which table to be dropped.
func (u UpsertBuilder) Into(name string) UpsertBuilder { func (u UpsertBuilder) into(name string) UpsertBuilder {
return builder.Set(u, "Into", name).(UpsertBuilder) return builder.Set(u, "Into", name).(UpsertBuilder)
} }
// Columns sets the columns for the data to be inserted.
func (u UpsertBuilder) Columns(columns ...string) UpsertBuilder { func (u UpsertBuilder) Columns(columns ...string) UpsertBuilder {
return builder.Extend(u, "Columns", columns).(UpsertBuilder) return builder.Extend(u, "Columns", columns).(UpsertBuilder)
} }
@ -44,6 +46,8 @@ func (u UpsertBuilder) Values(values ...interface{}) UpsertBuilder {
return builder.Append(u, "Values", values).(UpsertBuilder) return builder.Append(u, "Values", values).(UpsertBuilder)
} }
// Key specifies which key to be checked on conflict.
// Must be used on PostgreSQL and SQLite.
func (u UpsertBuilder) Key(key ...interface{}) UpsertBuilder { func (u UpsertBuilder) Key(key ...interface{}) UpsertBuilder {
var value interface{} var value interface{}
column := key[0] column := key[0]
@ -55,6 +59,8 @@ func (u UpsertBuilder) Key(key ...interface{}) UpsertBuilder {
return builder.Extend(u, "Key", []interface{}{column, value}).(UpsertBuilder) return builder.Extend(u, "Key", []interface{}{column, value}).(UpsertBuilder)
} }
// Replace sets the column and value respectively for the data to be changed on
// a specific row.
func (u UpsertBuilder) Replace(column interface{}, value interface{}) UpsertBuilder { func (u UpsertBuilder) Replace(column interface{}, value interface{}) UpsertBuilder {
return builder.Append(u, "Replace", []interface{}{column, value}).(UpsertBuilder) return builder.Append(u, "Replace", []interface{}{column, value}).(UpsertBuilder)
} }