mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-20 09:54:19 +01:00
249 lines
6.6 KiB
TypeScript
249 lines
6.6 KiB
TypeScript
/* auto-generated by NAPI-RS */
|
|
/* eslint-disable */
|
|
export declare class BatchExecutor {
|
|
stepSync(): number
|
|
reset(): void
|
|
}
|
|
|
|
/** A database connection. */
|
|
export declare class Database {
|
|
/**
|
|
* Creates a new database instance.
|
|
*
|
|
* # Arguments
|
|
* * `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. */
|
|
get path(): string
|
|
/** Returns whether the database connection is open. */
|
|
get open(): boolean
|
|
/**
|
|
* Prepares a statement for execution.
|
|
*
|
|
* # Arguments
|
|
*
|
|
* * `sql` - The SQL statement to prepare.
|
|
*
|
|
* # Returns
|
|
*
|
|
* A `Statement` instance.
|
|
*/
|
|
prepare(sql: string): Statement
|
|
executor(sql: string): BatchExecutor
|
|
/**
|
|
* Returns the rowid of the last row inserted.
|
|
*
|
|
* # Returns
|
|
*
|
|
* The rowid of the last row inserted.
|
|
*/
|
|
lastInsertRowid(): number
|
|
/**
|
|
* Returns the number of changes made by the last statement.
|
|
*
|
|
* # Returns
|
|
*
|
|
* The number of changes made by the last statement.
|
|
*/
|
|
changes(): number
|
|
/**
|
|
* Returns the total number of changes made by all statements.
|
|
*
|
|
* # Returns
|
|
*
|
|
* The total number of changes made by all statements.
|
|
*/
|
|
totalChanges(): number
|
|
/**
|
|
* Closes the database connection.
|
|
*
|
|
* # Returns
|
|
*
|
|
* `Ok(())` if the database is closed successfully.
|
|
*/
|
|
close(): void
|
|
/**
|
|
* Sets the default safe integers mode for all statements from this database.
|
|
*
|
|
* # Arguments
|
|
*
|
|
* * `toggle` - Whether to use safe integers by default.
|
|
*/
|
|
defaultSafeIntegers(toggle?: boolean | undefined | null): void
|
|
/** Runs the I/O loop synchronously. */
|
|
ioLoopSync(): void
|
|
/** Runs the I/O loop asynchronously, returning a Promise. */
|
|
ioLoopAsync(): Promise<void>
|
|
}
|
|
|
|
/** A prepared statement. */
|
|
export declare class Statement {
|
|
reset(): void
|
|
/** Returns the number of parameters in the statement. */
|
|
parameterCount(): number
|
|
/**
|
|
* Returns the name of a parameter at a specific 1-based index.
|
|
*
|
|
* # Arguments
|
|
*
|
|
* * `index` - The 1-based parameter index.
|
|
*/
|
|
parameterName(index: number): string | null
|
|
/**
|
|
* Binds a parameter at a specific 1-based index with explicit type.
|
|
*
|
|
* # Arguments
|
|
*
|
|
* * `index` - The 1-based parameter index.
|
|
* * `value_type` - The type constant (0=null, 1=int, 2=float, 3=text, 4=blob).
|
|
* * `value` - The value to bind.
|
|
*/
|
|
bindAt(index: number, value: unknown): void
|
|
/**
|
|
* Step the statement and return result code (executed on the main thread):
|
|
* 1 = Row available, 2 = Done, 3 = I/O needed
|
|
*/
|
|
stepSync(): number
|
|
/** Get the current row data according to the presentation mode */
|
|
row(): unknown
|
|
/** Sets the presentation mode to raw. */
|
|
raw(raw?: boolean | undefined | null): void
|
|
/** Sets the presentation mode to pluck. */
|
|
pluck(pluck?: boolean | undefined | null): void
|
|
/**
|
|
* Sets safe integers mode for this statement.
|
|
*
|
|
* # Arguments
|
|
*
|
|
* * `toggle` - Whether to use safe integers.
|
|
*/
|
|
safeIntegers(toggle?: boolean | undefined | null): void
|
|
/** Get column information for the statement */
|
|
columns(): Promise<any>
|
|
/** Finalizes the 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 {
|
|
resumeSync(error?: string | undefined | null): GeneratorResponse
|
|
resumeAsync(error?: string | undefined | null): Promise<unknown>
|
|
}
|
|
|
|
export declare class JsDataCompletion {
|
|
poison(err: string): void
|
|
status(value: number): void
|
|
pushBuffer(value: Buffer): void
|
|
pushTransform(values: Array<DatabaseRowTransformResultJs>): void
|
|
done(): void
|
|
}
|
|
|
|
export declare class JsProtocolIo {
|
|
takeRequest(): JsProtocolRequestBytes | null
|
|
}
|
|
|
|
export declare class JsProtocolRequestBytes {
|
|
request(): JsProtocolRequest
|
|
completion(): JsDataCompletion
|
|
}
|
|
|
|
export declare class SyncEngine {
|
|
constructor(opts: SyncEngineOpts)
|
|
connect(): GeneratorHolder
|
|
ioLoopSync(): void
|
|
/** Runs the I/O loop asynchronously, returning a Promise. */
|
|
ioLoopAsync(): Promise<void>
|
|
protocolIo(): JsProtocolRequestBytes | null
|
|
push(): GeneratorHolder
|
|
stats(): GeneratorHolder
|
|
wait(): GeneratorHolder
|
|
apply(changes: SyncEngineChanges): GeneratorHolder
|
|
checkpoint(): GeneratorHolder
|
|
db(): Database
|
|
close(): void
|
|
}
|
|
|
|
export declare class SyncEngineChanges {
|
|
empty(): boolean
|
|
}
|
|
|
|
export declare const enum DatabaseChangeTypeJs {
|
|
Insert = 'insert',
|
|
Update = 'update',
|
|
Delete = 'delete'
|
|
}
|
|
|
|
export interface DatabaseRowMutationJs {
|
|
changeTime: number
|
|
tableName: string
|
|
id: number
|
|
changeType: DatabaseChangeTypeJs
|
|
before?: Record<string, any>
|
|
after?: Record<string, any>
|
|
updates?: Record<string, any>
|
|
}
|
|
|
|
export interface DatabaseRowStatementJs {
|
|
sql: string
|
|
values: Array<any>
|
|
}
|
|
|
|
export type DatabaseRowTransformResultJs =
|
|
| { type: 'Keep' }
|
|
| { type: 'Skip' }
|
|
| { type: 'Rewrite', stmt: DatabaseRowStatementJs }
|
|
|
|
export type GeneratorResponse =
|
|
| { type: 'IO' }
|
|
| { type: 'Done' }
|
|
| { type: 'SyncEngineStats', operations: number, mainWal: number, revertWal: number, lastPullUnixTime?: number, lastPushUnixTime?: number, revision?: string }
|
|
| { type: 'SyncEngineChanges', changes: SyncEngineChanges }
|
|
|
|
export type JsProtocolRequest =
|
|
| { type: 'Http', method: string, path: string, body?: Array<number>, headers: Array<[string, string]> }
|
|
| { type: 'FullRead', path: string }
|
|
| { type: 'FullWrite', path: string, content: Array<number> }
|
|
| { type: 'Transform', mutations: Array<DatabaseRowMutationJs> }
|
|
|
|
export interface SyncEngineOpts {
|
|
path: string
|
|
clientName?: string
|
|
walPullBatchSize?: number
|
|
longPollTimeoutMs?: number
|
|
tracing?: string
|
|
tablesIgnore?: Array<string>
|
|
useTransform: boolean
|
|
protocolVersion?: SyncEngineProtocolVersion
|
|
bootstrapIfEmpty: boolean
|
|
remoteEncryption?: string
|
|
}
|
|
|
|
export declare const enum SyncEngineProtocolVersion {
|
|
Legacy = 'legacy',
|
|
V1 = 'v1'
|
|
}
|