查询 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 VM 中使用托管身份
有关托管身份的信息,请参阅 Microsoft 托管身份。
azure auth=MSI
SQL Server 到 Flux 数据类型转换
sql.from()
将 SQL Server 数据类型转换为 Flux 数据类型。
SQL Server 数据类型 | Flux 数据类型 |
---|---|
INT、TINYINT、SMALLINT、BIGINT | int |
DECIMAL、REAL、FLOAT、MONEY、SMALLMONEY | float |
DATETIMEOFFSET | time |
BIT | bool |
所有其他 SQL Server 数据类型(包括其他 日期/时间类型)都转换为字符串。
此页是否对您有帮助?
感谢您的反馈!