import type { Context } from "../context.js"; import { Resource } from "../resource.js"; import { CloudflareApi, type CloudflareApiOptions } from "./api.js"; /** * Properties for creating or updating a D1 Database */ export interface D1DatabaseProps extends CloudflareApiOptions { /** * Name of the database * * @default id */ name?: string; /** * Optional primary location hint for the database * Indicates the primary geographical location data will be stored */ primaryLocationHint?: "wnam" | "enam" | "weur" | "eeur" | "apac" | "auto" | string; /** * Read replication configuration * Only mutable property during updates */ readReplication?: { /** * Read replication mode * - auto: Automatic read replication * - disabled: No read replication */ mode: "auto" | "disabled"; }; /** * Whether to delete the database. * If set to false, the database will remain but the resource will be removed from state * * @default true */ delete?: boolean; /** * Whether to adopt an existing database with the same name if it exists * If true and a database with the same name exists, it will be adopted rather than creating a new one * * @default false */ adopt?: boolean; /** * These files will be generated internally with the D1Database wrapper function when migrationsDir is specified * * @private */ migrationsFiles?: Array<{ id: string; sql: string; }>; /** * Name of the table used to track migrations. Only used if migrationsDir is specified. Defaults to 'd1_migrations' * This is analogous to wrangler's `migrations_table`. */ migrationsTable?: string; /** * Directory containing migration SQL files. If not set, no migrations will be applied. * This is analogous to wrangler's `migrations_dir`. */ migrationsDir?: string; } /** * Output returned after D1 Database creation/update */ export type D1Database = Resource<"cloudflare::D1Database"> & D1DatabaseProps & { type: "d1"; /** * The unique ID of the database (UUID) */ id: string; /** * The name of the database */ name: string; /** * File size of the database */ fileSize: number; /** * Number of tables in the database */ numTables: number; /** * Version of the database */ version: string; /** * Read replication configuration */ readReplication?: { /** * Read replication mode */ mode: "auto" | "disabled"; }; }; export declare function D1Database(id: string, props: Omit): Promise; /** * Creates and manages Cloudflare D1 Databases. * * D1 Databases provide serverless SQL databases built on SQLite with * automatic data replication for high availability. * * @example * // Create a basic D1 database with default settings * const basicDatabase = await D1Database("my-app-db", { * name: "my-app-db" * }); * * @example * // Create a database with location hint for optimal performance * const westUsDatabase = await D1Database("west-us-db", { * name: "west-us-db", * primaryLocationHint: "wnam" * }); * * @example * // Adopt an existing database if it already exists instead of failing * const existingDb = await D1Database("existing-db", { * name: "existing-db", * adopt: true, * readReplication: { * mode: "auto" * } * }); * * @example * // Create a database with migrations * const dbWithMigrations = await D1Database("mydb", { * name: "mydb", * migrationsDir: "./migrations", * }); * * @see https://developers.cloudflare.com/d1/ */ export declare const D1DatabaseResource: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context, id: string, props?: D1DatabaseProps) => Promise); interface CloudflareD1Response { result: { uuid?: string; name: string; file_size: number; num_tables: number; version: string; primary_location_hint?: string; read_replication?: { mode: "auto" | "disabled"; }; }; success: boolean; errors: Array<{ code: number; message: string; }>; messages: string[]; } /** * Create a new D1 database */ export declare function createDatabase(api: CloudflareApi, databaseName: string, props: D1DatabaseProps): Promise; /** * Get a D1 database */ export declare function getDatabase(api: CloudflareApi, databaseId?: string): Promise; /** * Delete a D1 database */ export declare function deleteDatabase(api: CloudflareApi, databaseId?: string): Promise; /** * List all D1 databases in an account */ export declare function listDatabases(api: CloudflareApi, name?: string): Promise<{ name: string; id: string; }[]>; /** * Update a D1 database * * Note: According to Cloudflare API, only read_replication.mode can be modified during updates. */ export declare function updateDatabase(api: CloudflareApi, databaseId: string, props: D1DatabaseProps): Promise; export {}; //# sourceMappingURL=d1-database.d.ts.map