SQLServer Writer¶
SQLServer Writer 插件实现了写入数据到 SQL Server 库表的功能。
配置样例¶
这里使用一份从内存产生到 SQL Server 导入的数据。
{
"job": {
"setting": {
"speed": {
"channel": 1,
"bytes": -1
}
},
"content": {
"reader": {},
"writer": {
"name": "sqlserverwriter",
"parameter": {
"username": "root",
"password": "root",
"column": [
"db_id",
"db_type",
"db_ip",
"db_port",
"db_role",
"db_name",
"db_username",
"db_password",
"db_modify_time",
"db_modify_user",
"db_description",
"db_tddl_info"
],
"connection": {
"table": [
"db_info_for_writer"
],
"jdbcUrl": "jdbc:sqlserver://[HOST_NAME]:PORT;DatabaseName=[DATABASE_NAME]"
},
"preSql": [
"delete from @table where db_id = -1;"
],
"postSql": [
"update @table set db_modify_time = now() where db_id = 1;"
]
}
}
}
}
}
参数说明¶
该插件基于 RDBMS Writer 实现,因此可以参考 RDBMS Writer 的所有配置项。
writeMode¶
默认情况下, 采取 insert into
语法写入 SQL Server 表,如果你希望采取主键存在时更新,不存在则写入的方式,也就是 SQL Server 的 MERGE INTO
语法, 可以使用 update
模式。 假定表的主键为 id
,则 writeMode
配置方法如下:
{
"writeMode": "update(id)"
}
如果是联合唯一索引,则配置方法如下:
{
"writeMode": "update(col1, col2)"
}