dolphindb 0.0.11 → 0.0.14

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 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.js CHANGED
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
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;
4
4
  const tslib_1 = require("tslib");
5
5
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
- const customParseFormat_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat"));
7
- dayjs_1.default.extend(customParseFormat_1.default);
6
+ const customParseFormat_js_1 = tslib_1.__importDefault(require("dayjs/plugin/customParseFormat.js"));
7
+ dayjs_1.default.extend(customParseFormat_js_1.default);
8
8
  require("xshell/prototype.browser");
9
9
  const utils_browser_1 = require("xshell/utils.browser");
10
10
  var DdbForm;
@@ -115,7 +115,7 @@ class DdbObj {
115
115
  le,
116
116
  form,
117
117
  type,
118
- length: 2 + 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 += 2;
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
- const i_vector_head = i_start + 2;
158
- let col = this.parse_vector(buf_data.subarray(i_vector_head), le, type);
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 = i_vector_head + col.length;
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: 2 + keys.length + values.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 c = this.value[j];
837
- if (c.type === DdbType.ipaddr) {
838
- row[c.name] = c.value.subarray(16 * i, 16 * (i + 1));
839
- continue;
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
  }
@@ -1189,7 +1201,10 @@ class DDB {
1189
1201
  ' )\n' +
1190
1202
  '}\n', { urgent: true });
1191
1203
  if (login)
1192
- await this.call('login', [username, password], { urgent: true });
1204
+ if (this.python)
1205
+ await this.eval(`login(${username.quote('double')}, ${password.quote('double')})`, { urgent: true });
1206
+ else
1207
+ await this.call('login', [username, password], { urgent: true });
1193
1208
  }
1194
1209
  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
1210
  let flag = 0;