@cloudflare/actors
Version:
An easier way to build with Cloudflare Durable Objects
83 lines • 2.97 kB
TypeScript
import type { DurableObjectStorage } from "@cloudflare/workers-types";
import { SQLSchemaMigration, SQLSchemaMigrations } from "./sql-schema-migrations";
/**
* Represents a single SQL query request with optional parameters.
*/
export type QueryRequest = {
sql: string;
params?: any[];
};
/**
* Interface for SQL storage with transaction support
*/
interface SqlStorage {
exec(sql: string, ...params: unknown[]): any;
}
interface StudioQueryRequest {
type: 'query';
statement: string;
params?: any[];
}
interface StudioTransactionRequest {
type: 'transaction';
statements: string[];
params?: any[];
}
type StudioRequest = StudioQueryRequest | StudioTransactionRequest;
/**
* Handler class for executing SQL queries and transactions against a SQL storage backend.
* Provides methods for executing single queries and transactions with proper error handling
* and result formatting.
*
* This class also provides access to methods from the underlying DurableObjectStorage
* through the proxy pattern.
*/
export declare class Storage {
raw: DurableObjectStorage | undefined;
sqlStorage: SqlStorage | undefined;
private _migrationsArray;
hasRanMigrations: boolean;
/**
* Gets the current migrations array
*/
get migrations(): SQLSchemaMigration[];
/**
* Sets the migrations array and updates the SQLSchemaMigrations instance if available
*/
set migrations(value: SQLSchemaMigration[]);
_migrations: SQLSchemaMigrations | undefined;
/**
* Creates a new instance of Storage.
* @param sql - The SQL storage instance to use for queries
* @param storage - The Durable Object storage instance
*/
constructor(storage?: DurableObjectStorage);
/**
* Executes a raw SQL query with optional parameters.
* @param opts - Options containing the SQL query and optional parameters
* @returns Promise resolving to a cursor containing the query results
* @throws Error if the SQL execution fails
*/
private executeRawQuery;
/**
* Execute SQL queries against the Agent's database
* @template T Type of the returned rows
* @param strings SQL query template strings
* @param values Values to be inserted into the query
* @returns Array of query results
*/
sql<T = Record<string, string | number | boolean | null>>(strings: TemplateStringsArray, ...values: (string | number | boolean | null)[]): T[];
/**
* Executes a SQL query and formats the results based on the specified options.
* @param opts - Options containing the SQL query, parameters, and result format preference
* @returns Promise resolving to either raw query results or formatted array
*/
private query;
runMigrations(): Promise<{
rowsRead: number;
rowsWritten: number;
} | undefined>;
__studio(cmd: StudioRequest): Promise<any>;
}
export {};
//# sourceMappingURL=index.d.ts.map