mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 12:04:21 +01:00
fix stats method
This commit is contained in:
@@ -241,6 +241,7 @@ test('persistence-pull-push', async () => {
|
||||
const db1 = await connect({ path: path1, url: process.env.VITE_TURSO_DB_URL });
|
||||
await db1.exec(`INSERT INTO q VALUES ('k1', 'v1')`);
|
||||
await db1.exec(`INSERT INTO q VALUES ('k2', 'v2')`);
|
||||
const stats1 = await db1.stats();
|
||||
|
||||
const db2 = await connect({ path: path2, url: process.env.VITE_TURSO_DB_URL });
|
||||
await db2.exec(`INSERT INTO q VALUES ('k3', 'v3')`);
|
||||
@@ -248,6 +249,9 @@ test('persistence-pull-push', async () => {
|
||||
|
||||
await Promise.all([db1.push(), db2.push()]);
|
||||
await Promise.all([db1.pull(), db2.pull()]);
|
||||
const stats2 = await db1.stats();
|
||||
console.info(stats1, stats2);
|
||||
expect(stats1.revision).not.toBe(stats2.revision);
|
||||
|
||||
const rows1 = await db1.prepare('SELECT * FROM q').all();
|
||||
const rows2 = await db2.prepare('SELECT * FROM q').all();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { registerFileAtWorker, unregisterFileAtWorker } from "@tursodatabase/database-browser-common"
|
||||
import { DatabasePromise, DatabaseOpts, NativeDatabase } from "@tursodatabase/database-common"
|
||||
import { ProtocolIo, run, SyncOpts, RunOpts, memoryIO } from "@tursodatabase/sync-common";
|
||||
import { ProtocolIo, run, SyncOpts, RunOpts, memoryIO, SyncEngineStats } from "@tursodatabase/sync-common";
|
||||
|
||||
let BrowserIo: ProtocolIo = {
|
||||
async read(path: string): Promise<Buffer | Uint8Array | null> {
|
||||
@@ -44,7 +44,7 @@ class Database extends DatabasePromise {
|
||||
async checkpoint() {
|
||||
await run(this.runOpts, this.io, this.engine, this.engine.checkpoint());
|
||||
}
|
||||
async stats(): Promise<{ operations: number, mainWal: number, revertWal: number, lastPullUnixTime: number, lastPushUnixTime: number | null }> {
|
||||
async stats(): Promise<SyncEngineStats> {
|
||||
return (await run(this.runOpts, this.io, this.engine, this.engine.stats()));
|
||||
}
|
||||
override async close(): Promise<void> {
|
||||
|
||||
@@ -261,6 +261,7 @@ test('persistence-pull-push', async () => {
|
||||
const db1 = await connect({ path: path1, url: process.env.VITE_TURSO_DB_URL });
|
||||
await db1.exec(`INSERT INTO q VALUES ('k1', 'v1')`);
|
||||
await db1.exec(`INSERT INTO q VALUES ('k2', 'v2')`);
|
||||
const stats1 = await db1.stats();
|
||||
|
||||
const db2 = await connect({ path: path2, url: process.env.VITE_TURSO_DB_URL });
|
||||
await db2.exec(`INSERT INTO q VALUES ('k3', 'v3')`);
|
||||
@@ -268,6 +269,9 @@ test('persistence-pull-push', async () => {
|
||||
|
||||
await Promise.all([db1.push(), db2.push()]);
|
||||
await Promise.all([db1.pull(), db2.pull()]);
|
||||
const stats2 = await db1.stats();
|
||||
console.info(stats1, stats2);
|
||||
expect(stats1.revision).not.toBe(stats2.revision);
|
||||
|
||||
const rows1 = await db1.prepare('SELECT * FROM q').all();
|
||||
const rows2 = await db2.prepare('SELECT * FROM q').all();
|
||||
|
||||
Reference in New Issue
Block a user