Skip to main content

The mssql connector supports read and writing to/from a Microsoft SQL Server.

Tabset

Read​

Recipe​

read:
- mssql:
host: sql.domain
user: user
password: password
command: |
SELECT *
FROM table

# Optional
port: 1433
database: database
columns:
- column1
- column2

Function​

from wrangles.connectors import mssql
df = mssql.read(
host = 'sql.domain',
user = 'user',
password = 'password',
command = 'SELECT * FROM table'
)

Parameters​

ParameterRequiredData TypeNotes
host✓strHostname or IP address of the server.
user✓strThe user to connect to the database with.
password✓strPassword for the specified user.
command✓strTable name or SQL command to select data.
portintThe Port to connect to. Defaults to 1433.
databasestrThe database to connect to.
columnslistA list with a subset of the columns to import. This is less efficient than specifying in the command.
order_bystrUses SQL syntax to sort the input.
ifstrA condition that will determine whether the action runs or not as a whole.

Write​

Recipe​

write:
- mssql:
host: sql.domain
database: database
table: table
user: user
password: password

# Optional
port: 1433
columns:
- column1
- column2

Function​

from wrangles.connectors import mssql
mssql.write(
df,
host = 'sql.domain',
database = 'database',
table = 'table',
user = 'user',
password = 'password'
)

Parameters​

ParameterRequiredData TypeNotes
df✓DataFrameFunction only. DataFrame of contents to write to the database. Columns must match the target schema. By default, if the target table doesn't exist, it will be created.
host✓strHostname or IP address of the server.
database✓strDatabase to be exported to.
table✓strTable to be exported to.
user✓strUser with access to the database.
password✓strPassword for the specified user.
portintThe Port to connect to. Defaults to 1433.
columnslistSubset of the columns to be written. If not provided, all columns will be output.
order_bystrUses SQL syntax to sort the output.
ifstrA condition that will determine whether the action runs or not as a whole.

Run​

Added v0.5

Run a SQL command. For example, this can be used to trigger a stored procedure or move/transform data before or after the recipe is executed.

Recipe​

run:
on_start:
- mssql:
host: sql.domain
user: user
password: password
command: EXEC [StoredProc]

# Optional
database: database
port: 1433

Function​

from wrangles.connectors import mssql
mssql.run(
host = 'sql.domain',
user = 'user',
password = 'password',
command = 'EXEC [StoredProc]',
database = 'database'
)

Parameters​

ParameterRequiredData TypeNotes
host✓strHostname or IP address of the server.
user✓strUser with access to the database.
password✓strPassword for the specified user.
command✓strCommand to execute such as a SQL query or stored procedure.
portintThe Port to connect to. Defaults to 1433.
databasestrDatabase to execute the command against.
ifstrA condition that will determine whether the action runs or not as a whole.