Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable RenameTable, RenameColumn and DropColumn in the sqlite builder #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions builder_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,10 @@ func (b *SqliteBuilder) TruncateTable(table string) *Query {
return b.NewQuery(sql)
}

// DropColumn creates a Query that can be used to drop a column from a table.
func (b *SqliteBuilder) DropColumn(table, col string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support dropping columns")
return q
}

// RenameColumn creates a Query that can be used to rename a column in a table.
func (b *SqliteBuilder) RenameColumn(table, oldName, newName string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support renaming columns")
return q
// RenameTable creates a Query that can be used to rename a table.
func (b *SqliteBuilder) RenameTable(oldName, newName string) *Query {
sql := fmt.Sprintf("ALTER TABLE %v RENAME TO %v", b.db.QuoteTableName(oldName), b.db.QuoteTableName(newName))
return b.NewQuery(sql)
}

// AlterColumn creates a Query that can be used to change the definition of a table column.
Expand Down
12 changes: 3 additions & 9 deletions builder_sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ func TestSqliteBuilder_TruncateTable(t *testing.T) {
assert.Equal(t, q.SQL(), "DELETE FROM `users`", "t1")
}

func TestSqliteBuilder_DropColumn(t *testing.T) {
func TestSqliteBuilder_RenameTable(t *testing.T) {
b := getSqliteBuilder()
q := b.DropColumn("users", "age")
assert.NotEqual(t, q.LastError, nil, "t1")
}

func TestSqliteBuilder_RenameColumn(t *testing.T) {
b := getSqliteBuilder()
q := b.RenameColumn("users", "name", "username")
assert.NotEqual(t, q.LastError, nil, "t1")
q := b.RenameTable("usersOld", "usersNew")
assert.Equal(t, q.SQL(), "ALTER TABLE `usersOld` RENAME TO `usersNew`", "t1")
}

func TestSqliteBuilder_AlterColumn(t *testing.T) {
Expand Down