diff --git a/query-engine/prisma/src/tests/type_mappings/postgres_types.rs b/query-engine/prisma/src/tests/type_mappings/postgres_types.rs index ac15be4a1c87..47e64e8ae91e 100644 --- a/query-engine/prisma/src/tests/type_mappings/postgres_types.rs +++ b/query-engine/prisma/src/tests/type_mappings/postgres_types.rs @@ -290,3 +290,170 @@ async fn small_float_values_must_work(api: &TestApi) -> TestResult { Ok(()) } + +const CREATE_ARRAY_TYPES_TABLE: &str = indoc! { + r##" + CREATE TABLE "prisma-tests"."arraytypes" ( + id SERIAL PRIMARY KEY, + numeric_int2 int2[], + numeric_int4 int4[], + numeric_int8 int8[], + + numeric_decimal decimal(8, 4)[], + numeric_float4 float4[], + numeric_float8 float8[], + + numeric_money money[], + numeric_oid oid[], + + string_char char(8)[], + string_varchar varchar(20)[], + string_text text[], + + binary_bytea bytea[], + binary_bits bit(80)[], + binary_bits_varying bit varying(80)[], + binary_uuid uuid[], + + time_timestamp timestamp[], + time_timestamptz timestamptz[], + time_date date[], + time_time time[], + time_timetz timetz[], + + boolean_boolean boolean[], + + network_cidr cidr[], + network_inet inet[], + + json_json json[], + json_jsonb jsonb[] + ); + "## +}; + +#[test_each_connector(tags("postgres"), log = "debug")] +async fn postgres_array_types_roundtrip(api: &TestApi) -> TestResult { + api.execute(CREATE_ARRAY_TYPES_TABLE).await?; + + let (datamodel, engine) = api.create_engine().await?; + + datamodel.assert_model("arraytypes", |model| { + model + .assert_field_type("numeric_int2", ScalarType::Int)? + .assert_field_type("numeric_int4", ScalarType::Int)? + .assert_field_type("numeric_int8", ScalarType::Int)? + .assert_field_type("numeric_decimal", ScalarType::Float)? + .assert_field_type("numeric_float4", ScalarType::Float)? + .assert_field_type("numeric_float8", ScalarType::Float)? + .assert_field_type("numeric_money", ScalarType::Float)? + .assert_field_type("numeric_oid", ScalarType::Int)? + .assert_field_type("string_char", ScalarType::String)? + .assert_field_type("string_varchar", ScalarType::String)? + .assert_field_type("string_text", ScalarType::String)? + .assert_field_type("binary_bytea", ScalarType::String)? + .assert_field_type("binary_bits", ScalarType::String)? + .assert_field_type("binary_bits_varying", ScalarType::String)? + .assert_field_type("binary_uuid", ScalarType::String)? + .assert_field_type("time_timestamp", ScalarType::DateTime)? + .assert_field_type("time_timestamptz", ScalarType::DateTime)? + .assert_field_type("time_date", ScalarType::DateTime)? + .assert_field_type("time_time", ScalarType::DateTime)? + .assert_field_type("time_timetz", ScalarType::DateTime)? + .assert_field_type("boolean_boolean", ScalarType::Boolean)? + .assert_field_type("network_inet", ScalarType::String)? + .assert_field_type("json_json", ScalarType::String)? + .assert_field_type("json_jsonb", ScalarType::String) + })?; + + let query = indoc! { + r##" + mutation { + createOnearraytypes( + data: { + numeric_int2: { set: [12] } + numeric_int4: { set: [9002] } + numeric_int8: { set: [100000000] } + numeric_decimal: { set: [49.3444] } + numeric_float4: { set: [12.12] } + numeric_float8: { set: [3.139428] } + numeric_money: { set: [3.50] } + numeric_oid: { set: [2000] } + string_char: { set: ["yeet"] } + string_varchar: { set: ["yeet variable"] } + string_text: { set: ["to yeet or not to yeet"] } + binary_uuid: { set: ["111142ec-880b-4062-913d-8eac479ab957"] } + time_timestamp: { set: ["2020-03-02T08:00:00.000"] } + time_timestamptz: { set: ["2020-03-02T08:00:00.000"] } + time_date: { set: ["2020-03-05T00:00:00.000"] } + time_time: { set: ["2020-03-05T08:00:00.000"] } + time_timetz: { set: ["2020-03-05T08:00:00.000"] } + boolean_boolean: { set: [true, true, false, true] } + network_inet: { set: ["192.168.100.14"] } + json_json: { set: ["{ \"isJson\": true }"] } + json_jsonb: { set: ["{ \"isJSONB\": true }"] } + } + ) { + numeric_int2 + numeric_int4 + numeric_int8 + numeric_decimal + numeric_float4 + numeric_float8 + numeric_money + numeric_oid + string_char + string_varchar + string_text + # binary_uuid + time_timestamp + time_timestamptz + time_date + time_time + time_timetz + boolean_boolean + network_inet + json_json + json_jsonb + } + } + "## + }; + + let response = engine.request(query).await; + + let expected_response = json!({ + "data": { + "createOnetypes": { + "numeric_int2": [12], + "numeric_int4": [9002], + "numeric_int8": [100000000], + "numeric_serial2": [8], + "numeric_serial4": [80], + "numeric_serial8": [80000], + "numeric_decimal": [49.3444], + "numeric_float4": [12.12], + "numeric_float8": [3.139428], + "numeric_money": 3.5, + "numeric_oid": 2000, + "string_char": "yeet ", + "string_varchar": "yeet variable", + "string_text": "to yeet or not to yeet", + // "binary_uuid": "111142ec-880b-4062-913d-8eac479ab957", + "time_timestamp": "2020-03-02T08:00:00.000Z", + "time_timestamptz": "2020-03-02T08:00:00.000Z", + "time_date": "2020-03-05T00:00:00.000Z", + "time_time": "1970-01-01T08:00:00.000Z", + "time_timetz": "1970-01-01T08:00:00.000Z", + "boolean_boolean": true, + "network_inet": "192.168.100.14", + "json_json": ["{\"isJson\":true}"], + "json_jsonb": ["{\"isJSONB\":true}"], + } + } + }); + + assert_eq!(response, expected_response); + + Ok(()) +}