export { DrizzleD1Database } from 'drizzle-orm/d1';
import { SQLiteTransaction } from 'drizzle-orm/sqlite-core';

type Schema = Record<string, unknown>;
type SQLiteQuerier<S extends Schema = Record<string, never>> = {
    readonly _schema?: S;
    select: (...args: unknown[]) => unknown;
    insert: (table: unknown) => unknown;
    update: (table: unknown) => unknown;
    delete: (table: unknown) => unknown;
};
type SQLiteTransactionalDatabase<S extends Schema = Record<string, never>> = SQLiteQuerier<S> & {
    transaction<T>(fn: (tx: SQLiteTransaction<'async', unknown, S, Record<string, never>>) => Promise<T>): Promise<T>;
};

/**
 * D1Database binding type from Cloudflare Workers runtime.
 * Typed as unknown here to avoid requiring @cloudflare/workers-types as a dep.
 * The host provides the typed binding; we just pass it to drizzle.
 */
type D1Binding = unknown;
interface D1ClientOptions<S extends Schema> {
    schema?: S;
}
/**
 * Create a D1 database client.
 * D1 transactions use IMMEDIATE mode (no mid-tx lock escalation).
 *
 * @param binding - D1Database binding from Cloudflare Workers env
 */
declare function createD1Client<S extends Schema = Record<string, never>>(binding: D1Binding, opts?: D1ClientOptions<S>): SQLiteTransactionalDatabase<S>;

export { type D1Binding, type D1ClientOptions, createD1Client };
