Skip to content

Commit fd0b4cd

Browse files
committed
FIXES
1 parent 30b7d35 commit fd0b4cd

5 files changed

Lines changed: 19 additions & 31 deletions

File tree

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface Options {
99
syncUrl?: string
1010
syncPeriod?: number
1111
}
12+
export declare function databaseSyncSync(db: Database): SyncResult
1213
export declare function databasePrepareSync(db: Database, sql: string): Statement
1314
export interface RunResult {
1415
changes: number
@@ -44,8 +45,7 @@ export declare class Database {
4445
close(): void
4546
defaultSafeIntegers(toggle?: boolean | undefined | null): void
4647
unsafeMode(): void
47-
sync(): SyncResult
48-
syncUntil(replicationIndex: number): SyncResult
48+
sync(): Promise<SyncResult>
4949
}
5050
export declare class Statement {
5151
columns(): unknown[]

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,11 @@ if (!nativeBinding) {
310310
throw new Error(`Failed to load native binding`)
311311
}
312312

313-
const { SqliteError, Database, databasePrepareSync, Statement, RowsIterator, iteratorNextSync, Record } = nativeBinding
313+
const { SqliteError, Database, databaseSyncSync, databasePrepareSync, Statement, RowsIterator, iteratorNextSync, Record } = nativeBinding
314314

315315
module.exports.SqliteError = SqliteError
316316
module.exports.Database = Database
317+
module.exports.databaseSyncSync = databaseSyncSync
317318
module.exports.databasePrepareSync = databasePrepareSync
318319
module.exports.Statement = Statement
319320
module.exports.RowsIterator = RowsIterator

promise.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ class Database {
5252
}
5353

5454
sync() {
55-
throw new Error("not implemented");
55+
try {
56+
return this.db.sync();
57+
} catch (err) {
58+
throw convertError(err);
59+
}
5660
}
5761

5862
syncUntil(replicationIndex) {

src/lib.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -433,28 +433,19 @@ impl Database {
433433
}
434434

435435
#[napi]
436-
pub fn sync(&self) -> Result<SyncResult> {
437-
let rt = runtime()?;
438-
let result = rt.block_on(async move {
439-
self.db.sync().await.map_err(Error::from)
440-
})?;
436+
pub async fn sync(&self) -> Result<SyncResult> {
437+
let result = self.db.sync().await.map_err(Error::from)?;
441438
Ok(SyncResult {
442439
frames_synced: result.frames_synced() as f64,
443440
replication_index: result.frame_no().unwrap_or(0) as f64,
444441
})
445442
}
443+
}
446444

447-
#[napi]
448-
pub fn syncUntil(&self, replication_index: f64) -> Result<SyncResult> {
449-
let rt = runtime()?;
450-
let result = rt.block_on(async move {
451-
self.db.sync_until(replication_index as u64).await.map_err(Error::from)
452-
})?;
453-
Ok(SyncResult {
454-
frames_synced: result.frames_synced() as f64,
455-
replication_index: result.frame_no().unwrap_or(0) as f64,
456-
})
457-
}
445+
#[napi]
446+
pub fn database_sync_sync(db: &Database) -> Result<SyncResult> {
447+
let rt = runtime()?;
448+
rt.block_on(async move { db.sync().await })
458449
}
459450

460451
fn is_remote_path(path: &str) -> bool {

wrapper.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const { Database: NativeDb, databasePrepareSync, iteratorNextSync } = require("./index.js");
3+
const { Database: NativeDb, databasePrepareSync, databaseSyncSync, iteratorNextSync } = require("./index.js");
44
const SqliteError = require("./sqlite-error.js");
55
const Authorization = require("./auth");
66

@@ -53,7 +53,7 @@ class Database {
5353

5454
sync() {
5555
try {
56-
const result = this.db.sync();
56+
const result = databaseSyncSync(this.db);
5757
return {
5858
frames_synced: result.frames_synced,
5959
replication_index: result.replication_index
@@ -64,15 +64,7 @@ class Database {
6464
}
6565

6666
syncUntil(replicationIndex) {
67-
try {
68-
const result = this.db.syncUntil(replicationIndex);
69-
return {
70-
frames_synced: result.frames_synced,
71-
replication_index: result.replication_index
72-
};
73-
} catch (err) {
74-
throw convertError(err);
75-
}
67+
throw new Error("not implemented");
7668
}
7769

7870
/**

0 commit comments

Comments
 (0)