dolphindb 0.0.12 → 0.0.15
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 +1 -0
- package/browser.d.ts +25 -3
- package/browser.js +91 -31
- package/browser.js.map +1 -1
- package/index.d.ts +29 -4
- package/index.js +108 -32
- package/index.js.map +1 -1
- package/package.json +2 -2
package/README.zh.md
CHANGED
|
@@ -46,6 +46,7 @@ npm install dolphindb
|
|
|
46
46
|
```ts
|
|
47
47
|
import { DDB } from 'dolphindb'
|
|
48
48
|
// 已有的使用 CommonJS 模块的项目的导入方法为 const { DDB } = require('dolphindb')
|
|
49
|
+
// 在浏览器中使用: import { DDB } form 'dolphindb/browser.js'
|
|
49
50
|
|
|
50
51
|
// 创建数据库对象,初始化 WebSocket 连接地址
|
|
51
52
|
let ddb = new DDB('ws://127.0.0.1:8848')
|
package/browser.d.ts
CHANGED
|
@@ -195,11 +195,33 @@ export declare class DdbFunction extends DdbObj<DdbFunctionDefValue> {
|
|
|
195
195
|
}
|
|
196
196
|
export declare function date2str(date: number, format?: string): string;
|
|
197
197
|
export declare function datetime2str(datetime: number, format?: string): string;
|
|
198
|
-
|
|
198
|
+
/** format timestamp (bigint) to string
|
|
199
|
+
- timestamp: bigint value
|
|
200
|
+
- format?:
|
|
201
|
+
format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
|
|
202
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
203
|
+
*/
|
|
204
|
+
export declare function timestamp2str(timestamp: bigint, format?: string): string;
|
|
205
|
+
/** parse timestamp string to bigint value
|
|
206
|
+
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
207
|
+
- format?:
|
|
208
|
+
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
209
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
210
|
+
*/
|
|
211
|
+
export declare function str2timestamp(str: string, format?: string): bigint;
|
|
212
|
+
/** format nanotimestamp value (bigint) to string
|
|
213
|
+
- nanotimestamp: bigint value
|
|
214
|
+
- format?:
|
|
215
|
+
format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
216
|
+
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
217
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
218
|
+
*/
|
|
199
219
|
export declare function nanotimestamp2str(nanotimestamp: bigint, format?: string): string;
|
|
200
220
|
/** parse nano timestamp string to bigint value
|
|
201
|
-
- str: nano timestamp string,
|
|
202
|
-
- format?:
|
|
221
|
+
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
222
|
+
- format?:
|
|
223
|
+
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
224
|
+
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
203
225
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
204
226
|
*/
|
|
205
227
|
export declare function str2nanotimestamp(str: string, format?: string): bigint;
|
package/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ddb = exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbFunction = exports.DdbPair = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = exports.DdbVectorInt = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
|
|
3
|
+
exports.ddb = exports.DDB = exports.str2nanotimestamp = exports.nanotimestamp2str = exports.str2timestamp = exports.timestamp2str = exports.datetime2str = exports.date2str = exports.DdbFunction = exports.DdbPair = exports.DdbVectorAny = exports.DdbVectorDouble = exports.DdbVectorString = exports.DdbVectorInt = exports.DdbNanoTimeStamp = exports.DdbTimeStamp = exports.DdbDateTime = exports.DdbDouble = exports.DdbLong = exports.DdbString = exports.DdbInt = exports.DdbChar = exports.DdbBool = exports.DdbVoid = exports.DdbObj = exports.timezone_offset = exports.nulls = exports.DdbFunctionType = exports.DdbType = exports.DdbForm = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
6
|
const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
|
|
@@ -115,7 +115,7 @@ class DdbObj {
|
|
|
115
115
|
le,
|
|
116
116
|
form,
|
|
117
117
|
type,
|
|
118
|
-
length:
|
|
118
|
+
length: i_data + length,
|
|
119
119
|
value,
|
|
120
120
|
});
|
|
121
121
|
}
|
|
@@ -123,7 +123,7 @@ class DdbObj {
|
|
|
123
123
|
case DdbForm.pair:
|
|
124
124
|
case DdbForm.set: {
|
|
125
125
|
let vector = this.parse_vector(buf_data, le, type);
|
|
126
|
-
vector.length +=
|
|
126
|
+
vector.length += i_data;
|
|
127
127
|
vector.form = form;
|
|
128
128
|
return vector;
|
|
129
129
|
}
|
|
@@ -154,17 +154,17 @@ class DdbObj {
|
|
|
154
154
|
let i_start = i_items_start + len_items;
|
|
155
155
|
for (let i = 0; i < cols; i++) {
|
|
156
156
|
const type = buf_data[i_start];
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
let col = this.parse_vector(buf_data.subarray(i_start + 2), le, type);
|
|
158
|
+
col.length += 2;
|
|
159
159
|
col.name = colnames[i];
|
|
160
160
|
value[i] = col;
|
|
161
|
-
i_start
|
|
161
|
+
i_start += col.length;
|
|
162
162
|
}
|
|
163
163
|
return new this({
|
|
164
164
|
le,
|
|
165
165
|
form,
|
|
166
166
|
type,
|
|
167
|
-
length: i_start,
|
|
167
|
+
length: i_data + i_start,
|
|
168
168
|
name,
|
|
169
169
|
rows,
|
|
170
170
|
cols,
|
|
@@ -187,7 +187,7 @@ class DdbObj {
|
|
|
187
187
|
le,
|
|
188
188
|
form,
|
|
189
189
|
type,
|
|
190
|
-
length:
|
|
190
|
+
length: i_data + keys.length + values.length,
|
|
191
191
|
rows: keys.rows,
|
|
192
192
|
cols: 2,
|
|
193
193
|
value: [
|
|
@@ -220,7 +220,7 @@ class DdbObj {
|
|
|
220
220
|
le,
|
|
221
221
|
form,
|
|
222
222
|
type,
|
|
223
|
-
length: 11 + len_items,
|
|
223
|
+
length: i_data + 11 + len_items,
|
|
224
224
|
rows,
|
|
225
225
|
cols,
|
|
226
226
|
datatype,
|
|
@@ -232,7 +232,7 @@ class DdbObj {
|
|
|
232
232
|
le,
|
|
233
233
|
form,
|
|
234
234
|
type,
|
|
235
|
-
length: buf_data.length,
|
|
235
|
+
length: i_data + buf_data.length,
|
|
236
236
|
value: buf_data
|
|
237
237
|
});
|
|
238
238
|
}
|
|
@@ -788,7 +788,7 @@ class DdbObj {
|
|
|
788
788
|
case DdbForm.pair:
|
|
789
789
|
return `pair<${tname}>`;
|
|
790
790
|
case DdbForm.set:
|
|
791
|
-
return `set<${tname}
|
|
791
|
+
return `set<${tname}>[${this.rows}]`;
|
|
792
792
|
case DdbForm.table:
|
|
793
793
|
return `table[${this.rows} rows][${this.cols} cols]`;
|
|
794
794
|
case DdbForm.dict:
|
|
@@ -829,16 +829,28 @@ class DdbObj {
|
|
|
829
829
|
});
|
|
830
830
|
}
|
|
831
831
|
to_rows() {
|
|
832
|
+
if (this.form !== DdbForm.table)
|
|
833
|
+
throw new Error('this.form is not DdbForm.table, cannot call to_rows');
|
|
832
834
|
let rows = new Array(this.rows);
|
|
833
835
|
for (let i = 0; i < this.rows; i++) {
|
|
834
836
|
let row = {};
|
|
835
837
|
for (let j = 0; j < this.cols; j++) {
|
|
836
|
-
const
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
838
|
+
const { type, name, value } = this.value[j]; // column
|
|
839
|
+
switch (type) {
|
|
840
|
+
case DdbType.bool:
|
|
841
|
+
row[name] = Boolean(value[i]);
|
|
842
|
+
break;
|
|
843
|
+
case DdbType.ipaddr:
|
|
844
|
+
row[name] = value.subarray(16 * i, 16 * (i + 1));
|
|
845
|
+
break;
|
|
846
|
+
case DdbType.symbol_extended: {
|
|
847
|
+
const { base, data } = value;
|
|
848
|
+
row[name] = base[data[i]];
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
default:
|
|
852
|
+
row[name] = value[i];
|
|
840
853
|
}
|
|
841
|
-
row[c.name] = c.value[i];
|
|
842
854
|
}
|
|
843
855
|
rows[i] = row;
|
|
844
856
|
}
|
|
@@ -1064,34 +1076,79 @@ function datetime2str(datetime, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
|
1064
1076
|
(0, dayjs_1.default)(exports.timezone_offset + 1000 * datetime).format(format);
|
|
1065
1077
|
}
|
|
1066
1078
|
exports.datetime2str = datetime2str;
|
|
1067
|
-
|
|
1079
|
+
/** format timestamp (bigint) to string
|
|
1080
|
+
- timestamp: bigint value
|
|
1081
|
+
- format?:
|
|
1082
|
+
format string, default to `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1083
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1084
|
+
*/
|
|
1085
|
+
function timestamp2str(timestamp, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1068
1086
|
return timestamp === exports.nulls.int64 ?
|
|
1069
1087
|
''
|
|
1070
1088
|
:
|
|
1071
|
-
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(
|
|
1089
|
+
(0, dayjs_1.default)(exports.timezone_offset + Number(timestamp)).format(format);
|
|
1072
1090
|
}
|
|
1073
1091
|
exports.timestamp2str = timestamp2str;
|
|
1074
|
-
|
|
1075
|
-
return
|
|
1076
|
-
|
|
1077
|
-
:
|
|
1078
|
-
|
|
1092
|
+
/** parse timestamp string to bigint value
|
|
1093
|
+
- str: timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1094
|
+
- format?:
|
|
1095
|
+
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSS`
|
|
1096
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1097
|
+
*/
|
|
1098
|
+
function str2timestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSS') {
|
|
1099
|
+
if (!str)
|
|
1100
|
+
return exports.nulls.int64;
|
|
1101
|
+
if (str.length !== format.length)
|
|
1102
|
+
throw new Error('The length of the timestamp string is not equal to the length of the format string');
|
|
1103
|
+
return BigInt(-exports.timezone_offset +
|
|
1104
|
+
(0, dayjs_1.default)(str, format).valueOf());
|
|
1105
|
+
}
|
|
1106
|
+
exports.str2timestamp = str2timestamp;
|
|
1107
|
+
/** format nanotimestamp value (bigint) to string
|
|
1108
|
+
- nanotimestamp: bigint value
|
|
1109
|
+
- format?:
|
|
1110
|
+
format string, default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
1111
|
+
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1112
|
+
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1113
|
+
*/
|
|
1114
|
+
function nanotimestamp2str(nanotimestamp, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1115
|
+
if (nanotimestamp === exports.nulls.int64)
|
|
1116
|
+
return '';
|
|
1117
|
+
const i_second_start = format.indexOf('ss');
|
|
1118
|
+
if (i_second_start === -1)
|
|
1119
|
+
throw new Error('The format string must contain the format for seconds (ss)');
|
|
1120
|
+
const i_second_end = i_second_start + 2;
|
|
1121
|
+
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1122
|
+
if (i_nanosecond_start === -1)
|
|
1123
|
+
throw new Error('The format string must contain the format for nanoseconds (SSSSSSSSS)');
|
|
1124
|
+
return ((0, dayjs_1.default)(exports.timezone_offset + (Number(nanotimestamp) / 1000000)).format(format.slice(0, i_second_end)) +
|
|
1125
|
+
format.slice(i_second_end, i_nanosecond_start) +
|
|
1126
|
+
String(nanotimestamp % 1000000000n));
|
|
1079
1127
|
}
|
|
1080
1128
|
exports.nanotimestamp2str = nanotimestamp2str;
|
|
1081
1129
|
/** parse nano timestamp string to bigint value
|
|
1082
|
-
- str: nano timestamp string,
|
|
1083
|
-
- format?:
|
|
1130
|
+
- str: nano timestamp string, If it is an empty string, it will return the corresponding empty value (nulls.int64)
|
|
1131
|
+
- format?:
|
|
1132
|
+
The format string corresponding to the incoming string, the default is `YYYY.MM.DD HH:mm:ss.SSSSSSSSS`
|
|
1133
|
+
Seconds are in the format ss (must be included); nanoseconds are in the format SSSSSSSSS (must be included)
|
|
1084
1134
|
https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
|
|
1085
1135
|
*/
|
|
1086
|
-
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss') {
|
|
1136
|
+
function str2nanotimestamp(str, format = 'YYYY.MM.DD HH:mm:ss.SSSSSSSSS') {
|
|
1087
1137
|
if (!str)
|
|
1088
1138
|
return exports.nulls.int64;
|
|
1089
|
-
if (str.length
|
|
1090
|
-
throw new Error('nanotimestamp
|
|
1139
|
+
if (str.length !== format.length)
|
|
1140
|
+
throw new Error('nanotimestamp string length is not equal to format string length');
|
|
1141
|
+
const i_second_start = format.indexOf('ss');
|
|
1142
|
+
if (i_second_start === -1)
|
|
1143
|
+
throw new Error('The format string must contain the format for seconds (ss)');
|
|
1144
|
+
const i_second_end = i_second_start + 2;
|
|
1145
|
+
const i_nanosecond_start = format.indexOf('SSSSSSSSS', i_second_end);
|
|
1146
|
+
if (i_nanosecond_start === -1)
|
|
1147
|
+
throw new Error('Format string must contain nanosecond format (SSSSSSSSS)');
|
|
1091
1148
|
return (BigInt(-exports.timezone_offset +
|
|
1092
|
-
(0, dayjs_1.default)(str.slice(0, format.
|
|
1149
|
+
(0, dayjs_1.default)(str.slice(0, i_second_end), format.slice(0, i_second_end)).valueOf()) * 1000000n
|
|
1093
1150
|
+
|
|
1094
|
-
BigInt(str.slice(
|
|
1151
|
+
BigInt(str.slice(i_nanosecond_start, i_nanosecond_start + 9)));
|
|
1095
1152
|
}
|
|
1096
1153
|
exports.str2nanotimestamp = str2nanotimestamp;
|
|
1097
1154
|
class DDB {
|
|
@@ -1189,7 +1246,10 @@ class DDB {
|
|
|
1189
1246
|
' )\n' +
|
|
1190
1247
|
'}\n', { urgent: true });
|
|
1191
1248
|
if (login)
|
|
1192
|
-
|
|
1249
|
+
if (this.python)
|
|
1250
|
+
await this.eval(`login(${username.quote('double')}, ${password.quote('double')})`, { urgent: true });
|
|
1251
|
+
else
|
|
1252
|
+
await this.call('login', [username, password], { urgent: true });
|
|
1193
1253
|
}
|
|
1194
1254
|
get_rpc_options({ urgent = false, secondary = false, async: _async = false, pickle = false, clear = false, api = false, compress = false, cancellable = true, priority = urgent ? 8 : 4, parallelism = 8, root_id = '', limit, } = {}) {
|
|
1195
1255
|
let flag = 0;
|