sling-connections
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConnection Management
连接管理
Connections are named endpoints for databases, file systems, and APIs. Sling stores them in .
~/.sling/env.yaml连接是数据库、文件系统和API的命名端点。Sling会将它们存储在文件中。
~/.sling/env.yamlConnection Types
连接类型
| Type | Examples | Kind |
|---|---|---|
| Database | postgres, mysql, snowflake, bigquery | |
| File System | s3, gcs, azure, sftp, local | |
| API | Custom REST APIs via specs | |
| 类型 | 示例 | 类别 |
|---|---|---|
| Database | postgres, mysql, snowflake, bigquery | |
| File System | s3, gcs, azure, sftp, local | |
| API | Custom REST APIs via specs | |
MCP Operations
MCP 操作
List Connections
列出连接
json
{"action": "list", "input": {}}json
{"action": "list", "input": {}}Test Connection
测试连接
json
{
"action": "test",
"input": {
"connection": "MY_POSTGRES",
"debug": true
}
}json
{
"action": "test",
"input": {
"connection": "MY_POSTGRES",
"debug": true
}
}Discover Streams
发现数据流
json
{
"action": "discover",
"input": {
"connection": "MY_POSTGRES",
"pattern": "public.*",
"columns": true
}
}json
{
"action": "discover",
"input": {
"connection": "MY_POSTGRES",
"pattern": "public.*",
"columns": true
}
}Create Connection
创建连接
json
{
"action": "set",
"input": {
"name": "MY_POSTGRES",
"properties": {
"type": "postgres",
"host": "localhost",
"user": "myuser",
"database": "mydb"
}
}
}json
{
"action": "set",
"input": {
"name": "MY_POSTGRES",
"properties": {
"type": "postgres",
"host": "localhost",
"user": "myuser",
"database": "mydb"
}
}
}CLI Operations
CLI 操作
bash
sling conns list # List all
sling conns test MY_POSTGRES --debug # Test
sling conns discover MY_POSTGRES --pattern "public.*" # Discover
sling conns exec MY_POSTGRES -q "SELECT 1" # Execute SQLbash
sling conns list # 列出所有连接
sling conns test MY_POSTGRES --debug # 测试连接
sling conns discover MY_POSTGRES --pattern "public.*" # 发现数据流
sling conns exec MY_POSTGRES -q "SELECT 1" # 执行SQLConfiguration Methods
配置方式
1. Environment Variable
1. 环境变量
bash
export MY_POSTGRES='host=localhost user=postgres dbname=mydb'bash
export MY_POSTGRES='host=localhost user=postgres dbname=mydb'2. URL Format
2. URL格式
bash
export MY_POSTGRES='postgresql://user:pass@host:5432/dbname'bash
export MY_POSTGRES='postgresql://user:pass@host:5432/dbname'3. YAML in env.yaml
3. env.yaml中的YAML配置
yaml
undefinedyaml
undefined~/.sling/env.yaml
~/.sling/env.yaml
connections:
MY_POSTGRES:
type: postgres
host: localhost
user: postgres
password: ${PG_PASSWORD}
database: mydb
MY_S3:
type: s3
bucket: my-bucket
access_key_id: ${AWS_ACCESS_KEY}
secret_access_key: ${AWS_SECRET_KEY}
MY_API:
type: api
spec: stripe
secrets:
api_key: ${STRIPE_API_KEY}
undefinedconnections:
MY_POSTGRES:
type: postgres
host: localhost
user: postgres
password: ${PG_PASSWORD}
database: mydb
MY_S3:
type: s3
bucket: my-bucket
access_key_id: ${AWS_ACCESS_KEY}
secret_access_key: ${AWS_SECRET_KEY}
MY_API:
type: api
spec: stripe
secrets:
api_key: ${STRIPE_API_KEY}
undefinedCommon Connection Properties
通用连接属性
Database Connections
数据库连接
| Property | Description |
|---|---|
| Database type (postgres, mysql, etc.) |
| Hostname or IP |
| Port number |
| Username |
| Password |
| Database name |
| Default schema |
| SSH tunnel URL |
| 属性 | 描述 |
|---|---|
| 数据库类型(postgres、mysql等) |
| 主机名或IP地址 |
| 端口号 |
| 用户名 |
| 密码 |
| 数据库名称 |
| 默认模式 |
| SSH隧道URL |
File System Connections
文件系统连接
| Property | Description |
|---|---|
| File system type (s3, gcs, etc.) |
| Bucket/container name |
| Access key |
| Secret key |
| Cloud region |
| 属性 | 描述 |
|---|---|
| 文件系统类型(s3、gcs等) |
| 存储桶/容器名称 |
| 访问密钥ID |
| 秘密访问密钥 |
| 云区域 |
API Connections
API连接
| Property | Description |
|---|---|
| Must be |
| API spec name or path |
| Authentication credentials |
| Optional configuration |
| 属性 | 描述 |
|---|---|
| 必须为 |
| API规范名称或路径 |
| 认证凭证 |
| 可选配置 |
Discovery Patterns
发现模式
bash
sling conns discover MY_PG --pattern "public.*" # All in schema
sling conns discover MY_PG --pattern "sales.customer_*" # With prefix
sling conns discover MY_S3 --pattern "data/*.csv" # Files
sling conns discover MY_S3 --pattern "**/*.parquet" --recursive
sling conns discover MY_PG --pattern "public.users" --columnsbash
sling conns discover MY_PG --pattern "public.*" # 模式下的所有对象
sling conns discover MY_PG --pattern "sales.customer_*" # 带前缀的对象
sling conns discover MY_S3 --pattern "data/*.csv" # 指定文件
sling conns discover MY_S3 --pattern "**/*.parquet" --recursive
sling conns discover MY_PG --pattern "public.users" --columnsSecurity Best Practices
安全最佳实践
- Use environment variables for sensitive credentials
- Never commit env.yaml with real credentials to git
- Use IAM roles when possible (AWS, GCP)
- Test connections before running replications
- Use SSH tunnels for database access through bastion hosts
- 使用环境变量存储敏感凭证
- 切勿提交包含真实凭证的env.yaml到Git
- 尽可能使用IAM角色(AWS、GCP)
- 在运行复制任务前测试连接
- 使用SSH隧道通过堡垒机访问数据库
Troubleshooting
故障排除
Connection refused
连接被拒绝
- Check host/port accessibility:
telnet host port - Verify firewall rules
- Confirm database is running
- 检查主机/端口的可访问性:
telnet host port - 验证防火墙规则
- 确认数据库正在运行
Authentication failed
认证失败
- Verify username/password
- Check user permissions
- Review database logs
- 验证用户名/密码
- 检查用户权限
- 查看数据库日志
SSL/TLS errors
SSL/TLS错误
- Add for testing (not production)
sslmode=disable - Verify certificate validity
- 测试时添加(生产环境不建议)
sslmode=disable - 验证证书有效性
Full Documentation
完整文档
See https://docs.slingdata.io/connections.md for complete reference.