| <!doctype html><html itemscope itemtype=http://schema.org/WebPage lang=cn class=no-js><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=robots content="index, follow"><link rel="shortcut icon" href=/favicons/favicon.ico><link rel=apple-touch-icon href=/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/favicons/android-96x96.png sizes=96x96><link rel=icon type=image/png href=/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/favicons/android-192x192.png sizes=192x192><title>Rust | Apache HoraeDB</title><meta name=description content='安装 1 cargo add horaedb-client 你可以在这里找到最新的版本 here. |
| 初始化客户端 首先,我们需要初始化客户端。 |
| 创建客户端的 builder,你必须设置 endpoint 和 mode: endpoint 是类似 “ip/domain_name:port” 形式的字符串。 mode 用于指定访问 HoraeDB 服务器的方式,关于 mode 的详细信息。 1 let mut builder = Builder::new("ip/domain_name:port", Mode::Direct/Mode::Proxy); 创建和设置 rpc_config,可以按需进行定义或者直接使用默认值,更多详细参数请参考这里: 1 2 3 4 5 6 let rpc_config = RpcConfig { thread_num: Some(1), default_write_timeout: Duration::from_millis(1000), ..Default::default() }; let builder = builder.rpc_config(rpc_config); 设置 default_database,这会在执行 RPC 请求时未通过 RpcContext 设置 database 的情况下,将被作为目标 database 使用。 1 let builder = builder.default_database("public"); 最后,我们从 builder 中创建客户端: 1 let client = builder.build(); 管理表 为了方便使用,在使用 gRPC 的 write 接口进行写入时,如果某个表不存在,HoraeDB 会根据第一次的写入自动创建一个表。'><meta property="og:url" content="https://horaedb.apache.org/cn/docs/user-guide/sdk/rust/"><meta property="og:site_name" content="Apache HoraeDB"><meta property="og:title" content="Rust"><meta property="og:description" content='安装 1 cargo add horaedb-client 你可以在这里找到最新的版本 here. |
| 初始化客户端 首先,我们需要初始化客户端。 |
| 创建客户端的 builder,你必须设置 endpoint 和 mode: endpoint 是类似 “ip/domain_name:port” 形式的字符串。 mode 用于指定访问 HoraeDB 服务器的方式,关于 mode 的详细信息。 1 let mut builder = Builder::new("ip/domain_name:port", Mode::Direct/Mode::Proxy); 创建和设置 rpc_config,可以按需进行定义或者直接使用默认值,更多详细参数请参考这里: 1 2 3 4 5 6 let rpc_config = RpcConfig { thread_num: Some(1), default_write_timeout: Duration::from_millis(1000), ..Default::default() }; let builder = builder.rpc_config(rpc_config); 设置 default_database,这会在执行 RPC 请求时未通过 RpcContext 设置 database 的情况下,将被作为目标 database 使用。 1 let builder = builder.default_database("public"); 最后,我们从 builder 中创建客户端: 1 let client = builder.build(); 管理表 为了方便使用,在使用 gRPC 的 write 接口进行写入时,如果某个表不存在,HoraeDB 会根据第一次的写入自动创建一个表。'><meta property="og:locale" content="cn"><meta property="og:type" content="article"><meta property="article:section" content="docs"><meta property="article:modified_time" content="2024-12-10T13:46:16+08:00"><meta itemprop=name content="Rust"><meta itemprop=description content='安装 1 cargo add horaedb-client 你可以在这里找到最新的版本 here. |
| 初始化客户端 首先,我们需要初始化客户端。 |
| 创建客户端的 builder,你必须设置 endpoint 和 mode: endpoint 是类似 “ip/domain_name:port” 形式的字符串。 mode 用于指定访问 HoraeDB 服务器的方式,关于 mode 的详细信息。 1 let mut builder = Builder::new("ip/domain_name:port", Mode::Direct/Mode::Proxy); 创建和设置 rpc_config,可以按需进行定义或者直接使用默认值,更多详细参数请参考这里: 1 2 3 4 5 6 let rpc_config = RpcConfig { thread_num: Some(1), default_write_timeout: Duration::from_millis(1000), ..Default::default() }; let builder = builder.rpc_config(rpc_config); 设置 default_database,这会在执行 RPC 请求时未通过 RpcContext 设置 database 的情况下,将被作为目标 database 使用。 1 let builder = builder.default_database("public"); 最后,我们从 builder 中创建客户端: 1 let client = builder.build(); 管理表 为了方便使用,在使用 gRPC 的 write 接口进行写入时,如果某个表不存在,HoraeDB 会根据第一次的写入自动创建一个表。'><meta itemprop=dateModified content="2024-12-10T13:46:16+08:00"><meta itemprop=wordCount content="375"><meta name=twitter:card content="summary"><meta name=twitter:title content="Rust"><meta name=twitter:description content='安装 1 cargo add horaedb-client 你可以在这里找到最新的版本 here. |
| 初始化客户端 首先,我们需要初始化客户端。 |
| 创建客户端的 builder,你必须设置 endpoint 和 mode: endpoint 是类似 “ip/domain_name:port” 形式的字符串。 mode 用于指定访问 HoraeDB 服务器的方式,关于 mode 的详细信息。 1 let mut builder = Builder::new("ip/domain_name:port", Mode::Direct/Mode::Proxy); 创建和设置 rpc_config,可以按需进行定义或者直接使用默认值,更多详细参数请参考这里: 1 2 3 4 5 6 let rpc_config = RpcConfig { thread_num: Some(1), default_write_timeout: Duration::from_millis(1000), ..Default::default() }; let builder = builder.rpc_config(rpc_config); 设置 default_database,这会在执行 RPC 请求时未通过 RpcContext 设置 database 的情况下,将被作为目标 database 使用。 1 let builder = builder.default_database("public"); 最后,我们从 builder 中创建客户端: 1 let client = builder.build(); 管理表 为了方便使用,在使用 gRPC 的 write 接口进行写入时,如果某个表不存在,HoraeDB 会根据第一次的写入自动创建一个表。'><link rel=preload href=/scss/main.min.18c08ee35308968138c55945e86231cae563e39470a6efcb36f516f6b21b6a02.css as=style integrity="sha256-GMCO41MIloE4xVlF6GIxyuVj45Rwpu/LNvUW9rIbagI=" crossorigin=anonymous><link href=/scss/main.min.18c08ee35308968138c55945e86231cae563e39470a6efcb36f516f6b21b6a02.css rel=stylesheet integrity="sha256-GMCO41MIloE4xVlF6GIxyuVj45Rwpu/LNvUW9rIbagI=" crossorigin=anonymous><script src=https://code.jquery.com/jquery-3.7.1.min.js integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin=anonymous></script><script defer src=https://unpkg.com/lunr@2.3.9/lunr.min.js integrity=sha384-203J0SNzyqHby3iU6hzvzltrWi/M41wOP5Gu+BiJMz5nwKykbkUx8Kp7iti0Lpli crossorigin=anonymous></script></head><body class=td-page><header><nav class="td-navbar js-navbar-scroll" data-bs-theme=dark><div class="container-fluid flex-column flex-md-row"><a class=navbar-brand href=/cn/><span class="navbar-brand__logo navbar-logo"></span><span class=navbar-brand__name>Apache HoraeDB</span></a><div class="td-navbar-nav-scroll ms-md-auto" id=main_navbar><ul class=navbar-nav><li class=nav-item><a class="nav-link active" href=/cn/docs/><i class='fa-solid fa-book'></i><span>文档</span></a></li><li class=nav-item><a class=nav-link href=/cn/downloads/><i class='fa-solid fa-download'></i><span>下载</span></a></li><li class=nav-item><a class=nav-link href=/cn/blog/><i class='fa-brands fa-blogger'></i><span>博客</span></a></li><li class="nav-item dropdown d-none d-lg-block"><div class=dropdown><a class="nav-link dropdown-toggle" href=# role=button data-bs-toggle=dropdown aria-haspopup=true aria-expanded=false>中文</a><ul class=dropdown-menu><li><a class=dropdown-item href=/docs/user-guide/sdk/rust/>English</a></li></ul></div></li><li class="td-light-dark-menu nav-item dropdown"><svg class="d-none"><symbol id="check2" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5.0 010 .708l-7 7a.5.5.0 01-.708.0l-3.5-3.5a.5.5.0 11.708-.708L6.5 10.293l6.646-6.647a.5.5.0 01.708.0z"/></symbol><symbol id="circle-half" viewBox="0 0 16 16"><path d="M8 15A7 7 0 108 1v14zm0 1A8 8 0 118 0a8 8 0 010 16z"/></symbol><symbol id="moon-stars-fill" viewBox="0 0 16 16"><path d="M6 .278a.768.768.0 01.08.858 7.208 7.208.0 00-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527.0 1.04-.055 1.533-.16a.787.787.0 01.81.316.733.733.0 01-.031.893A8.349 8.349.0 018.344 16C3.734 16 0 12.286.0 7.71.0 4.266 2.114 1.312 5.124.06A.752.752.0 016 .278z"/><path d="M10.794 3.148a.217.217.0 01.412.0l.387 1.162c.173.518.579.924 1.097 1.097l1.162.387a.217.217.0 010 .412l-1.162.387A1.734 1.734.0 0011.593 7.69l-.387 1.162a.217.217.0 01-.412.0l-.387-1.162A1.734 1.734.0 009.31 6.593l-1.162-.387a.217.217.0 010-.412l1.162-.387a1.734 1.734.0 001.097-1.097l.387-1.162zM13.863.099a.145.145.0 01.274.0l.258.774c.115.346.386.617.732.732l.774.258a.145.145.0 010 .274l-.774.258a1.156 1.156.0 00-.732.732l-.258.774a.145.145.0 01-.274.0l-.258-.774a1.156 1.156.0 00-.732-.732l-.774-.258a.145.145.0 010-.274l.774-.258c.346-.115.617-.386.732-.732L13.863.1z"/></symbol><symbol id="sun-fill" viewBox="0 0 16 16"><path d="M8 12a4 4 0 100-8 4 4 0 000 8zM8 0a.5.5.0 01.5.5v2a.5.5.0 01-1 0v-2A.5.5.0 018 0zm0 13a.5.5.0 01.5.5v2a.5.5.0 01-1 0v-2A.5.5.0 018 13zm8-5a.5.5.0 01-.5.5h-2a.5.5.0 010-1h2a.5.5.0 01.5.5zM3 8a.5.5.0 01-.5.5h-2a.5.5.0 010-1h2A.5.5.0 013 8zm10.657-5.657a.5.5.0 010 .707l-1.414 1.415a.5.5.0 11-.707-.708l1.414-1.414a.5.5.0 01.707.0zm-9.193 9.193a.5.5.0 010 .707L3.05 13.657a.5.5.0 01-.707-.707l1.414-1.414a.5.5.0 01.707.0zm9.193 2.121a.5.5.0 01-.707.0l-1.414-1.414a.5.5.0 01.707-.707l1.414 1.414a.5.5.0 010 .707zM4.464 4.465a.5.5.0 01-.707.0L2.343 3.05a.5.5.0 11.707-.707l1.414 1.414a.5.5.0 010 .708z"/></symbol></svg> |
| <button class="btn btn-link nav-link dropdown-toggle d-flex align-items-center" id=bd-theme type=button aria-expanded=false data-bs-toggle=dropdown data-bs-display=static aria-label="Toggle theme (auto)"> |
| <svg class="bi my-1 theme-icon-active"><use href="#circle-half"/></svg></button><ul class="dropdown-menu dropdown-menu-end" aria-labelledby=bd-theme-text><li><button type=button class="dropdown-item d-flex align-items-center" data-bs-theme-value=light aria-pressed=false> |
| <svg class="bi me-2 opacity-50"><use href="#sun-fill"/></svg> |
| Light |
| <svg class="bi ms-auto d-none"><use href="#check2"/></svg></button></li><li><button type=button class="dropdown-item d-flex align-items-center" data-bs-theme-value=dark aria-pressed=false> |
| <svg class="bi me-2 opacity-50"><use href="#moon-stars-fill"/></svg> |
| Dark |
| <svg class="bi ms-auto d-none"><use href="#check2"/></svg></button></li><li><button type=button class="dropdown-item d-flex align-items-center active" data-bs-theme-value=auto aria-pressed=true> |
| <svg class="bi me-2 opacity-50"><use href="#circle-half"/></svg> |
| Auto |
| <svg class="bi ms-auto d-none"><use href="#check2"/></svg></button></li></ul></li></ul></div><div class="d-none d-lg-block"><div class="td-search td-search--offline"><div class=td-search__icon></div><input type=search class="td-search__input form-control" placeholder="Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.067de4e53d74cf984cf779c98419a9c1.json data-offline-search-base-href=/ data-offline-search-max-results=10></div></div></div></nav></header><div class="container-fluid td-outer"><div class=td-main><div class="row flex-xl-nowrap"><aside class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none"><div id=td-sidebar-menu class=td-sidebar__inner><form class="td-sidebar__search d-flex align-items-center"><div class="td-search td-search--offline"><div class=td-search__icon></div><input type=search class="td-search__input form-control" placeholder="Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.067de4e53d74cf984cf779c98419a9c1.json data-offline-search-base-href=/ data-offline-search-max-results=10></div><button class="btn btn-link td-sidebar__toggle d-md-none p-0 ms-3 fas fa-bars" type=button data-bs-toggle=collapse data-bs-target=#td-section-nav aria-controls=td-section-nav aria-expanded=false aria-label="Toggle section navigation"></button></form><nav class="td-sidebar-nav collapse foldable-nav" id=td-section-nav><div class="td-sidebar-nav__section nav-item dropdown d-block d-lg-none"><div class=dropdown><a class="nav-link dropdown-toggle" href=# role=button data-bs-toggle=dropdown aria-haspopup=true aria-expanded=false>中文</a><ul class=dropdown-menu><li><a class=dropdown-item href=/docs/user-guide/sdk/rust/>English</a></li></ul></div></div><ul class="td-sidebar-nav__section pe-md-3 ul-0"><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child active-path" id=m-cndocs-li><a href=/cn/docs/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section tree-root" id=m-cndocs><span>文档</span></a><ul class=ul-1><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsgetting-started-li><input type=checkbox id=m-cndocsgetting-started-check> |
| <label for=m-cndocsgetting-started-check><a href=/cn/docs/getting-started/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsgetting-started><span>快速开始</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child active-path" id=m-cndocsuser-guide-li><input type=checkbox id=m-cndocsuser-guide-check checked> |
| <label for=m-cndocsuser-guide-check><a href=/cn/docs/user-guide/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guide><span>用户指南</span></a></label><ul class="ul-2 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsuser-guidesql-li><input type=checkbox id=m-cndocsuser-guidesql-check> |
| <label for=m-cndocsuser-guidesql-check><a href=/cn/docs/user-guide/sql/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guidesql><span>SQL 语法</span></a></label><ul class="ul-3 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsuser-guidesqlmodel-li><input type=checkbox id=m-cndocsuser-guidesqlmodel-check> |
| <label for=m-cndocsuser-guidesqlmodel-check><a href=/cn/docs/user-guide/sql/model/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guidesqlmodel><span>数据模型</span></a></label><ul class="ul-4 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlmodeldata_types-li><input type=checkbox id=m-cndocsuser-guidesqlmodeldata_types-check> |
| <label for=m-cndocsuser-guidesqlmodeldata_types-check><a href=/cn/docs/user-guide/sql/model/data_types/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlmodeldata_types><span>数据类型</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlmodelspecial_columns-li><input type=checkbox id=m-cndocsuser-guidesqlmodelspecial_columns-check> |
| <label for=m-cndocsuser-guidesqlmodelspecial_columns-check><a href=/cn/docs/user-guide/sql/model/special_columns/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlmodelspecial_columns><span>特殊字段</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlidentifier-li><input type=checkbox id=m-cndocsuser-guidesqlidentifier-check> |
| <label for=m-cndocsuser-guidesqlidentifier-check><a href=/cn/docs/user-guide/sql/identifier/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlidentifier><span>标识符</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsuser-guidesqlddl-li><input type=checkbox id=m-cndocsuser-guidesqlddl-check> |
| <label for=m-cndocsuser-guidesqlddl-check><a href=/cn/docs/user-guide/sql/ddl/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guidesqlddl><span>表结构操作</span></a></label><ul class="ul-4 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlddlalter_table-li><input type=checkbox id=m-cndocsuser-guidesqlddlalter_table-check> |
| <label for=m-cndocsuser-guidesqlddlalter_table-check><a href=/cn/docs/user-guide/sql/ddl/alter_table/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlddlalter_table><span>ALTER TABLE</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlddldrop_table-li><input type=checkbox id=m-cndocsuser-guidesqlddldrop_table-check> |
| <label for=m-cndocsuser-guidesqlddldrop_table-check><a href=/cn/docs/user-guide/sql/ddl/drop_table/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlddldrop_table><span>DROP TABLE</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlddlcreate_table-li><input type=checkbox id=m-cndocsuser-guidesqlddlcreate_table-check> |
| <label for=m-cndocsuser-guidesqlddlcreate_table-check><a href=/cn/docs/user-guide/sql/ddl/create_table/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlddlcreate_table><span>创建表</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsuser-guidesqldml-li><input type=checkbox id=m-cndocsuser-guidesqldml-check> |
| <label for=m-cndocsuser-guidesqldml-check><a href=/cn/docs/user-guide/sql/dml/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guidesqldml><span>数据操作</span></a></label><ul class="ul-4 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqldmlinsert-li><input type=checkbox id=m-cndocsuser-guidesqldmlinsert-check> |
| <label for=m-cndocsuser-guidesqldmlinsert-check><a href=/cn/docs/user-guide/sql/dml/insert/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqldmlinsert><span>INSERT</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqldmlselect-li><input type=checkbox id=m-cndocsuser-guidesqldmlselect-check> |
| <label for=m-cndocsuser-guidesqldmlselect-check><a href=/cn/docs/user-guide/sql/dml/select/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqldmlselect><span>SELECT</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlutility-li><input type=checkbox id=m-cndocsuser-guidesqlutility-check> |
| <label for=m-cndocsuser-guidesqlutility-check><a href=/cn/docs/user-guide/sql/utility/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlutility><span>常用 SQL</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlengine_options-li><input type=checkbox id=m-cndocsuser-guidesqlengine_options-check> |
| <label for=m-cndocsuser-guidesqlengine_options-check><a href=/cn/docs/user-guide/sql/engine_options/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlengine_options><span>配置项</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlscalar_functions-li><input type=checkbox id=m-cndocsuser-guidesqlscalar_functions-check> |
| <label for=m-cndocsuser-guidesqlscalar_functions-check><a href=/cn/docs/user-guide/sql/scalar_functions/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlscalar_functions><span>标量函数</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesqlaggregate_functions-li><input type=checkbox id=m-cndocsuser-guidesqlaggregate_functions-check> |
| <label for=m-cndocsuser-guidesqlaggregate_functions-check><a href=/cn/docs/user-guide/sql/aggregate_functions/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesqlaggregate_functions><span>聚合函数</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsuser-guidecluster_deployment-li><input type=checkbox id=m-cndocsuser-guidecluster_deployment-check> |
| <label for=m-cndocsuser-guidecluster_deployment-check><a href=/cn/docs/user-guide/cluster_deployment/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guidecluster_deployment><span>集群部署</span></a></label><ul class="ul-3 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidecluster_deploymentno_meta-li><input type=checkbox id=m-cndocsuser-guidecluster_deploymentno_meta-check> |
| <label for=m-cndocsuser-guidecluster_deploymentno_meta-check><a href=/cn/docs/user-guide/cluster_deployment/no_meta/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidecluster_deploymentno_meta><span>NoMeta 模式</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidecluster_deploymentwith_meta-li><input type=checkbox id=m-cndocsuser-guidecluster_deploymentwith_meta-check> |
| <label for=m-cndocsuser-guidecluster_deploymentwith_meta-check><a href=/cn/docs/user-guide/cluster_deployment/with_meta/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidecluster_deploymentwith_meta><span>WithMeta 模式</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child active-path" id=m-cndocsuser-guidesdk-li><input type=checkbox id=m-cndocsuser-guidesdk-check checked> |
| <label for=m-cndocsuser-guidesdk-check><a href=/cn/docs/user-guide/sdk/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guidesdk><span>SDK 文档</span></a></label><ul class="ul-3 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesdkgo-li><input type=checkbox id=m-cndocsuser-guidesdkgo-check> |
| <label for=m-cndocsuser-guidesdkgo-check><a href=/cn/docs/user-guide/sdk/go/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesdkgo><span>Go</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesdkjava-li><input type=checkbox id=m-cndocsuser-guidesdkjava-check> |
| <label for=m-cndocsuser-guidesdkjava-check><a href=/cn/docs/user-guide/sdk/java/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesdkjava><span>Java</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guidesdkpython-li><input type=checkbox id=m-cndocsuser-guidesdkpython-check> |
| <label for=m-cndocsuser-guidesdkpython-check><a href=/cn/docs/user-guide/sdk/python/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesdkpython><span>Python</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child active-path" id=m-cndocsuser-guidesdkrust-li><input type=checkbox id=m-cndocsuser-guidesdkrust-check checked> |
| <label for=m-cndocsuser-guidesdkrust-check><a href=/cn/docs/user-guide/sdk/rust/ class="align-left ps-0 active td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guidesdkrust><span class=td-sidebar-nav-active-item>Rust</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsuser-guideoperation-li><input type=checkbox id=m-cndocsuser-guideoperation-check> |
| <label for=m-cndocsuser-guideoperation-check><a href=/cn/docs/user-guide/operation/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guideoperation><span>运维文档</span></a></label><ul class="ul-3 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideoperationobservability-li><input type=checkbox id=m-cndocsuser-guideoperationobservability-check> |
| <label for=m-cndocsuser-guideoperationobservability-check><a href=/cn/docs/user-guide/operation/observability/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideoperationobservability><span>监控</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideoperationsystem_table-li><input type=checkbox id=m-cndocsuser-guideoperationsystem_table-check> |
| <label for=m-cndocsuser-guideoperationsystem_table-check><a href=/cn/docs/user-guide/operation/system_table/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideoperationsystem_table><span>系统表</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideoperationtable-li><input type=checkbox id=m-cndocsuser-guideoperationtable-check> |
| <label for=m-cndocsuser-guideoperationtable-check><a href=/cn/docs/user-guide/operation/table/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideoperationtable><span>表操作</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideoperationhoraemeta-li><input type=checkbox id=m-cndocsuser-guideoperationhoraemeta-check> |
| <label for=m-cndocsuser-guideoperationhoraemeta-check><a href=/cn/docs/user-guide/operation/horaemeta/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideoperationhoraemeta><span>集群运维</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideoperationblock_list-li><input type=checkbox id=m-cndocsuser-guideoperationblock_list-check> |
| <label for=m-cndocsuser-guideoperationblock_list-check><a href=/cn/docs/user-guide/operation/block_list/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideoperationblock_list><span>黑名单</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsuser-guideecosystem-li><input type=checkbox id=m-cndocsuser-guideecosystem-check> |
| <label for=m-cndocsuser-guideecosystem-check><a href=/cn/docs/user-guide/ecosystem/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsuser-guideecosystem><span>周边生态</span></a></label><ul class="ul-3 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideecosysteminfluxdb-li><input type=checkbox id=m-cndocsuser-guideecosysteminfluxdb-check> |
| <label for=m-cndocsuser-guideecosysteminfluxdb-check><a href=/cn/docs/user-guide/ecosystem/influxdb/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideecosysteminfluxdb><span>InfluxDB</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideecosystemopentsdb-li><input type=checkbox id=m-cndocsuser-guideecosystemopentsdb-check> |
| <label for=m-cndocsuser-guideecosystemopentsdb-check><a href=/cn/docs/user-guide/ecosystem/opentsdb/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideecosystemopentsdb><span>OpenTSDB</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsuser-guideecosystemprometheus-li><input type=checkbox id=m-cndocsuser-guideecosystemprometheus-check> |
| <label for=m-cndocsuser-guideecosystemprometheus-check><a href=/cn/docs/user-guide/ecosystem/prometheus/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsuser-guideecosystemprometheus><span>Prometheus</span></a></label></li></ul></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsdev-li><input type=checkbox id=m-cndocsdev-check> |
| <label for=m-cndocsdev-check><a href=/cn/docs/dev/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsdev><span>开发手册</span></a></label><ul class="ul-2 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdevplatform-li><input type=checkbox id=m-cndocsdevplatform-check> |
| <label for=m-cndocsdevplatform-check><a href=/cn/docs/dev/platform/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdevplatform><span>支持平台</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdevcompile_run-li><input type=checkbox id=m-cndocsdevcompile_run-check> |
| <label for=m-cndocsdevcompile_run-check><a href=/cn/docs/dev/compile_run/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdevcompile_run><span>编译</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdevprofiling-li><input type=checkbox id=m-cndocsdevprofiling-check> |
| <label for=m-cndocsdevprofiling-check><a href=/cn/docs/dev/profiling/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdevprofiling><span>性能诊断</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdevroadmap-li><input type=checkbox id=m-cndocsdevroadmap-check> |
| <label for=m-cndocsdevroadmap-check><a href=/cn/docs/dev/roadmap/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdevroadmap><span>RoadMap</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-cndocsdesign-li><input type=checkbox id=m-cndocsdesign-check> |
| <label for=m-cndocsdesign-check><a href=/cn/docs/design/ class="align-left ps-0 td-sidebar-link td-sidebar-link__section" id=m-cndocsdesign><span>设计文档</span></a></label><ul class="ul-2 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesignarchitecture-li><input type=checkbox id=m-cndocsdesignarchitecture-check> |
| <label for=m-cndocsdesignarchitecture-check><a href=/cn/docs/design/architecture/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesignarchitecture><span>HoraeDB 架构介绍</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesignclustering-li><input type=checkbox id=m-cndocsdesignclustering-check> |
| <label for=m-cndocsdesignclustering-check><a href=/cn/docs/design/clustering/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesignclustering><span>集群模式</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesignstorage-li><input type=checkbox id=m-cndocsdesignstorage-check> |
| <label for=m-cndocsdesignstorage-check><a href=/cn/docs/design/storage/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesignstorage><span>存储引擎</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesignshared_nothing-li><input type=checkbox id=m-cndocsdesignshared_nothing-check> |
| <label for=m-cndocsdesignshared_nothing-check><a href=/cn/docs/design/shared_nothing/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesignshared_nothing><span>Shared Nothing 架构</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesigntable_partitioning-li><input type=checkbox id=m-cndocsdesigntable_partitioning-check> |
| <label for=m-cndocsdesigntable_partitioning-check><a href=/cn/docs/design/table_partitioning/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesigntable_partitioning><span>分区表</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesignwal_on_kafka-li><input type=checkbox id=m-cndocsdesignwal_on_kafka-check> |
| <label for=m-cndocsdesignwal_on_kafka-check><a href=/cn/docs/design/wal_on_kafka/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesignwal_on_kafka><span>基于 Kafka 的 WAL</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesignwal_on_rocksdb-li><input type=checkbox id=m-cndocsdesignwal_on_rocksdb-check> |
| <label for=m-cndocsdesignwal_on_rocksdb-check><a href=/cn/docs/design/wal_on_rocksdb/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesignwal_on_rocksdb><span>基于 RocksDB 的 WAL</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-cndocsdesignwal_on_disk-li><input type=checkbox id=m-cndocsdesignwal_on_disk-check> |
| <label for=m-cndocsdesignwal_on_disk-check><a href=/cn/docs/design/wal_on_disk/ class="align-left ps-0 td-sidebar-link td-sidebar-link__page" id=m-cndocsdesignwal_on_disk><span>基于本地磁盘的 WAL</span></a></label></li></ul></li></ul></li></ul></nav></div></aside><aside class="d-none d-xl-block col-xl-2 td-sidebar-toc d-print-none"><div class="td-page-meta ms-2 pb-1 pt-2 mb-0"><a href=https://github.com/apache/horaedb-docs/tree/main/content/cn/docs/user-guide/sdk/rust.md class="td-page-meta--view td-page-meta__view" target=_blank rel=noopener><i class="fa-solid fa-file-lines fa-fw"></i> View page source</a> |
| <a href=https://github.com/apache/horaedb-docs/edit/main/content/cn/docs/user-guide/sdk/rust.md class="td-page-meta--edit td-page-meta__edit" target=_blank rel=noopener><i class="fa-solid fa-pen-to-square fa-fw"></i> Edit this page</a> |
| <a href="https://github.com/apache/horaedb-docs/new/main/content/cn/docs/user-guide/sdk?filename=change-me.md&value=---%0Atitle%3A+%22Long+Page+Title%22%0AlinkTitle%3A+%22Short+Nav+Title%22%0Aweight%3A+100%0Adescription%3A+%3E-%0A+++++Page+description+for+heading+and+indexes.%0A---%0A%0A%23%23+Heading%0A%0AEdit+this+template+to+create+your+new+page.%0A%0A%2A+Give+it+a+good+name%2C+ending+in+%60.md%60+-+e.g.+%60getting-started.md%60%0A%2A+Edit+the+%22front+matter%22+section+at+the+top+of+the+page+%28weight+controls+how+its+ordered+amongst+other+pages+in+the+same+directory%3B+lowest+number+first%29.%0A%2A+Add+a+good+commit+message+at+the+bottom+of+the+page+%28%3C80+characters%3B+use+the+extended+description+field+for+more+detail%29.%0A%2A+Create+a+new+branch+so+you+can+preview+your+new+file+and+request+a+review+via+Pull+Request.%0A" class="td-page-meta--child td-page-meta__child" target=_blank rel=noopener><i class="fa-solid fa-pen-to-square fa-fw"></i> Create child page</a> |
| <a href="https://github.com/apache/horaedb-docs/issues/new?title=Rust" class="td-page-meta--issue td-page-meta__issue" target=_blank rel=noopener><i class="fa-solid fa-list-check fa-fw"></i> Create documentation issue</a> |
| <a href=https://github.com/apache/horaedb/issues/new class="td-page-meta--project td-page-meta__project-issue" target=_blank rel=noopener><i class="fa-solid fa-list-check fa-fw"></i> Create project issue</a> |
| <a id=print href=/cn/_print/docs/user-guide/sdk/><i class="fa-solid fa-print fa-fw"></i> Print entire section</a></div><div class=td-toc><nav id=TableOfContents><ul><li><a href=#安装>安装</a></li><li><a href=#初始化客户端>初始化客户端</a></li><li><a href=#管理表>管理表</a></li><li><a href=#写入数据>写入数据</a></li><li><a href=#sql-query>Sql query</a></li><li><a href=#示例>示例</a></li></ul></nav></div><div class="taxonomy taxonomy-terms-cloud taxo-tags"><h5 class=taxonomy-title>Tags</h5><ul class=taxonomy-terms><li><a class=taxonomy-term href=https://horaedb.apache.org/cn/tags/community/ data-taxonomy-term=community><span class=taxonomy-label>Community</span><span class=taxonomy-count>7</span></a></li><li><a class=taxonomy-term href=https://horaedb.apache.org/cn/tags/release/ data-taxonomy-term=release><span class=taxonomy-label>Release</span><span class=taxonomy-count>2</span></a></li></ul></div></aside><main class="col-12 col-md-9 col-xl-8 ps-md-5" role=main><nav aria-label=breadcrumb class=td-breadcrumbs><ol class=breadcrumb><li class=breadcrumb-item><a href=/cn/docs/>文档</a></li><li class=breadcrumb-item><a href=/cn/docs/user-guide/>用户指南</a></li><li class=breadcrumb-item><a href=/cn/docs/user-guide/sdk/>SDK 文档</a></li><li class="breadcrumb-item active" aria-current=page>Rust</li></ol></nav><div class=td-content><h1>Rust</h1><header class=article-meta></header><h2 id=安装>安装</h2><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash><span style=display:flex><span>cargo add horaedb-client |
| </span></span></code></pre></td></tr></table></div></div><p>你可以在这里找到最新的版本 <a href=https://github.com/apache/horaedb-client-rs/tags>here</a>.</p><h2 id=初始化客户端>初始化客户端</h2><p>首先,我们需要初始化客户端。</p><ul><li>创建客户端的 builder,你必须设置 <code>endpoint</code> 和 <code>mode</code>:<ul><li><code>endpoint</code> 是类似 “ip/domain_name:port” 形式的字符串。</li><li><code>mode</code> 用于指定访问 HoraeDB 服务器的方式,<a href=https://github.com/apache/incubator-horaedb-client-rs/blob/main/src/db_client/builder.rs#L20>关于 mode 的详细信息</a>。</li></ul></li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span><span style=color:green;font-weight:700>mut</span><span style=color:#bbb> </span>builder<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>Builder::new(<span style=color:#ba2121>"ip/domain_name:port"</span>,<span style=color:#bbb> </span>Mode::Direct<span style=color:#666>/</span>Mode::Proxy);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>创建和设置 <code>rpc_config</code>,可以按需进行定义或者直接使用默认值,更多详细参数请参考<a href=https://github.com/apache/incubator-horaedb-client-rs/blob/main/src/options.rs>这里</a>:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">2 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">3 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">4 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">5 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">6 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>rpc_config<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>RpcConfig<span style=color:#bbb> </span>{<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>thread_num: <span style=color:green>Some</span>(<span style=color:#666>1</span>),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>default_write_timeout: <span style=color:#00f;font-weight:700>Duration</span>::from_millis(<span style=color:#666>1000</span>),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span><span style=color:#666>..</span><span style=color:green>Default</span>::default()<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span>};<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>builder<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>builder.rpc_config(rpc_config);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>设置 <code>default_database</code>,这会在执行 RPC 请求时未通过 RpcContext 设置 database 的情况下,将被作为目标 database 使用。</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:#bbb> </span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>builder<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>builder.default_database(<span style=color:#ba2121>"public"</span>);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>最后,我们从 builder 中创建客户端:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:#bbb> </span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>client<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>builder.build();<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><h2 id=管理表>管理表</h2><p>为了方便使用,在使用 gRPC 的 write 接口进行写入时,如果某个表不存在,HoraeDB 会根据第一次的写入自动创建一个表。</p><p>当然你也可以通过 <code>create table</code> 语句来更精细化的管理的表(比如添加索引等)。</p><ul><li>建表:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 2 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 3 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 4 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 5 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 6 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 7 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 8 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 9 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">10 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">11 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">12 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">13 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">14 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">15 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">16 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">17 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">18 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">19 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>create_table_sql<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span><span style=color:#ba2121>r</span><span style=color:#ba2121>#"CREATE TABLE IF NOT EXISTS horaedb ( |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> str_tag string TAG, |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> int_tag int32 TAG, |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> var_tag varbinary TAG, |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> str_field string, |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> int_field int32, |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> bin_field varbinary, |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> t timestamp NOT NULL, |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> TIMESTAMP KEY(t)) ENGINE=Analytic with |
| </span></span></span><span style=display:flex><span><span style=color:#ba2121> (enable_ttl='false')"#</span>;<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>req<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>SqlQueryRequest<span style=color:#bbb> </span>{<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>tables: <span style=color:#00f;font-weight:700>vec</span><span style=color:#666>!</span>[<span style=color:#ba2121>"horaedb"</span>.to_string()],<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>sql: <span style=color:#00f;font-weight:700>create_table_sql</span>.to_string(),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span>};<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>resp<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>client<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.sql_query(rpc_ctx,<span style=color:#bbb> </span><span style=color:#666>&</span>req)<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.<span style=color:green;font-weight:700>await</span><span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.expect(<span style=color:#ba2121>"Should succeed to create table"</span>);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>删表:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 2 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 3 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 4 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 5 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 6 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 7 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 8 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 9 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">10 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>drop_table_sql<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span><span style=color:#ba2121>"DROP TABLE horaedb"</span>;<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>req<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>SqlQueryRequest<span style=color:#bbb> </span>{<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>tables: <span style=color:#00f;font-weight:700>vec</span><span style=color:#666>!</span>[<span style=color:#ba2121>"horaedb"</span>.to_string()],<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>sql: <span style=color:#00f;font-weight:700>drop_table_sql</span>.to_string(),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span>};<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>resp<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>client<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.sql_query(rpc_ctx,<span style=color:#bbb> </span><span style=color:#666>&</span>req)<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.<span style=color:green;font-weight:700>await</span><span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.expect(<span style=color:#ba2121>"Should succeed to create table"</span>);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><h2 id=写入数据>写入数据</h2><p>我们支持使用类似 <a href=https://awesome.influxdata.com/docs/part-2/influxdb-data-model>InfluxDB</a> 的时序数据模型进行写入。</p><ul><li>利用 <code>PointBuilder</code> 创建 <code>point</code>,<code>tag value</code> 和 <code>field value</code> 的相关数据结构为 <code>Value</code>,[<code>Value</code> 的详细信息](detail about Value](<a href=https://github.com/apache/incubator-horaedb-client-rs/blob/main/src/model/value.rs>https://github.com/apache/incubator-horaedb-client-rs/blob/main/src/model/value.rs</a>:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 2 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 3 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 4 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 5 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 6 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 7 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 8 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f"> 9 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">10 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">11 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">12 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">13 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">14 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">15 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">16 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">17 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">18 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">19 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">20 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">21 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>test_table<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span><span style=color:#ba2121>"horaedb"</span>;<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>ts<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>Local::now().timestamp_millis();<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>point<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>PointBuilder::new(test_table.to_string())<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.timestamp(ts)<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.tag(<span style=color:#ba2121>"str_tag"</span>.to_string(),<span style=color:#bbb> </span>Value::<span style=color:green>String</span>(<span style=color:#ba2121>"tag_val"</span>.to_string()))<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.tag(<span style=color:#ba2121>"int_tag"</span>.to_string(),<span style=color:#bbb> </span>Value::Int32(<span style=color:#666>42</span>))<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.tag(<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span><span style=color:#ba2121>"var_tag"</span>.to_string(),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>Value::Varbinary(<span style=color:#ba2121>b</span><span style=color:#ba2121>"tag_bin_val"</span>.to_vec()),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>)<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.field(<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span><span style=color:#ba2121>"str_field"</span>.to_string(),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>Value::<span style=color:green>String</span>(<span style=color:#ba2121>"field_val"</span>.to_string()),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>)<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.field(<span style=color:#ba2121>"int_field"</span>.to_string(),<span style=color:#bbb> </span>Value::Int32(<span style=color:#666>42</span>))<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.field(<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span><span style=color:#ba2121>"bin_field"</span>.to_string(),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>Value::Varbinary(<span style=color:#ba2121>b</span><span style=color:#ba2121>"field_bin_val"</span>.to_vec()),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>)<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.build()<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>.unwrap();<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>将 <code>point</code> 添加到 <code>write request</code> 中:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">2 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span><span style=color:green;font-weight:700>mut</span><span style=color:#bbb> </span>write_req<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>WriteRequest::default();<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span>write_req.add_point(point);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>创建 <code>rpc_ctx</code>,同样地可以按需设置或者使用默认值,<code>rpc_ctx</code> 的详细信息请参考<a href=https://github.com/apache/incubator-horaedb-client-rs/blob/main/src/rpc_client/mod.rs#L23>这里</a>:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">2 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">3 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">4 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>rpc_ctx<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>RpcContext<span style=color:#bbb> </span>{<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>database: <span style=color:green>Some</span>(<span style=color:#ba2121>"public"</span>.to_string()),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span><span style=color:#666>..</span><span style=color:green>Default</span>::default()<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span>};<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>最后,利用客户端写入数据到服务器:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">2 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">3 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">4 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">5 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>rpc_ctx<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>RpcContext<span style=color:#bbb> </span>{<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>database: <span style=color:green>Some</span>(<span style=color:#ba2121>"public"</span>.to_string()),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span><span style=color:#666>..</span><span style=color:green>Default</span>::default()<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span>};<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>resp<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>client.write(rpc_ctx,<span style=color:#bbb> </span><span style=color:#666>&</span>write_req).<span style=color:green;font-weight:700>await</span>.expect(<span style=color:#ba2121>"Should success to write"</span>);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><h2 id=sql-query>Sql query</h2><p>我们支持使用 sql 进行数据查询。</p><ul><li>在 <code>sql query request</code> 中指定相关的表和 sql 语句:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">2 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">3 |
| </span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">4 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>req<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>SqlQueryRequest<span style=color:#bbb> </span>{<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>tables: <span style=color:#00f;font-weight:700>vec</span><span style=color:#666>!</span>[table<span style=color:#bbb> </span>name<span style=color:#bbb> </span><span style=color:#666>1</span>,<span style=color:#666>..</span>.,table<span style=color:#bbb> </span>name<span style=color:#bbb> </span>n],<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb> </span>sql: <span style=color:#00f;font-weight:700>sql</span><span style=color:#bbb> </span>string<span style=color:#bbb> </span>(e.g.<span style=color:#bbb> </span>select<span style=color:#bbb> </span><span style=color:#666>*</span><span style=color:#bbb> </span>from<span style=color:#bbb> </span>xxx),<span style=color:#bbb> |
| </span></span></span><span style=display:flex><span><span style=color:#bbb></span>};<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><ul><li>利用客户端进行查询:</li></ul><div class=highlight><div style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><table style=border-spacing:0;padding:0;margin:0;border:0><tr><td style=vertical-align:top;padding:0;margin:0;border:0><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:.4em;padding:0 .4em;color:#7f7f7f">1 |
| </span></code></pre></td><td style=vertical-align:top;padding:0;margin:0;border:0;width:100%><pre tabindex=0 style=-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-rust data-lang=rust><span style=display:flex><span><span style=color:green;font-weight:700>let</span><span style=color:#bbb> </span>resp<span style=color:#bbb> </span><span style=color:#666>=</span><span style=color:#bbb> </span>client.sql_query(rpc_ctx,<span style=color:#bbb> </span><span style=color:#666>&</span>req).<span style=color:green;font-weight:700>await</span>.expect(<span style=color:#ba2121>"Should success to write"</span>);<span style=color:#bbb> |
| </span></span></span></code></pre></td></tr></table></div></div><h2 id=示例>示例</h2><p>你可以在本项目的仓库中找到<a href=https://github.com/apache/incubator-horaedb-client-rs/blob/main/examples/read_write.rs>完整的例子</a>。</p><div class=td-page-meta__lastmod>Last modified December 10, 2024: <a href=https://github.com/apache/horaedb-docs/commit/af9dbef65498422cbbb83020153f0ad6fad4952a>feat: add python client download links (#162) (af9dbef)</a></div></div></main></div></div><footer class="td-footer row d-print-none"><div class=container-fluid><div class="row mx-md-2"><div class=td-footer__center>Apache HoraeDB is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.<hr><span class=td-footer__copyright>© |
| 2023–2025 |
| <span class=td-footer__authors><p>The Apache Software Foundation, Licensed under the Apache License, Version 2.0.</p><p>Apache, the names of Apache projects, and the feather logo are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries.</p></span></span><span class=td-footer__all_rights_reserved>All Rights Reserved</span></div></div><hr><div class="row mx-md-2"><div class=td-footer__center><span class=td-footer__copyright>Found a bug in website? <a href=https://github.com/apache/horaedb-docs/issues/new>Open an issue</a> or <a href=https://github.com/apache/horaedb-docs/pulls>submit a pull request</a> on GitHub.</span></div></div><hr></div></footer></div><script src=/js/main.min.bf0cab613e991fc11bc28a4a07b0aedef47c7c7c2595703ac3adf962fd6a8099.js integrity="sha256-vwyrYT6ZH8EbwopKB7Cu3vR8fHwllXA6w635Yv1qgJk=" crossorigin=anonymous></script><script defer src=/js/click-to-copy.min.73478a7d4807698aed7e355eb23f9890ca18fea3158604c8471746d046702bad.js integrity="sha256-c0eKfUgHaYrtfjVesj+YkMoY/qMVhgTIRxdG0EZwK60=" crossorigin=anonymous></script><script src=/js/tabpane-persist.js></script></body></html> |