package spin:postgres@4.2.0; interface postgres { /// Errors related to interacting with a database. variant error { connection-failed(string), bad-parameter(string), query-failed(query-error), value-conversion-failed(string), other(string) } variant query-error { /// An error occurred but we do not have structured info for it text(string), /// Postgres returned a structured database error db-error(db-error), } record db-error { /// Stringised version of the error. This is primarily to facilitate migration of older code. as-text: string, severity: string, code: string, message: string, detail: option, /// Any error information provided by Postgres and not captured above. extras: list>, } /// Data types for a database column variant db-data-type { boolean, int8, int16, int32, int64, floating32, floating64, str, binary, date, time, datetime, timestamp, uuid, jsonb, decimal, range-int32, range-int64, range-decimal, array-int32, array-int64, array-decimal, array-str, interval, other(string), } /// Database values variant db-value { boolean(bool), int8(s8), int16(s16), int32(s32), int64(s64), floating32(f32), floating64(f64), str(string), binary(list), date(tuple), // (year, month, day) time(tuple), // (hour, minute, second, nanosecond) /// Date-time types are always treated as UTC (without timezone info). /// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) tuple. datetime(tuple), /// Unix timestamp (seconds since epoch) timestamp(s64), uuid(string), jsonb(list), decimal(string), // I admit defeat. Base 10 range-int32(tuple>, option>>), range-int64(tuple>, option>>), range-decimal(tuple>, option>>), array-int32(list>), array-int64(list>), array-decimal(list>), array-str(list>), interval(interval), db-null, unsupported(list), } /// Values used in parameterized queries variant parameter-value { boolean(bool), int8(s8), int16(s16), int32(s32), int64(s64), floating32(f32), floating64(f64), str(string), binary(list), date(tuple), // (year, month, day) time(tuple), // (hour, minute, second, nanosecond) /// Date-time types are always treated as UTC (without timezone info). /// The instant is represented as a (year, month, day, hour, minute, second, nanosecond) tuple. datetime(tuple), /// Unix timestamp (seconds since epoch) timestamp(s64), uuid(string), jsonb(list), decimal(string), // base 10 range-int32(tuple>, option>>), range-int64(tuple>, option>>), range-decimal(tuple>, option>>), array-int32(list>), array-int64(list>), array-decimal(list>), array-str(list>), interval(interval), db-null, } record interval { micros: s64, days: s32, months: s32, } /// A database column record column { name: string, data-type: db-data-type, } /// A database row type row = list; /// A set of database rows record row-set { columns: list, rows: list, } /// For range types, indicates if each bound is inclusive or exclusive enum range-bound-kind { inclusive, exclusive, } @since(version = 4.1.0) resource connection-builder { constructor(address: string); set-ca-root: func(certificate: string) -> result<_, error>; build: func() -> result; @since(version = 4.2.0) build-async: async func() -> result; } /// A connection to a postgres database. resource connection { /// Open a connection to the Postgres instance at `address`. open: static func(address: string) -> result; /// Open a connection to the Postgres instance at `address`. @since(version = 4.2.0) open-async: static async func(address: string) -> result; /// Query the database. query: func(statement: string, params: list) -> result; /// Query the database. @since(version = 4.2.0) query-async: async func(statement: string, params: list) -> result, stream, future>>, error>; /// Execute command to the database. execute: func(statement: string, params: list) -> result; /// Execute command to the database. @since(version = 4.2.0) execute-async: async func(statement: string, params: list) -> result; } }