use crate::extension_cases::TestExecution;
static TEST_TABLE: &str = r#"
CREATE TABLE test_table (
id INT,
json_col VARCHAR
) AS VALUES
(1, '{}'),
(2, '{ "a": 1 }'),
(3, '{ "a": 2 }'),
(4, '{ "a": 1, "b": 2 }'),
(5, '{ "a": 1, "b": 2, "c": 3 }')
"#;
#[tokio::test(flavor = "multi_thread")]
async fn test_basic() {
let execution = TestExecution::new().await.with_setup(TEST_TABLE).await;
let actual = execution
.run_and_format("SELECT id, json_contains(json_col, 'b') as json_contains FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +----+---------------+
- "| id | json_contains |"
- +----+---------------+
- "| 1 | false |"
- "| 2 | false |"
- "| 3 | false |"
- "| 4 | true |"
- "| 5 | true |"
- +----+---------------+
"###);
}
#[tokio::test(flavor = "multi_thread")]
async fn test_operators() {
let execution = TestExecution::new().await.with_setup(TEST_TABLE).await;
let actual = execution
.run_and_format("SELECT id, json_col->'a' as json_col_a FROM test_table")
.await;
insta::assert_yaml_snapshot!(actual, @r###"
- +----+------------+
- "| id | json_col_a |"
- +----+------------+
- "| 1 | {null=} |"
- "| 2 | {int=1} |"
- "| 3 | {int=2} |"
- "| 4 | {int=1} |"
- "| 5 | {int=1} |"
- +----+------------+
"###);
}