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

Function test_view_join_table

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

Source from the content-addressed store, hash-verified

971
972 #[tokio::test]
973 async fn test_view_join_table() -> anyhow::Result<()> {
974 let db = TestDB::in_memory()?;
975
976 let schema = [("a", AlgebraicType::U8), ("b", AlgebraicType::U8)];
977 let (_, v_id) = tests_utils::create_view_for_test(&db, "v", &schema, false)?;
978
979 let schema = [("c", AlgebraicType::U8), ("d", AlgebraicType::U8)];
980 let t_id = db.create_table_for_test("t", &schema, &[0.into()])?;
981
982 with_auto_commit(&db, |tx| -> Result<_, DBError> {
983 db.insert(tx, t_id, &product![0u8, 3u8].to_bsatn_vec().unwrap())?;
984 db.insert(tx, t_id, &product![1u8, 4u8].to_bsatn_vec().unwrap())?;
985 tests_utils::insert_into_view(&db, tx, v_id, Some(identity_from_u8(1)), product![0u8, 1u8])?;
986 tests_utils::insert_into_view(&db, tx, v_id, Some(identity_from_u8(2)), product![1u8, 2u8])?;
987 Ok(())
988 })?;
989
990 let id = identity_from_u8(2);
991 let auth = AuthCtx::new(Identity::ZERO, id);
992
993 assert_query_results(
994 db.clone(),
995 "select t.* from v join t on v.a = t.c",
996 auth.clone(),
997 [product![1u8, 4u8]],
998 )
999 .await;
1000 assert_query_results(
1001 db.clone(),
1002 "select v.* from v join t on v.a = t.c",
1003 auth.clone(),
1004 [product![1u8, 2u8]],
1005 )
1006 .await;
1007 assert_query_results(
1008 db.clone(),
1009 "select v.* from v join t where v.a = t.c",
1010 auth.clone(),
1011 [product![1u8, 2u8]],
1012 )
1013 .await;
1014 assert_query_results(
1015 db.clone(),
1016 "select v.b as b, t.d as d from v join t on v.a = t.c",
1017 auth.clone(),
1018 [product![2u8, 4u8]],
1019 )
1020 .await;
1021 assert_query_results(
1022 db.clone(),
1023 "select v.b as b, t.d as d from v join t where v.a = t.c",
1024 auth.clone(),
1025 [product![2u8, 4u8]],
1026 )
1027 .await;
1028
1029 Ok(())
1030 }

Callers

nothing calls this directly

Calls 12

create_view_for_testFunction · 0.85
with_auto_commitFunction · 0.85
insert_into_viewFunction · 0.85
assert_query_resultsFunction · 0.85
create_table_for_testMethod · 0.80
identity_from_u8Function · 0.70
insertMethod · 0.65
OkFunction · 0.50
newFunction · 0.50
unwrapMethod · 0.45
to_bsatn_vecMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…