package trailbase:database@0.1.1;

interface sqlite {
  // WARNING: Evolving a variant currently breaks the ABI:
  //   https://github.com/WebAssembly/component-model/issues/454
  variant tx-error {
    other(string)
  }

  variant value {
    null,
    text(string),
    blob(list<u8>),
    integer(s64),
    real(f64),
  }

  // NOTE: Post WASIp3 (and guest support in place, e.g. wstd) with native
  // async/future support, DB queries should be routed through below functions.
  //
  // @since(version = 0.1.0)
  // execute: func(query: string, params: list<value>) -> future<result<u64, tx-error>>;
  // @since(version = 0.1.0)
  // query: func(query: string, params: list<value>) -> future<result<list<list<value>>, tx-error>>;

  @since(version = 0.1.1)
  resource transaction {
    constructor();
    commit: func() -> result<_, tx-error>;
    rollback: func() -> result<_, tx-error>;
    execute: func(query: string, params: list<value>) -> result<u64, tx-error>;
    query: func(query: string, params: list<value>) -> result<list<list<value>>, tx-error>;
  }

  @since(version = 0.1.0)
  @deprecated(version = 0.1.1)
  tx-begin: func() -> result<_, tx-error>;
  @since(version = 0.1.0)
  @deprecated(version = 0.1.1)
  tx-commit: func() -> result<_, tx-error>;
  @since(version = 0.1.0)
  @deprecated(version = 0.1.1)
  tx-rollback: func() -> result<_, tx-error>;

  @since(version = 0.1.0)
  @deprecated(version = 0.1.1)
  tx-execute: func(query: string, params: list<value>) -> result<u64, tx-error>;
  @since(version = 0.1.0)
  @deprecated(version = 0.1.1)
  tx-query: func(query: string, params: list<value>) -> result<list<list<value>>, tx-error>;
}

world interfaces {
  import sqlite;
}
