sap-hana-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SAP HANA Developer CLI (hana-cli)

SAP HANA Developer CLI (hana-cli)

Related Skills

相关技能

  • sap-cap-capire: Use for CAP database development, HDI container management, and CDS syntax comparison
  • sap-btp-cloud-platform: Use for HANA Cloud operations, BTP integration, and cloud instance management
  • sap-abap-cds: Use for comparing CDS syntax between CAP and ABAP or understanding HANA CDS features
  • sap-datasphere: Use when working with SAP Datasphere integration or data warehousing scenarios
A developer-centric command-line interface for SAP HANA database development, particularly useful in non-SAP tooling environments like VS Code.
Repository: https://github.com/SAP-samples/hana-developer-cli-tool-example npm Package: https://www.npmjs.com/package/hana-cli Current Version: 3.202405.1 (April 2024) Node.js Requirement: ≥20.19.0

  • sap-cap-capire: 用于CAP数据库开发、HDI容器管理以及CDS语法对比
  • sap-btp-cloud-platform: 用于HANA Cloud操作、BTP集成以及云实例管理
  • sap-abap-cds: 用于对比CAP与ABAP的CDS语法,或理解HANA CDS特性
  • sap-datasphere: 用于SAP Datasphere集成或数据仓库场景
一款面向开发者的命令行界面,专为SAP HANA数据库开发设计,在VS Code等非SAP工具环境中尤为实用。
代码仓库: https://github.com/SAP-samples/hana-developer-cli-tool-example npm包: https://www.npmjs.com/package/hana-cli 当前版本: 3.202405.1(2024年4月) Node.js要求: ≥20.19.0

Table of Contents

目录

Quick Start

快速开始

Installation

安装

bash
undefined
bash
undefined

Install globally via npm (recommended)

通过npm全局安装(推荐)

npm install -g hana-cli
npm install -g hana-cli

Verify installation

验证安装

hana-cli version
undefined
hana-cli version
undefined

First Connection

首次连接

bash
undefined
bash
undefined

Interactive connection setup

交互式连接设置

hana-cli connect
hana-cli connect

Or specify connection directly

或直接指定连接信息

hana-cli connect -n "hostname:port" -u DBUSER -p PASSWORD --save
hana-cli connect -n "hostname:port" -u DBUSER -p PASSWORD --save

Using service key (HANA Cloud)

使用服务密钥(HANA Cloud)

hana-cli connectViaServiceKey

---
hana-cli connectViaServiceKey

---

MCP Integration (AI-Driven Database Operations)

MCP集成(AI驱动的数据库操作)

Overview

概述

The hana-mcp-server integration enables natural language database operations through Claude's Model Context Protocol. Use conversational queries alongside traditional CLI commands for a complete development workflow.
hana-mcp-server集成通过Claude的模型上下文协议(Model Context Protocol)支持自然语言数据库操作。可在传统CLI命令之外使用对话式查询,实现完整的开发工作流。

Setup

设置

1. Environment Variables

1. 环境变量

Required configuration (add to ~/.zshrc, ~/.bashrc, or project .env):
bash
export HANA_HOST="your-hana-host.hanacloud.ondemand.com"
export HANA_PORT="443"
export HANA_USER="DBADMIN"
export HANA_PASSWORD="your-password"
export HANA_ENCRYPT="true"  # Optional, defaults to true
export HANA_DATABASE=""     # Optional, for MDC tenant
export HANA_CONNECTION_TYPE="single-container"  # Optional
需配置以下环境变量(添加至~/.zshrc、~/.bashrc或项目的.env文件):
bash
export HANA_HOST="your-hana-host.hanacloud.ondemand.com"
export HANA_PORT="443"
export HANA_USER="DBADMIN"
export HANA_PASSWORD="your-password"
export HANA_ENCRYPT="true"  # 可选,默认值为true
export HANA_DATABASE=""     # 可选,适用于MDC租户
export HANA_CONNECTION_TYPE="single-container"  # 可选

