dolphindb 0.0.1 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 DolphinDB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -13,57 +13,61 @@
13
13
  </a>
14
14
  </p>
15
15
 
16
- ## 简介
17
- DolphinDB JavaScript API 封装了操作 DolphinDB 数据库的能力,如:连接数据库、执行脚本、调用函数、上传变量等
16
+ ## English | [中文](./README.zh.md)
18
17
 
19
- ## 特性
20
- - 使用 WebSocket 与 DolphinDB 数据库通信,用二进制格式进行数据交换
21
- - 支持在浏览器环境和 Node.js 环境中运行
22
- - 使用了 JavaScript 中的 Int32Array 等 TypedArray 处理二进制数据,性能较高
23
- - 单次调用支持最大 2 GB 数据的序列化上传,下载数据量不受限制
18
+ ## Overview
19
+ DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB database, such as: connecting to the database, executing scripts, calling functions, uploading variables, etc.
24
20
 
25
- ## 安装
21
+ https://www.npmjs.com/package/dolphindb
22
+
23
+ ## Features
24
+ - Communicate with DolphinDB database using WebSocket, exchange data in binary format
25
+ - Support running in browser environment and Node.js environment
26
+ - Use TypedArray such as Int32Array in JavaScript to process binary data, with high performance
27
+ - A single call supports serialized upload of up to 2GB of data, and the amount of downloaded data is not limited
28
+
29
+ ## Installation
26
30
  ```bash
27
- # 在机器上安装最新版的 Node.js 及浏览器
31
+ # Install the latest version of Node.js and browser on the machine
28
32
 
29
- # 在项目中安装 npm 包
33
+ # Install npm packages in your project
30
34
  npm install dolphindb
31
35
  ```
32
36
 
33
- ## 用法
34
- ### 0. 初始化并连接到 DolphinDB
37
+ ## Usage
38
+ ### 0. Initialize and connect to DolphinDB
35
39
  ```ts
36
40
  import DDB from 'dolphindb'
37
41
 
38
- // 初始化 WebSocket 连接地址
42
+ // Create a database object and initialize the WebSocket URL
39
43
  let ddb = new DDB('ws://127.0.0.1:8848')
40
44
 
41
- // 建立到 DolphinDB 的 WebSocket 连接
45
+ // Establish a WebSocket connection to DolphinDB (requires DolphinDB database version at least 1.30.16 or 2.00.4)
42
46
  await ddb.connect()
43
47
  ```
44
48
 
45
- #### connect 方法声明
49
+ #### Connect Method Declaration
46
50
  ```ts
47
51
  async connect (
48
52
  options?: {
49
- /** 默认使用实例初始化时传入的 WebSocket 链接地址 */
53
+ /** by default, the WebSocket URL passed in when the instance is initialized is used */
50
54
  ws_url?: string
51
55
 
52
- /** 是否在建立连接后自动登录,默认 true */
56
+ /** whether to automatically log in after the connection is established, the default is true */
53
57
  login?: boolean
54
58
 
55
- /** DolphinDB 登录用户名 */
59
+ /** DolphinDB username */
56
60
  username?: string
57
61
 
58
- /** DolphinDB 登录密码 */
62
+ /** DolphinDB password */
59
63
  password?: string
60
64
  } = { }
61
65
  ): Promise<void>
62
66
  ```
63
67
 
64
68
 
65
- ### 1. 调用函数
66
- #### 例子
69
+ ### 1. Call Functions
70
+ #### Example
67
71
  ```ts
68
72
  import { DdbInt } from 'dolphindb'
69
73
 
@@ -72,52 +76,52 @@ const result = await ddb.call<DdbInt>('add', [new DdbInt(1), new DdbInt(1)])
72
76
  console.log(result.value === 2) // true
73
77
  ```
74
78
 
