fix stats method

This commit is contained in:
Nikita Sivukhin
2025-09-15 11:03:29 +04:00
parent 23e8204bfc
commit 9b5656d4dc
4 changed files with 12 additions and 6 deletions

View File

@@ -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();

View File

@@ -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> {

View File

@@ -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();