Skip to content

Commit

Permalink
Adding MSSQL DDL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Nov 19, 2024
1 parent aae7f1a commit d4050ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 2 additions & 8 deletions clients/mssql/dialect/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

mssql "github.com/microsoft/go-mssqldb"

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/sql"
"github.com/artie-labs/transfer/lib/typing"
)
Expand Down Expand Up @@ -35,20 +34,15 @@ WHERE
}

func (md MSSQLDialect) BuildAddColumnQuery(tableID sql.TableIdentifier, sqlPart string) string {
return md.buildAlterColumnQuery(tableID, constants.Add, sqlPart)
return fmt.Sprintf("ALTER TABLE %s ADD %s", tableID.FullyQualifiedName(), sqlPart)
}

func (md MSSQLDialect) BuildDropColumnQuery(tableID sql.TableIdentifier, colName string) string {
return md.buildAlterColumnQuery(tableID, constants.Delete, colName)
return fmt.Sprintf("ALTER TABLE %s DROP %s", tableID.FullyQualifiedName(), colName)
}

func (MSSQLDialect) BuildCreateTableQuery(tableID sql.TableIdentifier, _ bool, colSQLParts []string) string {
// Microsoft SQL Server uses the same syntax for temporary and permanent tables.
// Microsoft SQL Server doesn't support IF NOT EXISTS
return fmt.Sprintf("CREATE TABLE %s (%s);", tableID.FullyQualifiedName(), strings.Join(colSQLParts, ","))
}

func (MSSQLDialect) buildAlterColumnQuery(tableID sql.TableIdentifier, columnOp constants.ColumnOperation, colSQLPart string) string {
// Microsoft SQL Server doesn't support the COLUMN keyword
return fmt.Sprintf("ALTER TABLE %s %s %s", tableID.FullyQualifiedName(), columnOp, colSQLPart)
}
4 changes: 2 additions & 2 deletions clients/mssql/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMSSQLDialect_BuildAddColumnQuery(t *testing.T) {
fakeTableID.FullyQualifiedNameReturns("{TABLE}")

assert.Equal(t,
"ALTER TABLE {TABLE} add {SQL_PART}",
"ALTER TABLE {TABLE} ADD {SQL_PART}",
MSSQLDialect{}.BuildAddColumnQuery(fakeTableID, "{SQL_PART}"),
)
}
Expand All @@ -75,7 +75,7 @@ func TestMSSQLDialect_BuildDropColumnQuery(t *testing.T) {
fakeTableID.FullyQualifiedNameReturns("{TABLE}")

assert.Equal(t,
"ALTER TABLE {TABLE} drop {SQL_PART}",
"ALTER TABLE {TABLE} DROP {SQL_PART}",
MSSQLDialect{}.BuildDropColumnQuery(fakeTableID, "{SQL_PART}"),
)
}
Expand Down

0 comments on commit d4050ce

Please sign in to comment.