dolphindb 2.0.1000 → 2.0.1002
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.md +14 -0
- package/README.zh.md +15 -0
- package/browser.d.ts +10 -0
- package/browser.js +26 -12
- package/browser.js.map +1 -1
- package/docs.zh.json +4106 -337
- package/index.d.ts +10 -0
- package/index.js +26 -12
- package/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ npm install dolphindb
|
|
|
43
43
|
|
|
44
44
|
## Usage
|
|
45
45
|
### 0. Initialize and connect to DolphinDB
|
|
46
|
+
#### NPM
|
|
46
47
|
```ts
|
|
47
48
|
import { DDB } from 'dolphindb'
|
|
48
49
|
// The import method for existing projects using CommonJS modules is const { DDB } = await import('dolphindb')
|
|
@@ -58,6 +59,19 @@ let ddb = new DDB('ws://127.0.0.1:8848')
|
|
|
58
59
|
await ddb.connect()
|
|
59
60
|
```
|
|
60
61
|
|
|
62
|
+
#### CDN
|
|
63
|
+
```html
|
|
64
|
+
<script src="https://cdn.dolphindb.cn/assets/api.umd.js"></script>
|
|
65
|
+
<script>
|
|
66
|
+
let ddb = new dolphindb.DDB('ws://127.0.0.1:8848')
|
|
67
|
+
console.log(ddb)
|
|
68
|
+
</script>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Code completion, function prompt data:
|
|
72
|
+
https://cdn.dolphindb.cn/assets/docs.zh.json
|
|
73
|
+
https://cdn.dolphindb.cn/assets/docs.en.json
|
|
74
|
+
|
|
61
75
|
#### DDB options
|
|
62
76
|
```ts
|
|
63
77
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
package/README.zh.md
CHANGED
|
@@ -43,6 +43,7 @@ npm install dolphindb
|
|
|
43
43
|
|
|
44
44
|
## 用法
|
|
45
45
|
### 0. 初始化并连接到 DolphinDB
|
|
46
|
+
#### NPM
|
|
46
47
|
```ts
|
|
47
48
|
import { DDB } from 'dolphindb'
|
|
48
49
|
// 已有的使用 CommonJS 模块的项目的导入方法为 const { DDB } = await import('dolphindb')
|
|
@@ -58,6 +59,20 @@ let ddb = new DDB('ws://127.0.0.1:8848')
|
|
|
58
59
|
await ddb.connect()
|
|
59
60
|
```
|
|
60
61
|
|
|
62
|
+
#### CDN
|
|
63
|
+
```html
|
|
64
|
+
<script src="https://cdn.dolphindb.cn/assets/api.umd.js"></script>
|
|
65
|
+
<script>
|
|
66
|
+
let ddb = new dolphindb.DDB('ws://127.0.0.1:8848')
|
|
67
|
+
console.log(ddb)
|
|
68
|
+
</script>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
代码补全、函数提示数据:
|
|
72
|
+
https://cdn.dolphindb.cn/assets/docs.zh.json
|
|
73
|
+
https://cdn.dolphindb.cn/assets/docs.en.json
|
|
74
|
+
|
|
75
|
+
|
|
61
76
|
#### DDB 选项
|
|
62
77
|
```ts
|
|
63
78
|
let ddb = new DDB('ws://127.0.0.1:8848', {
|
package/browser.d.ts
CHANGED
|
@@ -384,11 +384,18 @@ export declare class DdbDatabaseError extends Error {
|
|
|
384
384
|
options: DdbRpcOptions;
|
|
385
385
|
constructor(message: string, ddb: DDB, type: DdbRpcType, options: DdbRpcOptions);
|
|
386
386
|
}
|
|
387
|
+
/** SQL Standrd 标准类型 */
|
|
388
|
+
export declare enum SqlStandard {
|
|
389
|
+
DolphinDB = 0,
|
|
390
|
+
Oracle = 1,
|
|
391
|
+
MySQL = 2
|
|
392
|
+
}
|
|
387
393
|
export interface DdbOptions {
|
|
388
394
|
autologin?: boolean;
|
|
389
395
|
username?: string;
|
|
390
396
|
password?: string;
|
|
391
397
|
python?: boolean;
|
|
398
|
+
sql?: SqlStandard;
|
|
392
399
|
streaming?: StreamingParams;
|
|
393
400
|
verbose?: boolean;
|
|
394
401
|
}
|
|
@@ -416,6 +423,8 @@ export declare class DDB {
|
|
|
416
423
|
password: string;
|
|
417
424
|
/** python session flag (2048) */
|
|
418
425
|
python: boolean;
|
|
426
|
+
/** 表示本次会话执行的 SQL 标准 */
|
|
427
|
+
sql: SqlStandard;
|
|
419
428
|
/** 是否为流数据连接,非流数据这个字段恒为 null Whether it is a streaming data connection, this field is always null for non-streaming data */
|
|
420
429
|
streaming: StreamingData;
|
|
421
430
|
/** 是否打印每个 rpc 的信息用于调试 */
|
|
@@ -450,6 +459,7 @@ export declare class DDB {
|
|
|
450
459
|
- python?: 设置 python session flag,默认 `false` set python session flag, default `false`
|
|
451
460
|
- streaming?: 设置该选项后,该 WebSocket 连接只用于流数据 When this option is set, the WebSocket connection is only used for streaming data
|
|
452
461
|
- verbose?: 是否打印每个 rpc 的信息用于调试
|
|
462
|
+
- sql?: 设置当前会话执行的 sql 标准, 请使用 SqlStandard 枚举进行传参,默认 `DolphinDB`
|
|
453
463
|
|
|
454
464
|
@example
|
|
455
465
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
package/browser.js
CHANGED
|
@@ -1217,10 +1217,12 @@ export class DdbObj {
|
|
|
1217
1217
|
}
|
|
1218
1218
|
}
|
|
1219
1219
|
/** 整数一定用这个 number formatter, InspectOptions.decimals 不传也用这个 Integer must use this number formatter, InspectOptions.decimals also use this if not passed */
|
|
1220
|
-
let default_formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
|
|
1220
|
+
let default_formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
|
|
1221
1221
|
let _decimals = 20;
|
|
1222
1222
|
/** 缓存,为了优化性能,通常 options.decimals 都是不变的 Cache, in order to optimize performance, usually options.decimals are unchanged */
|
|
1223
|
-
let _formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
|
|
1223
|
+
let _formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: 20 });
|
|
1224
|
+
/** 用来处理时差 To deal with jet lag */
|
|
1225
|
+
let _datetime_formatter = new Intl.DateTimeFormat('zh-CN', { dateStyle: 'short', timeStyle: 'medium', timeZone: 'UTC' });
|
|
1224
1226
|
/** 根据 DdbType 格式化单个元素 (value) 为字符串 Formats a single element (value) as a string according to DdbType, null returns a 'null' string */
|
|
1225
1227
|
export function format(type, value, le, options = {}) {
|
|
1226
1228
|
const { decimals, nullstr = false, colors = false, quote = false } = options;
|
|
@@ -1229,7 +1231,7 @@ export function format(type, value, le, options = {}) {
|
|
|
1229
1231
|
return default_formatter;
|
|
1230
1232
|
if (decimals !== _decimals) {
|
|
1231
1233
|
_decimals = decimals;
|
|
1232
|
-
_formatter = Intl.NumberFormat('en-US', { maximumFractionDigits: decimals, minimumFractionDigits: decimals });
|
|
1234
|
+
_formatter = new Intl.NumberFormat('en-US', { maximumFractionDigits: decimals, minimumFractionDigits: decimals });
|
|
1233
1235
|
}
|
|
1234
1236
|
return _formatter;
|
|
1235
1237
|
})();
|
|
@@ -1927,8 +1929,8 @@ export function second2str(second, format = 'HH:mm:ss') {
|
|
|
1927
1929
|
export function datetime2ms(datetime) {
|
|
1928
1930
|
if (datetime === null || datetime === nulls.int32)
|
|
1929
1931
|
return null;
|
|
1930
|
-
const
|
|
1931
|
-
return
|
|
1932
|
+
const date = new Date(1000 * datetime);
|
|
1933
|
+
return dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
|
|
1932
1934
|
}
|
|
1933
1935
|
export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1934
1936
|
return (datetime === null || datetime === nulls.int32) ?
|
|
@@ -1939,8 +1941,8 @@ export function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
|
1939
1941
|
export function timestamp2ms(timestamp) {
|
|
1940
1942
|
if (timestamp === null || timestamp === nulls.int64)
|
|
1941
1943
|
return null;
|
|
1942
|
-
const
|
|
1943
|
-
return
|
|
1944
|
+
const date = new Date(Number(timestamp));
|
|
1945
|
+
return dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf();
|
|
1944
1946
|
}
|
|
1945
1947
|
/** format timestamp (bigint) to string
|
|
1946
1948
|
- timestamp: bigint value
|
|
@@ -2003,8 +2005,8 @@ export function nanotime2str(nanotime, format = 'HH:mm:ss.SSSSSSSSS') {
|
|
|
2003
2005
|
export function nanotimestamp2ns(nanotimestamp) {
|
|
2004
2006
|
if (nanotimestamp === null || nanotimestamp === nulls.int64)
|
|
2005
2007
|
return null;
|
|
2006
|
-
const
|
|
2007
|
-
return BigInt(
|
|
2008
|
+
const date = new Date(Number(nanotimestamp / 1000000n));
|
|
2009
|
+
return BigInt(dayjs(`${_datetime_formatter.format(date)}.${date.getUTCMilliseconds()}`).valueOf()) * 1000000n + nanotimestamp % 1000000n;
|
|
2008
2010
|
}
|
|
2009
2011
|
/** format nanotimestamp value (bigint) to string
|
|
2010
2012
|
- nanotimestamp: bigint value
|
|
@@ -2030,9 +2032,7 @@ export function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.S
|
|
|
2030
2032
|
const remainder = nanotimestamp % 1000000000n;
|
|
2031
2033
|
const borrow = remainder < 0n;
|
|
2032
2034
|
const ms = Number(nanotimestamp / 1000000n);
|
|
2033
|
-
return (dayjs(
|
|
2034
|
-
// 去掉 9 位的纳秒部分,转化为毫秒
|
|
2035
|
-
Number((nanotimestamp - remainder + (borrow ? -1000000000n : 0n)) / 1000000n)).format(format.slice(0, i_second_end)) +
|
|
2035
|
+
return (dayjs(_datetime_formatter.format(new Date(ms))).format(format.slice(0, i_second_end)) +
|
|
2036
2036
|
format.slice(i_second_end, i_nanosecond_start) +
|
|
2037
2037
|
String(borrow ?
|
|
2038
2038
|
(remainder + 1000000000n) % 1000000000n
|
|
@@ -2109,6 +2109,13 @@ export class DdbDatabaseError extends Error {
|
|
|
2109
2109
|
this.options = options;
|
|
2110
2110
|
}
|
|
2111
2111
|
}
|
|
2112
|
+
/** SQL Standrd 标准类型 */
|
|
2113
|
+
export var SqlStandard;
|
|
2114
|
+
(function (SqlStandard) {
|
|
2115
|
+
SqlStandard[SqlStandard["DolphinDB"] = 0] = "DolphinDB";
|
|
2116
|
+
SqlStandard[SqlStandard["Oracle"] = 1] = "Oracle";
|
|
2117
|
+
SqlStandard[SqlStandard["MySQL"] = 2] = "MySQL";
|
|
2118
|
+
})(SqlStandard || (SqlStandard = {}));
|
|
2112
2119
|
export class DDB {
|
|
2113
2120
|
/** 当前的 session id (http 或 tcp) */
|
|
2114
2121
|
sid = '0';
|
|
@@ -2133,6 +2140,8 @@ export class DDB {
|
|
|
2133
2140
|
password = '123456';
|
|
2134
2141
|
/** python session flag (2048) */
|
|
2135
2142
|
python = false;
|
|
2143
|
+
/** 表示本次会话执行的 SQL 标准 */
|
|
2144
|
+
sql = SqlStandard.DolphinDB;
|
|
2136
2145
|
/** 是否为流数据连接,非流数据这个字段恒为 null Whether it is a streaming data connection, this field is always null for non-streaming data */
|
|
2137
2146
|
streaming = null;
|
|
2138
2147
|
/** 是否打印每个 rpc 的信息用于调试 */
|
|
@@ -2172,6 +2181,7 @@ export class DDB {
|
|
|
2172
2181
|
- python?: 设置 python session flag,默认 `false` set python session flag, default `false`
|
|
2173
2182
|
- streaming?: 设置该选项后,该 WebSocket 连接只用于流数据 When this option is set, the WebSocket connection is only used for streaming data
|
|
2174
2183
|
- verbose?: 是否打印每个 rpc 的信息用于调试
|
|
2184
|
+
- sql?: 设置当前会话执行的 sql 标准, 请使用 SqlStandard 枚举进行传参,默认 `DolphinDB`
|
|
2175
2185
|
|
|
2176
2186
|
@example
|
|
2177
2187
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
|
@@ -2195,6 +2205,8 @@ export class DDB {
|
|
|
2195
2205
|
this.password = options.password;
|
|
2196
2206
|
if (options.python !== undefined)
|
|
2197
2207
|
this.python = options.python;
|
|
2208
|
+
if (options.sql !== undefined)
|
|
2209
|
+
this.sql = options.sql;
|
|
2198
2210
|
if (options.streaming !== undefined)
|
|
2199
2211
|
this.streaming = options.streaming;
|
|
2200
2212
|
}
|
|
@@ -2283,6 +2295,8 @@ export class DDB {
|
|
|
2283
2295
|
// python session
|
|
2284
2296
|
if (this.python)
|
|
2285
2297
|
flag += 2048;
|
|
2298
|
+
// sql standrd
|
|
2299
|
+
flag += 2 ** 19 * this.sql;
|
|
2286
2300
|
const options = [
|
|
2287
2301
|
flag,
|
|
2288
2302
|
cancellable ? 1 : 0,
|