@quantform/sqlite 0.7.21 → 0.7.24
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/lib/sqlite-language.d.ts.map +1 -1
- package/lib/sqlite-language.js +4 -3
- package/lib/sqlite-language.spec.js +6 -15
- package/lib/sqlite-storage.d.ts.map +1 -1
- package/lib/sqlite-storage.js +39 -52
- package/lib/sqlite-storage.spec.js +118 -131
- package/package.json +3 -3
- package/src/sqlite-language.ts +2 -0
- package/src/sqlite-storage.spec.ts +68 -69
- package/src/sqlite-storage.ts +4 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-language.d.ts","sourceRoot":"","sources":["../src/sqlite-language.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,UAAU,EACX,MAAM,iBAAiB,CAAC;AAEzB,qBAAa,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,gBAAgB;
|
|
1
|
+
{"version":3,"file":"sqlite-language.d.ts","sourceRoot":"","sources":["../src/sqlite-language.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,UAAU,EACX,MAAM,iBAAiB,CAAC;AAEzB,qBAAa,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,gBAAgB;IAYrC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,GAAG;IAYlD,MAAM,CAAC,aAAa,CAClB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,UAAU;IAiBxB,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC;IAQ/E,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC9D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAwCnC,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC;CAW5E"}
|
package/lib/sqlite-language.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.SQLiteLanguage = void 0;
|
|
|
4
4
|
class SQLiteLanguage {
|
|
5
5
|
static getType(type) {
|
|
6
6
|
switch (type) {
|
|
7
|
+
case 'bigint':
|
|
7
8
|
case 'number':
|
|
8
9
|
return 'INTEGER';
|
|
9
10
|
case 'decimal':
|
|
@@ -14,6 +15,7 @@ class SQLiteLanguage {
|
|
|
14
15
|
}
|
|
15
16
|
static getValue(type, value) {
|
|
16
17
|
switch (type) {
|
|
18
|
+
case 'bigint':
|
|
17
19
|
case 'number':
|
|
18
20
|
return value;
|
|
19
21
|
case 'decimal':
|
|
@@ -23,7 +25,7 @@ class SQLiteLanguage {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
static getConstraint(columnName, type, constraint) {
|
|
26
|
-
switch (constraint
|
|
28
|
+
switch (constraint?.type) {
|
|
27
29
|
case 'eq':
|
|
28
30
|
return `${columnName} = ${SQLiteLanguage.getValue(type, constraint.value)}`;
|
|
29
31
|
case 'gt':
|
|
@@ -41,7 +43,6 @@ class SQLiteLanguage {
|
|
|
41
43
|
return `CREATE TABLE IF NOT EXISTS "${type.discriminator}" (${columns}, PRIMARY KEY (timestamp))`;
|
|
42
44
|
}
|
|
43
45
|
static query(type, query) {
|
|
44
|
-
var _a;
|
|
45
46
|
const columns = `${Object.entries(type.type)
|
|
46
47
|
.map(([name]) => `${name}`)
|
|
47
48
|
.join(', ')}`;
|
|
@@ -58,7 +59,7 @@ class SQLiteLanguage {
|
|
|
58
59
|
sql = `${sql} WHERE ${where.join(' AND ')}`;
|
|
59
60
|
}
|
|
60
61
|
if (query.orderBy) {
|
|
61
|
-
sql = `${sql} ORDER BY timestamp ${
|
|
62
|
+
sql = `${sql} ORDER BY timestamp ${query.orderBy ?? 'ASC'}`;
|
|
62
63
|
}
|
|
63
64
|
if (query.limit) {
|
|
64
65
|
sql = `${sql} LIMIT ${query.limit}`;
|
|
@@ -1,18 +1,9 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const core_1 = require("@quantform/core");
|
|
13
4
|
const sqlite_language_1 = require("./sqlite-language");
|
|
14
5
|
describe(sqlite_language_1.SQLiteLanguage.name, () => {
|
|
15
|
-
test('create table for object', () =>
|
|
6
|
+
test('create table for object', async () => {
|
|
16
7
|
const object = core_1.Storage.createObject('orders', {
|
|
17
8
|
timestamp: 'number',
|
|
18
9
|
price: 'decimal',
|
|
@@ -20,8 +11,8 @@ describe(sqlite_language_1.SQLiteLanguage.name, () => {
|
|
|
20
11
|
});
|
|
21
12
|
const sql = sqlite_language_1.SQLiteLanguage.createTable(object);
|
|
22
13
|
expect(sql).toEqual(`CREATE TABLE IF NOT EXISTS "orders" (timestamp INTEGER NOT NULL, price TEXT NOT NULL, id TEXT NOT NULL, PRIMARY KEY (timestamp))`);
|
|
23
|
-
})
|
|
24
|
-
test('select to query object', () =>
|
|
14
|
+
});
|
|
15
|
+
test('select to query object', async () => {
|
|
25
16
|
const object = core_1.Storage.createObject('orders', {
|
|
26
17
|
timestamp: 'number',
|
|
27
18
|
price: 'decimal',
|
|
@@ -37,8 +28,8 @@ describe(sqlite_language_1.SQLiteLanguage.name, () => {
|
|
|
37
28
|
offset: 2
|
|
38
29
|
});
|
|
39
30
|
expect(sql).toEqual(`SELECT timestamp, price, id FROM "orders" WHERE timestamp < 100 AND id = 'unique-id' AND price = '1.123456789123456789' LIMIT 3 OFFSET 2`);
|
|
40
|
-
})
|
|
41
|
-
test('replace statement', () =>
|
|
31
|
+
});
|
|
32
|
+
test('replace statement', async () => {
|
|
42
33
|
const object = core_1.Storage.createObject('orders', {
|
|
43
34
|
timestamp: 'number',
|
|
44
35
|
price: 'decimal',
|
|
@@ -46,5 +37,5 @@ describe(sqlite_language_1.SQLiteLanguage.name, () => {
|
|
|
46
37
|
});
|
|
47
38
|
const sql = sqlite_language_1.SQLiteLanguage.replace(object);
|
|
48
39
|
expect(sql).toEqual(`REPLACE INTO "orders" (timestamp, price, id) VALUES(?, ?, ?)`);
|
|
49
|
-
})
|
|
40
|
+
});
|
|
50
41
|
});
|
|
@@ -1 +1 @@
|
|
|
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,gBAAgB,EAEhB,KAAK,EACL,WAAW,EACX,eAAe,EACf,OAAO,EACP,cAAc,EAEf,MAAM,iBAAiB,CAAC;AAIzB,qBACa,oBAAqB,YAAW,cAAc;IAC7C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAAV,SAAS,CAAC,oBAAQ;IAE/C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAK1B;AAED,qBAAa,aAAc,YAAW,OAAO;IAI/B,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAHrC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAC,CAAW;gBAEL,QAAQ,EAAE,MAAM;IAQ/B,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAQ/B,KAAK,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC7D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,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,gBAAgB,EAEhB,KAAK,EACL,WAAW,EACX,eAAe,EACf,OAAO,EACP,cAAc,EAEf,MAAM,iBAAiB,CAAC;AAIzB,qBACa,oBAAqB,YAAW,cAAc;IAC7C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAAV,SAAS,CAAC,oBAAQ;IAE/C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAK1B;AAED,qBAAa,aAAc,YAAW,OAAO;IAI/B,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAHrC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAC,CAAW;gBAEL,QAAQ,EAAE,MAAM;IAQ/B,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAQ/B,KAAK,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC7D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IA8B3B,IAAI,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAC5D,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAC7B,OAAO,CAAC,IAAI,CAAC;CAuBjB"}
|
package/lib/sqlite-storage.js
CHANGED
|
@@ -8,15 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
12
|
exports.SQLiteStorage = exports.SQLiteStorageFactory = void 0;
|
|
22
13
|
const bettersqlite3 = require("better-sqlite3");
|
|
@@ -29,8 +20,7 @@ let SQLiteStorageFactory = class SQLiteStorageFactory {
|
|
|
29
20
|
this.directory = directory;
|
|
30
21
|
}
|
|
31
22
|
for(key) {
|
|
32
|
-
|
|
33
|
-
return new SQLiteStorage((0, path_1.join)((_a = this.directory) !== null && _a !== void 0 ? _a : (0, core_1.workingDirectory)(), `/${key}.sqlite`));
|
|
23
|
+
return new SQLiteStorage((0, path_1.join)(this.directory ?? (0, core_1.workingDirectory)(), `/${key}.sqlite`));
|
|
34
24
|
}
|
|
35
25
|
};
|
|
36
26
|
SQLiteStorageFactory = __decorate([
|
|
@@ -46,52 +36,49 @@ class SQLiteStorage {
|
|
|
46
36
|
}
|
|
47
37
|
this.connection = bettersqlite3(this.filename);
|
|
48
38
|
}
|
|
49
|
-
index() {
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.map((it) => it.name);
|
|
55
|
-
});
|
|
39
|
+
async index() {
|
|
40
|
+
return this.connection
|
|
41
|
+
.prepare("SELECT name FROM sqlite_master WHERE type='table'")
|
|
42
|
+
.all()
|
|
43
|
+
.map((it) => it.name);
|
|
56
44
|
}
|
|
57
45
|
// eslint-disable-next-line complexity
|
|
58
|
-
query(type, query) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
46
|
+
async query(type, query) {
|
|
47
|
+
if (!this.tables) {
|
|
48
|
+
this.tables = await this.index();
|
|
49
|
+
}
|
|
50
|
+
if (!this.tables.includes(type.discriminator)) {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
const objects = await this.connection
|
|
54
|
+
.prepare(sqlite_language_1.SQLiteLanguage.query(type, query))
|
|
55
|
+
.all();
|
|
56
|
+
const types = Object.keys(type.type);
|
|
57
|
+
objects.forEach((it) => {
|
|
58
|
+
for (const prop of types) {
|
|
59
|
+
if (type.type[prop] == 'decimal') {
|
|
60
|
+
it[prop] = (0, core_1.d)(it[prop]);
|
|
61
|
+
}
|
|
62
|
+
if (type.type[prop] == 'bigint') {
|
|
63
|
+
it[prop] = BigInt(it[prop]);
|
|
75
64
|
}
|
|
76
|
-
});
|
|
77
|
-
return objects;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
save(type, objects) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
if (!this.tables) {
|
|
83
|
-
this.tables = yield this.index();
|
|
84
|
-
}
|
|
85
|
-
if (!this.tables.includes(type.discriminator)) {
|
|
86
|
-
this.connection.exec(sqlite_language_1.SQLiteLanguage.createTable(type));
|
|
87
|
-
this.tables = undefined;
|
|
88
65
|
}
|
|
89
|
-
const statement = this.connection.prepare(sqlite_language_1.SQLiteLanguage.replace(type));
|
|
90
|
-
const types = Object.keys(type.type);
|
|
91
|
-
const mapper = (it) => types.map(type => it[type].toString());
|
|
92
|
-
const insertMany = this.connection.transaction(rows => rows.forEach((it) => statement.run(mapper(it))));
|
|
93
|
-
insertMany(objects);
|
|
94
66
|
});
|
|
67
|
+
return objects;
|
|
68
|
+
}
|
|
69
|
+
async save(type, objects) {
|
|
70
|
+
if (!this.tables) {
|
|
71
|
+
this.tables = await this.index();
|
|
72
|
+
}
|
|
73
|
+
if (!this.tables.includes(type.discriminator)) {
|
|
74
|
+
this.connection.exec(sqlite_language_1.SQLiteLanguage.createTable(type));
|
|
75
|
+
this.tables = undefined;
|
|
76
|
+
}
|
|
77
|
+
const statement = this.connection.prepare(sqlite_language_1.SQLiteLanguage.replace(type));
|
|
78
|
+
const types = Object.keys(type.type);
|
|
79
|
+
const mapper = (it) => types.map(type => it[type].toString());
|
|
80
|
+
const insertMany = this.connection.transaction(rows => rows.forEach((it) => statement.run(mapper(it))));
|
|
81
|
+
insertMany(objects);
|
|
95
82
|
}
|
|
96
83
|
}
|
|
97
84
|
exports.SQLiteStorage = SQLiteStorage;
|
|
@@ -1,204 +1,191 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const fs_1 = require("fs");
|
|
13
4
|
const core_1 = require("@quantform/core");
|
|
14
5
|
const sqlite_storage_1 = require("./sqlite-storage");
|
|
15
6
|
describe(sqlite_storage_1.SQLiteStorage.name, () => {
|
|
16
7
|
let fixtures;
|
|
17
|
-
beforeEach(() =>
|
|
18
|
-
fixtures =
|
|
19
|
-
})
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
fixtures = await getFixtures();
|
|
10
|
+
});
|
|
20
11
|
afterEach(() => {
|
|
21
12
|
fixtures.dispose();
|
|
22
13
|
});
|
|
23
|
-
|
|
24
|
-
test('index return the names of discriminators', async () => {
|
|
25
|
-
const { sut } = fixtures;
|
|
26
|
-
|
|
27
|
-
await sut.save({ discriminator: 'pricing' }, [{ timestamp: 1, message: 'test-1' }]);
|
|
28
|
-
await sut.save({ discriminator: 'ordering' }, [{ timestamp: 1, message: 'test-1' }]);
|
|
29
|
-
|
|
30
|
-
const index = await sut.index();
|
|
31
|
-
|
|
32
|
-
expect(index).toEqual(['pricing', 'ordering']);
|
|
33
|
-
});
|
|
34
|
-
*/
|
|
35
|
-
test('write and read single object', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
test('write and read single object', async () => {
|
|
36
15
|
const { sut, object } = fixtures;
|
|
37
|
-
|
|
38
|
-
{
|
|
16
|
+
await sut.save(object, [
|
|
17
|
+
{
|
|
18
|
+
timestamp: (0, core_1.ns)(1),
|
|
19
|
+
id: '123 123',
|
|
20
|
+
price: (0, core_1.d)('1.123456789123456789'),
|
|
21
|
+
quantity: 5
|
|
22
|
+
}
|
|
39
23
|
]);
|
|
40
|
-
const set =
|
|
24
|
+
const set = await sut.query(object, {
|
|
41
25
|
where: {
|
|
42
26
|
id: (0, core_1.eq)('123 123')
|
|
43
27
|
}
|
|
44
28
|
});
|
|
45
29
|
expect(set).toEqual([
|
|
46
|
-
{
|
|
30
|
+
{
|
|
31
|
+
timestamp: (0, core_1.ns)(1),
|
|
32
|
+
id: '123 123',
|
|
33
|
+
price: (0, core_1.d)('1.123456789123456789'),
|
|
34
|
+
quantity: 5
|
|
35
|
+
}
|
|
47
36
|
]);
|
|
48
|
-
})
|
|
49
|
-
test('save and read full data', () =>
|
|
37
|
+
});
|
|
38
|
+
test('save and read full data', async () => {
|
|
50
39
|
const { sut } = fixtures;
|
|
51
40
|
const pricing = core_1.Storage.createObject('pricing', {
|
|
52
|
-
timestamp: '
|
|
41
|
+
timestamp: 'bigint',
|
|
53
42
|
rate: 'decimal'
|
|
54
43
|
});
|
|
55
|
-
|
|
56
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
57
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
58
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
59
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
60
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
44
|
+
await sut.save(pricing, [
|
|
45
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
46
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
47
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
48
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
49
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
61
50
|
]);
|
|
62
|
-
const set =
|
|
51
|
+
const set = await sut.query(pricing, {});
|
|
63
52
|
expect(set).toEqual([
|
|
64
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
65
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
66
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
67
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
68
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
53
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
54
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
55
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
56
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
57
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
69
58
|
]);
|
|
70
|
-
})
|
|
71
|
-
test('save and read limited data', () =>
|
|
59
|
+
});
|
|
60
|
+
test('save and read limited data', async () => {
|
|
72
61
|
const { sut } = fixtures;
|
|
73
62
|
const pricing = core_1.Storage.createObject('pricing', {
|
|
74
|
-
timestamp: '
|
|
63
|
+
timestamp: 'bigint',
|
|
75
64
|
rate: 'decimal'
|
|
76
65
|
});
|
|
77
|
-
|
|
78
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
79
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
80
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
81
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
82
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
66
|
+
await sut.save(pricing, [
|
|
67
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
68
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
69
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
70
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
71
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
83
72
|
]);
|
|
84
|
-
const set =
|
|
73
|
+
const set = await sut.query(pricing, { limit: 3 });
|
|
85
74
|
expect(set).toEqual([
|
|
86
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
87
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
88
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) }
|
|
75
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
76
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
77
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) }
|
|
89
78
|
]);
|
|
90
|
-
})
|
|
91
|
-
test('save and read desc ordered data', () =>
|
|
79
|
+
});
|
|
80
|
+
test('save and read desc ordered data', async () => {
|
|
92
81
|
const { sut } = fixtures;
|
|
93
82
|
const pricing = core_1.Storage.createObject('pricing', {
|
|
94
|
-
timestamp: '
|
|
83
|
+
timestamp: 'bigint',
|
|
95
84
|
rate: 'decimal'
|
|
96
85
|
});
|
|
97
|
-
|
|
98
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
99
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
100
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
101
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
102
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
86
|
+
await sut.save(pricing, [
|
|
87
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
88
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
89
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
90
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
91
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
103
92
|
]);
|
|
104
|
-
const set =
|
|
93
|
+
const set = await sut.query(pricing, { orderBy: 'DESC' });
|
|
105
94
|
expect(set).toEqual([
|
|
106
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) },
|
|
107
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
108
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
109
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
110
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) }
|
|
95
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) },
|
|
96
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
97
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
98
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
99
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) }
|
|
111
100
|
]);
|
|
112
|
-
})
|
|
113
|
-
test('save and read filtered eq data', () =>
|
|
101
|
+
});
|
|
102
|
+
test('save and read filtered eq data', async () => {
|
|
114
103
|
const { sut } = fixtures;
|
|
115
104
|
const pricing = core_1.Storage.createObject('pricing', {
|
|
116
|
-
timestamp: '
|
|
105
|
+
timestamp: 'bigint',
|
|
117
106
|
rate: 'decimal'
|
|
118
107
|
});
|
|
119
|
-
|
|
120
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
121
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
122
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
123
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
124
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
108
|
+
await sut.save(pricing, [
|
|
109
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
110
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
111
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
112
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
113
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
125
114
|
]);
|
|
126
|
-
const set =
|
|
115
|
+
const set = await sut.query(pricing, {
|
|
127
116
|
where: {
|
|
128
117
|
timestamp: (0, core_1.eq)(4)
|
|
129
118
|
}
|
|
130
119
|
});
|
|
131
|
-
expect(set).toEqual([{ timestamp: 4, rate: (0, core_1.d)(4) }]);
|
|
132
|
-
})
|
|
133
|
-
test('save and read filtered lt data', () =>
|
|
120
|
+
expect(set).toEqual([{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) }]);
|
|
121
|
+
});
|
|
122
|
+
test('save and read filtered lt data', async () => {
|
|
134
123
|
const { sut } = fixtures;
|
|
135
124
|
const pricing = core_1.Storage.createObject('pricing', {
|
|
136
|
-
timestamp: '
|
|
125
|
+
timestamp: 'bigint',
|
|
137
126
|
rate: 'decimal'
|
|
138
127
|
});
|
|
139
|
-
|
|
140
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
141
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
142
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
143
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
144
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
128
|
+
await sut.save(pricing, [
|
|
129
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
130
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
131
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
132
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
133
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
145
134
|
]);
|
|
146
|
-
const set =
|
|
135
|
+
const set = await sut.query(pricing, {
|
|
147
136
|
where: {
|
|
148
137
|
timestamp: (0, core_1.lt)(3)
|
|
149
138
|
}
|
|
150
139
|
});
|
|
151
140
|
expect(set).toEqual([
|
|
152
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
153
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) }
|
|
141
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
142
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) }
|
|
154
143
|
]);
|
|
155
|
-
})
|
|
156
|
-
test('save and read filtered gt data', () =>
|
|
144
|
+
});
|
|
145
|
+
test('save and read filtered gt data', async () => {
|
|
157
146
|
const { sut } = fixtures;
|
|
158
147
|
const pricing = core_1.Storage.createObject('pricing', {
|
|
159
|
-
timestamp: '
|
|
148
|
+
timestamp: 'bigint',
|
|
160
149
|
rate: 'decimal'
|
|
161
150
|
});
|
|
162
|
-
|
|
163
|
-
{ timestamp: 1, rate: (0, core_1.d)(1) },
|
|
164
|
-
{ timestamp: 2, rate: (0, core_1.d)(2) },
|
|
165
|
-
{ timestamp: 3, rate: (0, core_1.d)(3) },
|
|
166
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
167
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
151
|
+
await sut.save(pricing, [
|
|
152
|
+
{ timestamp: (0, core_1.ns)(1), rate: (0, core_1.d)(1) },
|
|
153
|
+
{ timestamp: (0, core_1.ns)(2), rate: (0, core_1.d)(2) },
|
|
154
|
+
{ timestamp: (0, core_1.ns)(3), rate: (0, core_1.d)(3) },
|
|
155
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
156
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
168
157
|
]);
|
|
169
|
-
const set =
|
|
158
|
+
const set = await sut.query(pricing, {
|
|
170
159
|
where: {
|
|
171
160
|
timestamp: (0, core_1.gt)(3)
|
|
172
161
|
}
|
|
173
162
|
});
|
|
174
163
|
expect(set).toEqual([
|
|
175
|
-
{ timestamp: 4, rate: (0, core_1.d)(4) },
|
|
176
|
-
{ timestamp: 5, rate: (0, core_1.d)(5) }
|
|
164
|
+
{ timestamp: (0, core_1.ns)(4), rate: (0, core_1.d)(4) },
|
|
165
|
+
{ timestamp: (0, core_1.ns)(5), rate: (0, core_1.d)(5) }
|
|
177
166
|
]);
|
|
178
|
-
})
|
|
167
|
+
});
|
|
179
168
|
});
|
|
180
|
-
function getFixtures() {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
(0, fs_1.unlinkSync)(sut.filename);
|
|
200
|
-
}
|
|
169
|
+
async function getFixtures() {
|
|
170
|
+
const { get } = await (0, core_1.makeTestModule)([
|
|
171
|
+
{
|
|
172
|
+
provide: 'storage',
|
|
173
|
+
useValue: new sqlite_storage_1.SQLiteStorage('test.db')
|
|
174
|
+
}
|
|
175
|
+
]);
|
|
176
|
+
const sut = get('storage');
|
|
177
|
+
return {
|
|
178
|
+
sut,
|
|
179
|
+
object: core_1.Storage.createObject('test', {
|
|
180
|
+
timestamp: 'bigint',
|
|
181
|
+
price: 'decimal',
|
|
182
|
+
quantity: 'number',
|
|
183
|
+
id: 'string'
|
|
184
|
+
}),
|
|
185
|
+
dispose() {
|
|
186
|
+
if ((0, fs_1.existsSync)(sut.filename)) {
|
|
187
|
+
(0, fs_1.unlinkSync)(sut.filename);
|
|
201
188
|
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
204
191
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quantform/sqlite",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Mateusz Majchrzak",
|
|
6
6
|
"description": "Node.js library for building systematic trading strategies in reactive way.",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"typings": "lib/index.d.ts",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/better-sqlite3": "^7.6.12",
|
|
18
|
-
"@quantform/core": "0.7.
|
|
18
|
+
"@quantform/core": "0.7.24"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@quantform/core": "0.7.
|
|
21
|
+
"@quantform/core": "0.7.24"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"better-sqlite3": "^11.9.1"
|
package/src/sqlite-language.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
export class SQLiteLanguage {
|
|
11
11
|
static getType(type: QueryMappingType) {
|
|
12
12
|
switch (type) {
|
|
13
|
+
case 'bigint':
|
|
13
14
|
case 'number':
|
|
14
15
|
return 'INTEGER';
|
|
15
16
|
case 'decimal':
|
|
@@ -21,6 +22,7 @@ export class SQLiteLanguage {
|
|
|
21
22
|
|
|
22
23
|
static getValue(type: QueryMappingType, value: any) {
|
|
23
24
|
switch (type) {
|
|
25
|
+
case 'bigint':
|
|
24
26
|
case 'number':
|
|
25
27
|
return value;
|
|
26
28
|
case 'decimal':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, unlinkSync } from 'fs';
|
|
2
2
|
|
|
3
|
-
import { d, eq, gt, lt, makeTestModule, Storage } from '@quantform/core';
|
|
3
|
+
import { d, eq, gt, lt, makeTestModule, ns, Storage } from '@quantform/core';
|
|
4
4
|
|
|
5
5
|
import { SQLiteStorage } from './sqlite-storage';
|
|
6
6
|
|
|
@@ -14,23 +14,17 @@ describe(SQLiteStorage.name, () => {
|
|
|
14
14
|
afterEach(() => {
|
|
15
15
|
fixtures.dispose();
|
|
16
16
|
});
|
|
17
|
-
/*
|
|
18
|
-
test('index return the names of discriminators', async () => {
|
|
19
|
-
const { sut } = fixtures;
|
|
20
|
-
|
|
21
|
-
await sut.save({ discriminator: 'pricing' }, [{ timestamp: 1, message: 'test-1' }]);
|
|
22
|
-
await sut.save({ discriminator: 'ordering' }, [{ timestamp: 1, message: 'test-1' }]);
|
|
23
|
-
|
|
24
|
-
const index = await sut.index();
|
|
25
17
|
|
|
26
|
-
expect(index).toEqual(['pricing', 'ordering']);
|
|
27
|
-
});
|
|
28
|
-
*/
|
|
29
18
|
test('write and read single object', async () => {
|
|
30
19
|
const { sut, object } = fixtures;
|
|
31
20
|
|
|
32
21
|
await sut.save(object, [
|
|
33
|
-
{
|
|
22
|
+
{
|
|
23
|
+
timestamp: ns(1),
|
|
24
|
+
id: '123 123',
|
|
25
|
+
price: d('1.123456789123456789'),
|
|
26
|
+
quantity: 5
|
|
27
|
+
}
|
|
34
28
|
]);
|
|
35
29
|
|
|
36
30
|
const set = await sut.query(object, {
|
|
@@ -40,7 +34,12 @@ describe(SQLiteStorage.name, () => {
|
|
|
40
34
|
});
|
|
41
35
|
|
|
42
36
|
expect(set).toEqual([
|
|
43
|
-
{
|
|
37
|
+
{
|
|
38
|
+
timestamp: ns(1),
|
|
39
|
+
id: '123 123',
|
|
40
|
+
price: d('1.123456789123456789'),
|
|
41
|
+
quantity: 5
|
|
42
|
+
}
|
|
44
43
|
]);
|
|
45
44
|
});
|
|
46
45
|
|
|
@@ -48,26 +47,26 @@ describe(SQLiteStorage.name, () => {
|
|
|
48
47
|
const { sut } = fixtures;
|
|
49
48
|
|
|
50
49
|
const pricing = Storage.createObject('pricing', {
|
|
51
|
-
timestamp: '
|
|
50
|
+
timestamp: 'bigint',
|
|
52
51
|
rate: 'decimal'
|
|
53
52
|
});
|
|
54
53
|
|
|
55
54
|
await sut.save(pricing, [
|
|
56
|
-
{ timestamp: 1, rate: d(1) },
|
|
57
|
-
{ timestamp: 2, rate: d(2) },
|
|
58
|
-
{ timestamp: 3, rate: d(3) },
|
|
59
|
-
{ timestamp: 4, rate: d(4) },
|
|
60
|
-
{ timestamp: 5, rate: d(5) }
|
|
55
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
56
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
57
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
58
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
59
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
61
60
|
]);
|
|
62
61
|
|
|
63
62
|
const set = await sut.query(pricing, {});
|
|
64
63
|
|
|
65
64
|
expect(set).toEqual([
|
|
66
|
-
{ timestamp: 1, rate: d(1) },
|
|
67
|
-
{ timestamp: 2, rate: d(2) },
|
|
68
|
-
{ timestamp: 3, rate: d(3) },
|
|
69
|
-
{ timestamp: 4, rate: d(4) },
|
|
70
|
-
{ timestamp: 5, rate: d(5) }
|
|
65
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
66
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
67
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
68
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
69
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
71
70
|
]);
|
|
72
71
|
});
|
|
73
72
|
|
|
@@ -75,24 +74,24 @@ describe(SQLiteStorage.name, () => {
|
|
|
75
74
|
const { sut } = fixtures;
|
|
76
75
|
|
|
77
76
|
const pricing = Storage.createObject('pricing', {
|
|
78
|
-
timestamp: '
|
|
77
|
+
timestamp: 'bigint',
|
|
79
78
|
rate: 'decimal'
|
|
80
79
|
});
|
|
81
80
|
|
|
82
81
|
await sut.save(pricing, [
|
|
83
|
-
{ timestamp: 1, rate: d(1) },
|
|
84
|
-
{ timestamp: 2, rate: d(2) },
|
|
85
|
-
{ timestamp: 3, rate: d(3) },
|
|
86
|
-
{ timestamp: 4, rate: d(4) },
|
|
87
|
-
{ timestamp: 5, rate: d(5) }
|
|
82
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
83
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
84
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
85
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
86
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
88
87
|
]);
|
|
89
88
|
|
|
90
89
|
const set = await sut.query(pricing, { limit: 3 });
|
|
91
90
|
|
|
92
91
|
expect(set).toEqual([
|
|
93
|
-
{ timestamp: 1, rate: d(1) },
|
|
94
|
-
{ timestamp: 2, rate: d(2) },
|
|
95
|
-
{ timestamp: 3, rate: d(3) }
|
|
92
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
93
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
94
|
+
{ timestamp: ns(3), rate: d(3) }
|
|
96
95
|
]);
|
|
97
96
|
});
|
|
98
97
|
|
|
@@ -100,26 +99,26 @@ describe(SQLiteStorage.name, () => {
|
|
|
100
99
|
const { sut } = fixtures;
|
|
101
100
|
|
|
102
101
|
const pricing = Storage.createObject('pricing', {
|
|
103
|
-
timestamp: '
|
|
102
|
+
timestamp: 'bigint',
|
|
104
103
|
rate: 'decimal'
|
|
105
104
|
});
|
|
106
105
|
|
|
107
106
|
await sut.save(pricing, [
|
|
108
|
-
{ timestamp: 1, rate: d(1) },
|
|
109
|
-
{ timestamp: 2, rate: d(2) },
|
|
110
|
-
{ timestamp: 3, rate: d(3) },
|
|
111
|
-
{ timestamp: 4, rate: d(4) },
|
|
112
|
-
{ timestamp: 5, rate: d(5) }
|
|
107
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
108
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
109
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
110
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
111
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
113
112
|
]);
|
|
114
113
|
|
|
115
114
|
const set = await sut.query(pricing, { orderBy: 'DESC' });
|
|
116
115
|
|
|
117
116
|
expect(set).toEqual([
|
|
118
|
-
{ timestamp: 5, rate: d(5) },
|
|
119
|
-
{ timestamp: 4, rate: d(4) },
|
|
120
|
-
{ timestamp: 3, rate: d(3) },
|
|
121
|
-
{ timestamp: 2, rate: d(2) },
|
|
122
|
-
{ timestamp: 1, rate: d(1) }
|
|
117
|
+
{ timestamp: ns(5), rate: d(5) },
|
|
118
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
119
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
120
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
121
|
+
{ timestamp: ns(1), rate: d(1) }
|
|
123
122
|
]);
|
|
124
123
|
});
|
|
125
124
|
|
|
@@ -127,16 +126,16 @@ describe(SQLiteStorage.name, () => {
|
|
|
127
126
|
const { sut } = fixtures;
|
|
128
127
|
|
|
129
128
|
const pricing = Storage.createObject('pricing', {
|
|
130
|
-
timestamp: '
|
|
129
|
+
timestamp: 'bigint',
|
|
131
130
|
rate: 'decimal'
|
|
132
131
|
});
|
|
133
132
|
|
|
134
133
|
await sut.save(pricing, [
|
|
135
|
-
{ timestamp: 1, rate: d(1) },
|
|
136
|
-
{ timestamp: 2, rate: d(2) },
|
|
137
|
-
{ timestamp: 3, rate: d(3) },
|
|
138
|
-
{ timestamp: 4, rate: d(4) },
|
|
139
|
-
{ timestamp: 5, rate: d(5) }
|
|
134
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
135
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
136
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
137
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
138
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
140
139
|
]);
|
|
141
140
|
|
|
142
141
|
const set = await sut.query(pricing, {
|
|
@@ -145,23 +144,23 @@ describe(SQLiteStorage.name, () => {
|
|
|
145
144
|
}
|
|
146
145
|
});
|
|
147
146
|
|
|
148
|
-
expect(set).toEqual([{ timestamp: 4, rate: d(4) }]);
|
|
147
|
+
expect(set).toEqual([{ timestamp: ns(4), rate: d(4) }]);
|
|
149
148
|
});
|
|
150
149
|
|
|
151
150
|
test('save and read filtered lt data', async () => {
|
|
152
151
|
const { sut } = fixtures;
|
|
153
152
|
|
|
154
153
|
const pricing = Storage.createObject('pricing', {
|
|
155
|
-
timestamp: '
|
|
154
|
+
timestamp: 'bigint',
|
|
156
155
|
rate: 'decimal'
|
|
157
156
|
});
|
|
158
157
|
|
|
159
158
|
await sut.save(pricing, [
|
|
160
|
-
{ timestamp: 1, rate: d(1) },
|
|
161
|
-
{ timestamp: 2, rate: d(2) },
|
|
162
|
-
{ timestamp: 3, rate: d(3) },
|
|
163
|
-
{ timestamp: 4, rate: d(4) },
|
|
164
|
-
{ timestamp: 5, rate: d(5) }
|
|
159
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
160
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
161
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
162
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
163
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
165
164
|
]);
|
|
166
165
|
|
|
167
166
|
const set = await sut.query(pricing, {
|
|
@@ -171,8 +170,8 @@ describe(SQLiteStorage.name, () => {
|
|
|
171
170
|
});
|
|
172
171
|
|
|
173
172
|
expect(set).toEqual([
|
|
174
|
-
{ timestamp: 1, rate: d(1) },
|
|
175
|
-
{ timestamp: 2, rate: d(2) }
|
|
173
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
174
|
+
{ timestamp: ns(2), rate: d(2) }
|
|
176
175
|
]);
|
|
177
176
|
});
|
|
178
177
|
|
|
@@ -180,16 +179,16 @@ describe(SQLiteStorage.name, () => {
|
|
|
180
179
|
const { sut } = fixtures;
|
|
181
180
|
|
|
182
181
|
const pricing = Storage.createObject('pricing', {
|
|
183
|
-
timestamp: '
|
|
182
|
+
timestamp: 'bigint',
|
|
184
183
|
rate: 'decimal'
|
|
185
184
|
});
|
|
186
185
|
|
|
187
186
|
await sut.save(pricing, [
|
|
188
|
-
{ timestamp: 1, rate: d(1) },
|
|
189
|
-
{ timestamp: 2, rate: d(2) },
|
|
190
|
-
{ timestamp: 3, rate: d(3) },
|
|
191
|
-
{ timestamp: 4, rate: d(4) },
|
|
192
|
-
{ timestamp: 5, rate: d(5) }
|
|
187
|
+
{ timestamp: ns(1), rate: d(1) },
|
|
188
|
+
{ timestamp: ns(2), rate: d(2) },
|
|
189
|
+
{ timestamp: ns(3), rate: d(3) },
|
|
190
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
191
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
193
192
|
]);
|
|
194
193
|
|
|
195
194
|
const set = await sut.query(pricing, {
|
|
@@ -199,8 +198,8 @@ describe(SQLiteStorage.name, () => {
|
|
|
199
198
|
});
|
|
200
199
|
|
|
201
200
|
expect(set).toEqual([
|
|
202
|
-
{ timestamp: 4, rate: d(4) },
|
|
203
|
-
{ timestamp: 5, rate: d(5) }
|
|
201
|
+
{ timestamp: ns(4), rate: d(4) },
|
|
202
|
+
{ timestamp: ns(5), rate: d(5) }
|
|
204
203
|
]);
|
|
205
204
|
});
|
|
206
205
|
});
|
|
@@ -218,7 +217,7 @@ async function getFixtures() {
|
|
|
218
217
|
return {
|
|
219
218
|
sut,
|
|
220
219
|
object: Storage.createObject('test', {
|
|
221
|
-
timestamp: '
|
|
220
|
+
timestamp: 'bigint',
|
|
222
221
|
price: 'decimal',
|
|
223
222
|
quantity: 'number',
|
|
224
223
|
id: 'string'
|