查询 SQL Server
使用Flux查询 Microsoft SQL Server:
导入
sql包。使用
sql.from()并提供以下参数:- driverName: sqlserver
- dataSourceName: 查看数据源名称
- query: 要执行的SQL查询
import "sql"
sql.from(
driverName: "sqlserver",
dataSourceName: "sqlserver://user:password@localhost:1433?database=examplebdb",
query: "GO SELECT * FROM Example.Table",
)
SQL Server 数据源名称
根据连接字符串,sqlserver 驱动程序使用以下 DSN 语法:
sqlserver://username:password@localhost:1433?database=examplebdb
server=localhost;user id=username;database=examplebdb;
server=localhost;user id=username;database=examplebdb;azure auth=ENV
server=localhost;user id=username;database=examplebdbr;azure tenant id=77e7d537;azure client id=58879ce8;azure client secret=0143356789
SQL Server ADO 认证
使用以下方法之一来提供 SQL Server 认证凭据作为 ActiveX 数据对象 (ADO) DSN 参数:
从环境变量中检索认证凭据
azure auth=ENV
从文件中获取身份验证凭据
InfluxDB Cloud 和 InfluxDB OSS 不 可以访问 底层文件系统,并且不支持从文件中读取凭据。 要从文件中检索 SQL Server 凭据,请在你的本地计算机上执行查询 Flux REPL。
azure auth=C:\secure\azure.auth
在DSN中指定身份验证凭据
# Example of providing tenant ID, client ID, and client secret token
azure tenant id=77...;azure client id=58...;azure client secret=0cf123..
# Example of providing tenant ID, client ID, certificate path and certificate password
azure tenant id=77...;azure client id=58...;azure certificate path=C:\secure\...;azure certificate password=xY...
# Example of providing tenant ID, client ID, and Azure username and password
azure tenant id=77...;azure client id=58...;azure username=some@myorg;azure password=a1...
在Azure虚拟机中使用托管标识
有关托管身份的信息,请参阅 Microsoft managed identities。
azure auth=MSI
SQL Server 到 Flux 数据类型转换
sql.from() 将 SQL Server 数据类型转换为 Flux 数据类型。
| SQL Server 数据类型 | Flux 数据类型 |
|---|---|
| 整数, 微整数, 小整数, 大整数 | int |
| 十进制,实数,浮点数,货币,小货币 | float |
| 日期时间偏移 | time |
| 位 | bool |
所有其他 SQL Server 数据类型(包括其他 日期/时间类型)都被转换为字符串。