MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / test_view_join_view

Function test_view_join_view

crates/core/src/sql/execute.rs:1033–1090  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1031
1032 #[tokio::test]
1033 async fn test_view_join_view() -> anyhow::Result<()> {
1034 let db = TestDB::in_memory()?;
1035
1036 let schema = [("a", AlgebraicType::U8), ("b", AlgebraicType::U8)];
1037 let (_, u_id) = tests_utils::create_view_for_test(&db, "u", &schema, false)?;
1038
1039 let schema = [("c", AlgebraicType::U8), ("d", AlgebraicType::U8)];
1040 let (_, v_id) = tests_utils::create_view_for_test(&db, "v", &schema, false)?;
1041
1042 with_auto_commit(&db, |tx| -> Result<_, DBError> {
1043 tests_utils::insert_into_view(&db, tx, u_id, Some(identity_from_u8(1)), product![0u8, 1u8])?;
1044 tests_utils::insert_into_view(&db, tx, u_id, Some(identity_from_u8(2)), product![1u8, 2u8])?;
1045 tests_utils::insert_into_view(&db, tx, v_id, Some(identity_from_u8(1)), product![0u8, 3u8])?;
1046 tests_utils::insert_into_view(&db, tx, v_id, Some(identity_from_u8(2)), product![1u8, 4u8])?;
1047 Ok(())
1048 })?;
1049
1050 let id = identity_from_u8(2);
1051 let auth = AuthCtx::new(Identity::ZERO, id);
1052
1053 assert_query_results(
1054 db.clone(),
1055 "select u.* from u join v on u.a = v.c",
1056 auth.clone(),
1057 [product![1u8, 2u8]],
1058 )
1059 .await;
1060 assert_query_results(
1061 db.clone(),
1062 "select v.* from u join v on u.a = v.c",
1063 auth.clone(),
1064 [product![1u8, 4u8]],
1065 )
1066 .await;
1067 assert_query_results(
1068 db.clone(),
1069 "select v.* from u join v where u.a = v.c",
1070 auth.clone(),
1071 [product![1u8, 4u8]],
1072 )
1073 .await;
1074 assert_query_results(
1075 db.clone(),
1076 "select u.b as b, v.d as d from u join v on u.a = v.c",
1077 auth.clone(),
1078 [product![2u8, 4u8]],
1079 )
1080 .await;
1081 assert_query_results(
1082 db.clone(),
1083 "select u.b as b, v.d as d from u join v where u.a = v.c",
1084 auth,
1085 [product![2u8, 4u8]],
1086 )
1087 .await;
1088
1089 Ok(())
1090 }

Callers

nothing calls this directly

Calls 8

create_view_for_testFunction · 0.85
with_auto_commitFunction · 0.85
insert_into_viewFunction · 0.85
assert_query_resultsFunction · 0.85
identity_from_u8Function · 0.70
OkFunction · 0.50
newFunction · 0.50
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…