75
- #### DolphinDB JavaScript API 用 DdbObj 对象来表示 DolphinDB 中的数据类型
76
- 上面例子中,上传了两个参数 1 (对应 DolphinDB 中的 int 类型) 到 DolphinDB 数据库,作为 add 函数的参数,并接收函数调用的结果 result
79
+ #### The DolphinDB JavaScript API uses DdbObj objects to represent data types in DolphinDB
80
+ In the above example, two parameters 1 (corresponding to the int type in DolphinDB) are uploaded to the DolphinDB database as parameters of the add function, then the result of the function call is received.
77
81
 
78
- `<DdbInt>` 用于 TypeScript 推断返回值的类型
82
+ `<DdbInt>` is used by TypeScript to infer the type of the return value
79
83
 
80
- - result 是一个 `DdbInt`,也是 `DdbObj<number>`
81
- - result.form 是 `DdbForm.scalar`
82
- - result.type 是 `DdbType.int`
83
- - result.value 是 JavaScript 中原生的 `number` (int 的取值范围及精度可以用 JavaScript 的 number 准确表示)
84
+ - result is a `DdbInt`, which is also a `DdbObj<number>`
85
+ - result.form is a `DdbForm.scalar`
86
+ - result.type is a `DdbType.int`
87
+ - result.value is native `number` in JavaScript (the value range and precision of int can be accurately represented by JavaScript number)
84
88
 
85
89
  ```ts
86
- /** 可以表示所有 DolphinDB 数据库中的数据 */
90
+ /** Can represent all data types in DolphinDB databases */
87
91
  class DdbObj <T extends DdbValue = DdbValue> {
88
- /** 是否为小端 (little endian) */
92
+ /** is it little endian */
89
93
  le: boolean
90
94
 
91
- /** 数据形式 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataForms/index.html */
95
+ /** data form https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataForms/index.html */
92
96
  form: DdbForm
93
97
 
94
- /** 数据类型 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataTypes/index.html */
98
+ /** data type https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataTypes/index.html */
95
99
  type: DdbType
96
100
 
97
- /** 占用 parse 时传入的 buf 的长度 */
101
+ /** consumed length in buf parsed */
98
102
  length: number
99
103
 
100
104
  /** table name / column name */
101
105
  name?: string
102
106
 
103
107
  /**
104
- 最低维、第 1 维
108
+ Lowest dimension
105
109
  - vector: rows = n, cols = 1
106
110
  - pair: rows = 2, cols = 1
107
111
  - matrix: rows = n, cols = m
108
- - set: 同 vector
109
- - dict: 包含 keys, values 向量
110
- - table: 同 matrix
112
+ - set: the same as vector
113
+ - dict: include keys, values vector
114
+ - table: the same as matrix
111
115
  */
112
116
  rows?: number
113
117
 
114
- /** 第 2 维 */
118
+ /** 2nd dimension */
115
119
  cols?: number
116
120
 
117
- /** matrix 中值的类型,仅 matrix 才有 */
121
+ /** the type of the value in matrix (only matrix has this field) */
118
122
  datatype?: DdbType
119
123
 
120
- /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
124
+ /** the actual data. Different DdbForm, DdbType use different types in DdbValue to represent actual data */
121
125
  value: T
122
126
 
123
127
  constructor (data: Partial<DdbObj> & { form: DdbForm, type: DdbType, length: number }) {
@@ -136,7 +140,7 @@ class DdbInt extends DdbObj<number> {
136
140
  }
137
141
  }
138
142
 
139
- // ... 还有很多快捷类,如 DdbString, DdbLong, DdbDouble, DdbVectorDouble, DdbVectorAny 等
143
+ // ... There are also many utility classes, such as DdbString, DdbLong, DdbDouble, DdbVectorDouble, DdbVectorAny, etc.
140
144
 
141
145
  type DdbValue =
142
146
  null | boolean | number | [number, number] | bigint | string | string[] |
@@ -174,38 +178,38 @@ enum DdbType {
174
178
  }
175
179
  ```
176
180
 
