Switch backend to wait for SQL Server and use direct INSERTs
Replace stored procedure calls with inline INSERT statements and SCOPE_IDENTITY() Add netcat for readiness check in new entrypoint.sh Introduce dedicated SQL Server and init-db services in docker-compose
This commit is contained in:
@@ -41,17 +41,9 @@ func main() {
|
||||
// -----------------------------------------------------------------
|
||||
var newCustID int
|
||||
insertCustSQL := `
|
||||
DECLARE @NewID int;
|
||||
EXEC dbo.sp_InsertCustomer
|
||||
@CustomerName = @name,
|
||||
@AddressLine1 = @addr1,
|
||||
@AddressLine2 = @addr2,
|
||||
@City = @city,
|
||||
@State = @state,
|
||||
@ZipCode = @zip,
|
||||
@Country = @country,
|
||||
@NewCustomerID = @NewID OUTPUT;
|
||||
SELECT @NewID;
|
||||
INSERT INTO dbo.Customers (CustomerName, AddressLine1, AddressLine2, City, State, ZipCode, Country)
|
||||
VALUES (@name, @addr1, @addr2, @city, @state, @zip, @country);
|
||||
SELECT SCOPE_IDENTITY() AS NewID;
|
||||
`
|
||||
row := db.QueryRow(insertCustSQL,
|
||||
sql.Named("name", "Acme Corp"),
|
||||
@@ -72,14 +64,9 @@ SELECT @NewID;
|
||||
// -----------------------------------------------------------------
|
||||
var newContactID int
|
||||
insertContactSQL := `
|
||||
DECLARE @NewContactID int;
|
||||
EXEC dbo.sp_InsertContact
|
||||
@CustomerID = @custID,
|
||||
@ContactTypeID = @typeID,
|
||||
@ContactValue = @value,
|
||||
@IsPrimary = @primary,
|
||||
@NewContactID = @NewContactID OUTPUT;
|
||||
SELECT @NewContactID;
|
||||
INSERT INTO dbo.Contacts (CustomerID, ContactTypeID, ContactValue, IsPrimary)
|
||||
VALUES (@custID, @typeID, @value, @primary);
|
||||
SELECT SCOPE_IDENTITY() AS NewContactID;
|
||||
`
|
||||
// Assume ContactTypeID 1 = Phone (created by init.sql)
|
||||
row = db.QueryRow(insertContactSQL,
|
||||
|
||||
Reference in New Issue
Block a user