Skip to content

Commit f4e9a08

Browse files
committed
docs(mssql): add docs for WithScripts and GetSQLCmdPath
1 parent 7714a24 commit f4e9a08

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/modules/mssql.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
4848

4949
When starting the MS SQL Server container, you can pass options in a variadic way to configure it.
5050

51+
#### Init Scripts
52+
53+
If you need to execute SQL scripts when the container starts, you can use `mssql.WithScripts(scripts
54+
...string)` with one or more `*.sql` scripts. The scripts will be executed in order after the
55+
container is ready.
56+
57+
<!--codeinclude-->
58+
[Example of SQL script](../../modules/mssql/testdata/seed.sql)
59+
<!--/codeinclude-->
60+
61+
This will:
62+
1. Copy each script into the container.
63+
2. Execute them using `sqlcmd` after the container is ready.
64+
65+
#### SQL Command Path
66+
67+
The `mssql.GetSQLCmdPath` helper function returns the appropriate path to the `sqlcmd` executable based on the MS SQL Server image being used. This is used internally by the `WithScripts` option but can also be used directly if needed.
68+
69+
```golang
70+
path := mssql.GetSQLCmdPath("mcr.microsoft.com/mssql/server:2022-latest")
71+
```
72+
5173
#### Image
5274

5375
If you need to set a different MS SQL Server Docker image, you can set a valid Docker image as the second argument in the `Run` function.

0 commit comments

Comments
 (0)