2. Connection Types

2. 连接类型

  • single-container (default): Standard HANA databases
  • mdc-system: Multi-tenant system database
  • mdc-tenant: Specific tenant in multi-tenant environment
  • single-container(默认):标准HANA数据库
  • mdc-system:多租户系统数据库
  • mdc-tenant:多租户环境中的特定租户

When to Use: CLI vs MCP

使用场景:CLI vs MCP

ScenarioRecommended ToolWhy
Exploratory queries, ad-hoc analysisMCPNatural language, no syntax needed
Automation scripts, CI/CD pipelinesCLIScriptable, consistent output
Learning database structureMCPConversational discovery
Generating CDS/EDMX/OpenAPI outputCLISupports 17+ formats
Complex multi-step workflowsCLIFine-grained control
Quick data sampling and inspectionMCPFaster for one-off queries
场景推荐工具原因
探索式查询、临时分析MCP支持自然语言,无需语法知识
自动化脚本、CI/CD流水线CLI可编写脚本,输出一致
学习数据库结构MCP对话式探索
生成CDS/EDMX/OpenAPI输出CLI支持17种以上格式
复杂多步骤工作流CLI精细控制
快速数据采样与检查MCP一次性查询更高效

Example Natural Language Queries

自然语言查询示例

Schema & Table Discovery

架构与表发现

  • "Show me all schemas in this HANA database"
  • "List all tables in the SYSTEM schema"
  • "What tables exist in the MY_APP schema?"
  • "Show me all views in the PUBLIC schema"
  • "显示此HANA数据库中的所有架构"
  • "列出SYSTEM架构中的所有表"
  • "MY_APP架构中有哪些表?"
  • "显示PUBLIC架构中的所有视图"

Table Structure & Metadata

表结构与元数据

  • "Describe the structure of the USERS table"
  • "What columns does the ORDERS table have?"
  • "Show me the data types for MY_TABLE"
  • "What is the primary key of the CUSTOMERS table?"
  • "描述USERS表的结构"
  • "ORDERS表有哪些列?"
  • "显示MY_TABLE的数据类型"
  • "CUSTOMERS表的主键是什么?"

Data Sampling & Inspection

数据采样与检查

  • "Sample 5 rows from the PRODUCTS table"
  • "Show me the first 10 records from SALES_DATA"
  • "Get sample data from ORDER_ITEMS table"
  • "Display a few rows from MY_TABLE"
  • "从PRODUCTS表中采样5行数据"
  • "显示SALES_DATA的前10条记录"
  • "获取ORDER_ITEMS表的样本数据"
  • "显示MY_TABLE的若干行数据"

Query Execution

查询执行

  • "How many rows are in the CUSTOMERS table?"
  • "Show me distinct values in the STATUS column of ORDERS"
  • "What is the maximum value in the PRICE column of PRODUCTS?"
  • "Find all records in USERS where country is 'USA'"
  • "CUSTOMERS表中有多少行数据?"
  • "显示ORDERS表STATUS列的不同值"
  • "PRODUCTS表PRICE列的最大值是多少?"
  • "查找USERS表中国家为'USA'的所有记录"

System Performance & Monitoring

系统性能与监控

  • "Check the HANA database status"
  • "Show me system performance metrics"
  • "What is the current database version?"
  • "检查HANA数据库状态"
  • "显示系统性能指标"
  • "当前数据库版本是什么?"

MCP Tools Available

可用的MCP工具

The hana-mcp-server provides these MCP tools:
  • list_schemas
    : Enumerate all schemas
  • list_tables
    : Show tables in a schema
  • describe_table
    : Get table structure and metadata
  • query
    : Execute SQL queries from natural language
  • sample_data
    : Retrieve sample rows
  • system_info
    : Database status and performance
