sling-connections

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Connection Management

连接管理

Connections are named endpoints for databases, file systems, and APIs. Sling stores them in
~/.sling/env.yaml
.
连接是数据库、文件系统和API的命名端点。Sling会将它们存储在
~/.sling/env.yaml
文件中。

Connection Types

连接类型

TypeExamplesKind
Databasepostgres, mysql, snowflake, bigquery
database
File Systems3, gcs, azure, sftp, local
file
APICustom REST APIs via specs
api
类型示例类别
Databasepostgres, mysql, snowflake, bigquery
database
File Systems3, gcs, azure, sftp, local
file
APICustom REST APIs via specs
api

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 SQL
bash
sling conns list                              # 列出所有连接
sling conns test MY_POSTGRES --debug          # 测试连接
sling conns discover MY_POSTGRES --pattern "public.*"  # 发现数据流
sling conns exec MY_POSTGRES -q "SELECT 1"    # 执行SQL

Configuration 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
undefined
yaml
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}
undefined
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}
undefined

Common Connection Properties

通用连接属性

Database Connections

数据库连接

PropertyDescription
type
Database type (postgres, mysql, etc.)
host
Hostname or IP
port
Port number
user
Username
password
Password
database
Database name
schema
Default schema
ssh_tunnel
SSH tunnel URL
属性描述
type
数据库类型(postgres、mysql等)
host
主机名或IP地址
port
端口号
user
用户名
password
密码
database
数据库名称
schema
默认模式
ssh_tunnel
SSH隧道URL

File System Connections

文件系统连接

PropertyDescription
type
File system type (s3, gcs, etc.)
bucket
Bucket/container name
access_key_id
Access key
secret_access_key
Secret key
region
Cloud region
属性描述
type
文件系统类型(s3、gcs等)
bucket
存储桶/容器名称
access_key_id
访问密钥ID
secret_access_key
秘密访问密钥
region
云区域

API Connections

API连接

PropertyDescription
type
Must be
api
spec
API spec name or path
secrets
Authentication credentials
inputs
Optional configuration
属性描述
type
必须为
api
spec
API规范名称或路径
secrets
认证凭证
inputs
可选配置

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" --columns
bash
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" --columns

Security Best Practices

安全最佳实践

  1. Use environment variables for sensitive credentials
  2. Never commit env.yaml with real credentials to git
  3. Use IAM roles when possible (AWS, GCP)
  4. Test connections before running replications
  5. Use SSH tunnels for database access through bastion hosts
  1. 使用环境变量存储敏感凭证
  2. 切勿提交包含真实凭证的env.yaml到Git
  3. 尽可能使用IAM角色(AWS、GCP)
  4. 在运行复制任务前测试连接
  5. 使用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
    sslmode=disable
    for testing (not production)
  • Verify certificate validity
  • 测试时添加
    sslmode=disable
    (生产环境不建议)
  • 验证证书有效性

Full Documentation

完整文档