177
- #### call 方法声明
181
+ #### `call` Method Declaration
178
182
  ```ts
179
183
  async call <T extends DdbObj> (
180
- /** 函数名 */
184
+ /** function name */
181
185
  func: string,
182
186
 
183
- /** 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>) */
187
+ /** function arguments (The incoming native string and boolean will be automatically converted to DdbObj<string> and DdbObj<boolean>) */
184
188
  args?: (DdbObj | string | boolean)[] = [ ],
185
189
 
186
- /** 调用选项 */
190
+ /** calling options */
187
191
  options?: {
188
- /** 紧急 flag,使用 urgent worker 处理,防止被其它作业阻塞 */
192
+ /** Urgent flag. Use urgent worker to execute to prevent being blocked by other jobs */
189
193
  urgent?: boolean
190
194
 
191
- /** 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法) */
195
+ /** When the node alias is set, the function is sent to the corresponding node in the cluster for execution (using the rpc method in DolphinDB) */
192
196
  node?: string
193
197
 
194
- /** 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法) */
198
+ /** When setting multiple node aliases, send them to the corresponding multiple nodes in the cluster for execution (using the pnodeRun method in DolphinDB) */
195
199
  nodes?: string[]
196
200
 
197
- /** 设置 node 参数时必传,需指定函数类型,其它情况下不传 */
201
+ /** It must be passed when setting the node parameter, the function type needs to be specified, and it is not passed in other cases */
198
202
  func_type?: DdbFunctionType
199
203
 
200
- /** 设置 nodes 参数时选传,其它情况不传 */
204
+ /** It may be passed when setting the nodes parameter, otherwise may not be passed */
201
205
  add_node_alias?: boolean
202
206
  } = { }
203
207
  ): Promise<T>
204
208
  ```
205
209
 
206
210
 
207
- ### 2. 执行脚本
208
- #### 例子
211
+ ### 2. Execute Script
212
+ #### Example
209
213
  ```ts
210
214
  import type { DdbLong } from 'dolphindb'
211
215
 
@@ -219,34 +223,34 @@ const result = await ddb.eval<DdbLong>(
219
223
  console.log(result.value === 2n) // true
220
224
  ```
221
225
 
222
- 上面例子中,通过字符串上传了一段脚本到 DolphinDB 数据库执行,并接收最后一条语句 `foo(1l, 1l)` 执行结果 result
226
+ In the above example, a script is uploaded through a string to the DolphinDB database for execution, and the execution result of the last statement `foo(1l, 1l)` is received.
223
227
 
224
- `<DdbInt>` 用于 TypeScript 推断返回值的类型
228
+ `<DdbLong>` is used by TypeScript to infer the type of the return value
225
229
 
226
- - result 是一个 `DdbLong`,也是 `DdbObj<bigint>`
227
- - result.form 是 `DdbForm.scalar`
228
- - result.type 是 `DdbType.long`
229
- - result.value 是 JavaScript 中原生的 `bigint` (long 的精度不能用 JavaScript 的 number 准确表示,但可以用 bigint 表示)
230
+ - result is a `DdbLong`, which is also a `DdbObj<bigint>`
231
+ - result.form is `DdbForm.scalar`
232
+ - result.type is `DdbType.long`
233
+ - result.value is the native `bigint` in JavaScript (the precision of long cannot be accurately represented by JavaScript number, but it can be represented by bigint)
230
234
 
231
- 只要 WebSocket 连接不断开,在后续的会话中 `foo` 这个自定义函数会一直存在,可复用,比如后续通过 `await ddb.call<DdbInt>('foo', [new DdbInt(1), new DdbInt(1)])` 调用这个自定义函数
235
+ As long as the WebSocket connection is not disconnected, the custom function `foo` will always exist in the subsequent session and can be reused, for example, you can use `await ddb.call<DdbInt>('foo', [new DdbInt(1), new DdbInt(1)])` to call this custom function
232
236
 
233
- #### eval 方法声明
237
+ #### `eval` Method Declaration
234
238
  ```ts
235
239
  async eval <T extends DdbObj> (
236
- /** 执行的脚本 */
240
+ /** the script to execute */
237
241
  script: string,
238
242
 
239
- /** 执行选项 */
243
+ /** calling options */
240
244
  options: {
241
- /** 紧急 flag,使用 urgent worker 处理,防止被其它作业阻塞 */
245
+ /** Urgent flag. Use urgent worker to execute to prevent being blocked by other jobs */
242
246
  urgent?: boolean
243
247
  } = { }
244
248
  ): Promise<T>
245
249
  ```