hana-mcp-server提供以下MCP工具:
  • list_schemas
    :枚举所有架构
  • list_tables
    :显示架构中的表
  • describe_table
    :获取表结构与元数据
  • query
    :将自然语言转换为SQL并执行
  • sample_data
    :获取样本行数据
  • system_info
    :数据库状态与性能信息

Example: MCP + CLI Workflow

示例:MCP + CLI工作流

bash
undefined
bash
undefined

1. Use MCP to explore (natural language)

1. 使用MCP探索(自然语言)

"Show me all tables in the PRODUCTS schema"
"显示PRODUCTS架构中的所有表"

2. Use MCP to understand structure

2. 使用MCP了解结构

"Describe the PRODUCTS.INVENTORY table"
"描述PRODUCTS.INVENTORY表"

3. Use CLI for format conversion (precise output)

3. 使用CLI进行格式转换(精确输出)

hana-cli inspectTable -t INVENTORY -s PRODUCTS -o cds
hana-cli inspectTable -t INVENTORY -s PRODUCTS -o cds

4. Use CLI for HDI operations

4. 使用CLI执行HDI操作

hana-cli createContainer -c MY_CONTAINER

---
hana-cli createContainer -c MY_CONTAINER

---

Core Command Categories

核心命令分类

Database Object Inspection

数据库对象检查

CommandAliasesPurpose
inspectTable
it
,
table
Inspect table structure
inspectView
-Inspect view definition
inspectProcedure
-Inspect stored procedure
inspectFunction
-Inspect function definition
tables
-List all tables in schema
views
-List all views in schema
procedures
-List stored procedures
functions
-List functions
命令别名用途
inspectTable
it
,
table
检查表结构
inspectView
-检查视图定义
inspectProcedure
-检查存储过程
inspectFunction
-检查函数定义
tables
-列出架构中的所有表
views
-列出架构中的所有视图
procedures
-列出存储过程
functions
-列出函数

Query Execution

查询执行

CommandAliasesPurpose
querySimple
qs
Execute SQL query
callProcedure
cp
Execute stored procedure
hdbsql
-Direct SQL execution
命令别名用途
querySimple
qs
执行SQL查询
callProcedure
cp
执行存储过程
hdbsql
-直接执行SQL

HDI Container Management

HDI容器管理

CommandAliasesPurpose
containers
cont
List HDI containers
createContainer
-Create new container
dropContainer
-Remove container
activateHDI
-Enable HDI service
adminHDI
-Administer HDI privileges
命令别名用途
containers
cont
列出HDI容器
createContainer
-创建新容器
dropContainer
-删除容器
activateHDI
-启用HDI服务
adminHDI
-管理HDI权限

Cloud & BTP Operations

云与BTP操作

CommandAliasesPurpose
hanaCloudInstances
-List HANA Cloud instances
hanaCloudStart
-Start cloud instance
hanaCloudStop
-Stop cloud instance
btp
-Configure BTP CLI
btpInfo
-Display BTP target info

命令别名用途
hanaCloudInstances
-列出HANA Cloud实例
hanaCloudStart
-启动云实例
hanaCloudStop
-停止云实例
btp
-配置BTP CLI
btpInfo
-显示BTP目标信息

Output Formats

输出格式

The
--output
/
-o
option supports 17+ formats:
FormatUse Case
tbl
Human-readable table (default)
json
JSON data
yaml
YAML format
csv
CSV export
excel
Excel file
cds
CAP CDS definitions
hdbcds
HANA CDS format
hdbtable
HDB Table definitions
sql
SQL DDL statements
edmx
OData EDMX metadata
openapi
OpenAPI/Swagger spec
graphql
GraphQL schema

--output
/
-o
选项支持17种以上格式:
格式使用场景
tbl
人类可读表格(默认)
json
JSON数据
yaml
YAML格式
csv
CSV导出
excel
Excel文件
cds
CAP CDS定义
hdbcds
HANA CDS格式
hdbtable
HDB表定义
sql
SQL DDL语句
edmx
OData EDMX元数据
openapi
OpenAPI/Swagger规范
graphql
GraphQL架构

