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:sqlite@0.1.0;

/// SQLite type codecs for encoding query arguments and decoding results.
/// Raw storage types use storage class names (int64, float64, string, blob).
/// Semantic types use their own names (bool, json, date, uuid, etc.).
/// All functions support NULL values via option types.
interface codecs {
  use wasm-sql:core/query-types@0.1.0.{sql-arguments, query-results};
  use wasm-sql:core/util-types@0.1.0.{error};
  use wasm-sql:core/codecs@0.1.0.{push-result, value-position};

  // === Raw storage types ===

  /// Encodes a 64-bit signed integer (INTEGER).
  push-int64: func(value: option<s64>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a 64-bit signed integer (INTEGER) from results.
  get-int64: func(%result: borrow<query-results>, position: value-position) -> result<option<s64>, error>;

  /// Encodes a 64-bit float (REAL).
  push-float64: func(value: option<f64>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a 64-bit float (REAL) from results.
  get-float64: func(%result: borrow<query-results>, position: value-position) -> result<option<f64>, error>;

  /// Encodes a string (TEXT).
  push-string: func(value: option<string>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a string (TEXT) from results.
  get-string: func(%result: borrow<query-results>, position: value-position) -> result<option<string>, error>;

  /// Encodes binary data (BLOB).
  push-blob: func(value: option<list<u8>>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes binary data (BLOB) from results.
  get-blob: func(%result: borrow<query-results>, position: value-position) -> result<option<list<u8>>, error>;

  // === Semantic types ===

  /// Encodes a boolean as INTEGER (0 = false, 1 = true).
  push-bool: func(value: option<bool>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a boolean from INTEGER (0 = false, 1 = true).
  get-bool: func(%result: borrow<query-results>, position: value-position) -> result<option<bool>, error>;

  /// Encodes a JSON value as TEXT. Validates JSON before encoding.
  push-json: func(value: option<string>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a JSON value from TEXT.
  get-json: func(%result: borrow<query-results>, position: value-position) -> result<option<string>, error>;

  /// UUID as hyphenated string (e.g., "550e8400-e29b-41d4-a716-446655440000").
  type uuid = string;

  /// Encodes a UUID value. Stored as TEXT or BLOB by sqlx.
  push-uuid: func(value: option<uuid>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a UUID value from results.
  get-uuid: func(%result: borrow<query-results>, position: value-position) -> result<option<uuid>, error>;

  /// DATE represented as ISO 8601 string "YYYY-MM-DD" (e.g., "2024-01-15").
  type date = string;

  /// Encodes a DATE value via chrono.
  push-date: func(value: option<date>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a DATE value from results via chrono.
  get-date: func(%result: borrow<query-results>, position: value-position) -> result<option<date>, error>;

  /// TIME represented as ISO 8601 string "HH:MM:SS" or "HH:MM:SS.ffffff" (e.g., "14:30:00").
  type time = string;

  /// Encodes a TIME value via chrono.
  push-time: func(value: option<time>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a TIME value from results via chrono.
  get-time: func(%result: borrow<query-results>, position: value-position) -> result<option<time>, error>;

  /// DATETIME (without timezone) as ISO 8601 string (e.g., "2024-01-15T14:30:00").
  type datetime = string;

  /// Encodes a DATETIME value via chrono NaiveDateTime.
  push-datetime: func(value: option<datetime>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a DATETIME value from results via chrono NaiveDateTime.
  get-datetime: func(%result: borrow<query-results>, position: value-position) -> result<option<datetime>, error>;

  /// DATETIME with UTC timezone as RFC 3339 string (e.g., "2024-01-15T14:30:00Z").
  type datetime-utc = string;

  /// Encodes a DATETIME with UTC timezone via chrono DateTime<Utc>.
  push-datetime-utc: func(value: option<datetime-utc>, to: borrow<sql-arguments>) -> push-result;
  /// Decodes a DATETIME with UTC timezone from results via chrono DateTime<Utc>.
  get-datetime-utc: func(%result: borrow<query-results>, position: value-position) -> result<option<datetime-utc>, error>;
}