wasm-sql 0.1.6

Wasmtime host implementation for a SQL component WIT interface. Enables Wasm components to interact with SQL databases via the WebAssembly Component Model.
Documentation
package wasm-sql:core@0.1.0;

/// Connection pool interface for managing database connections.
/// The pool automatically handles connection lifecycle and reuse.
interface pool {
  use util-types.{error};
  use transaction.{transaction};
  use connection.{connection};

  /// Pool state statistics
  record pool-state {
    /// Total connections currently managed by the pool
    size: u64,
    /// Number of idle (available) connections
    idle: u64,
  }

  /// Begins a new transaction from the pool.
  /// If dropped without explicit commit or rollback, the transaction is automatically rolled back.
  begin-transaction: async func() -> result<transaction, error>;

  /// Acquires a dedicated connection from the pool.
  /// Use this when you need multiple operations on the same connection.
  acquire-connection: async func() -> result<connection, error>;

  /// Returns current pool state
  get-pool-state: func() -> pool-state;
}

/// Database transaction interface for atomic operations.
interface transaction {
  use util-types.{error};

  /// A database transaction that groups multiple operations atomically.
  /// Default behavior on drop: automatic rollback (safe by default).
  resource transaction {
    /// Commits all changes made within this transaction.
    /// Consumes the transaction resource.
    commit: static async func(this: transaction) -> result<_, error>;

    /// Rolls back all changes made within this transaction.
    /// Consumes the transaction resource.
    rollback: static async func(this: transaction) -> result<_, error>;
  }
}

/// Dedicated database connection interface.
interface connection {
  use util-types.{error};
  use transaction.{transaction};

  /// A dedicated database connection acquired from the pool.
  /// Returned to the pool when dropped or explicitly called release.
  resource connection {
    /// Begins a new transaction on this connection.
    /// If dropped without explicit commit or rollback, the transaction is automatically rolled back.
    begin-transaction: async func() -> result<transaction, error>;

    /// Explicitly releases the connection back to the pool.
    /// Consumes the connection resource.
    release: static func(this: connection);
  }
}