Connection Configuration

连接配置

Connection credentials are searched in priority order:
  1. default-env-admin.json
    (with
    --admin
    flag)
  2. .cdsrc-private.json
    (via
    cds bind
    )
  3. .env
    file with VCAP_SERVICES
  4. File specified via
    --conn
    parameter
  5. default-env.json
    in current/parent directories
  6. ~/.hana-cli/default.json
For connection templates, see
templates/default-env.json
.

连接凭据按以下优先级顺序查找:
  1. default-env-admin.json
    (配合
    --admin
    参数使用)
  2. .cdsrc-private.json
    (通过
    cds bind
    获取)
  3. 包含VCAP_SERVICES的
    .env
    文件
  4. 通过
    --conn
    参数指定的文件
  5. 当前/父目录中的
    default-env.json
  6. ~/.hana-cli/default.json
连接模板可查看
templates/default-env.json

Common Workflows

常见工作流

Inspect and Convert Table to CDS

检查表结构并转换为CDS格式

bash
undefined
bash
undefined

Inspect table structure

检查表结构

hana-cli inspectTable -s MYSCHEMA -t MYTABLE
hana-cli inspectTable -s MYSCHEMA -t MYTABLE

Convert to CDS format

转换为CDS格式

hana-cli inspectTable -s MYSCHEMA -t MYTABLE -o cds
undefined
hana-cli inspectTable -s MYSCHEMA -t MYTABLE -o cds
undefined

Mass Convert Schema Objects

批量转换架构对象

bash
undefined
bash
undefined

Convert all objects in schema to CDS

将架构中的所有对象转换为CDS格式

hana-cli massConvert -s MYSCHEMA
undefined
hana-cli massConvert -s MYSCHEMA
undefined

Execute Query with Export

执行查询并导出结果

bash
undefined
bash
undefined

Run query and export to JSON

执行查询并导出为JSON

hana-cli querySimple -q "SELECT * FROM MYTABLE" -o json
hana-cli querySimple -q "SELECT * FROM MYTABLE" -o json

Export to Excel file

导出为Excel文件

hana-cli querySimple -q "SELECT * FROM MYTABLE" -o excel -f ./output -n report
undefined
hana-cli querySimple -q "SELECT * FROM MYTABLE" -o excel -f ./output -n report
undefined

Manage HDI Containers

管理HDI容器

bash
undefined
bash
undefined

List all containers

列出所有容器

hana-cli containers
hana-cli containers

Create new container

创建新容器

hana-cli createContainer -c MY_CONTAINER -g MY_GROUP
hana-cli createContainer -c MY_CONTAINER -g MY_GROUP

Create container users

创建容器用户

hana-cli createContainerUsers -c MY_CONTAINER

---
hana-cli createContainerUsers -c MY_CONTAINER

---

UI Commands

UI命令

Many commands have browser-based UI alternatives (suffix
UI
):
  • tablesUI
    - Browse tables visually
  • containersUI
    - Manage containers in browser
  • massConvertUI
    - Visual mass conversion
  • querySimpleUI
    - Query builder interface
  • systemInfoUI
    - System dashboard

许多命令提供基于浏览器的UI替代方案(后缀为
UI
):
  • tablesUI
    - 可视化浏览表
  • containersUI
    - 在浏览器中管理容器
  • massConvertUI
    - 可视化批量转换
  • querySimpleUI
    - 查询构建器界面
  • systemInfoUI
    - 系统仪表板

Key Features