246
250
 
247
251
 
248
- ### 3. 上传变量
249
- #### 例子
252
+ ### 3. Upload Variables
253
+ #### Example
250
254
  ```ts
251
255
  import { DdbVectorDouble } from 'dolphindb'
252
256
 
@@ -256,17 +260,17 @@ a.fill(1.0)
256
260
  ddb.upload(['bar1', 'bar2'], [new DdbVectorDouble(a), new DdbVectorDouble(a)])
257
261
  ```
258
262
 
259
- 上面的例子中,上传了 `bar1`, `bar2` 两个变量,变量值是长度为 10000 的 double 向量
263
+ In the above example, two variables `bar1`, `bar2` are uploaded, and the variable value is a double vector of length 10000
260
264
 
261
- 只要 WebSocket 连接不断开,在后续的会话中 `bar1`, `bar2` 这些变量会一直存在,可复用
265
+ As long as the WebSocket connection is not disconnected, the variables `bar1`, `bar2` will always exist in the subsequent session and can be reused
262
266
 
263
- #### upload 方法声明
267
+ #### `upload` Method Declaration
264
268
  ```ts
265
269
  async upload (
266
- /** 上传的变量名 */
270
+ /** variable names */
267
271
  vars: string[],
268
272
 
269
- /** 上传的变量值 */
273
+ /** variable values */
270
274
  args: (DdbObj | string | boolean)[]
271
275
  ): Promise<void>
272
276
  ```
