adjust sync native package

This commit is contained in:
Nikita Sivukhin
2025-09-24 18:43:50 +04:00
parent 28c9850b57
commit afbfa98a8d
7 changed files with 284 additions and 154 deletions

View File

@@ -9,6 +9,18 @@ export declare class Database {
* * `path` - The path to the database file.
*/
constructor(path: string, opts?: DatabaseOpts | undefined | null)
/**
* Connect the database synchronously
* This method is idempotent and can be called multiple times safely until the database will be closed
*/
connectSync(): void
/**
* Connect the database asynchronously
* This method is idempotent and can be called multiple times safely until the database will be closed
*/
connectAsync(): Promise<void>
/** Returns whether the database is in readonly-only mode. */
get readonly(): boolean
/** Returns whether the database is in memory-only mode. */
get memory(): boolean
/** Returns whether the database is in memory-only mode. */
@@ -101,11 +113,6 @@ export declare class Statement {
* 1 = Row available, 2 = Done, 3 = I/O needed
*/
stepSync(): number
/**
* Step the statement and return result code (executed on the background thread):
* 1 = Row available, 2 = Done, 3 = I/O needed
*/
stepAsync(): Promise<number>
/** Get the current row data according to the presentation mode */
row(): unknown
/** Sets the presentation mode to raw. */
@@ -126,7 +133,14 @@ export declare class Statement {
finalize(): void
}
/**
* Most of the options are aligned with better-sqlite API
* (see https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#new-databasepath-options)
*/
export interface DatabaseOpts {
readonly?: boolean
timeout?: number
fileMustExist?: boolean
tracing?: string
}
export declare class GeneratorHolder {
@@ -153,7 +167,7 @@ export declare class JsProtocolRequestBytes {
export declare class SyncEngine {
constructor(opts: SyncEngineOpts)
init(): GeneratorHolder
connect(): GeneratorHolder
ioLoopSync(): void
/** Runs the I/O loop asynchronously, returning a Promise. */
ioLoopAsync(): Promise<void>
@@ -163,22 +177,18 @@ export declare class SyncEngine {
wait(): GeneratorHolder
apply(changes: SyncEngineChanges): GeneratorHolder
checkpoint(): GeneratorHolder
open(): Database
db(): Database
close(): void
}
export declare class SyncEngineChanges {
empty(): boolean
}
export declare const enum DatabaseChangeTypeJs {
Insert = 0,
Update = 1,
Delete = 2
}
export interface DatabaseOpts {
path: string
Insert = 'insert',
Update = 'update',
Delete = 'delete'
}
export interface DatabaseRowMutationJs {
@@ -225,6 +235,6 @@ export interface SyncEngineOpts {
}
export declare const enum SyncEngineProtocolVersion {
Legacy = 0,
V1 = 1
Legacy = 'legacy',
V1 = 'v1'
}