dolphindb 3.0.21 → 3.0.22
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/README.zh.md +98 -13
- package/browser.js +9 -3
- package/browser.js.map +1 -1
- package/index.js +9 -3
- package/index.js.map +1 -1
- package/package.json +2 -2
package/README.zh.md
CHANGED
|
@@ -49,7 +49,7 @@ https://www.npmjs.com/package/dolphindb
|
|
|
49
49
|
await ddb.connect()
|
|
50
50
|
|
|
51
51
|
console.log(
|
|
52
|
-
await ddb.
|
|
52
|
+
await ddb.execute('1 + 1')
|
|
53
53
|
)
|
|
54
54
|
</script>
|
|
55
55
|
</body>
|
|
@@ -127,7 +127,54 @@ let ddb = new DDB('ws://127.0.0.1:8848', {
|
|
|
127
127
|
|
|
128
128
|
|
|
129
129
|
### 调用函数
|
|
130
|
-
####
|
|
130
|
+
#### `invoke` 方法
|
|
131
|
+
##### `invoke` 方法代码示例
|
|
132
|
+
```ts
|
|
133
|
+
const result = await ddb.invoke('add', [1, 1])
|
|
134
|
+
// TypeScript: const result = await ddb.invoke<number>('add', [1, 1])
|
|
135
|
+
|
|
136
|
+
console.log(result === 2) // true
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
上面例子中,上传了两个参数 1 (对应 DolphinDB 中的 int 类型) 到 DolphinDB 数据库,作为 add 函数的参数,并接收函数调用的结果 result
|
|
140
|
+
|
|
141
|
+
`<number>` 用于 TypeScript 推断返回值的类型
|
|
142
|
+
|
|
143
|
+
##### `invoke` 方法声明
|
|
144
|
+
```ts
|
|
145
|
+
/** 调用 dolphindb 函数,传入 js 原生数组作为参数,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)*/
|
|
146
|
+
async invoke <TResult = any> (
|
|
147
|
+
/** 函数名 */
|
|
148
|
+
func: string,
|
|
149
|
+
|
|
150
|
+
/** `[ ]` 调用参数,可以是 js 原生数组 */
|
|
151
|
+
args?: any[],
|
|
152
|
+
|
|
153
|
+
/** 调用选项 */
|
|
154
|
+
options?: {
|
|
155
|
+
/** 紧急 flag。使用 urgent worker 执行,防止被其它作业阻塞 */
|
|
156
|
+
urgent?: boolean
|
|
157
|
+
|
|
158
|
+
/** 设置结点 alias 时发送到集群中对应的结点执行 (使用 DolphinDB 中的 rpc 方法) */
|
|
159
|
+
node?: string
|
|
160
|
+
|
|
161
|
+
/** 设置多个结点 alias 时发送到集群中对应的多个结点执行 (使用 DolphinDB 中的 pnodeRun 方法) */
|
|
162
|
+
nodes?: string[]
|
|
163
|
+
|
|
164
|
+
/** 设置 node 参数且参数数组为空时必传,需指定函数类型,其它情况下不传 */
|
|
165
|
+
func_type?: DdbFunctionType
|
|
166
|
+
|
|
167
|
+
/** 设置 nodes 参数时选传,其它情况不传 */
|
|
168
|
+
add_node_alias?: boolean
|
|
169
|
+
|
|
170
|
+
/** 处理本次 rpc 期间的消息 (DdbMessage) */
|
|
171
|
+
listener?: DdbMessageListener
|
|
172
|
+
} = { }
|
|
173
|
+
): Promise<TResult>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### `call` 方法
|
|
177
|
+
##### `call` 方法代码示例
|
|
131
178
|
```ts
|
|
132
179
|
import { DdbInt } from 'dolphindb'
|
|
133
180
|
|
|
@@ -137,7 +184,7 @@ const result = await ddb.call('add', [new DdbInt(1), new DdbInt(1)])
|
|
|
137
184
|
console.log(result.value === 2) // true
|
|
138
185
|
```
|
|
139
186
|
|
|
140
|
-
|
|
187
|
+
###### 用 DdbObj 对象来表示 DolphinDB 中的数据类型
|
|
141
188
|
|
|
142
189
|
上面例子中,上传了两个参数 1 (对应 DolphinDB 中的 int 类型) 到 DolphinDB 数据库,作为 add 函数的参数,并接收函数调用的结果 result
|
|
143
190
|
|
|
@@ -244,7 +291,7 @@ enum DdbType {
|
|
|
244
291
|
}
|
|
245
292
|
```
|
|
246
293
|
|
|
247
|
-
|
|
294
|
+
###### 无快捷类的类型
|
|
248
295
|
|
|
249
296
|
对于没有快捷类的类型,可指定 form 和 type 手动创建 DdbObj 对象
|
|
250
297
|
|
|
@@ -284,7 +331,7 @@ const obj = new DdbSetInt(
|
|
|
284
331
|
)
|
|
285
332
|
```
|
|
286
333
|
|
|
287
|
-
|
|
334
|
+
###### scalar 形式的 NULL 对象
|
|
288
335
|
|
|
289
336
|
scalar 形式的 NULL 对象,其对应 DdbObj 的 value 为 JavaScript 中的 null:
|
|
290
337
|
|
|
@@ -296,8 +343,7 @@ new DdbInt(null)
|
|
|
296
343
|
new DdbDouble(null)
|
|
297
344
|
```
|
|
298
345
|
|
|
299
|
-
|
|
300
|
-
#### `call` 方法声明
|
|
346
|
+
##### `call` 方法声明
|
|
301
347
|
```ts
|
|
302
348
|
async call <T extends DdbObj> (
|
|
303
349
|
/** 函数名 */
|
|
@@ -326,9 +372,50 @@ async call <T extends DdbObj> (
|
|
|
326
372
|
): Promise<T>
|
|
327
373
|
```
|
|
328
374
|
|
|
329
|
-
|
|
330
375
|
### 执行脚本
|
|
331
|
-
####
|
|
376
|
+
#### `execute` 方法
|
|
377
|
+
##### `execute` 方法代码示例
|
|
378
|
+
```ts
|
|
379
|
+
const result = await ddb.execute(
|
|
380
|
+
'def foo (a, b) {\n' +
|
|
381
|
+
' return a + b\n' +
|
|
382
|
+
'}\n' +
|
|
383
|
+
'foo(1l, 1l)\n'
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
// TypeScript:
|
|
387
|
+
// const result = await ddb.execute<bigint>(...)
|
|
388
|
+
|
|
389
|
+
console.log(result.value === 2n) // true
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
上面例子中,通过字符串上传了一段脚本到 DolphinDB 数据库执行,并接收最后一条语句 `foo(1l, 1l)` 执行结果 result
|
|
393
|
+
|
|
394
|
+
`<bigint>` 用于 TypeScript 推断返回值的类型
|
|
395
|
+
|
|
396
|
+
- result 是一个 `bigint`
|
|
397
|
+
|
|
398
|
+
只要 WebSocket 连接不断开,在后续的会话中 `foo` 这个自定义函数会一直存在,可复用,比如后续通过 `await ddb.call<DdbInt>('foo', [new DdbInt(1), new DdbInt(1)])` 调用这个自定义函数
|
|
399
|
+
|
|
400
|
+
##### `execute` 方法声明
|
|
401
|
+
```ts
|
|
402
|
+
/** 执行 dolphindb 脚本,返回 js 原生对象或值(调用 DdbObj.data() 后的结果)*/
|
|
403
|
+
async execute <TResult = any> (
|
|
404
|
+
/** 执行的脚本 */
|
|
405
|
+
script: string,
|
|
406
|
+
|
|
407
|
+
/** 执行选项 */
|
|
408
|
+
options?: {
|
|
409
|
+
/** 紧急 flag,确保提交的脚本使用 urgent worker 处理,防止被其它作业阻塞 */
|
|
410
|
+
urgent?: boolean
|
|
411
|
+
/** listener?: 处理本次 rpc 期间的消息 (DdbMessage) */
|
|
412
|
+
listener?: DdbMessageListener
|
|
413
|
+
}
|
|
414
|
+
): Promise<TResult>
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
#### `eval` 方法
|
|
418
|
+
##### `eval` 方法代码示例
|
|
332
419
|
```ts
|
|
333
420
|
const result = await ddb.eval(
|
|
334
421
|
'def foo (a, b) {\n' +
|
|
@@ -353,10 +440,9 @@ console.log(result.value === 2n) // true
|
|
|
353
440
|
- result.type 是 `DdbType.long`
|
|
354
441
|
- result.value 是 JavaScript 中原生的 `bigint` (long 的精度不能用 JavaScript 的 number 准确表示,但可以用 bigint 表示)
|
|
355
442
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
#### `eval` 方法声明
|
|
443
|
+
##### `eval` 方法声明
|
|
359
444
|
```ts
|
|
445
|
+
/** 执行 dolphindb 脚本,返回 DdbObj 对象)*/
|
|
360
446
|
async eval <T extends DdbObj> (
|
|
361
447
|
/** 执行的脚本 */
|
|
362
448
|
script: string,
|
|
@@ -369,7 +455,6 @@ async eval <T extends DdbObj> (
|
|
|
369
455
|
): Promise<T>
|
|
370
456
|
```
|
|
371
457
|
|
|
372
|
-
|
|
373
458
|
### 上传变量
|
|
374
459
|
#### 例子
|
|
375
460
|
```ts
|
package/browser.js
CHANGED
|
@@ -1876,9 +1876,7 @@ export function converts(type, value, rows, le) {
|
|
|
1876
1876
|
case DdbType.decimal64:
|
|
1877
1877
|
case DdbType.decimal128: {
|
|
1878
1878
|
const { scale, data } = value;
|
|
1879
|
-
|
|
1880
|
-
return seq(rows, i => {
|
|
1881
|
-
const x = data[i];
|
|
1879
|
+
return Array.prototype.map.call(data, (x) => {
|
|
1882
1880
|
if (is_decimal_null_value(type, x))
|
|
1883
1881
|
return '';
|
|
1884
1882
|
const s = String(x < 0 ? -x : x).padStart(scale, '0');
|
|
@@ -3206,6 +3204,14 @@ export class BigInt128Array {
|
|
|
3206
3204
|
return true;
|
|
3207
3205
|
}
|
|
3208
3206
|
return Reflect.set(target, key, value);
|
|
3207
|
+
},
|
|
3208
|
+
has(target, key) {
|
|
3209
|
+
if (typeof key === 'string') {
|
|
3210
|
+
const index = Number(key);
|
|
3211
|
+
if (Number.isInteger(index) && index >= 0 && index < target.length)
|
|
3212
|
+
return true;
|
|
3213
|
+
}
|
|
3214
|
+
return Reflect.has(target, key);
|
|
3209
3215
|
}
|
|
3210
3216
|
});
|
|
3211
3217
|
}
|