@quantform/sqlite 0.6.6 → 0.6.7
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/dist/error.d.ts +3 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/sqlite-feed.spec.d.ts +2 -0
- package/dist/sqlite-feed.spec.d.ts.map +1 -0
- package/dist/sqlite-feed.spec.js +120 -0
- package/dist/sqlite-measurement.spec.d.ts +2 -0
- package/dist/sqlite-measurement.spec.d.ts.map +1 -0
- package/dist/sqlite-measurement.spec.js +122 -0
- package/dist/sqlite-storage.d.ts +1 -1
- package/dist/sqlite-storage.d.ts.map +1 -1
- package/dist/sqlite-storage.js +5 -5
- package/jest.config.ts +24 -2
- package/package.json +4 -4
- package/src/error.ts +4 -2
- package/src/index.ts +1 -1
- package/src/sqlite-feed.spec.ts +4 -3
- package/src/sqlite-measurement.spec.ts +3 -2
- package/src/sqlite-storage.ts +10 -9
- package/tsconfig.json +7 -4
package/dist/error.d.ts
CHANGED
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;;CAI3C"}
|
package/dist/error.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.NoConnectionError = void 0;
|
|
4
|
+
class NoConnectionError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super('Missing database connection connection!');
|
|
7
|
+
}
|
|
6
8
|
}
|
|
7
|
-
exports.
|
|
9
|
+
exports.NoConnectionError = NoConnectionError;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-feed.spec.d.ts","sourceRoot":"","sources":["../src/sqlite-feed.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const core_1 = require("@quantform/core");
|
|
14
|
+
const sqlite_storage_1 = require("./sqlite-storage");
|
|
15
|
+
describe(sqlite_storage_1.SQLiteStorage.name, () => {
|
|
16
|
+
const dbName = 'test.db';
|
|
17
|
+
const instrument = new core_1.Instrument(0, new core_1.Asset('btc', 'binance', 8), new core_1.Asset('usdt', 'binance', 2), '', core_1.Commission.Zero);
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
if ((0, fs_1.existsSync)(dbName)) {
|
|
20
|
+
(0, fs_1.unlinkSync)(dbName);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
test('should create db file in user directory', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const feed = new core_1.Feed(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
25
|
+
const input = [
|
|
26
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(1.12345678), 1616175004063)
|
|
27
|
+
];
|
|
28
|
+
yield feed.save(input);
|
|
29
|
+
const output = yield feed.query(instrument, {
|
|
30
|
+
from: 1616175004062,
|
|
31
|
+
to: 1616234152109,
|
|
32
|
+
count: 100
|
|
33
|
+
});
|
|
34
|
+
expect(output.length).toBe(1);
|
|
35
|
+
}));
|
|
36
|
+
test('should insert multiple rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const feed = new core_1.Feed(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
38
|
+
const input = [
|
|
39
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(1.12345678), 1616175004063),
|
|
40
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(2.12345678), 1616221874143),
|
|
41
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(3.12345678), 1616234152108)
|
|
42
|
+
];
|
|
43
|
+
yield feed.save(input);
|
|
44
|
+
const output = yield feed.query(instrument, {
|
|
45
|
+
from: 1616175004062,
|
|
46
|
+
to: 1616234152109,
|
|
47
|
+
count: 100
|
|
48
|
+
});
|
|
49
|
+
expect(output.length).toBe(3);
|
|
50
|
+
for (let i = 0; i < 3; i++) {
|
|
51
|
+
expect(output[i]).toEqual(input[i]);
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
test('should limit result', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const feed = new core_1.Feed(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
56
|
+
const input = [
|
|
57
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(1.12345678), 1616175004063),
|
|
58
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(2.12345678), 1616221874143),
|
|
59
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(3.12345678), 1616234152108)
|
|
60
|
+
];
|
|
61
|
+
yield feed.save(input);
|
|
62
|
+
const output = yield feed.query(instrument, {
|
|
63
|
+
from: 1616175004062,
|
|
64
|
+
to: 1616234152109,
|
|
65
|
+
count: 2
|
|
66
|
+
});
|
|
67
|
+
expect(output.length).toBe(2);
|
|
68
|
+
expect(output[0].timestamp).toBe(input[0].timestamp);
|
|
69
|
+
expect(output[1].timestamp).toBe(input[1].timestamp);
|
|
70
|
+
}));
|
|
71
|
+
test('should override duplicated rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const feed = new core_1.Feed(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
73
|
+
yield feed.save([
|
|
74
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(1.12345678), 1616175004063),
|
|
75
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(2.12345678), 1616221874143),
|
|
76
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1234.56789), (0, core_1.d)(3.12345678), 1616234152108)
|
|
77
|
+
]);
|
|
78
|
+
const result = yield feed.query(instrument, {
|
|
79
|
+
from: 1616175004062,
|
|
80
|
+
to: 1616175004064,
|
|
81
|
+
count: 100
|
|
82
|
+
});
|
|
83
|
+
expect(result.length).toBe(1);
|
|
84
|
+
}));
|
|
85
|
+
test('should patch a store with events', done => {
|
|
86
|
+
const feed = new core_1.Feed(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
87
|
+
const store = new core_1.Store();
|
|
88
|
+
store.snapshot.universe.instrument.upsert(instrument);
|
|
89
|
+
store.snapshot.subscription.instrument.upsert(instrument);
|
|
90
|
+
const streamer = new core_1.BacktesterStreamer(store, feed, {
|
|
91
|
+
from: 0,
|
|
92
|
+
to: 10
|
|
93
|
+
}, {
|
|
94
|
+
onBacktestCompleted: () => {
|
|
95
|
+
var _a;
|
|
96
|
+
const trade = (_a = store.snapshot.trade.get(instrument.id)) !== null && _a !== void 0 ? _a : fail();
|
|
97
|
+
expect(trade.timestamp).toEqual(8);
|
|
98
|
+
expect(trade.rate).toEqual((0, core_1.d)(8));
|
|
99
|
+
expect(trade.quantity).toEqual((0, core_1.d)(8));
|
|
100
|
+
expect(store.snapshot.timestamp).toEqual(8);
|
|
101
|
+
done();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
feed
|
|
105
|
+
.save([
|
|
106
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(1), (0, core_1.d)(1), 1),
|
|
107
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(2), (0, core_1.d)(2), 2),
|
|
108
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(3), (0, core_1.d)(3), 3),
|
|
109
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(4), (0, core_1.d)(4), 4),
|
|
110
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(5), (0, core_1.d)(5), 5),
|
|
111
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(6), (0, core_1.d)(6), 6),
|
|
112
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(7), (0, core_1.d)(7), 7),
|
|
113
|
+
new core_1.TradePatchEvent(instrument, (0, core_1.d)(8), (0, core_1.d)(8), 8)
|
|
114
|
+
])
|
|
115
|
+
.then(() => {
|
|
116
|
+
streamer.subscribe(instrument);
|
|
117
|
+
streamer.tryContinue();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-measurement.spec.d.ts","sourceRoot":"","sources":["../src/sqlite-measurement.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const core_1 = require("@quantform/core");
|
|
14
|
+
const sqlite_storage_1 = require("./sqlite-storage");
|
|
15
|
+
describe('sqlite measurement tests', () => {
|
|
16
|
+
const dbName = 'measurement.db';
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
if ((0, fs_1.existsSync)(dbName)) {
|
|
19
|
+
(0, fs_1.unlinkSync)(dbName);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
afterAll(() => {
|
|
23
|
+
if ((0, fs_1.existsSync)(dbName)) {
|
|
24
|
+
(0, fs_1.unlinkSync)(dbName);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
test('should return empty array for unknown session', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const measurement = new core_1.Measurement(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
29
|
+
const measure = yield measurement.query(0, {
|
|
30
|
+
from: 0,
|
|
31
|
+
count: 100
|
|
32
|
+
});
|
|
33
|
+
expect(measure).toEqual([]);
|
|
34
|
+
}));
|
|
35
|
+
test('should list written sessions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const measurement = new core_1.Measurement(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
37
|
+
yield measurement.save(1, [...Array(10).keys()].map(it => ({
|
|
38
|
+
timestamp: it + 1,
|
|
39
|
+
kind: 'spread',
|
|
40
|
+
payload: { value: it + 1 }
|
|
41
|
+
})));
|
|
42
|
+
yield measurement.save(2, [...Array(10).keys()].map(it => ({
|
|
43
|
+
timestamp: it + 1,
|
|
44
|
+
kind: 'spread',
|
|
45
|
+
payload: { value: it + 1 }
|
|
46
|
+
})));
|
|
47
|
+
const index = yield measurement.index();
|
|
48
|
+
expect(index.length).toBe(2);
|
|
49
|
+
expect(index[0]).toBe(1);
|
|
50
|
+
expect(index[1]).toBe(2);
|
|
51
|
+
}));
|
|
52
|
+
test('should read and write measurement', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const measurement = new core_1.Measurement(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
54
|
+
const session = 1;
|
|
55
|
+
yield measurement.save(session, [...Array(10).keys()].map(it => ({
|
|
56
|
+
timestamp: it + 1,
|
|
57
|
+
kind: 'spread',
|
|
58
|
+
payload: { value: it + 1 }
|
|
59
|
+
})));
|
|
60
|
+
const after = yield measurement.query(session, {
|
|
61
|
+
from: 5,
|
|
62
|
+
count: 100
|
|
63
|
+
});
|
|
64
|
+
expect(after.length).toBe(5);
|
|
65
|
+
expect(after[0].timestamp).toBe(6);
|
|
66
|
+
expect(after[0].kind).toBe('spread');
|
|
67
|
+
expect(after[0].payload.value).toBe(6);
|
|
68
|
+
expect(after[1].timestamp).toBe(7);
|
|
69
|
+
expect(after[1].kind).toBe('spread');
|
|
70
|
+
expect(after[1].payload.value).toBe(7);
|
|
71
|
+
expect(after[2].timestamp).toBe(8);
|
|
72
|
+
expect(after[2].kind).toBe('spread');
|
|
73
|
+
expect(after[2].payload.value).toBe(8);
|
|
74
|
+
const before = yield measurement.query(session, {
|
|
75
|
+
to: 6,
|
|
76
|
+
count: 100
|
|
77
|
+
});
|
|
78
|
+
expect(before.length).toBe(5);
|
|
79
|
+
expect(before[0].timestamp).toBe(1);
|
|
80
|
+
expect(before[0].kind).toBe('spread');
|
|
81
|
+
expect(before[0].payload.value).toBe(1);
|
|
82
|
+
expect(before[1].timestamp).toBe(2);
|
|
83
|
+
expect(before[1].kind).toBe('spread');
|
|
84
|
+
expect(before[1].payload.value).toBe(2);
|
|
85
|
+
expect(before[2].timestamp).toBe(3);
|
|
86
|
+
expect(before[2].kind).toBe('spread');
|
|
87
|
+
expect(before[2].payload.value).toBe(3);
|
|
88
|
+
}));
|
|
89
|
+
test('should read and write specific measurement (state)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
const measurement = new core_1.Measurement(new sqlite_storage_1.SQLiteStorage(dbName));
|
|
91
|
+
const session = 1;
|
|
92
|
+
yield measurement.save(session, [
|
|
93
|
+
{
|
|
94
|
+
timestamp: 1,
|
|
95
|
+
kind: 'order-completed',
|
|
96
|
+
payload: { rate: 100 }
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
timestamp: 5,
|
|
100
|
+
kind: 'order-completed',
|
|
101
|
+
payload: { rate: 105 }
|
|
102
|
+
}
|
|
103
|
+
]);
|
|
104
|
+
let measure = yield measurement.query(session, {
|
|
105
|
+
to: 2,
|
|
106
|
+
count: 1,
|
|
107
|
+
kind: 'order-completed'
|
|
108
|
+
});
|
|
109
|
+
expect(measure.length).toBe(1);
|
|
110
|
+
expect(measure[0].timestamp).toBe(1);
|
|
111
|
+
expect(measure[0].kind).toBe('order-completed');
|
|
112
|
+
expect(measure[0].payload.rate).toBe(100);
|
|
113
|
+
measure = yield measurement.query(session, {
|
|
114
|
+
to: 6,
|
|
115
|
+
count: 1
|
|
116
|
+
});
|
|
117
|
+
expect(measure.length).toBe(1);
|
|
118
|
+
expect(measure[0].timestamp).toBe(5);
|
|
119
|
+
expect(measure[0].kind).toBe('order-completed');
|
|
120
|
+
expect(measure[0].payload.rate).toBe(105);
|
|
121
|
+
}));
|
|
122
|
+
});
|
package/dist/sqlite-storage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SessionFeature, Storage, StorageDocument, StorageQueryOptions } from '@quantform/core';
|
|
2
1
|
import { Database } from 'better-sqlite3';
|
|
2
|
+
import { SessionFeature, Storage, StorageDocument, StorageQueryOptions } from '@quantform/core';
|
|
3
3
|
export declare function sqlite(directory?: string): SessionFeature;
|
|
4
4
|
export declare class SQLiteStorage implements Storage {
|
|
5
5
|
private readonly filename;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-storage.d.ts","sourceRoot":"","sources":["../src/sqlite-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,OAAO,EACP,eAAe,EACf,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite-storage.d.ts","sourceRoot":"","sources":["../src/sqlite-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK1C,OAAO,EAEL,cAAc,EACd,OAAO,EACP,eAAe,EACf,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;AAIzB,wBAAgB,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,CAOzD;AAED,qBAAa,aAAc,YAAW,OAAO;IAG/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,SAAS,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC;gBAEH,QAAQ,EAAE,MAAM;IAE7C,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,cAAc;IAehB,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAa/B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAwChF,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAoBzE"}
|
package/dist/sqlite-storage.js
CHANGED
|
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SQLiteStorage = exports.sqlite = void 0;
|
|
13
|
-
const core_1 = require("@quantform/core");
|
|
14
13
|
const bettersqlite3 = require("better-sqlite3");
|
|
15
14
|
const fs_1 = require("fs");
|
|
16
15
|
const path_1 = require("path");
|
|
16
|
+
const core_1 = require("@quantform/core");
|
|
17
17
|
const error_1 = require("./error");
|
|
18
18
|
function sqlite(directory) {
|
|
19
19
|
return (builder) => {
|
|
@@ -36,7 +36,7 @@ class SQLiteStorage {
|
|
|
36
36
|
}
|
|
37
37
|
tryCreateTable(table) {
|
|
38
38
|
if (!this.connection) {
|
|
39
|
-
throw
|
|
39
|
+
throw new error_1.NoConnectionError();
|
|
40
40
|
}
|
|
41
41
|
this.connection.exec(`CREATE TABLE IF NOT EXISTS "${table}" (
|
|
42
42
|
timestamp INTEGER NOT NULL,
|
|
@@ -49,7 +49,7 @@ class SQLiteStorage {
|
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
50
|
this.tryConnect();
|
|
51
51
|
if (!this.connection) {
|
|
52
|
-
throw
|
|
52
|
+
throw new error_1.NoConnectionError();
|
|
53
53
|
}
|
|
54
54
|
return this.connection
|
|
55
55
|
.prepare("SELECT name FROM sqlite_master WHERE type='table'")
|
|
@@ -62,7 +62,7 @@ class SQLiteStorage {
|
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
63
|
this.tryConnect();
|
|
64
64
|
if (!this.connection) {
|
|
65
|
-
throw
|
|
65
|
+
throw new error_1.NoConnectionError();
|
|
66
66
|
}
|
|
67
67
|
if (!this.connection
|
|
68
68
|
.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='${library}'`)
|
|
@@ -86,7 +86,7 @@ class SQLiteStorage {
|
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
87
|
this.tryConnect();
|
|
88
88
|
if (!this.connection) {
|
|
89
|
-
throw
|
|
89
|
+
throw new error_1.NoConnectionError();
|
|
90
90
|
}
|
|
91
91
|
this.tryCreateTable(library);
|
|
92
92
|
const statement = this.connection.prepare(`
|
package/jest.config.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import { Config } from 'jest';
|
|
2
|
+
import { pathsToModuleNameMapper } from 'ts-jest';
|
|
3
|
+
import { parseJsonConfigFileContent, readConfigFile, sys } from 'typescript';
|
|
4
|
+
|
|
5
|
+
const tsconfig = parseJsonConfigFileContent(
|
|
6
|
+
readConfigFile('tsconfig.json', sys.readFile).config,
|
|
7
|
+
sys,
|
|
8
|
+
process.cwd()
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const compilerOptions = tsconfig.raw.compilerOptions as any;
|
|
2
12
|
|
|
3
13
|
const config: Config = {
|
|
4
14
|
preset: 'ts-jest',
|
|
5
15
|
testEnvironment: 'node',
|
|
6
16
|
testMatch: ['**/src/**/?(*.)+(spec|test).[jt]s?(x)'],
|
|
7
17
|
transform: {
|
|
8
|
-
'^.+\\.ts?$':
|
|
9
|
-
|
|
18
|
+
'^.+\\.ts?$': [
|
|
19
|
+
'ts-jest',
|
|
20
|
+
{
|
|
21
|
+
isolatedModules: true,
|
|
22
|
+
tsconfig: { ...compilerOptions, sourceMap: true }
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
testPathIgnorePatterns: ['<rootDir>/dist/'],
|
|
27
|
+
roots: ['<rootDir>'],
|
|
28
|
+
modulePaths: [compilerOptions.baseUrl],
|
|
29
|
+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
|
|
30
|
+
prefix: '<rootDir>'
|
|
31
|
+
})
|
|
10
32
|
};
|
|
11
33
|
|
|
12
34
|
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quantform/sqlite",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Mateusz Majchrzak",
|
|
6
6
|
"description": "Node.js library for building systematic trading strategies in reactive way.",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/better-sqlite3": "^7.6.0",
|
|
21
|
-
"@quantform/core": "0.6.
|
|
21
|
+
"@quantform/core": "0.6.7"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@quantform/core": "0.6.
|
|
24
|
+
"@quantform/core": "0.6.7"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "tsc",
|
|
27
|
+
"build": "tsc && tsc-alias",
|
|
28
28
|
"test": "jest"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/error.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from '@lib/sqlite-storage';
|
package/src/sqlite-feed.spec.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync, unlinkSync } from 'fs';
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
Asset,
|
|
3
5
|
BacktesterStreamer,
|
|
@@ -8,11 +10,10 @@ import {
|
|
|
8
10
|
Store,
|
|
9
11
|
TradePatchEvent
|
|
10
12
|
} from '@quantform/core';
|
|
11
|
-
import { existsSync, unlinkSync } from 'fs';
|
|
12
13
|
|
|
13
|
-
import { SQLiteStorage } from '
|
|
14
|
+
import { SQLiteStorage } from '@lib/sqlite-storage';
|
|
14
15
|
|
|
15
|
-
describe(
|
|
16
|
+
describe(SQLiteStorage.name, () => {
|
|
16
17
|
const dbName = 'test.db';
|
|
17
18
|
const instrument = new Instrument(
|
|
18
19
|
0,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Measurement } from '@quantform/core';
|
|
2
1
|
import { existsSync, unlinkSync } from 'fs';
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { Measurement } from '@quantform/core';
|
|
4
|
+
|
|
5
|
+
import { SQLiteStorage } from '@lib/sqlite-storage';
|
|
5
6
|
|
|
6
7
|
describe('sqlite measurement tests', () => {
|
|
7
8
|
const dbName = 'measurement.db';
|
package/src/sqlite-storage.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { Database } from 'better-sqlite3';
|
|
2
|
+
import * as bettersqlite3 from 'better-sqlite3';
|
|
3
|
+
import { existsSync, mkdirSync } from 'fs';
|
|
4
|
+
import { dirname, join } from 'path';
|
|
5
|
+
|
|
1
6
|
import {
|
|
2
7
|
SessionBuilder,
|
|
3
8
|
SessionFeature,
|
|
@@ -6,12 +11,8 @@ import {
|
|
|
6
11
|
StorageQueryOptions,
|
|
7
12
|
workingDirectory
|
|
8
13
|
} from '@quantform/core';
|
|
9
|
-
import { Database } from 'better-sqlite3';
|
|
10
|
-
import * as bettersqlite3 from 'better-sqlite3';
|
|
11
|
-
import { existsSync, mkdirSync } from 'fs';
|
|
12
|
-
import { dirname, join } from 'path';
|
|
13
14
|
|
|
14
|
-
import {
|
|
15
|
+
import { NoConnectionError } from '@lib/error';
|
|
15
16
|
|
|
16
17
|
export function sqlite(directory?: string): SessionFeature {
|
|
17
18
|
return (builder: SessionBuilder) => {
|
|
@@ -41,7 +42,7 @@ export class SQLiteStorage implements Storage {
|
|
|
41
42
|
|
|
42
43
|
private tryCreateTable(table: string) {
|
|
43
44
|
if (!this.connection) {
|
|
44
|
-
throw
|
|
45
|
+
throw new NoConnectionError();
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
this.connection.exec(
|
|
@@ -58,7 +59,7 @@ export class SQLiteStorage implements Storage {
|
|
|
58
59
|
this.tryConnect();
|
|
59
60
|
|
|
60
61
|
if (!this.connection) {
|
|
61
|
-
throw
|
|
62
|
+
throw new NoConnectionError();
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
return this.connection
|
|
@@ -71,7 +72,7 @@ export class SQLiteStorage implements Storage {
|
|
|
71
72
|
this.tryConnect();
|
|
72
73
|
|
|
73
74
|
if (!this.connection) {
|
|
74
|
-
throw
|
|
75
|
+
throw new NoConnectionError();
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
if (
|
|
@@ -111,7 +112,7 @@ export class SQLiteStorage implements Storage {
|
|
|
111
112
|
this.tryConnect();
|
|
112
113
|
|
|
113
114
|
if (!this.connection) {
|
|
114
|
-
throw
|
|
115
|
+
throw new NoConnectionError();
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
this.tryCreateTable(library);
|
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.lib.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"baseUrl": ".",
|
|
4
6
|
"outDir": "dist",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@lib/*": ["src/*"]
|
|
9
|
+
},
|
|
5
10
|
"esModuleInterop": false
|
|
6
11
|
},
|
|
7
12
|
"include": [
|
|
8
13
|
"src/**/*",
|
|
9
14
|
],
|
|
10
15
|
"exclude": [
|
|
11
|
-
"jest.config.
|
|
12
|
-
"
|
|
13
|
-
"**/*.test.ts",
|
|
14
|
-
"lib/**/*"
|
|
16
|
+
"jest.config.js",
|
|
17
|
+
"dist/**/*"
|
|
15
18
|
]
|
|
16
19
|
}
|