核心特性

  • Multi-database support: HANA, PostgreSQL, SQLite backends
  • Format conversion: 17+ output formats including CDS, EDMX, OpenAPI
  • HDI management: Full container lifecycle management
  • Cloud integration: SAP BTP CLI and HANA Cloud support
  • Interactive prompts: Missing parameters prompted automatically
  • Service key auth: Secure cloud authentication

  • 多数据库支持:HANA、PostgreSQL、SQLite后端
  • 格式转换:17种以上输出格式,包括CDS、EDMX、OpenAPI
  • HDI管理:完整的容器生命周期管理
  • 云集成:SAP BTP CLI与HANA Cloud支持
  • 交互式提示:自动提示缺失的参数
  • 服务密钥认证:安全的云认证方式

Detailed References

详细参考文档

For comprehensive documentation:
  • All 91 Commands: See
    references/command-reference.md
  • Connection & Security: See
    references/connection-security.md
  • HDI Management: See
    references/hdi-management.md
  • Output Formats: See
    references/output-formats.md
  • Cloud Operations: See
    references/cloud-operations.md
  • Database Inspection: See
    references/db-inspection.md
  • Mass Operations: See
    references/mass-operations.md
  • System Administration: See
    references/system-admin.md
  • Web UI Interface: See
    references/web-ui.md
  • Troubleshooting Guide: See
    references/troubleshooting.md
  • Development Environment: See
    references/development-environment.md
  • ABAP Programming Patterns: See
    references/abap-programming.md

如需完整文档,请查看:
  • 全部91条命令:查看
    references/command-reference.md
  • 连接与安全:查看
    references/connection-security.md
  • HDI管理:查看
    references/hdi-management.md
  • 输出格式:查看
    references/output-formats.md
  • 云操作:查看
    references/cloud-operations.md
  • 数据库检查:查看
    references/db-inspection.md
  • 批量操作:查看
    references/mass-operations.md
  • 系统管理:查看
    references/system-admin.md
  • Web UI界面:查看
    references/web-ui.md
  • 故障排查指南:查看
    references/troubleshooting.md
  • 开发环境:查看
    references/development-environment.md
  • ABAP编程模式:查看
    references/abap-programming.md

Troubleshooting

故障排查

Connection Issues

连接问题

bash
undefined
bash
undefined

Check current connection status

检查当前连接状态

hana-cli status
hana-cli status

Test with explicit credentials

使用显式凭据测试连接

hana-cli connect -n "host:443" -u USER -p PASS --encrypt true
hana-cli connect -n "host:443" -u USER -p PASS --encrypt true

Use SSL trust store

使用SSL信任库

hana-cli connect --trustStore /path/to/certificate.pem
undefined
hana-cli connect --trustStore /path/to/certificate.pem
undefined

Permission Errors

权限错误

bash
undefined
bash
undefined

Diagnose privilege errors

诊断权限错误

hana-cli privilegeError
hana-cli privilegeError

View current user info

查看当前用户信息

hana-cli inspectUser
undefined
hana-cli inspectUser
undefined

Version Compatibility

版本兼容性

  • Node.js: Requires ≥20.19.0
  • @sap/cds: Uses 9.4.4
  • @sap/cds-dk: Requires ≥8.9 for cds bind

  • Node.js:需要≥20.19.0
  • @sap/cds:使用9.4.4版本
  • @sap/cds-dk:需要≥8.9版本以支持cds bind

Bundled Resources

内置资源

Reference Documentation

参考文档

  • references/command-reference.md
    - Complete command reference with all options
  • references/abap-programming.md
    - ABAP-specific programming patterns
  • references/quick-start.md
    - Quick start guide and examples
  • references/command-reference.md
    - 包含所有选项的完整命令参考
  • references/abap-programming.md
    - ABAP特定编程模式
  • references/quick-start.md
    - 快速入门指南与示例

Scripts

脚本

  • scripts/hana-setup.sh
    - HANA development environment setup script
  • scripts/migration-helper.sh
    - Migration helper script for existing projects
  • scripts/hana-setup.sh
    - HANA开发环境设置脚本
  • scripts/migration-helper.sh
    - 现有项目迁移辅助脚本

Resources

相关资源