package/README.zh.md ADDED
@@ -0,0 +1,277 @@
1
+ # DolphinDB JavaScript API
2
+
3
+ <p align='center'>
4
+ <img src='./ddb.svg' alt='DolphinDB' width='256'>
5
+ </p>
6
+
7
+ <p align='center'>
8
+ <a href='https://www.npmjs.com/package/dolphindb' target='_blank'>
9
+ <img alt='npm version' src='https://img.shields.io/npm/v/dolphindb.svg?style=flat-square&color=brightgreen' />
10
+ </a>
11
+ <a href='https://www.npmjs.com/package/dolphindb' target='_blank'>
12
+ <img alt='npm downloads' src='https://img.shields.io/npm/dt/dolphindb?style=flat-square&color=brightgreen' />
13
+ </a>
14
+ </p>
15
+
16
+ ## [English](./README.md) | 中文
17
+
18
+ ## 简介
19
+ DolphinDB JavaScript API 是一个 JavaScript 库,封装了操作 DolphinDB 数据库的能力,如:连接数据库、执行脚本、调用函数、上传变量等
20
+
21
+ https://www.npmjs.com/package/dolphindb
22
+
23
+ ## 特性
24
+ - 使用 WebSocket 与 DolphinDB 数据库通信,用二进制格式进行数据交换
25
+ - 支持在浏览器环境和 Node.js 环境中运行
26
+ - 使用了 JavaScript 中的 Int32Array 等 TypedArray 处理二进制数据,性能较高
27
+ - 单次调用支持最大 2 GB 数据的序列化上传,下载数据量不受限制
28
+
29
+ ## 安装
30
+ ```bash
31
+ # 在机器上安装最新版的 Node.js 及浏览器
32
+
33
+ # 在项目中安装 npm 包
34
+ npm install dolphindb
35
+ ```
36
+
37
+ ## 用法
38
+ ### 0. 初始化并连接到 DolphinDB
39
+ ```ts
40
+ import DDB from 'dolphindb'
41
+
42
+ // 创建数据库对象,初始化 WebSocket 连接地址
43
+ let ddb = new DDB('ws://127.0.0.1:8848')
44
+
45
+ // 建立到 DolphinDB 的 WebSocket 连接(要求 DolphinDB 数据库版本不低于 1.30.16 或 2.00.4)
46
+ await ddb.connect()
47
+ ```
48
+
49
+ #### connect 方法声明
50
+ ```ts
51
+ async connect (
52
+ options?: {
53
+ /** 默认使用实例初始化时传入的 WebSocket 链接 */
54
+ ws_url?: string
55
+
56
+ /** 是否在建立连接后自动登录,默认 true */
57
+ login?: boolean
58
+
59
+ /** DolphinDB 登录用户名 */
60
+ username?: string
61
+
62
+ /** DolphinDB 登录密码 */
63
+ password?: string
64
+ } = { }
65
+ ): Promise<void>
66
+ ```
67
+
68
+
69
+ ### 1. 调用函数
70
+ #### 例子
71
+ ```ts
72
+ import { DdbInt } from 'dolphindb'
73
+
74
+ const result = await ddb.call<DdbInt>('add', [new DdbInt(1), new DdbInt(1)])
75
+
76
+ console.log(result.value === 2) // true
77
+ ```
78
+
79
+ #### DolphinDB JavaScript API 用 DdbObj 对象来表示 DolphinDB 中的数据类型
80
+ 上面例子中,上传了两个参数 1 (对应 DolphinDB 中的 int 类型) 到 DolphinDB 数据库,作为 add 函数的参数,并接收函数调用的结果 result
81
+
82
+ `<DdbInt>` 用于 TypeScript 推断返回值的类型
83
+
84
+ - result 是一个 `DdbInt`,也是 `DdbObj<number>`
85
+ - result.form 是 `DdbForm.scalar`
86
+ - result.type 是 `DdbType.int`
87
+ - result.value 是 JavaScript 中原生的 `number` (int 的取值范围及精度可以用 JavaScript 的 number 准确表示)
88
+
89
+ ```ts
90
+ /** 可以表示所有 DolphinDB 数据库中的数据类型 */
91
+ class DdbObj <T extends DdbValue = DdbValue> {
92
+ /** 是否为小端 (little endian) */
93
+ le: boolean
94
+
95
+ /** 数据形式 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataForms/index.html */
96
+ form: DdbForm
97
+
98
+ /** 数据类型 https://www.dolphindb.cn/cn/help/DataTypesandStructures/DataTypes/index.html */
99
+ type: DdbType
100
+
101
+ /** 占用 parse 时传入的 buf 的长度 */
102
+ length: number
103
+
104
+ /** table name / column name */
105
+ name?: string
106
+
107
+ /**
108
+ 最低维、第 1 维
109
+ - vector: rows = n, cols = 1
110
+ - pair: rows = 2, cols = 1
111
+ - matrix: rows = n, cols = m
112
+ - set: 同 vector
113
+ - dict: 包含 keys, values 向量
114
+ - table: 同 matrix
115
+ */
116
+ rows?: number
117
+
118
+ /** 第 2 维 */
119
+ cols?: number
120
+
121
+ /** matrix 中值的类型,仅 matrix 才有 */
122
+ datatype?: DdbType
123
+
124
+ /** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
125
+ value: T
126
+
127
+ constructor (data: Partial<DdbObj> & { form: DdbForm, type: DdbType, length: number }) {
128
+ Object.assign(this, data)
129
+ }
130
+ }
131
+
132
+ class DdbInt extends DdbObj<number> {
133
+ constructor (value: number) {
134
+ super({
135
+ form: DdbForm.scalar,
136
+ type: DdbType.int,
137
+ length: 4,
138
+ value
139
+ })
140
+ }
141
+ }
142
+
143
+ // ... 还有很多快捷类,如 DdbString, DdbLong, DdbDouble, DdbVectorDouble, DdbVectorAny 等
144
+
145
+ type DdbValue =
146
+ null | boolean | number | [number, number] | bigint | string | string[] |
147
+ Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] |
148
+ DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue
149
+
150
+
151
+ enum DdbForm {
152
+ scalar = 0,
153
+ vector = 1,
154
+ pair = 2,
155
+ matrix = 3,
156
+ set = 4,
157
+ dict = 5,
158
+ table = 6,
159
+ chart = 7,
160
+ chunk = 8,
161
+ }
162
+
163
+
164
+ enum DdbType {
165
+ void = 0,
166
+ bool = 1,
167
+ char = 2,
168
+ short = 3,
169
+ int = 4,
170
+ long = 5,
171
+ // ...
172
+ timestamp = 12,
173
+ // ...
174
+ double = 16,
175
+ symbol = 17,
176
+ string = 18,
177
+ // ...
178
+ }
179
+ ```
180
+
181
+ #### `call` 方法声明
182
+ ```ts
183
+ async call <T extends DdbObj> (
184
+ /** 函数名 */
185
+ func: string,
186
+
187
+ /** 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>) */
188
+ args?: (DdbObj | string | boolean)[] = [ ],
189
+
190
+ /** 调用选项 */
191
+ options?: {
192
+ /** 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞 */
193
+ urgent?: boolean
194
+
195
+ /** 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法) */
196
+ node?: string
197
+
198
+ /** 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法) */
199
+ nodes?: string[]
200
+
201
+ /** 设置 node 参数时必传,需指定函数类型,其它情况下不传 */
202
+ func_type?: DdbFunctionType
203
+
204
+ /** 设置 nodes 参数时选传,其它情况不传 */
205
+ add_node_alias?: boolean
206
+ } = { }
207
+ ): Promise<T>
208
+ ```
209
+
210
+
211
+ ### 2. 执行脚本
212
+ #### 例子
213
+ ```ts
214
+ import type { DdbLong } from 'dolphindb'
215
+
216
+ const result = await ddb.eval<DdbLong>(
217
+ 'def foo (a, b) {\n' +
218
+ ' return a + b\n' +
219
+ '}\n' +
220
+ 'foo(1l, 1l)\n'
221
+ )
222
+
223
+ console.log(result.value === 2n) // true
224
+ ```
225
+
226
+ 上面例子中,通过字符串上传了一段脚本到 DolphinDB 数据库执行,并接收最后一条语句 `foo(1l, 1l)` 执行结果 result
227
+
228
+ `<DdbLong>` 用于 TypeScript 推断返回值的类型
229
+
230
+ - result 是一个 `DdbLong`,也是 `DdbObj<bigint>`
231
+ - result.form 是 `DdbForm.scalar`
232
+ - result.type 是 `DdbType.long`
233
+ - result.value 是 JavaScript 中原生的 `bigint` (long 的精度不能用 JavaScript 的 number 准确表示,但可以用 bigint 表示)
234
+
235
+ 只要 WebSocket 连接不断开,在后续的会话中 `foo` 这个自定义函数会一直存在,可复用,比如后续通过 `await ddb.call<DdbInt>('foo', [new DdbInt(1), new DdbInt(1)])` 调用这个自定义函数
236
+
237
+ #### `eval` 方法声明
238
+ ```ts
239
+ async eval <T extends DdbObj> (
240
+ /** 执行的脚本 */
241
+ script: string,
242
+
243
+ /** 执行选项 */
244
+ options: {
245
+ /** 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞 */
246
+ urgent?: boolean
247
+ } = { }
248
+ ): Promise<T>
249
+ ```
250
+
251
+
252
+ ### 3. 上传变量
253
+ #### 例子
254
+ ```ts
255
+ import { DdbVectorDouble } from 'dolphindb'
256
+
257
+ let a = new Array(10000)
258
+ a.fill(1.0)
259
+
260
+ ddb.upload(['bar1', 'bar2'], [new DdbVectorDouble(a), new DdbVectorDouble(a)])
261
+ ```
262
+
263
+ 上面的例子中,上传了 `bar1`, `bar2` 两个变量,变量值是长度为 10000 的 double 向量
264
+
265
+ 只要 WebSocket 连接不断开,在后续的会话中 `bar1`, `bar2` 这些变量会一直存在,可复用
266
+
267
+ #### `upload` 方法声明
268
+ ```ts
269
+ async upload (
270
+ /** 上传的变量名 */
271
+ vars: string[],
272
+
273
+ /** 上传的变量值 */
274
+ args: (DdbObj | string | boolean)[]
275
+ ): Promise<void>
276
+ ```
277
+
package/browser.d.ts CHANGED
@@ -66,16 +66,24 @@ export interface DdbFunctionDefValue {
66
66
  export interface DdbSymbolExtendedValue {
67
67
  base_id: number;
68
68
  base: string[];
69
- value: Uint32Array;
69
+ data: Uint32Array;
70
70
  }
71
- export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue;
72
- export declare type DdbVectorValue = string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue;
71
+ export interface DdbArrayVectorBlock {
72
+ unit: 1 | 2 | 4;
73
+ rows: number;
74
+ lengths: Uint8Array | Uint16Array | Uint32Array;
75
+ data: DdbVectorValue;
76
+ }
77
+ export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
78
+ export declare type DdbVectorValue = string | string[] | Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
73
79
  export declare const nulls: {
74
80
  readonly char: "€";
75
81
  readonly int16: -32768;
76
82
  readonly int32: -2147483648;
77
83
  readonly int64: -9223372036854775808n;
78
84
  };
85
+ export declare const timezone_offset: number;
86
+ /** 可以表示所有 DolphinDB 数据库中的数据类型 */
79
87
  export declare class DdbObj<T extends DdbValue = DdbValue> {
80
88
  static dec: TextDecoder;
81
89
  static enc: TextEncoder;
@@ -130,6 +138,10 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
130
138
  toString(): string;
131
139
  to_cols(): any[];
132
140
  to_rows<T extends Record<string, any> = Record<string, any>>(): T[];
141
+ to_dict<T = Record<string, any>>(): T;
142
+ }
143
+ export declare class DdbVoid extends DdbObj<undefined> {
144
+ constructor();
133
145
  }
134
146
  export declare class DdbBool extends DdbObj<boolean> {
135
147
  constructor(value: boolean);
@@ -164,6 +176,8 @@ export declare class DdbPair extends DdbObj<Int32Array> {
164
176
  export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
165
177
  constructor(name: string, type: DdbFunctionType);
166
178
  }
179
+ export declare function date2str(date: number): string;
180
+ export declare function timestamp2str(timestamp: bigint): string;
167
181
  export declare class DDB {
168
182
  /** 当前的 session id (http 或 tcp) */
169
183
  sid: string;
@@ -183,7 +197,7 @@ export declare class DDB {
183
197
  constructor(ws_url?: string);
184
198
  /** 连接到 DolphinDB Server */
185
199
  connect({ ws_url, login, username, password, }?: {
186
- /** 默认使用实例初始化时传入的 WebSocket 链接地址 */
200
+ /** 默认使用实例初始化时传入的 WebSocket 链接 */
187
201
  ws_url?: string;
188
202
  /** 是否在建立连接后自动登录,默认 true */
189
203
  login?: boolean;
@@ -193,7 +207,7 @@ export declare class DDB {
193
207
  password?: string;
194
208
  }): Promise<void>;
195
209
  disconnect(): void;
196
- /** rpc through websocket (function command)
210
+ /** rpc through websocket (function/script/variable command)
197
211
  - type: API 类型: 'script' | 'function' | 'variable'
198
212
  - options:
199
213
  - urgent?: 决定 `行为标识` 那一行字符串的取值(只适用于 script 和 function)
@@ -212,14 +226,14 @@ export declare class DDB {
212
226
  script: string,
213
227
  /** 执行选项 */
214
228
  { urgent }?: {
215
- /** 紧急 flag,使用 urgent worker 处理,防止被其它作业阻塞 */
229
+ /** 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞 */
216
230
  urgent?: boolean;
217
231
  }): Promise<T>;
218
232
  /** call function through websocket (function command)
219
233
  - func: 函数名
220
234
  - args?: `[ ]` 调用参数 (传入的原生 string 和 boolean 会被自动转换为 DdbObj<string> 和 DdbObj<boolean>)
221
235
  - options?: 调用选项
222
- - urgent?: 紧急 flag,使用 urgent worker 处理,防止被其它作业阻塞
236
+ - urgent?: 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞
223
237
  - node?: 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法)
224
238
  - nodes?: 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法)
225
239
  - func_type?: 设置 node 参数时必传,需指定函数类型,其它情况下不传