├── .github └── workflows │ ├── CI.yml │ └── test.yml ├── .gitignore ├── .uroborosqlfmtrc.json ├── .vscode └── settings.json ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── build.sh ├── crates ├── uroborosql-fmt-cli │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── uroborosql-fmt-napi │ ├── .gitignore │ ├── .npmignore │ ├── .yarnrc.yml │ ├── Cargo.toml │ ├── __test__ │ │ └── index.spec.mjs │ ├── build.rs │ ├── index.d.ts │ ├── index.js │ ├── npm │ │ ├── darwin-x64 │ │ │ ├── README.md │ │ │ └── package.json │ │ ├── linux-x64-gnu │ │ │ ├── README.md │ │ │ └── package.json │ │ └── win32-x64-msvc │ │ │ ├── README.md │ │ │ └── package.json │ ├── package-lock.json │ ├── package.json │ ├── run.js │ ├── rustfmt.toml │ ├── src │ │ └── lib.rs │ ├── test.sql │ └── yarn.lock ├── uroborosql-fmt-wasm │ ├── Cargo.toml │ └── src │ │ └── lib.rs └── uroborosql-fmt │ ├── Cargo.toml │ ├── src │ ├── config.rs │ ├── cst.rs │ ├── cst │ │ ├── body.rs │ │ ├── body │ │ │ ├── insert.rs │ │ │ ├── select.rs │ │ │ ├── separeted_lines.rs │ │ │ ├── single_line.rs │ │ │ └── with.rs │ │ ├── clause.rs │ │ ├── expr.rs │ │ ├── expr │ │ │ ├── aligned.rs │ │ │ ├── asterisk.rs │ │ │ ├── column_list.rs │ │ │ ├── cond.rs │ │ │ ├── conflict_target.rs │ │ │ ├── expr_seq.rs │ │ │ ├── function.rs │ │ │ ├── paren.rs │ │ │ ├── primary.rs │ │ │ ├── subquery.rs │ │ │ ├── type_cast.rs │ │ │ └── unary.rs │ │ └── statement.rs │ ├── error.rs │ ├── lib.rs │ ├── re.rs │ ├── two_way_sql.rs │ ├── two_way_sql │ │ ├── dag.rs │ │ ├── merge.rs │ │ └── tree.rs │ ├── util.rs │ ├── validate.rs │ ├── visitor.rs │ └── visitor │ │ ├── clause.rs │ │ ├── clause │ │ ├── for_update.rs │ │ ├── frame.rs │ │ ├── from.rs │ │ ├── group_by.rs │ │ ├── having.rs │ │ ├── join.rs │ │ ├── limit.rs │ │ ├── offset.rs │ │ ├── order_by.rs │ │ ├── select.rs │ │ ├── set.rs │ │ ├── simple.rs │ │ ├── where_clause.rs │ │ └── with.rs │ │ ├── expr.rs │ │ ├── expr │ │ ├── aliasable.rs │ │ ├── assignment.rs │ │ ├── binary.rs │ │ ├── boolean.rs │ │ ├── column_list.rs │ │ ├── cond.rs │ │ ├── conflict_target.rs │ │ ├── function.rs │ │ ├── in_expr.rs │ │ ├── is.rs │ │ ├── paren.rs │ │ ├── subquery.rs │ │ ├── type_cast.rs │ │ └── unary.rs │ │ ├── statement.rs │ │ └── statement │ │ ├── delete.rs │ │ ├── insert.rs │ │ ├── select.rs │ │ └── update.rs │ ├── testfiles │ ├── config_test │ │ ├── configs │ │ │ ├── config1.json │ │ │ ├── config2.json │ │ │ ├── config3.json │ │ │ ├── config4.json │ │ │ ├── config5.json │ │ │ └── config6.json │ │ ├── dst_config1 │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ │ ├── dst_config2 │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ │ ├── dst_config3 │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ │ ├── dst_config4 │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ │ ├── dst_config5 │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ │ ├── dst_config6 │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ │ ├── dst_default │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ │ └── src │ │ │ ├── all_subquery.sql │ │ │ ├── case.sql │ │ │ ├── cast.sql │ │ │ ├── comment.sql │ │ │ ├── complement_as.sql │ │ │ ├── japanese.sql │ │ │ ├── join.sql │ │ │ ├── keyword.sql │ │ │ ├── long_func.sql │ │ │ ├── not_euqal.sql │ │ │ ├── order_by.sql │ │ │ ├── over.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── redundant_paren.sql │ │ │ ├── trim_bind.sql │ │ │ ├── where.sql │ │ │ └── window.sql │ ├── dst │ │ ├── 2way_sql(doma) │ │ │ ├── else.sql │ │ │ ├── elseif.sql │ │ │ ├── if.sql │ │ │ ├── multiple.sql │ │ │ └── nest.sql │ │ ├── 2way_sql(go-twowaysql) │ │ │ ├── elif.sql │ │ │ ├── else.sql │ │ │ ├── if.sql │ │ │ ├── multiple.sql │ │ │ └── nest.sql │ │ ├── 2way_sql │ │ │ ├── align.sql │ │ │ ├── begin.sql │ │ │ ├── comment.sql │ │ │ ├── elif.sql │ │ │ ├── else.sql │ │ │ ├── if.sql │ │ │ ├── multiple.sql │ │ │ └── nest.sql │ │ ├── comment │ │ │ ├── align_comment.sql │ │ │ ├── case_comment.sql │ │ │ ├── col_list_comment.sql │ │ │ ├── head_comment.sql │ │ │ ├── hint_comment.sql │ │ │ ├── many_comments.sql │ │ │ ├── multi_line_block_comment.sql │ │ │ ├── paren_with_comment.sql │ │ │ ├── sql_id.sql │ │ │ └── tail_comment.sql │ │ ├── delete │ │ │ ├── delete.sql │ │ │ ├── delete_returning.sql │ │ │ ├── using.sql │ │ │ └── with.sql │ │ ├── insert │ │ │ ├── insert.sql │ │ │ ├── insert2.sql │ │ │ ├── insert_on_conflict.sql │ │ │ ├── insert_returning.sql │ │ │ ├── insert_select.sql │ │ │ ├── insert_sql_id.sql │ │ │ └── with.sql │ │ ├── select │ │ │ ├── absense-of-select-clause-body.sql │ │ │ ├── aggregate_function.sql │ │ │ ├── all_distinct.sql │ │ │ ├── all_some_any_subquery.sql │ │ │ ├── as_in_from.sql │ │ │ ├── asterisk.sql │ │ │ ├── between.sql │ │ │ ├── bind_param.sql │ │ │ ├── case.sql │ │ │ ├── case_rhs.sql │ │ │ ├── cast.sql │ │ │ ├── comma_and_trailing_comment.sql │ │ │ ├── comp_op.sql │ │ │ ├── complement_alias.sql │ │ │ ├── exists_subquery.sql │ │ │ ├── for_update.sql │ │ │ ├── from.sql │ │ │ ├── function.sql │ │ │ ├── group_by.sql │ │ │ ├── in_subquery.sql │ │ │ ├── join.sql │ │ │ ├── like.sql │ │ │ ├── limit_offset.sql │ │ │ ├── long_bind_param.sql │ │ │ ├── multi_statement.sql │ │ │ ├── null_type_cast.sql │ │ │ ├── or_and.sql │ │ │ ├── order_by.sql │ │ │ ├── paren.sql │ │ │ ├── postgre_cast.sql │ │ │ ├── select.sql │ │ │ ├── select_sub_lhs.sql │ │ │ ├── string_literal.sql │ │ │ ├── unary.sql │ │ │ ├── union.sql │ │ │ ├── where.sql │ │ │ ├── window.sql │ │ │ └── with.sql │ │ └── update │ │ │ ├── column_list_syntax.sql │ │ │ ├── join.sql │ │ │ ├── update.sql │ │ │ ├── update_from.sql │ │ │ ├── update_returning.sql │ │ │ └── with.sql │ ├── readme.md │ └── src │ │ ├── 2way_sql(doma) │ │ ├── else.sql │ │ ├── elseif.sql │ │ ├── if.sql │ │ ├── multiple.sql │ │ └── nest.sql │ │ ├── 2way_sql(go-twowaysql) │ │ ├── elif.sql │ │ ├── else.sql │ │ ├── if.sql │ │ ├── multiple.sql │ │ └── nest.sql │ │ ├── 2way_sql │ │ ├── align.sql │ │ ├── begin.sql │ │ ├── comment.sql │ │ ├── elif.sql │ │ ├── else.sql │ │ ├── if.sql │ │ ├── multiple.sql │ │ └── nest.sql │ │ ├── comment │ │ ├── align_comment.sql │ │ ├── case_comment.sql │ │ ├── col_list_comment.sql │ │ ├── head_comment.sql │ │ ├── hint_comment.sql │ │ ├── many_comments.sql │ │ ├── multi_line_block_comment.sql │ │ ├── paren_with_comment.sql │ │ ├── sql_id.sql │ │ └── tail_comment.sql │ │ ├── delete │ │ ├── delete.sql │ │ ├── delete_returning.sql │ │ ├── using.sql │ │ └── with.sql │ │ ├── insert │ │ ├── insert.sql │ │ ├── insert2.sql │ │ ├── insert_on_conflict.sql │ │ ├── insert_returning.sql │ │ ├── insert_select.sql │ │ ├── insert_sql_id.sql │ │ └── with.sql │ │ ├── select │ │ ├── absense-of-select-clause-body.sql │ │ ├── aggregate_function.sql │ │ ├── all_distinct.sql │ │ ├── all_some_any_subquery.sql │ │ ├── as_in_from.sql │ │ ├── asterisk.sql │ │ ├── between.sql │ │ ├── bind_param.sql │ │ ├── case.sql │ │ ├── case_rhs.sql │ │ ├── cast.sql │ │ ├── comma_and_trailing_comment.sql │ │ ├── comp_op.sql │ │ ├── complement_alias.sql │ │ ├── exists_subquery.sql │ │ ├── for_update.sql │ │ ├── from.sql │ │ ├── function.sql │ │ ├── group_by.sql │ │ ├── in_subquery.sql │ │ ├── join.sql │ │ ├── like.sql │ │ ├── limit_offset.sql │ │ ├── long_bind_param.sql │ │ ├── multi_statement.sql │ │ ├── null_type_cast.sql │ │ ├── or_and.sql │ │ ├── order_by.sql │ │ ├── paren.sql │ │ ├── postgre_cast.sql │ │ ├── select.sql │ │ ├── select_sub_lhs.sql │ │ ├── string_literal.sql │ │ ├── unary.sql │ │ ├── union.sql │ │ ├── where.sql │ │ ├── window.sql │ │ └── with.sql │ │ └── update │ │ ├── column_list_syntax.sql │ │ ├── join.sql │ │ ├── update.sql │ │ ├── update_from.sql │ │ ├── update_returning.sql │ │ └── with.sql │ └── tests │ └── test_all.rs ├── demo ├── for_blog.sql └── for_readme.sql ├── docs ├── options │ ├── complement_alias.md │ ├── complement_column_as_keyword.md │ ├── complement_outer_keyword.md │ ├── complement_sql_id.md │ ├── convert_double_colon_cast.md │ ├── debug.md │ ├── identifier_case.md │ ├── indent_tab.md │ ├── keyword_case.md │ ├── max_char_per_line.md │ ├── remove_redundant_nest.md │ ├── remove_table_as_keyword.md │ ├── tab_size.md │ ├── trim_bind_param.md │ └── unify_not_equal.md └── structure │ ├── how_to_format_2way_sql.md │ └── overview_of_the_process_flow.md ├── examples ├── as.sql ├── multi_content_lhs.sql ├── or.sql ├── simple.sql ├── target.sql └── test.sql ├── images ├── 2way_sql.png ├── demo.gif ├── logo.png ├── process_flow.png └── wasm_demo.gif ├── package-lock.json ├── package.json └── wasm ├── index.html ├── ja.html ├── main.js └── style.css /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test and Check 2 | env: 3 | TEST_FILES_DST_DIR: crates/uroborosql-fmt/testfiles/dst 4 | on: 5 | workflow_call: null 6 | workflow_dispatch: null 7 | jobs: 8 | test-and-check: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | 13 | - name: Setup cargo 14 | uses: dtolnay/rust-toolchain@stable 15 | with: 16 | toolchain: stable 17 | components: rustfmt, clippy 18 | 19 | - name: Check error and warning 20 | run: | 21 | result=$(cargo check --quiet 2>&1) 22 | echo ${result} 23 | test -z ${result} 24 | 25 | - name: Fmt 26 | run: cargo fmt --check 27 | 28 | - name: Clippy 29 | run: cargo clippy -- --deny warnings 30 | 31 | - name: Execute test 32 | run: cargo test --workspace 33 | 34 | - name: Check test files diff 35 | run: git diff --exit-code 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /node_modules 3 | uroborosql-fmt.js 4 | uroborosql-fmt.wasm 5 | -------------------------------------------------------------------------------- /.uroborosqlfmtrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | "tab_size": 4, 4 | "complement_alias": true, 5 | "trim_bind_param": false, 6 | "keyword_case": "preserve", 7 | "identifier_case": "preserve", 8 | "max_char_per_line": 50, 9 | "complement_outer_keyword": true, 10 | "complement_column_as_keyword": true, 11 | "remove_table_as_keyword": true, 12 | "remove_redundant_nest": true, 13 | "complement_sql_id": true, 14 | "convert_double_colon_cast": false, 15 | "unify_not_equal": true, 16 | "indent_tab": true 17 | } 18 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[rust]": { 3 | "editor.formatOnSave": true 4 | } 5 | } -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "crates/uroborosql-fmt", 4 | "crates/uroborosql-fmt-cli", 5 | "crates/uroborosql-fmt-napi", 6 | "crates/uroborosql-fmt-wasm" 7 | ] 8 | resolver = "2" 9 | 10 | [workspace.package] 11 | authors = ["Future Corporation"] 12 | edition = "2021" 13 | license = "BUSL-1.1" 14 | repository = "https://github.com/future-architect/uroborosql-fmt" 15 | 16 | [workspace.dependencies] 17 | # Internal crates 18 | uroborosql-fmt = { path = "./crates/uroborosql-fmt" } 19 | 20 | [profile.release] 21 | lto = true 22 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | # emccを有効にする 2 | source ../emsdk/emsdk_env.sh 3 | 4 | # emccの設定変更 5 | export EMCC_CFLAGS="-O3" 6 | # tree-sitter-sqlのビルドを実行 7 | cargo build --package tree-sitter-sql --target wasm32-unknown-emscripten --release 8 | 9 | # emccの設定変更 10 | export EMCC_CFLAGS="-O3 11 | -o ./wasm/uroborosql-fmt.js 12 | -s ALLOW_MEMORY_GROWTH=1 13 | -s STACK_SIZE=5MB 14 | -s EXPORTED_FUNCTIONS=['_format_sql','_get_result_address','_get_error_msg_address'] 15 | -s EXPORTED_RUNTIME_METHODS=ccall" 16 | # 全体のビルドを実行 17 | cargo build --package uroborosql-fmt-wasm --target wasm32-unknown-emscripten --release 18 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uroborosql-fmt-cli" 3 | version = "0.1.0" 4 | description = "Crate to run uroborosql-fmt on the CLI" 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [dependencies] 13 | uroborosql-fmt = { workspace = true } 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-cli/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs::read_to_string; 2 | use std::fs::File; 3 | use std::io::Write; 4 | use std::path::Path; 5 | 6 | use uroborosql_fmt::format_sql; 7 | 8 | fn main() { 9 | let msg = "arguments error"; 10 | let input_file = std::env::args().nth(1).expect(msg); 11 | 12 | let output_file = std::env::args().nth(2); 13 | 14 | let src = read_to_string(input_file).unwrap(); 15 | 16 | let config_path = match Path::is_file(Path::new("./.uroborosqlfmtrc.json")) { 17 | true => Some("./.uroborosqlfmtrc.json"), 18 | false => { 19 | eprintln!("hint: Create the file '.uroborosqlfmtrc.json' if you want to customize the configuration"); 20 | None 21 | } 22 | }; 23 | 24 | let result = match format_sql(src.as_ref(), None, config_path) { 25 | Ok(res) => res, 26 | Err(e) => { 27 | eprintln!("{e}"); 28 | src 29 | } 30 | }; 31 | 32 | match output_file { 33 | Some(path) => { 34 | let mut file = File::create(path).unwrap(); 35 | file.write_all(result.as_bytes()).unwrap(); 36 | } 37 | None => println!("{result}"), 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/.npmignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | .cargo 4 | .github 5 | npm 6 | .eslintrc 7 | .prettierignore 8 | rustfmt.toml 9 | yarn.lock 10 | *.node 11 | .yarn 12 | __test__ 13 | renovate.json 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | edition = "2021" 3 | name = "uroborosql-fmt-napi" 4 | version = "0.0.0" 5 | 6 | [lib] 7 | crate-type = ["cdylib"] 8 | 9 | [dependencies] 10 | # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix 11 | napi = { version = "2.12.2", default-features = false, features = ["napi4"] } 12 | napi-derive = "2.12.2" 13 | uroborosql-fmt = { workspace = true } 14 | 15 | [build-dependencies] 16 | napi-build = "2.0.1" 17 | 18 | [lints.rust] 19 | unexpected_cfgs = { level = "allow", check-cfg = ['cfg(napi)'] } 20 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/__test__/index.spec.mjs: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | import { runfmtWithSettings } from '../index.js' 4 | 5 | test('format with settings', (t) => { 6 | const src = 'select A from B' 7 | const settings = { 8 | keyword_case: 'upper', 9 | identifier_case: 'lower', 10 | complement_alias: false, 11 | } 12 | const dst = runfmtWithSettings(src, JSON.stringify(settings), null) 13 | t.is(dst, 'SELECT\n\ta\nFROM\n\tb\n') 14 | }) 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/build.rs: -------------------------------------------------------------------------------- 1 | extern crate napi_build; 2 | 3 | fn main() { 4 | napi_build::setup(); 5 | } 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/index.d.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable */ 2 | /* eslint-disable */ 3 | 4 | /* auto-generated by NAPI-RS */ 5 | 6 | export function runfmt(input: string, configPath?: string | undefined | null): string 7 | export function runfmtWithSettings(input: string, settingsJson: string, configPath?: string | undefined | null): string 8 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/npm/darwin-x64/README.md: -------------------------------------------------------------------------------- 1 | # `uroborosql-fmt-napi-darwin-x64` 2 | 3 | This is the **x86_64-apple-darwin** binary for `uroborosql-fmt-napi` 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/npm/darwin-x64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uroborosql-fmt-napi-darwin-x64", 3 | "version": "0.0.0", 4 | "os": [ 5 | "darwin" 6 | ], 7 | "cpu": [ 8 | "x64" 9 | ], 10 | "main": "uroborosql-fmt-napi.darwin-x64.node", 11 | "files": [ 12 | "uroborosql-fmt-napi.darwin-x64.node" 13 | ], 14 | "license": "MIT", 15 | "engines": { 16 | "node": ">= 10" 17 | } 18 | } -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/npm/linux-x64-gnu/README.md: -------------------------------------------------------------------------------- 1 | # `uroborosql-fmt-napi-linux-x64-gnu` 2 | 3 | This is the **x86_64-unknown-linux-gnu** binary for `uroborosql-fmt-napi` 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/npm/linux-x64-gnu/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uroborosql-fmt-napi-linux-x64-gnu", 3 | "version": "0.0.0", 4 | "os": [ 5 | "linux" 6 | ], 7 | "cpu": [ 8 | "x64" 9 | ], 10 | "main": "uroborosql-fmt-napi.linux-x64-gnu.node", 11 | "files": [ 12 | "uroborosql-fmt-napi.linux-x64-gnu.node" 13 | ], 14 | "license": "MIT", 15 | "engines": { 16 | "node": ">= 10" 17 | }, 18 | "libc": [ 19 | "glibc" 20 | ] 21 | } -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/npm/win32-x64-msvc/README.md: -------------------------------------------------------------------------------- 1 | # `uroborosql-fmt-napi-win32-x64-msvc` 2 | 3 | This is the **x86_64-pc-windows-msvc** binary for `uroborosql-fmt-napi` 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/npm/win32-x64-msvc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uroborosql-fmt-napi-win32-x64-msvc", 3 | "version": "0.0.0", 4 | "os": [ 5 | "win32" 6 | ], 7 | "cpu": [ 8 | "x64" 9 | ], 10 | "main": "uroborosql-fmt-napi.win32-x64-msvc.node", 11 | "files": [ 12 | "uroborosql-fmt-napi.win32-x64-msvc.node" 13 | ], 14 | "license": "MIT", 15 | "engines": { 16 | "node": ">= 10" 17 | } 18 | } -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uroborosql-fmt-napi", 3 | "version": "0.0.0", 4 | "main": "index.js", 5 | "types": "index.d.ts", 6 | "napi": { 7 | "name": "uroborosql-fmt-napi", 8 | "triples": {} 9 | }, 10 | "license": "BUSL-1.1", 11 | "devDependencies": { 12 | "@napi-rs/cli": "^2.16.3", 13 | "ava": "^5.1.1" 14 | }, 15 | "ava": { 16 | "timeout": "3m" 17 | }, 18 | "engines": { 19 | "node": ">= 10" 20 | }, 21 | "scripts": { 22 | "artifacts": "napi artifacts", 23 | "build": "napi build --platform --release", 24 | "build:debug": "napi build --platform", 25 | "prepublishOnly": "napi prepublish -t npm", 26 | "test": "ava", 27 | "universal": "napi universal", 28 | "version": "napi version" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/run.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | 3 | const { runfmt } = require("./index.js"); 4 | 5 | let target = fs.readFileSync("./test.sql", "utf-8"); 6 | try { 7 | const startTime = performance.now(); 8 | let res = runfmt(target, null); 9 | console.log(res); 10 | const endTime = performance.now(); 11 | console.log(`format complete: ${endTime - startTime} ms`); 12 | } catch (e) { 13 | console.log(e); 14 | } 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/rustfmt.toml: -------------------------------------------------------------------------------- 1 | tab_spaces = 2 2 | edition = "2021" 3 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(clippy::all)] 2 | 3 | use napi::{Error, Result, Status}; 4 | use uroborosql_fmt::format_sql; 5 | 6 | #[macro_use] 7 | extern crate napi_derive; 8 | 9 | #[napi] 10 | pub fn runfmt(input: String, config_path: Option<&str>) -> Result { 11 | let result = format_sql(&input, None, config_path); 12 | 13 | match result { 14 | Ok(res) => Ok(res), 15 | Err(e) => Err(Error::new(Status::GenericFailure, format!("{e}"))), 16 | } 17 | } 18 | 19 | #[napi] 20 | pub fn runfmt_with_settings( 21 | input: String, 22 | settings_json: String, 23 | config_path: Option<&str>, 24 | ) -> Result { 25 | format_sql(&input, Some(&settings_json), config_path) 26 | .map_err(|e| Error::new(Status::GenericFailure, format!("{e}"))) 27 | } 28 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-napi/test.sql: -------------------------------------------------------------------------------- 1 | select 2 | std.id as id, -- identifier 3 | std.grade -- students grade 4 | from 5 | student std left join subject sbj 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt-wasm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uroborosql-fmt-wasm" 3 | version = "0.1.0" 4 | description = "Crate to build uroborosql-fmt wasm" 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [lib] 13 | crate-type = ["cdylib"] 14 | 15 | [dependencies] 16 | once_cell = "1.18.0" 17 | uroborosql-fmt = { workspace = true } 18 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uroborosql-fmt" 3 | version = "0.1.0" 4 | description = "The core of uroborosql-fmt" 5 | authors.workspace = true 6 | edition.workspace = true 7 | license.workspace = true 8 | repository.workspace = true 9 | 10 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 | 13 | [dependencies] 14 | annotate-snippets = "0.9.1" 15 | indexmap = "1.9.3" 16 | itertools = "0.10.3" 17 | once_cell = "1.17.0" 18 | regex = "1.8.4" 19 | serde = { version = "1.0.152", features = ["derive"] } 20 | serde_json = "1.0.91" 21 | thiserror = "1.0.38" 22 | tree-sitter = "~0.20.3" 23 | 24 | # git config --global core.longpaths true を管理者権限で実行しないといけない 25 | tree-sitter-sql = { git = "https://github.com/future-architect/tree-sitter-sql" } 26 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/cst/expr/asterisk.rs: -------------------------------------------------------------------------------- 1 | use crate::{cst::Location, error::UroboroSQLFmtError}; 2 | 3 | /// アスタリスクを表す。 4 | /// テーブル名を含む場合もある。 (例: tab.*) 5 | #[derive(Debug, Clone)] 6 | pub(crate) struct AsteriskExpr { 7 | content: String, 8 | loc: Location, 9 | } 10 | 11 | impl AsteriskExpr { 12 | pub(crate) fn new(content: impl Into, loc: Location) -> AsteriskExpr { 13 | let content = content.into(); 14 | AsteriskExpr { content, loc } 15 | } 16 | 17 | pub(crate) fn loc(&self) -> Location { 18 | self.loc.clone() 19 | } 20 | 21 | pub(crate) fn last_line_len(&self) -> usize { 22 | self.content.len() 23 | } 24 | 25 | pub(crate) fn render(&self) -> Result { 26 | Ok(self.content.clone()) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/error.rs: -------------------------------------------------------------------------------- 1 | use thiserror::Error; 2 | 3 | #[derive(Error, Debug)] 4 | pub enum UroboroSQLFmtError { 5 | #[error("Illegal operation error: {0}")] 6 | IllegalOperation(String), 7 | #[error("Unexpected syntax error: {0}")] 8 | UnexpectedSyntax(String), 9 | #[error("Unimplemented Error: {0}")] 10 | Unimplemented(String), 11 | #[error("File not found error: {0}")] 12 | FileNotFound(String), 13 | #[error("Illegal setting file error: {0}")] 14 | IllegalSettingFile(String), 15 | #[error("Rendering Error: {0}")] 16 | Rendering(String), 17 | #[error("Runtime Error: {0}")] 18 | Runtime(String), 19 | #[error("Validation Error: {error_msg}")] 20 | Validation { 21 | format_result: String, 22 | error_msg: String, 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/re.rs: -------------------------------------------------------------------------------- 1 | use once_cell::sync::Lazy; 2 | use regex::Regex; 3 | 4 | static IF_PATTERN: &str = r"/\*[ %]?(?i)(IF)[ ]+.*[ ]?\*/"; 5 | static ELIF_PATTERN: &str = r"(/\*[ ]?(ELIF)[ ]+.*[ ]?\*/)|(/\*%elseif[ ]+.*[ ]?\*/)"; 6 | static ELSE_PATTERN: &str = r"/\*[ %]?(?i)(ELSE)[ ]?\*/"; 7 | static END_PATTERN: &str = r"/\*[ %]?(?i)(END)[ ]?\*/"; 8 | static BEGIN_PATTERN: &str = r"/\*[ %]?(?i)(BEGIN)[ ]?\*/"; 9 | 10 | /// コンパイル済み正規表現を保持する構造体 11 | pub(crate) struct Re { 12 | /// `/*IF ..*/`にマッチするregex 13 | pub(crate) if_re: Regex, 14 | /// `/*ELIF ..*/`にマッチするregex 15 | pub(crate) elif_re: Regex, 16 | /// `/*ELSE*/`にマッチするregex 17 | pub(crate) else_re: Regex, 18 | /// `/*END*/`にマッチするregex 19 | pub(crate) end_re: Regex, 20 | /// `/*BEGIN*/`にマッチするregex 21 | pub(crate) begin_re: Regex, 22 | /// 2way-sqlにおける分岐に関するキーワード(`/*IF ..*/`, `/*ELIF ..*/`,`/*ELSE*/`,`/*END*/`,`/*BEGIN*/`)にマッチするregex 23 | pub(crate) branching_keyword_re: Regex, 24 | } 25 | 26 | /// コンパイル済み正規表現を保持するグローバル変数 27 | pub(crate) static RE: Lazy = Lazy::new(|| Re { 28 | if_re: Regex::new(IF_PATTERN).unwrap(), 29 | elif_re: Regex::new(ELIF_PATTERN).unwrap(), 30 | else_re: Regex::new(ELSE_PATTERN).unwrap(), 31 | end_re: Regex::new(END_PATTERN).unwrap(), 32 | begin_re: Regex::new(BEGIN_PATTERN).unwrap(), 33 | branching_keyword_re: Regex::new( 34 | format!( 35 | "({IF_PATTERN})|({ELIF_PATTERN})|({ELSE_PATTERN})|({END_PATTERN})|({BEGIN_PATTERN})" 36 | ) 37 | .as_str(), 38 | ) 39 | .unwrap(), 40 | }); 41 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/clause.rs: -------------------------------------------------------------------------------- 1 | mod for_update; 2 | mod frame; 3 | mod from; 4 | mod group_by; 5 | mod having; 6 | mod join; 7 | mod limit; 8 | mod offset; 9 | mod order_by; 10 | mod select; 11 | mod set; 12 | mod simple; 13 | mod where_clause; 14 | mod with; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/clause/from.rs: -------------------------------------------------------------------------------- 1 | use tree_sitter::TreeCursor; 2 | 3 | use crate::{ 4 | cst::*, 5 | error::UroboroSQLFmtError, 6 | visitor::{ 7 | create_clause, ensure_kind, 8 | expr::{ComplementConfig, ComplementKind}, 9 | Visitor, 10 | }, 11 | }; 12 | 13 | impl Visitor { 14 | /// FROM句をClause構造体で返す 15 | pub(crate) fn visit_from_clause( 16 | &mut self, 17 | cursor: &mut TreeCursor, 18 | src: &str, 19 | ) -> Result { 20 | // from_clauseは必ずFROMを子供に持つ 21 | cursor.goto_first_child(); 22 | 23 | // cursor -> FROM 24 | let mut clause = create_clause(cursor, src, "FROM")?; 25 | cursor.goto_next_sibling(); 26 | self.consume_comment_in_clause(cursor, src, &mut clause)?; 27 | 28 | // cursor -> aliasable_expression 29 | // commaSep1(_aliasable_expression) 30 | 31 | // ASがあれば除去する 32 | // エイリアス補完は現状行わない 33 | let complement_config = ComplementConfig::new(ComplementKind::TableName, true, false); 34 | let body = self.visit_comma_sep_alias(cursor, src, Some(&complement_config))?; 35 | 36 | clause.set_body(body); 37 | 38 | // cursorをfrom_clauseに戻す 39 | cursor.goto_parent(); 40 | ensure_kind(cursor, "from_clause", src)?; 41 | 42 | Ok(clause) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/clause/having.rs: -------------------------------------------------------------------------------- 1 | use tree_sitter::TreeCursor; 2 | 3 | use crate::{ 4 | cst::*, 5 | error::UroboroSQLFmtError, 6 | visitor::{create_clause, ensure_kind, Visitor}, 7 | }; 8 | 9 | impl Visitor { 10 | /// HAVING句をClauseで返す 11 | pub(crate) fn visit_having_clause( 12 | &mut self, 13 | cursor: &mut TreeCursor, 14 | src: &str, 15 | ) -> Result { 16 | cursor.goto_first_child(); 17 | 18 | let mut clause = create_clause(cursor, src, "HAVING")?; 19 | cursor.goto_next_sibling(); 20 | self.consume_comment_in_clause(cursor, src, &mut clause)?; 21 | 22 | // cursor -> _expression 23 | let expr = self.visit_expr(cursor, src)?; 24 | 25 | // 結果として得られた式をBodyに変換する 26 | let body = Body::from(expr); 27 | 28 | clause.set_body(body); 29 | 30 | // cursorを戻す 31 | cursor.goto_parent(); 32 | ensure_kind(cursor, "having_clause", src)?; 33 | 34 | Ok(clause) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/clause/offset.rs: -------------------------------------------------------------------------------- 1 | use tree_sitter::TreeCursor; 2 | 3 | use crate::{ 4 | cst::*, 5 | error::UroboroSQLFmtError, 6 | visitor::{ensure_kind, Visitor}, 7 | }; 8 | 9 | impl Visitor { 10 | /// OFFSET句をClause構造体で返す 11 | /// SELECT文で使用する 12 | pub(crate) fn visit_offset_clause( 13 | &mut self, 14 | cursor: &mut TreeCursor, 15 | src: &str, 16 | ) -> Result { 17 | cursor.goto_first_child(); 18 | ensure_kind(cursor, "OFFSET", src)?; 19 | 20 | let mut offset_clause = Clause::from_node(cursor.node(), src); 21 | 22 | cursor.goto_next_sibling(); 23 | // cursor -> number 24 | 25 | // numberをExprに格納 26 | let number = self.visit_expr(cursor, src)?; 27 | 28 | // numberからBody::SingleLineを作成 29 | let body = Body::SingleLine(Box::new(SingleLine::new(number))); 30 | 31 | offset_clause.set_body(body); 32 | 33 | cursor.goto_parent(); 34 | ensure_kind(cursor, "offset_clause", src)?; 35 | 36 | Ok(offset_clause) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/clause/simple.rs: -------------------------------------------------------------------------------- 1 | use tree_sitter::TreeCursor; 2 | 3 | use crate::{ 4 | cst::*, 5 | error::UroboroSQLFmtError, 6 | visitor::{create_clause, ensure_kind, Visitor}, 7 | }; 8 | 9 | impl Visitor { 10 | /// キーワードとカンマで区切られた式からなる、単純な句をフォーマットする。 11 | /// 引数の `clause_node_name` に句のノード名を、`clause_keyword` にキーワードを与える。 12 | /// 例えば、`visit_simple_clause(cursor, src, "having_clause", "HAVING")` のように使用する。 13 | /// 14 | /// ```sql 15 | /// KEYWORD 16 | /// EXPR1 17 | /// , EXPR2 18 | /// ... 19 | /// ``` 20 | pub(crate) fn visit_simple_clause( 21 | &mut self, 22 | cursor: &mut TreeCursor, 23 | src: &str, 24 | clause_node_name: &str, 25 | clause_keyword: &str, 26 | ) -> Result { 27 | cursor.goto_first_child(); 28 | 29 | let mut clause = create_clause(cursor, src, clause_keyword)?; 30 | cursor.goto_next_sibling(); 31 | self.consume_comment_in_clause(cursor, src, &mut clause)?; 32 | 33 | // SimpleClauseは現状補完を行わない 34 | let body = self.visit_comma_sep_alias(cursor, src, None)?; 35 | 36 | clause.set_body(body); 37 | 38 | // cursorを戻す 39 | cursor.goto_parent(); 40 | ensure_kind(cursor, clause_node_name, src)?; 41 | 42 | Ok(clause) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/clause/where_clause.rs: -------------------------------------------------------------------------------- 1 | use tree_sitter::TreeCursor; 2 | 3 | use crate::{ 4 | cst::*, 5 | error::UroboroSQLFmtError, 6 | visitor::{create_clause, ensure_kind, Visitor}, 7 | }; 8 | 9 | impl Visitor { 10 | pub(crate) fn visit_where_clause( 11 | &mut self, 12 | cursor: &mut TreeCursor, 13 | src: &str, 14 | ) -> Result { 15 | // where_clauseは必ずWHEREを子供に持つ 16 | cursor.goto_first_child(); 17 | 18 | // cursor -> WHERE 19 | let mut clause = create_clause(cursor, src, "WHERE")?; 20 | cursor.goto_next_sibling(); 21 | self.consume_comment_in_clause(cursor, src, &mut clause)?; 22 | 23 | // cursor -> _expression 24 | let expr = self.visit_expr(cursor, src)?; 25 | 26 | // 結果として得られた式をBodyに変換する 27 | let body = Body::from(expr); 28 | 29 | clause.set_body(body); 30 | 31 | // cursorをwhere_clauseに戻す 32 | cursor.goto_parent(); 33 | ensure_kind(cursor, "where_clause", src)?; 34 | 35 | Ok(clause) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/expr/assignment.rs: -------------------------------------------------------------------------------- 1 | use tree_sitter::TreeCursor; 2 | 3 | use crate::{ 4 | cst::*, 5 | error::UroboroSQLFmtError, 6 | visitor::{ensure_kind, Visitor}, 7 | }; 8 | 9 | impl Visitor { 10 | /// SET句における代入式をフォーマットする 11 | pub(crate) fn visit_assign_expr( 12 | &mut self, 13 | cursor: &mut TreeCursor, 14 | src: &str, 15 | ) -> Result { 16 | cursor.goto_first_child(); 17 | let identifier = self.visit_expr(cursor, src)?; 18 | cursor.goto_next_sibling(); 19 | ensure_kind(cursor, "=", src)?; 20 | cursor.goto_next_sibling(); 21 | let expr = self.visit_expr(cursor, src)?; 22 | 23 | let mut aligned = AlignedExpr::new(identifier); 24 | aligned.add_rhs(Some("=".to_string()), expr); 25 | cursor.goto_parent(); 26 | ensure_kind(cursor, "assigment_expression", src)?; 27 | 28 | Ok(aligned) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/expr/unary.rs: -------------------------------------------------------------------------------- 1 | use tree_sitter::TreeCursor; 2 | 3 | use crate::{ 4 | cst::{unary::UnaryExpr, Location}, 5 | error::UroboroSQLFmtError, 6 | visitor::{ensure_kind, Visitor}, 7 | }; 8 | 9 | impl Visitor { 10 | pub(crate) fn visit_unary_expr( 11 | &mut self, 12 | cursor: &mut TreeCursor, 13 | src: &str, 14 | ) -> Result { 15 | // cursor -> unary_expression 16 | 17 | let mut loc = Location::new(cursor.node().range()); 18 | 19 | cursor.goto_first_child(); 20 | // cursor -> op ("+", "-", "!!", "~", "@", "|/", "||/") 21 | let operator = cursor.node().utf8_text(src.as_bytes()).unwrap(); 22 | 23 | cursor.goto_next_sibling(); 24 | // cursor -> _expression 25 | 26 | let operand = self.visit_expr(cursor, src)?; 27 | loc.append(operand.loc()); 28 | 29 | cursor.goto_parent(); 30 | ensure_kind(cursor, "unary_expression", src)?; 31 | 32 | Ok(UnaryExpr::new(operator, operand, loc)) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/src/visitor/statement.rs: -------------------------------------------------------------------------------- 1 | mod delete; 2 | mod insert; 3 | mod select; 4 | mod update; 5 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/configs/config1.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | "tab_size": 4, 4 | "complement_alias": false, 5 | "trim_bind_param": false, 6 | "keyword_case": "upper", 7 | "identifier_case": "upper", 8 | "max_char_per_line": -1, 9 | "complement_outer_keyword": false, 10 | "complement_column_as_keyword": true, 11 | "remove_table_as_keyword": false, 12 | "remove_redundant_parentheses": true, 13 | "complement_sql_id": true, 14 | "convert_double_colon_cast": true, 15 | "unify_not_equal": true 16 | } 17 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/configs/config2.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | "tab_size": 4, 4 | "complement_alias": true, 5 | "trim_bind_param": true, 6 | "keyword_case": "upper", 7 | "identifier_case": "lower", 8 | "max_char_per_line": 30, 9 | "complement_outer_keyword": true, 10 | "complement_column_as_keyword": true, 11 | "remove_table_as_keyword": true, 12 | "remove_redundant_nest": false, 13 | "complement_sql_id": false, 14 | "convert_double_colon_cast": true, 15 | "unify_not_equal": true 16 | } 17 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/configs/config3.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | "tab_size": 4, 4 | "complement_alias": true, 5 | "trim_bind_param": true, 6 | "keyword_case": "lower", 7 | "identifier_case": "preserve", 8 | "max_char_per_line": 50, 9 | "complement_outer_keyword": false, 10 | "complement_column_as_keyword": true, 11 | "remove_table_as_keyword": false, 12 | "remove_redundant_parentheses": true, 13 | "complement_sql_id": false, 14 | "convert_double_colon_cast": false, 15 | "unify_not_equal": false 16 | } 17 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/configs/config4.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | "tab_size": 4, 4 | "complement_alias": true, 5 | "trim_bind_param": true, 6 | "keyword_case": "preserve", 7 | "identifier_case": "upper", 8 | "max_char_per_line": 70, 9 | "complement_outer_keyword": true, 10 | "complement_column_as_keyword": false, 11 | "remove_table_as_keyword": false, 12 | "remove_redundant_nest": false, 13 | "complement_sql_id": false, 14 | "convert_double_colon_cast": false, 15 | "unify_not_equal": false 16 | } 17 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/configs/config5.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | "tab_size": 2, 4 | "complement_alias": true, 5 | "trim_bind_param": true, 6 | "keyword_case": "upper", 7 | "identifier_case": "lower", 8 | "max_char_per_line": 70, 9 | "complement_outer_keyword": true, 10 | "complement_column_as_keyword": false, 11 | "remove_table_as_keyword": false, 12 | "remove_redundant_nest": false, 13 | "complement_sql_id": false, 14 | "convert_double_colon_cast": false, 15 | "unify_not_equal": false 16 | } 17 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/configs/config6.json: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | "tab_size": 2, 4 | "complement_alias": false, 5 | "trim_bind_param": true, 6 | "keyword_case": "upper", 7 | "identifier_case": "lower", 8 | "max_char_per_line": 70, 9 | "complement_outer_keyword": true, 10 | "complement_column_as_keyword": false, 11 | "remove_table_as_keyword": false, 12 | "remove_redundant_nest": false, 13 | "complement_sql_id": false, 14 | "convert_double_colon_cast": false, 15 | "unify_not_equal": false, 16 | "indent_tab": false 17 | } 18 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/all_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | * 3 | FROM 4 | STUDENTS 5 | WHERE 6 | STUDENT_ID <> ALL ( 7 | SELECT 8 | STUDENT_ID 9 | FROM 10 | EXAM_RESULTS 11 | WHERE 12 | STUDENT_ID IS NOT NULL 13 | ) 14 | AND LONGLONGLONGLONGLONGLONG = TEST 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/case.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | ID AS ID 3 | , CASE 4 | WHEN 5 | GRADE_POINT >= 80 6 | THEN 7 | 'A' 8 | WHEN 9 | GRADE_POINT < 80 10 | AND GRADE_POINT >= 70 11 | THEN 12 | 'B' 13 | WHEN 14 | GRADE_POINT < 70 15 | AND GRADE_POINT >= 60 16 | THEN 17 | 'C' 18 | ELSE 19 | 'D' 20 | END 21 | AS GRADE 22 | FROM 23 | RISYU 24 | WHERE 25 | SUBJECT_NUMBER = '005' 26 | ; 27 | SELECT 28 | ID 29 | , CASE 30 | GRADE 31 | WHEN 32 | 'A' 33 | THEN 34 | 5 35 | WHEN 36 | 'B' 37 | THEN 38 | 4 39 | WHEN 40 | 'C' 41 | THEN 42 | 3 43 | ELSE 44 | 0 45 | END 46 | AS P 47 | FROM 48 | RISYU 49 | WHERE 50 | SUBJECT_NUMBER = '006' 51 | ; 52 | SELECT 53 | CASE 54 | /*param*/A -- simple case cond 55 | WHEN 56 | /*a*/'a' 57 | THEN 58 | 'A' 59 | ELSE 60 | 'B' 61 | END 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/cast.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | CAST('2023-01-01' AS DATE) 3 | , CAST(100 AS CHAR(3)) 4 | , CAST((1 + 2) AS CHAR(1)) 5 | WHERE 6 | TEST = TEST 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/complement_as.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | IDENTIFIER AS ID 3 | , STUDENT_NAME 4 | FROM 5 | JAPANESE_STUDENT_TABLE 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/japanese.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | "テーブルエイリアス".ID -- コメント1 3 | AS ID -- コメント2 4 | , "テーブルエイリアス".COLUMN AS JAPANESE_COLUMN -- コメント3 5 | FROM 6 | TBL "テーブルエイリアス" -- コメント4 7 | WHERE 8 | 1 = 1 -- コメント5 9 | AND "テーブルエイリアス".ID = 1 -- コメント6 10 | AND "テーブルエイリアス"."カラムX" = 3 -- コメント7 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/join.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | * 3 | FROM 4 | T1 5 | INNER JOIN 6 | T2 7 | ON 8 | T1.NUM = T2.NUM 9 | ; 10 | SELECT 11 | * 12 | FROM 13 | T1 14 | LEFT JOIN 15 | T2 16 | ON 17 | T1.NUM = T2.NUM 18 | ; 19 | SELECT 20 | * 21 | FROM 22 | T1 23 | RIGHT JOIN 24 | T2 25 | ON 26 | T1.NUM = T2.NUM 27 | ; 28 | SELECT 29 | * 30 | FROM 31 | T1 32 | FULL JOIN 33 | T2 34 | ON 35 | T1.NUM = T2.NUM 36 | ; 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/keyword.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | CASE 3 | WHEN 4 | A = 1 5 | THEN 6 | 'one' 7 | ELSE 8 | 'other' 9 | END 10 | AS GRADE 11 | FROM 12 | STUDENT STD 13 | WHERE 14 | GRADE BETWEEN /*start1*/60 AND /*end1*/100 15 | AND GRADE NOT BETWEEN /*start2*/70 AND /*end2*/80 16 | ; 17 | UPDATE 18 | WEATHER 19 | SET 20 | (TEMP_LO, TEMP_HI, PRCP) = (TEMP_LO + 1, TEMP_LO + 15, DEFAULT) 21 | WHERE 22 | CITY = 'San Francisco' 23 | ; 24 | DELETE 25 | FROM 26 | PRODUCTS 27 | WHERE 28 | OBSOLETION_DATE = 'today' 29 | RETURNING 30 | * 31 | ; 32 | INSERT 33 | INTO 34 | DISTRIBUTORS 35 | ( 36 | DID 37 | , DNAME 38 | ) VALUES ( 39 | DEFAULT 40 | , 'XYZ Widgets' 41 | ) 42 | RETURNING 43 | DID 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/long_func.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | NORMAL_FUNC(COL1 + COL2, PARAM2) 3 | ; 4 | SELECT 5 | MANY_ARGS_FUNC(PARAM1, PARAM2, PARAM3, PARAM4) 6 | ; 7 | SELECT 8 | LONG_ARGS_FUNC(COL1 + LONGLONGLONGLONGLONGLONGLONG, PARAM2) 9 | ; 10 | SELECT 11 | LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC(PARAM1, PARAM2, PARAM3) 12 | ; 13 | SELECT 14 | FUNC1( 15 | CASE 16 | WHEN 17 | Z = 1 18 | THEN 19 | FUNC3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 20 | ELSE 21 | FUNC2( 22 | CASE 23 | WHEN 24 | Z = 1 25 | THEN 26 | 'ONE' 27 | ELSE 28 | FUNC3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 29 | END 30 | ) 31 | END 32 | ) 33 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/not_euqal.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | * 3 | FROM 4 | STUDENTS 5 | WHERE 6 | STUDENT_ID != 2 7 | ; 8 | SELECT 9 | * 10 | FROM 11 | STUDENTS 12 | WHERE 13 | STUDENT_ID != 2 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/order_by.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | COL 3 | FROM 4 | TAB 5 | ORDER BY 6 | COL ASC -- 昇順 7 | , LONG_COL DESC NULLS FIRST -- 降順 8 | , NULL_COL NULLS FIRST -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/over.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | DEPNAME 3 | , EMPNO 4 | , SALARY 5 | , RANK() OVER( 6 | PARTITION BY 7 | DEPNAME 8 | ORDER BY 9 | SALARY DESC 10 | ) 11 | FROM 12 | EMPSALARY 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | CAST('' AS JSONB) 3 | FROM 4 | TBL 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | A 3 | FROM 4 | B 5 | WHERE 6 | (1 = 1) 7 | AND ( 8 | (A = B) 9 | OR (A) = (42) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/trim_bind.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | IDENTIFIER 3 | FROM 4 | JAPANESE_STUDENT_TABLE 5 | WHERE 6 | SBJ.GRADE > /* grade */50 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/where.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | * 3 | FROM 4 | TBL T 5 | WHERE 6 | T.ID = ( 7 | SELECT 8 | MAX(T2.ID) 9 | FROM 10 | TBL T2 11 | ) 12 | AND T.AGE < 100 13 | ; 14 | SELECT 15 | * 16 | FROM 17 | TBL T 18 | WHERE 19 | T.ID = ( 20 | SELECT 21 | MAX(T2.ID) 22 | FROM 23 | TBL T2 24 | ) 25 | OR T.ID = 2 26 | ; 27 | SELECT 28 | * 29 | FROM 30 | TBL T 31 | WHERE 32 | -- comment 33 | T.ID = ( 34 | SELECT 35 | MAX(T2.ID) 36 | FROM 37 | TBL T2 38 | ) 39 | AND -- comment 40 | -- comment 41 | T.AGE < 100 42 | ; 43 | SELECT 44 | * 45 | FROM 46 | TBL T 47 | WHERE 48 | -- comment 49 | T.ID = ( 50 | SELECT 51 | MAX(T2.ID) 52 | FROM 53 | TBL T2 54 | ) 55 | OR -- comment 56 | -- comment 57 | T.ID = 2 58 | ; 59 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config1/window.sql: -------------------------------------------------------------------------------- 1 | SELECT /* _SQL_ID_ */ 2 | DEPNAME 3 | , EMPNO 4 | , SALARY 5 | , RANK() OVER( 6 | PARTITION BY 7 | DEPNAME 8 | ORDER BY 9 | SALARY DESC 10 | ) 11 | FROM 12 | EMPSALARY 13 | ; 14 | -- 0 argument over 15 | SELECT 16 | SALARY -- salary 17 | , SUM(SALARY) OVER() -- sum 18 | FROM 19 | EMPSALARY 20 | ; 21 | -- frame_clause 22 | SELECT 23 | ORDER_ID 24 | , ITEM 25 | , QTY 26 | , SUM(QTY) OVER( 27 | ORDER BY 28 | ORDER_ID 29 | ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING 30 | ) AS RESULT 31 | FROM 32 | TEST_ORDERS 33 | ; 34 | SELECT 35 | * 36 | , STRING_AGG(V, ',') OVER( 37 | PARTITION BY 38 | COLOR 39 | /* partition by */ 40 | ORDER BY 41 | V 42 | /* order by */ 43 | GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE NO OTHERS 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | FROM 48 | T 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/all_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | students 5 | WHERE 6 | student_id <> ALL ( 7 | SELECT 8 | student_id AS student_id 9 | FROM 10 | exam_results 11 | WHERE 12 | student_id IS NOT NULL 13 | ) 14 | AND longlonglonglonglonglong = test 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/case.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | id AS id 3 | , CASE 4 | WHEN 5 | grade_point >= 80 6 | THEN 7 | 'A' 8 | WHEN 9 | grade_point < 80 10 | AND grade_point >= 70 11 | THEN 12 | 'B' 13 | WHEN 14 | grade_point < 70 15 | AND grade_point >= 60 16 | THEN 17 | 'C' 18 | ELSE 19 | 'D' 20 | END 21 | AS grade 22 | FROM 23 | risyu 24 | WHERE 25 | subject_number = '005' 26 | ; 27 | SELECT 28 | id AS id 29 | , CASE 30 | grade 31 | WHEN 32 | 'A' 33 | THEN 34 | 5 35 | WHEN 36 | 'B' 37 | THEN 38 | 4 39 | WHEN 40 | 'C' 41 | THEN 42 | 3 43 | ELSE 44 | 0 45 | END 46 | AS p 47 | FROM 48 | risyu 49 | WHERE 50 | subject_number = '006' 51 | ; 52 | SELECT 53 | CASE 54 | /*param*/a -- simple case cond 55 | WHEN 56 | /*a*/'a' 57 | THEN 58 | 'A' 59 | ELSE 60 | 'B' 61 | END 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CAST( 3 | '2023-01-01' AS DATE 4 | ) 5 | , CAST(100 AS CHAR(3)) 6 | , CAST( 7 | (1 + 2) AS CHAR(1) 8 | ) 9 | WHERE 10 | test = test 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/comment.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | 123456789 -- hoge 3 | AS col 4 | FROM 5 | tbl t 6 | ; 7 | SELECT 8 | 1 -- hoge 9 | AS col1 10 | , 123456789 -- fuga 11 | AS col2 12 | FROM 13 | tbl t 14 | ; 15 | SELECT 16 | a AS a 17 | , CASE 18 | -- case trailing 19 | /* case */ 20 | WHEN 21 | -- cond_1 22 | a = 1 -- a equals 1 23 | THEN 24 | -- cond_1 == true 25 | 'one' -- one 26 | WHEN 27 | -- cond_2 28 | a = 2 -- a equals 2 29 | THEN 30 | -- cond_2 == true 31 | 'two' -- two 32 | ELSE 33 | -- forall i: cond_i == false 34 | 'other' -- other 35 | END -- comment 36 | 37 | AS col 38 | FROM 39 | test -- test table 40 | SELECT 41 | 123456789 -- hoge 42 | AS col 43 | FROM 44 | tbl t 45 | ; 46 | SELECT 47 | 1 -- hoge 48 | AS col1 49 | , 123456789 -- fuga 50 | AS col2 51 | FROM 52 | tbl t 53 | ; 54 | SELECT 55 | a AS a 56 | , CASE 57 | -- case trailing 58 | /* case */ 59 | WHEN 60 | -- cond_1 61 | a = 1 -- a equals 1 62 | THEN 63 | -- cond_1 == true 64 | 'one' -- one 65 | WHEN 66 | -- cond_2 67 | a = 2 -- a equals 2 68 | THEN 69 | -- cond_2 == true 70 | 'two' -- two 71 | ELSE 72 | -- forall i: cond_i == false 73 | 'other' -- other 74 | END -- comment 75 | 76 | AS col 77 | FROM 78 | test -- test table 79 | WHERE 80 | CASE 81 | WHEN 82 | a = 1 83 | THEN 84 | 'one' 85 | ELSE 86 | 'other' 87 | END 88 | = 89 | CASE 90 | WHEN 91 | a = 1 92 | THEN 93 | 'one' 94 | ELSE 95 | 'other' 96 | END 97 | ; 98 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/complement_as.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | identifier AS id 3 | , student_name AS student_name 4 | FROM 5 | japanese_student_table 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/japanese.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | "テーブルエイリアス".id -- コメント1 3 | AS id -- コメント2 4 | , "テーブルエイリアス".column AS japanese_column -- コメント3 5 | FROM 6 | tbl "テーブルエイリアス" -- コメント4 7 | WHERE 8 | 1 = 1 -- コメント5 9 | AND "テーブルエイリアス".id = 1 -- コメント6 10 | AND "テーブルエイリアス"."カラムX" = 3 -- コメント7 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/join.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | t1 5 | INNER JOIN 6 | t2 7 | ON 8 | t1.num = t2.num 9 | ; 10 | SELECT 11 | * 12 | FROM 13 | t1 14 | LEFT OUTER JOIN 15 | t2 16 | ON 17 | t1.num = t2.num 18 | ; 19 | SELECT 20 | * 21 | FROM 22 | t1 23 | RIGHT OUTER JOIN 24 | t2 25 | ON 26 | t1.num = t2.num 27 | ; 28 | SELECT 29 | * 30 | FROM 31 | t1 32 | FULL OUTER JOIN 33 | t2 34 | ON 35 | t1.num = t2.num 36 | ; 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/keyword.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CASE 3 | WHEN 4 | a = 1 5 | THEN 6 | 'one' 7 | ELSE 8 | 'other' 9 | END 10 | AS grade 11 | FROM 12 | student std 13 | WHERE 14 | grade BETWEEN /*start1*/60 AND /*end1*/100 15 | AND grade NOT BETWEEN /*start2*/70 AND /*end2*/80 16 | ; 17 | UPDATE 18 | weather 19 | SET 20 | (temp_lo, temp_hi, prcp) = (temp_lo + 1, temp_lo + 15, DEFAULT) 21 | WHERE 22 | city = 'San Francisco' 23 | ; 24 | DELETE 25 | FROM 26 | products 27 | WHERE 28 | obsoletion_date = 'today' 29 | RETURNING 30 | * 31 | ; 32 | INSERT 33 | INTO 34 | distributors 35 | ( 36 | did 37 | , dname 38 | ) VALUES ( 39 | DEFAULT 40 | , 'XYZ Widgets' 41 | ) 42 | RETURNING 43 | did 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/long_func.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | NORMAL_FUNC( 3 | col1 + col2 4 | , param2 5 | ) 6 | ; 7 | SELECT 8 | MANY_ARGS_FUNC( 9 | param1 10 | , param2 11 | , param3 12 | , param4 13 | ) 14 | ; 15 | SELECT 16 | LONG_ARGS_FUNC( 17 | col1 + longlonglonglonglonglonglong 18 | , param2 19 | ) 20 | ; 21 | SELECT 22 | LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC( 23 | param1 24 | , param2 25 | , param3 26 | ) 27 | ; 28 | SELECT 29 | FUNC1( 30 | CASE 31 | WHEN 32 | z = 1 33 | THEN 34 | FUNC3( 35 | param1 36 | , param2 37 | , param3 38 | , param4 39 | , param5 40 | ) 41 | ELSE 42 | FUNC2( 43 | CASE 44 | WHEN 45 | z = 1 46 | THEN 47 | 'ONE' 48 | ELSE 49 | FUNC3( 50 | param1 51 | , param2 52 | , param3 53 | , param4 54 | , param5 55 | ) 56 | END 57 | ) 58 | END 59 | ) 60 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/not_euqal.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | students 5 | WHERE 6 | student_id != 2 7 | ; 8 | SELECT 9 | * 10 | FROM 11 | students 12 | WHERE 13 | student_id != 2 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/order_by.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | col AS col 3 | FROM 4 | tab 5 | ORDER BY 6 | col ASC -- 昇順 7 | , long_col DESC NULLS FIRST -- 降順 8 | , null_col NULLS FIRST -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/over.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | depname AS depname 3 | , empno AS empno 4 | , salary AS salary 5 | , RANK() OVER( 6 | PARTITION BY 7 | depname 8 | ORDER BY 9 | salary DESC 10 | ) 11 | FROM 12 | empsalary 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CAST('' AS JSONB) 3 | FROM 4 | tbl 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a AS a 3 | FROM 4 | b 5 | WHERE 6 | (((1 = 1))) 7 | AND ( 8 | ((a = b)) 9 | OR (a) = (((42))) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/trim_bind.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | identifier AS identifier 3 | FROM 4 | japanese_student_table 5 | WHERE 6 | sbj.grade > /*grade*/50 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/where.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | tbl t 5 | WHERE 6 | t.id = ( 7 | SELECT 8 | MAX(t2.id) 9 | FROM 10 | tbl t2 11 | ) 12 | AND t.age < 100 13 | ; 14 | SELECT 15 | * 16 | FROM 17 | tbl t 18 | WHERE 19 | t.id = ( 20 | SELECT 21 | MAX(t2.id) 22 | FROM 23 | tbl t2 24 | ) 25 | OR t.id = 2 26 | ; 27 | SELECT 28 | * 29 | FROM 30 | tbl t 31 | WHERE 32 | -- comment 33 | t.id = ( 34 | SELECT 35 | MAX(t2.id) 36 | FROM 37 | tbl t2 38 | ) 39 | AND -- comment 40 | -- comment 41 | t.age < 100 42 | ; 43 | SELECT 44 | * 45 | FROM 46 | tbl t 47 | WHERE 48 | -- comment 49 | t.id = ( 50 | SELECT 51 | MAX(t2.id) 52 | FROM 53 | tbl t2 54 | ) 55 | OR -- comment 56 | -- comment 57 | t.id = 2 58 | ; 59 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config2/window.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | depname AS depname 3 | , empno AS empno 4 | , salary AS salary 5 | , RANK() OVER( 6 | PARTITION BY 7 | depname 8 | ORDER BY 9 | salary DESC 10 | ) 11 | FROM 12 | empsalary 13 | ; 14 | -- 0 argument over 15 | SELECT 16 | salary AS salary -- salary 17 | , SUM(salary) OVER() -- sum 18 | FROM 19 | empsalary 20 | ; 21 | -- frame_clause 22 | SELECT 23 | order_id AS order_id 24 | , item AS item 25 | , qty AS qty 26 | , SUM(qty) OVER( 27 | ORDER BY 28 | order_id 29 | ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING 30 | ) AS result 31 | FROM 32 | test_orders 33 | ; 34 | SELECT 35 | * 36 | , STRING_AGG(v, ',') OVER( 37 | PARTITION BY 38 | color 39 | /* partition by */ 40 | ORDER BY 41 | v 42 | /* order by */ 43 | GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE NO OTHERS 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | FROM 48 | t 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/all_subquery.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | students 5 | where 6 | student_id <> all ( 7 | select 8 | student_id as student_id 9 | from 10 | exam_results 11 | where 12 | student_id is not null 13 | ) 14 | and longlonglonglonglonglong = test 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/case.sql: -------------------------------------------------------------------------------- 1 | select 2 | ID as ID 3 | , case 4 | when 5 | GRADE_POInT >= 80 6 | then 7 | 'A' 8 | when 9 | GRADE_POInT < 80 10 | and GRADE_POInT >= 70 11 | then 12 | 'B' 13 | when 14 | GRADE_point < 70 15 | and GRADE_POInT >= 60 16 | then 17 | 'C' 18 | else 19 | 'D' 20 | end 21 | as GRADE 22 | from 23 | RISYU 24 | where 25 | SUBJECT_NUMBEr = '005' 26 | ; 27 | select 28 | Id as Id 29 | , case 30 | GRaDE 31 | when 32 | 'A' 33 | then 34 | 5 35 | when 36 | 'B' 37 | then 38 | 4 39 | when 40 | 'C' 41 | then 42 | 3 43 | else 44 | 0 45 | end 46 | as P 47 | from 48 | RISyU 49 | where 50 | SUBJECT_NUMber = '006' 51 | ; 52 | select 53 | case 54 | /*param*/A -- simple case cond 55 | when 56 | /*a*/'a' 57 | then 58 | 'A' 59 | else 60 | 'B' 61 | end 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/cast.sql: -------------------------------------------------------------------------------- 1 | select 2 | cast('2023-01-01' as date) 3 | , cast(100 as char(3)) 4 | , cast((1 + 2) as char(1)) 5 | where 6 | tesT = tEst 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/complement_as.sql: -------------------------------------------------------------------------------- 1 | select 2 | Identifier as iD 3 | , stuDent_name as stuDent_name 4 | from 5 | japanesE_student_table 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/japanese.sql: -------------------------------------------------------------------------------- 1 | select 2 | "テーブルエイリアス".ID -- コメント1 3 | as ID -- コメント2 4 | , "テーブルエイリアス".column as japanese_column -- コメント3 5 | from 6 | TBL "テーブルエイリアス" -- コメント4 7 | where 8 | 1 = 1 -- コメント5 9 | and "テーブルエイリアス".ID = 1 -- コメント6 10 | and "テーブルエイリアス"."カラムX" = 3 -- コメント7 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/join.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | t1 5 | inner join 6 | t2 7 | on 8 | t1.num = t2.num 9 | ; 10 | select 11 | * 12 | from 13 | t1 14 | left join 15 | t2 16 | on 17 | t1.num = t2.num 18 | ; 19 | select 20 | * 21 | from 22 | t1 23 | right join 24 | t2 25 | on 26 | t1.num = t2.num 27 | ; 28 | select 29 | * 30 | from 31 | t1 32 | full join 33 | t2 34 | on 35 | t1.num = t2.num 36 | ; 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/keyword.sql: -------------------------------------------------------------------------------- 1 | select 2 | case 3 | when 4 | a = 1 5 | then 6 | 'one' 7 | else 8 | 'other' 9 | end 10 | as GRADE 11 | from 12 | student std 13 | where 14 | grade between /*start1*/60 and /*end1*/100 15 | and grade not between /*start2*/70 and /*end2*/80 16 | ; 17 | update 18 | weAther 19 | set 20 | (temp_lo, temp_hi, prcp) = (tEmp_lo + 1, temp_lo + 15, default) 21 | where 22 | city = 'San Francisco' 23 | ; 24 | delete 25 | from 26 | products 27 | where 28 | obsoletion_date = 'today' 29 | returning 30 | * 31 | ; 32 | insert 33 | into 34 | distributors 35 | ( 36 | did 37 | , dname 38 | ) values ( 39 | default 40 | , 'XYZ Widgets' 41 | ) 42 | returning 43 | did 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/long_func.sql: -------------------------------------------------------------------------------- 1 | select 2 | normal_func(COL1 + COL2, PARAM2) 3 | ; 4 | select 5 | many_args_func(PARAM1, PARAM2, PARAM3, PARAM4) 6 | ; 7 | select 8 | long_args_func( 9 | COL1 + LONGLONGLONGLONGLONGLONGLONG 10 | , PARAM2 11 | ) 12 | ; 13 | select 14 | longlonglonglonglonglonglonglonglonglonglonglong_func( 15 | PARAM1 16 | , PARAM2 17 | , PARAM3 18 | ) 19 | ; 20 | select 21 | func1( 22 | case 23 | when 24 | Z = 1 25 | then 26 | func3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 27 | else 28 | func2( 29 | case 30 | when 31 | Z = 1 32 | then 33 | 'ONE' 34 | else 35 | func3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 36 | end 37 | ) 38 | end 39 | ) 40 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/not_euqal.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | students 5 | where 6 | student_id <> 2 7 | ; 8 | select 9 | * 10 | from 11 | students 12 | where 13 | student_id != 2 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/order_by.sql: -------------------------------------------------------------------------------- 1 | select 2 | COL as COL 3 | from 4 | TAB 5 | order by 6 | CoL asc -- 昇順 7 | , LoNG_COL desc nulls first -- 降順 8 | , NuLL_COL nulls first -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/over.sql: -------------------------------------------------------------------------------- 1 | select 2 | DEpNAME as DEpNAME 3 | , EMPNo as EMPNo 4 | , SALARY as SALARY 5 | , rank() over( 6 | partition by 7 | DEPNAME 8 | order by 9 | SALARY desc 10 | ) 11 | from 12 | EMPSALARY 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | select 2 | ''::jsonb 3 | from 4 | tbl 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | b 5 | where 6 | (1 = 1) 7 | and ( 8 | (a = b) 9 | or (a) = (42) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/trim_bind.sql: -------------------------------------------------------------------------------- 1 | select 2 | Identifier as Identifier 3 | from 4 | japanese_student_table 5 | where 6 | SBJ.grade > /*grade*/50 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/where.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | tbl t 5 | where 6 | t.id = ( 7 | select 8 | max(t2.id) 9 | from 10 | tbl t2 11 | ) 12 | and t.age < 100 13 | ; 14 | select 15 | * 16 | from 17 | tbl t 18 | where 19 | t.id = ( 20 | select 21 | max(t2.id) 22 | from 23 | tbl t2 24 | ) 25 | or t.id = 2 26 | ; 27 | select 28 | * 29 | from 30 | tbl t 31 | where 32 | -- comment 33 | t.id = ( 34 | select 35 | max(t2.id) 36 | from 37 | tbl t2 38 | ) 39 | and -- comment 40 | -- comment 41 | t.age < 100 42 | ; 43 | select 44 | * 45 | from 46 | tbl t 47 | where 48 | -- comment 49 | t.id = ( 50 | select 51 | max(t2.id) 52 | from 53 | tbl t2 54 | ) 55 | or -- comment 56 | -- comment 57 | t.id = 2 58 | ; 59 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config3/window.sql: -------------------------------------------------------------------------------- 1 | select 2 | dePname as dePname 3 | , empno as empno 4 | , sAlary as sAlary 5 | , rank() over( 6 | partition by 7 | depname 8 | order by 9 | salary desc 10 | ) 11 | from 12 | empsalary 13 | ; 14 | -- 0 argument over 15 | select 16 | salary as salary -- salary 17 | , sum(sAlary) over() -- sum 18 | from 19 | empsalaRy 20 | ; 21 | -- frame_clause 22 | select 23 | order_id as order_id 24 | , itEm as itEm 25 | , qty as qty 26 | , sum(qty) over( 27 | order by 28 | order_id 29 | rows between 1 preceding and 1 following 30 | ) as result 31 | from 32 | test_orders 33 | ; 34 | select 35 | * 36 | , string_agg(v, ',') over( 37 | partition by 38 | color 39 | /* partition by */ 40 | order by 41 | v 42 | /* order by */ 43 | groups between unbounded preceding and current row exclude no others 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | from 48 | t 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/all_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | STUDENTS 5 | WHERE 6 | STUDENT_ID <> ALL ( 7 | SELECT 8 | STUDENT_ID AS STUDENT_ID 9 | FROM 10 | EXAM_RESULTS 11 | WHERE 12 | STUDENT_ID IS NOT NULL 13 | ) 14 | AND LONGLONGLONGLONGLONGLONG = TEST 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/case.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ID As ID 3 | , case 4 | when 5 | GRADE_POINT >= 80 6 | THEN 7 | 'A' 8 | WHEN 9 | GRADE_POINT < 80 10 | AND GRADE_POINT >= 70 11 | THEN 12 | 'B' 13 | WHEN 14 | GRADE_POINT < 70 15 | AND GRADE_POINT >= 60 16 | THEN 17 | 'C' 18 | ELSE 19 | 'D' 20 | EnD 21 | As GRADE 22 | FROM 23 | RISYU 24 | WHERe 25 | SUBJECT_NUMBER = '005' 26 | ; 27 | SELECt 28 | ID AS ID 29 | , CAse 30 | GRADE 31 | WHeN 32 | 'A' 33 | ThEN 34 | 5 35 | WHEn 36 | 'B' 37 | THen 38 | 4 39 | WHen 40 | 'C' 41 | Then 42 | 3 43 | ELSE 44 | 0 45 | End 46 | AS P 47 | FROm 48 | RISYU 49 | WHere 50 | SUBJECT_NUMBER = '006' 51 | ; 52 | SELECt 53 | cASe 54 | /*param*/A -- simple case cond 55 | WHeN 56 | /*a*/'a' 57 | THEn 58 | 'A' 59 | Else 60 | 'B' 61 | eND 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/cast.sql: -------------------------------------------------------------------------------- 1 | selecT 2 | cast('2023-01-01' As DaTE) 3 | , CaST(100 As CHaR(3)) 4 | , CaST((1 + 2) aS CHaR(1)) 5 | WHERe 6 | TEST = TEST 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | 123456789 -- hoge 3 | as COL 4 | from 5 | TBL T 6 | ; 7 | select 8 | 1 -- hoge 9 | as COL1 10 | , 123456789 -- fuga 11 | as COL2 12 | from 13 | TBL T 14 | ; 15 | SELECT 16 | A AS A 17 | , CASE 18 | -- case trailing 19 | /* case */ 20 | WHEN 21 | -- cond_1 22 | A = 1 -- a equals 1 23 | THEN 24 | -- cond_1 == true 25 | 'one' -- one 26 | WHEN 27 | -- cond_2 28 | A = 2 -- a equals 2 29 | THEN 30 | -- cond_2 == true 31 | 'two' -- two 32 | ELSE 33 | -- forall i: cond_i == false 34 | 'other' -- other 35 | END -- comment 36 | 37 | as COL 38 | FROM 39 | TEST -- test table 40 | select 41 | 123456789 -- hoge 42 | COL 43 | from 44 | TBL T 45 | ; 46 | select 47 | 1 -- hoge 48 | COL1 49 | , 123456789 -- fuga 50 | COL2 51 | from 52 | TBL T 53 | ; 54 | SELECT 55 | A AS A 56 | , CASE 57 | -- case trailing 58 | /* case */ 59 | WHEN 60 | -- cond_1 61 | A = 1 -- a equals 1 62 | THEN 63 | -- cond_1 == true 64 | 'one' -- one 65 | WHEN 66 | -- cond_2 67 | A = 2 -- a equals 2 68 | THEN 69 | -- cond_2 == true 70 | 'two' -- two 71 | ELSE 72 | -- forall i: cond_i == false 73 | 'other' -- other 74 | END -- comment 75 | 76 | COL 77 | FROM 78 | TEST -- test table 79 | where 80 | CASE 81 | WHEN 82 | A = 1 83 | THEN 84 | 'one' 85 | ELSE 86 | 'other' 87 | END 88 | = 89 | CASE 90 | WHEN 91 | A = 1 92 | THEN 93 | 'one' 94 | ELSE 95 | 'other' 96 | END 97 | ; 98 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/complement_as.sql: -------------------------------------------------------------------------------- 1 | selecT 2 | IDENTIFIER as ID 3 | , STUDENT_NAME AS STUDENT_NAME 4 | froM 5 | JAPANESE_STUDENT_TABLE 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/japanese.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | "テーブルエイリアス".ID -- コメント1 3 | as ID -- コメント2 4 | , "テーブルエイリアス".COLUMN as JAPANESE_COLUMN -- コメント3 5 | FROM 6 | TBL "テーブルエイリアス" -- コメント4 7 | WHERE 8 | 1 = 1 -- コメント5 9 | and "テーブルエイリアス".ID = 1 -- コメント6 10 | and "テーブルエイリアス"."カラムX" = 3 -- コメント7 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/join.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | T1 5 | inner join 6 | T2 7 | on 8 | T1.NUM = T2.NUM 9 | ; 10 | select 11 | * 12 | from 13 | T1 14 | left OUTER join 15 | T2 16 | on 17 | T1.NUM = T2.NUM 18 | ; 19 | select 20 | * 21 | from 22 | T1 23 | right OUTER join 24 | T2 25 | on 26 | T1.NUM = T2.NUM 27 | ; 28 | select 29 | * 30 | from 31 | T1 32 | full OUTER join 33 | T2 34 | on 35 | T1.NUM = T2.NUM 36 | ; 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/keyword.sql: -------------------------------------------------------------------------------- 1 | select 2 | CASE 3 | when 4 | A = 1 5 | THEN 6 | 'one' 7 | else 8 | 'other' 9 | END 10 | AS GRADE 11 | from 12 | STUDENT STD 13 | whEre 14 | GRADE BeTWEEN /*start1*/60 AND /*end1*/100 15 | and GRADE NOT between /*start2*/70 and /*end2*/80 16 | ; 17 | UPDATE 18 | WEATHER 19 | SET 20 | (TEMP_LO, TEMP_HI, PRCP) = (TEMP_LO + 1, TEMP_LO + 15, DEfAULT) 21 | WHeRE 22 | CITY = 'San Francisco' 23 | ; 24 | DELeTE 25 | from 26 | PRODUCTS 27 | WHeRE 28 | OBSOLETION_DATE = 'today' 29 | RETURNING 30 | * 31 | ; 32 | INSeRT 33 | into 34 | DISTRIBUTORS 35 | ( 36 | DID 37 | , DNAME 38 | ) VALUES ( 39 | deFault 40 | , 'XYZ Widgets' 41 | ) 42 | RETURNING 43 | DID 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/long_func.sql: -------------------------------------------------------------------------------- 1 | select 2 | normal_func(COL1 + COL2, PARAM2) 3 | ; 4 | select 5 | many_args_func(PARAM1, PARAM2, PARAM3, PARAM4) 6 | ; 7 | select 8 | long_args_func(COL1 + LONGLONGLONGLONGLONGLONGLONG, PARAM2) 9 | ; 10 | select 11 | longlonglonglonglonglonglonglonglonglonglonglong_func( 12 | PARAM1 13 | , PARAM2 14 | , PARAM3 15 | ) 16 | ; 17 | select 18 | func1( 19 | CASE 20 | WHEN 21 | Z = 1 22 | THEN 23 | func3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 24 | ELSE 25 | func2( 26 | CASE 27 | WHEN 28 | Z = 1 29 | THEN 30 | 'ONE' 31 | ELSE 32 | func3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 33 | END 34 | ) 35 | END 36 | ) 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/not_euqal.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | STUDENTS 5 | WHERE 6 | STUDENT_ID <> 2 7 | ; 8 | SELECT 9 | * 10 | FROM 11 | STUDENTS 12 | WHERE 13 | STUDENT_ID != 2 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/order_by.sql: -------------------------------------------------------------------------------- 1 | SElECT 2 | COL AS COL 3 | FRoM 4 | TAB 5 | ORdER By 6 | COL ASc -- 昇順 7 | , LONG_COL DEsC NUllS FiRST -- 降順 8 | , NULL_COL NULlS First -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/over.sql: -------------------------------------------------------------------------------- 1 | SELECt 2 | DEPNAME AS DEPNAME 3 | , EMPNO AS EMPNO 4 | , SALARY AS SALARY 5 | , RANK() OVeR( 6 | PARtITiON By 7 | DEPNAME 8 | ORDeR By 9 | SALARY DESc 10 | ) 11 | FROm 12 | EMPSALARY 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ''::JSONB 3 | from 4 | TBL 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | select 2 | A AS A 3 | from 4 | B 5 | where 6 | (((1 = 1))) 7 | and ( 8 | ((A = B)) 9 | or (A) = (((42))) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/trim_bind.sql: -------------------------------------------------------------------------------- 1 | SELeCT 2 | IDENTIFIER AS IDENTIFIER 3 | FrOM 4 | JAPANESE_STUDENT_TABLE 5 | WHeRE 6 | SBJ.GRADE > /*grade*/50 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/where.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | TBL T 5 | where 6 | T.ID = ( 7 | SELECT 8 | MAX(T2.ID) 9 | FROM 10 | TBL T2 11 | ) 12 | and T.AGE < 100 13 | ; 14 | select 15 | * 16 | from 17 | TBL T 18 | where 19 | T.ID = ( 20 | SELECT 21 | MAX(T2.ID) 22 | FROM 23 | TBL T2 24 | ) 25 | or T.ID = 2 26 | ; 27 | select 28 | * 29 | from 30 | TBL T 31 | where 32 | -- comment 33 | T.ID = ( 34 | SELECT 35 | MAX(T2.ID) 36 | FROM 37 | TBL T2 38 | ) 39 | and -- comment 40 | -- comment 41 | T.AGE < 100 42 | ; 43 | select 44 | * 45 | from 46 | TBL T 47 | where 48 | -- comment 49 | T.ID = ( 50 | SELECT 51 | MAX(T2.ID) 52 | FROM 53 | TBL T2 54 | ) 55 | or -- comment 56 | -- comment 57 | T.ID = 2 58 | ; 59 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config4/window.sql: -------------------------------------------------------------------------------- 1 | SELEcT 2 | DEPNAME AS DEPNAME 3 | , EMPNO AS EMPNO 4 | , SALARY AS SALARY 5 | , rank() OVER( 6 | PArTITION bY 7 | DEPNAME 8 | OrDER bY 9 | SALARY DEsC 10 | ) 11 | FROM 12 | EMPSALARY 13 | ; 14 | -- 0 argument over 15 | SELECT 16 | SALARY AS SALARY -- salary 17 | , sUm(SALARY) OVeR() -- sum 18 | FrOM 19 | EMPSALARY 20 | ; 21 | -- frame_clause 22 | SELECT 23 | ORDER_ID AS ORDER_ID 24 | , ITEM AS ITEM 25 | , QTY AS QTY 26 | , SuM(QTY) OVeR( 27 | OrDER By 28 | ORDER_ID 29 | ROWS BEtWEEN 1 PRECeDING AnD 1 FOLLOwING 30 | ) RESULT 31 | FROM 32 | TEST_ORDERS 33 | ; 34 | SELECT 35 | * 36 | , sTring_agg(V, ',') OVeR( 37 | PARTiTION BY 38 | COLOR 39 | /* partition by */ 40 | ORdER By 41 | V 42 | /* order by */ 43 | GROUPS BeTWEEN UNbOUNDED PREcEDING AnD CURRENT ROw EXCLUDE No OTHERS 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | FROM 48 | T 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/all_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | students 5 | WHERE 6 | student_id <> ALL ( 7 | SELECT 8 | student_id AS student_id 9 | FROM 10 | exam_results 11 | WHERE 12 | student_id IS NOT NULL 13 | ) 14 | AND longlonglonglonglonglong = test 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/case.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | id AS id 3 | , CASE 4 | WHEN 5 | grade_point >= 80 6 | THEN 7 | 'A' 8 | WHEN 9 | grade_point < 80 10 | AND grade_point >= 70 11 | THEN 12 | 'B' 13 | WHEN 14 | grade_point < 70 15 | AND grade_point >= 60 16 | THEN 17 | 'C' 18 | ELSE 19 | 'D' 20 | END 21 | AS grade 22 | FROM 23 | risyu 24 | WHERE 25 | subject_number = '005' 26 | ; 27 | SELECT 28 | id AS id 29 | , CASE 30 | grade 31 | WHEN 32 | 'A' 33 | THEN 34 | 5 35 | WHEN 36 | 'B' 37 | THEN 38 | 4 39 | WHEN 40 | 'C' 41 | THEN 42 | 3 43 | ELSE 44 | 0 45 | END 46 | AS p 47 | FROM 48 | risyu 49 | WHERE 50 | subject_number = '006' 51 | ; 52 | SELECT 53 | CASE 54 | /*param*/a -- simple case cond 55 | WHEN 56 | /*a*/'a' 57 | THEN 58 | 'A' 59 | ELSE 60 | 'B' 61 | END 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CAST('2023-01-01' AS DATE) 3 | , CAST(100 AS CHAR(3)) 4 | , CAST((1 + 2) AS CHAR(1)) 5 | WHERE 6 | test = test 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/comment.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | 123456789 -- hoge 3 | AS col 4 | FROM 5 | tbl t 6 | ; 7 | SELECT 8 | 1 -- hoge 9 | AS col1 10 | , 123456789 -- fuga 11 | AS col2 12 | FROM 13 | tbl t 14 | ; 15 | SELECT 16 | a AS a 17 | , CASE 18 | -- case trailing 19 | /* case */ 20 | WHEN 21 | -- cond_1 22 | a = 1 -- a equals 1 23 | THEN 24 | -- cond_1 == true 25 | 'one' -- one 26 | WHEN 27 | -- cond_2 28 | a = 2 -- a equals 2 29 | THEN 30 | -- cond_2 == true 31 | 'two' -- two 32 | ELSE 33 | -- forall i: cond_i == false 34 | 'other' -- other 35 | END -- comment 36 | 37 | AS col 38 | FROM 39 | test -- test table 40 | SELECT 41 | 123456789 -- hoge 42 | col 43 | FROM 44 | tbl t 45 | ; 46 | SELECT 47 | 1 -- hoge 48 | col1 49 | , 123456789 -- fuga 50 | col2 51 | FROM 52 | tbl t 53 | ; 54 | SELECT 55 | a AS a 56 | , CASE 57 | -- case trailing 58 | /* case */ 59 | WHEN 60 | -- cond_1 61 | a = 1 -- a equals 1 62 | THEN 63 | -- cond_1 == true 64 | 'one' -- one 65 | WHEN 66 | -- cond_2 67 | a = 2 -- a equals 2 68 | THEN 69 | -- cond_2 == true 70 | 'two' -- two 71 | ELSE 72 | -- forall i: cond_i == false 73 | 'other' -- other 74 | END -- comment 75 | 76 | col 77 | FROM 78 | test -- test table 79 | WHERE 80 | CASE 81 | WHEN 82 | a = 1 83 | THEN 84 | 'one' 85 | ELSE 86 | 'other' 87 | END 88 | = 89 | CASE 90 | WHEN 91 | a = 1 92 | THEN 93 | 'one' 94 | ELSE 95 | 'other' 96 | END 97 | ; 98 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/complement_as.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | identifier AS id 3 | , student_name AS student_name 4 | FROM 5 | japanese_student_table 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/japanese.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | "テーブルエイリアス".id -- コメント1 3 | AS id -- コメント2 4 | , "テーブルエイリアス".column AS japanese_column -- コメント3 5 | FROM 6 | tbl "テーブルエイリアス" -- コメント4 7 | WHERE 8 | 1 = 1 -- コメント5 9 | AND "テーブルエイリアス".id = 1 -- コメント6 10 | AND "テーブルエイリアス"."カラムX" = 3 -- コメント7 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/join.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | t1 5 | INNER JOIN 6 | t2 7 | ON 8 | t1.num = t2.num 9 | ; 10 | SELECT 11 | * 12 | FROM 13 | t1 14 | LEFT OUTER JOIN 15 | t2 16 | ON 17 | t1.num = t2.num 18 | ; 19 | SELECT 20 | * 21 | FROM 22 | t1 23 | RIGHT OUTER JOIN 24 | t2 25 | ON 26 | t1.num = t2.num 27 | ; 28 | SELECT 29 | * 30 | FROM 31 | t1 32 | FULL OUTER JOIN 33 | t2 34 | ON 35 | t1.num = t2.num 36 | ; 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/keyword.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CASE 3 | WHEN 4 | a = 1 5 | THEN 6 | 'one' 7 | ELSE 8 | 'other' 9 | END 10 | AS grade 11 | FROM 12 | student std 13 | WHERE 14 | grade BETWEEN /*start1*/60 AND /*end1*/100 15 | AND grade NOT BETWEEN /*start2*/70 AND /*end2*/80 16 | ; 17 | UPDATE 18 | weather 19 | SET 20 | (temp_lo, temp_hi, prcp) = (temp_lo + 1, temp_lo + 15, DEFAULT) 21 | WHERE 22 | city = 'San Francisco' 23 | ; 24 | DELETE 25 | FROM 26 | products 27 | WHERE 28 | obsoletion_date = 'today' 29 | RETURNING 30 | * 31 | ; 32 | INSERT 33 | INTO 34 | distributors 35 | ( 36 | did 37 | , dname 38 | ) VALUES ( 39 | DEFAULT 40 | , 'XYZ Widgets' 41 | ) 42 | RETURNING 43 | did 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/long_func.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | NORMAL_FUNC(col1 + col2, param2) 3 | ; 4 | SELECT 5 | MANY_ARGS_FUNC(param1, param2, param3, param4) 6 | ; 7 | SELECT 8 | LONG_ARGS_FUNC(col1 + longlonglonglonglonglonglong, param2) 9 | ; 10 | SELECT 11 | LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC( 12 | param1 13 | , param2 14 | , param3 15 | ) 16 | ; 17 | SELECT 18 | FUNC1( 19 | CASE 20 | WHEN 21 | z = 1 22 | THEN 23 | FUNC3(param1, param2, param3, param4, param5) 24 | ELSE 25 | FUNC2( 26 | CASE 27 | WHEN 28 | z = 1 29 | THEN 30 | 'ONE' 31 | ELSE 32 | FUNC3(param1, param2, param3, param4, param5) 33 | END 34 | ) 35 | END 36 | ) 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/not_euqal.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | students 5 | WHERE 6 | student_id <> 2 7 | ; 8 | SELECT 9 | * 10 | FROM 11 | students 12 | WHERE 13 | student_id != 2 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/order_by.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | col AS col 3 | FROM 4 | tab 5 | ORDER BY 6 | col ASC -- 昇順 7 | , long_col DESC NULLS FIRST -- 降順 8 | , null_col NULLS FIRST -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/over.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | depname AS depname 3 | , empno AS empno 4 | , salary AS salary 5 | , RANK() OVER( 6 | PARTITION BY 7 | depname 8 | ORDER BY 9 | salary DESC 10 | ) 11 | FROM 12 | empsalary 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ''::JSONB 3 | FROM 4 | tbl 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a AS a 3 | FROM 4 | b 5 | WHERE 6 | (((1 = 1))) 7 | AND ( 8 | ((a = b)) 9 | OR (a) = (((42))) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/trim_bind.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | identifier AS identifier 3 | FROM 4 | japanese_student_table 5 | WHERE 6 | sbj.grade > /*grade*/50 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/where.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | tbl t 5 | WHERE 6 | t.id = ( 7 | SELECT 8 | MAX(t2.id) 9 | FROM 10 | tbl t2 11 | ) 12 | AND t.age < 100 13 | ; 14 | SELECT 15 | * 16 | FROM 17 | tbl t 18 | WHERE 19 | t.id = ( 20 | SELECT 21 | MAX(t2.id) 22 | FROM 23 | tbl t2 24 | ) 25 | OR t.id = 2 26 | ; 27 | SELECT 28 | * 29 | FROM 30 | tbl t 31 | WHERE 32 | -- comment 33 | t.id = ( 34 | SELECT 35 | MAX(t2.id) 36 | FROM 37 | tbl t2 38 | ) 39 | AND -- comment 40 | -- comment 41 | t.age < 100 42 | ; 43 | SELECT 44 | * 45 | FROM 46 | tbl t 47 | WHERE 48 | -- comment 49 | t.id = ( 50 | SELECT 51 | MAX(t2.id) 52 | FROM 53 | tbl t2 54 | ) 55 | OR -- comment 56 | -- comment 57 | t.id = 2 58 | ; 59 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config5/window.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | depname AS depname 3 | , empno AS empno 4 | , salary AS salary 5 | , RANK() OVER( 6 | PARTITION BY 7 | depname 8 | ORDER BY 9 | salary DESC 10 | ) 11 | FROM 12 | empsalary 13 | ; 14 | -- 0 argument over 15 | SELECT 16 | salary AS salary -- salary 17 | , SUM(salary) OVER() -- sum 18 | FROM 19 | empsalary 20 | ; 21 | -- frame_clause 22 | SELECT 23 | order_id AS order_id 24 | , item AS item 25 | , qty AS qty 26 | , SUM(qty) OVER( 27 | ORDER BY 28 | order_id 29 | ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING 30 | ) result 31 | FROM 32 | test_orders 33 | ; 34 | SELECT 35 | * 36 | , STRING_AGG(v, ',') OVER( 37 | PARTITION BY 38 | color 39 | /* partition by */ 40 | ORDER BY 41 | v 42 | /* order by */ 43 | GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE NO OTHERS 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | FROM 48 | t 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/all_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | students 5 | WHERE 6 | student_id <> ALL ( 7 | SELECT 8 | student_id 9 | FROM 10 | exam_results 11 | WHERE 12 | student_id IS NOT NULL 13 | ) 14 | AND longlonglonglonglonglong = test 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/case.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | id AS id 3 | , CASE 4 | WHEN 5 | grade_point >= 80 6 | THEN 7 | 'A' 8 | WHEN 9 | grade_point < 80 10 | AND grade_point >= 70 11 | THEN 12 | 'B' 13 | WHEN 14 | grade_point < 70 15 | AND grade_point >= 60 16 | THEN 17 | 'C' 18 | ELSE 19 | 'D' 20 | END 21 | AS grade 22 | FROM 23 | risyu 24 | WHERE 25 | subject_number = '005' 26 | ; 27 | SELECT 28 | id 29 | , CASE 30 | grade 31 | WHEN 32 | 'A' 33 | THEN 34 | 5 35 | WHEN 36 | 'B' 37 | THEN 38 | 4 39 | WHEN 40 | 'C' 41 | THEN 42 | 3 43 | ELSE 44 | 0 45 | END 46 | AS p 47 | FROM 48 | risyu 49 | WHERE 50 | subject_number = '006' 51 | ; 52 | SELECT 53 | CASE 54 | /*param*/a -- simple case cond 55 | WHEN 56 | /*a*/'a' 57 | THEN 58 | 'A' 59 | ELSE 60 | 'B' 61 | END 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CAST('2023-01-01' AS DATE) 3 | , CAST(100 AS CHAR(3)) 4 | , CAST((1 + 2) AS CHAR(1)) 5 | WHERE 6 | test = test 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/complement_as.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | identifier AS id 3 | , student_name 4 | FROM 5 | japanese_student_table 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/japanese.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | "テーブルエイリアス".id -- コメント1 3 | AS id -- コメント2 4 | , "テーブルエイリアス".column AS japanese_column -- コメント3 5 | FROM 6 | tbl "テーブルエイリアス" -- コメント4 7 | WHERE 8 | 1 = 1 -- コメント5 9 | AND "テーブルエイリアス".id = 1 -- コメント6 10 | AND "テーブルエイリアス"."カラムX" = 3 -- コメント7 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/join.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | t1 5 | INNER JOIN 6 | t2 7 | ON 8 | t1.num = t2.num 9 | ; 10 | SELECT 11 | * 12 | FROM 13 | t1 14 | LEFT OUTER JOIN 15 | t2 16 | ON 17 | t1.num = t2.num 18 | ; 19 | SELECT 20 | * 21 | FROM 22 | t1 23 | RIGHT OUTER JOIN 24 | t2 25 | ON 26 | t1.num = t2.num 27 | ; 28 | SELECT 29 | * 30 | FROM 31 | t1 32 | FULL OUTER JOIN 33 | t2 34 | ON 35 | t1.num = t2.num 36 | ; 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/keyword.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CASE 3 | WHEN 4 | a = 1 5 | THEN 6 | 'one' 7 | ELSE 8 | 'other' 9 | END 10 | AS grade 11 | FROM 12 | student std 13 | WHERE 14 | grade BETWEEN /*start1*/60 AND /*end1*/100 15 | AND grade NOT BETWEEN /*start2*/70 AND /*end2*/80 16 | ; 17 | UPDATE 18 | weather 19 | SET 20 | (temp_lo, temp_hi, prcp) = (temp_lo + 1, temp_lo + 15, DEFAULT) 21 | WHERE 22 | city = 'San Francisco' 23 | ; 24 | DELETE 25 | FROM 26 | products 27 | WHERE 28 | obsoletion_date = 'today' 29 | RETURNING 30 | * 31 | ; 32 | INSERT 33 | INTO 34 | distributors 35 | ( 36 | did 37 | , dname 38 | ) VALUES ( 39 | DEFAULT 40 | , 'XYZ Widgets' 41 | ) 42 | RETURNING 43 | did 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/long_func.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | NORMAL_FUNC(col1 + col2, param2) 3 | ; 4 | SELECT 5 | MANY_ARGS_FUNC(param1, param2, param3, param4) 6 | ; 7 | SELECT 8 | LONG_ARGS_FUNC(col1 + longlonglonglonglonglonglong, param2) 9 | ; 10 | SELECT 11 | LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC( 12 | param1 13 | , param2 14 | , param3 15 | ) 16 | ; 17 | SELECT 18 | FUNC1( 19 | CASE 20 | WHEN 21 | z = 1 22 | THEN 23 | FUNC3(param1, param2, param3, param4, param5) 24 | ELSE 25 | FUNC2( 26 | CASE 27 | WHEN 28 | z = 1 29 | THEN 30 | 'ONE' 31 | ELSE 32 | FUNC3(param1, param2, param3, param4, param5) 33 | END 34 | ) 35 | END 36 | ) 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/not_euqal.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | students 5 | WHERE 6 | student_id <> 2 7 | ; 8 | SELECT 9 | * 10 | FROM 11 | students 12 | WHERE 13 | student_id != 2 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/order_by.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | col 3 | FROM 4 | tab 5 | ORDER BY 6 | col ASC -- 昇順 7 | , long_col DESC NULLS FIRST -- 降順 8 | , null_col NULLS FIRST -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/over.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | depname 3 | , empno 4 | , salary 5 | , RANK() OVER( 6 | PARTITION BY 7 | depname 8 | ORDER BY 9 | salary DESC 10 | ) 11 | FROM 12 | empsalary 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ''::JSONB 3 | FROM 4 | tbl 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a 3 | FROM 4 | b 5 | WHERE 6 | (((1 = 1))) 7 | AND ( 8 | ((a = b)) 9 | OR (a) = (((42))) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/trim_bind.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | identifier 3 | FROM 4 | japanese_student_table 5 | WHERE 6 | sbj.grade > /*grade*/50 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/where.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | tbl t 5 | WHERE 6 | t.id = ( 7 | SELECT 8 | MAX(t2.id) 9 | FROM 10 | tbl t2 11 | ) 12 | AND t.age < 100 13 | ; 14 | SELECT 15 | * 16 | FROM 17 | tbl t 18 | WHERE 19 | t.id = ( 20 | SELECT 21 | MAX(t2.id) 22 | FROM 23 | tbl t2 24 | ) 25 | OR t.id = 2 26 | ; 27 | SELECT 28 | * 29 | FROM 30 | tbl t 31 | WHERE 32 | -- comment 33 | t.id = ( 34 | SELECT 35 | MAX(t2.id) 36 | FROM 37 | tbl t2 38 | ) 39 | AND -- comment 40 | -- comment 41 | t.age < 100 42 | ; 43 | SELECT 44 | * 45 | FROM 46 | tbl t 47 | WHERE 48 | -- comment 49 | t.id = ( 50 | SELECT 51 | MAX(t2.id) 52 | FROM 53 | tbl t2 54 | ) 55 | OR -- comment 56 | -- comment 57 | t.id = 2 58 | ; 59 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_config6/window.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | depname 3 | , empno 4 | , salary 5 | , RANK() OVER( 6 | PARTITION BY 7 | depname 8 | ORDER BY 9 | salary DESC 10 | ) 11 | FROM 12 | empsalary 13 | ; 14 | -- 0 argument over 15 | SELECT 16 | salary -- salary 17 | , SUM(salary) OVER() -- sum 18 | FROM 19 | empsalary 20 | ; 21 | -- frame_clause 22 | SELECT 23 | order_id 24 | , item 25 | , qty 26 | , SUM(qty) OVER( 27 | ORDER BY 28 | order_id 29 | ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING 30 | ) result 31 | FROM 32 | test_orders 33 | ; 34 | SELECT 35 | * 36 | , STRING_AGG(v, ',') OVER( 37 | PARTITION BY 38 | color 39 | /* partition by */ 40 | ORDER BY 41 | v 42 | /* order by */ 43 | GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE NO OTHERS 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | FROM 48 | t 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/all_subquery.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | students 5 | where 6 | student_id <> all ( 7 | select 8 | student_id as student_id 9 | from 10 | exam_results 11 | where 12 | student_id is not null 13 | ) 14 | and longlonglonglonglonglong = test 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/case.sql: -------------------------------------------------------------------------------- 1 | select 2 | id as id 3 | , case 4 | when 5 | grade_point >= 80 6 | then 7 | 'A' 8 | when 9 | grade_point < 80 10 | and grade_point >= 70 11 | then 12 | 'B' 13 | when 14 | grade_point < 70 15 | and grade_point >= 60 16 | then 17 | 'C' 18 | else 19 | 'D' 20 | end 21 | as grade 22 | from 23 | risyu 24 | where 25 | subject_number = '005' 26 | ; 27 | select 28 | id as id 29 | , case 30 | grade 31 | when 32 | 'A' 33 | then 34 | 5 35 | when 36 | 'B' 37 | then 38 | 4 39 | when 40 | 'C' 41 | then 42 | 3 43 | else 44 | 0 45 | end 46 | as p 47 | from 48 | risyu 49 | where 50 | subject_number = '006' 51 | ; 52 | select 53 | case 54 | /*param*/a -- simple case cond 55 | when 56 | /*a*/'a' 57 | then 58 | 'A' 59 | else 60 | 'B' 61 | end 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/cast.sql: -------------------------------------------------------------------------------- 1 | select 2 | cast('2023-01-01' as date) 3 | , cast(100 as char(3)) 4 | , cast((1 + 2) as char(1)) 5 | where 6 | test = test 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/complement_as.sql: -------------------------------------------------------------------------------- 1 | select 2 | identifier as id 3 | , student_name as student_name 4 | from 5 | japanese_student_table 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/japanese.sql: -------------------------------------------------------------------------------- 1 | select 2 | "テーブルエイリアス".id -- コメント1 3 | as id -- コメント2 4 | , "テーブルエイリアス".column as japanese_column -- コメント3 5 | from 6 | tbl "テーブルエイリアス" -- コメント4 7 | where 8 | 1 = 1 -- コメント5 9 | and "テーブルエイリアス".id = 1 -- コメント6 10 | and "テーブルエイリアス"."カラムX" = 3 -- コメント7 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/join.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | t1 5 | inner join 6 | t2 7 | on 8 | t1.num = t2.num 9 | ; 10 | select 11 | * 12 | from 13 | t1 14 | left outer join 15 | t2 16 | on 17 | t1.num = t2.num 18 | ; 19 | select 20 | * 21 | from 22 | t1 23 | right outer join 24 | t2 25 | on 26 | t1.num = t2.num 27 | ; 28 | select 29 | * 30 | from 31 | t1 32 | full outer join 33 | t2 34 | on 35 | t1.num = t2.num 36 | ; 37 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/keyword.sql: -------------------------------------------------------------------------------- 1 | select 2 | case 3 | when 4 | a = 1 5 | then 6 | 'one' 7 | else 8 | 'other' 9 | end 10 | as grade 11 | from 12 | student std 13 | where 14 | grade between /*start1*/60 and /*end1*/100 15 | and grade not between /*start2*/70 and /*end2*/80 16 | ; 17 | update 18 | weather 19 | set 20 | (temp_lo, temp_hi, prcp) = (temp_lo + 1, temp_lo + 15, default) 21 | where 22 | city = 'San Francisco' 23 | ; 24 | delete 25 | from 26 | products 27 | where 28 | obsoletion_date = 'today' 29 | returning 30 | * 31 | ; 32 | insert 33 | into 34 | distributors 35 | ( 36 | did 37 | , dname 38 | ) values ( 39 | default 40 | , 'XYZ Widgets' 41 | ) 42 | returning 43 | did 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/long_func.sql: -------------------------------------------------------------------------------- 1 | select 2 | normal_func(col1 + col2, param2) 3 | ; 4 | select 5 | many_args_func(param1, param2, param3, param4) 6 | ; 7 | select 8 | long_args_func( 9 | col1 + longlonglonglonglonglonglong 10 | , param2 11 | ) 12 | ; 13 | select 14 | longlonglonglonglonglonglonglonglonglonglonglong_func( 15 | param1 16 | , param2 17 | , param3 18 | ) 19 | ; 20 | select 21 | func1( 22 | case 23 | when 24 | z = 1 25 | then 26 | func3(param1, param2, param3, param4, param5) 27 | else 28 | func2( 29 | case 30 | when 31 | z = 1 32 | then 33 | 'ONE' 34 | else 35 | func3(param1, param2, param3, param4, param5) 36 | end 37 | ) 38 | end 39 | ) 40 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/not_euqal.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | students 5 | where 6 | student_id != 2 7 | ; 8 | select 9 | * 10 | from 11 | students 12 | where 13 | student_id != 2 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/order_by.sql: -------------------------------------------------------------------------------- 1 | select 2 | col as col 3 | from 4 | tab 5 | order by 6 | col asc -- 昇順 7 | , long_col desc nulls first -- 降順 8 | , null_col nulls first -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/over.sql: -------------------------------------------------------------------------------- 1 | select 2 | depname as depname 3 | , empno as empno 4 | , salary as salary 5 | , rank() over( 6 | partition by 7 | depname 8 | order by 9 | salary desc 10 | ) 11 | from 12 | empsalary 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | select 2 | cast('' as jsonb) 3 | from 4 | tbl 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | b 5 | where 6 | (1 = 1) 7 | and ( 8 | (a = b) 9 | or (a) = (42) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/trim_bind.sql: -------------------------------------------------------------------------------- 1 | select 2 | identifier as identifier 3 | from 4 | japanese_student_table 5 | where 6 | sbj.grade > /* grade */50 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/where.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | tbl t 5 | where 6 | t.id = ( 7 | select 8 | max(t2.id) 9 | from 10 | tbl t2 11 | ) 12 | and t.age < 100 13 | ; 14 | select 15 | * 16 | from 17 | tbl t 18 | where 19 | t.id = ( 20 | select 21 | max(t2.id) 22 | from 23 | tbl t2 24 | ) 25 | or t.id = 2 26 | ; 27 | select 28 | * 29 | from 30 | tbl t 31 | where 32 | -- comment 33 | t.id = ( 34 | select 35 | max(t2.id) 36 | from 37 | tbl t2 38 | ) 39 | and -- comment 40 | -- comment 41 | t.age < 100 42 | ; 43 | select 44 | * 45 | from 46 | tbl t 47 | where 48 | -- comment 49 | t.id = ( 50 | select 51 | max(t2.id) 52 | from 53 | tbl t2 54 | ) 55 | or -- comment 56 | -- comment 57 | t.id = 2 58 | ; 59 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/dst_default/window.sql: -------------------------------------------------------------------------------- 1 | select 2 | depname as depname 3 | , empno as empno 4 | , salary as salary 5 | , rank() over( 6 | partition by 7 | depname 8 | order by 9 | salary desc 10 | ) 11 | from 12 | empsalary 13 | ; 14 | -- 0 argument over 15 | select 16 | salary as salary -- salary 17 | , sum(salary) over() -- sum 18 | from 19 | empsalary 20 | ; 21 | -- frame_clause 22 | select 23 | order_id as order_id 24 | , item as item 25 | , qty as qty 26 | , sum(qty) over( 27 | order by 28 | order_id 29 | rows between 1 preceding and 1 following 30 | ) as result 31 | from 32 | test_orders 33 | ; 34 | select 35 | * 36 | , string_agg(v, ',') over( 37 | partition by 38 | color 39 | /* partition by */ 40 | order by 41 | v 42 | /* order by */ 43 | groups between unbounded preceding and current row exclude no others 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | from 48 | t 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/all_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM students 3 | WHERE student_id <> ALL 4 | (SELECT student_id 5 | FROM exam_results 6 | WHERE student_id IS NOT NULL) 7 | AND 8 | longlonglonglonglonglong = test 9 | ; 10 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/case.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ID As ID 3 | , case 4 | when 5 | GRADE_POInT >= 80 6 | THEN 7 | 'A' 8 | WHEN 9 | GRADE_POInT < 80 10 | AND GRADE_POInT >= 70 11 | THEN 12 | 'B' 13 | WHEN 14 | GRADE_point< 70 15 | AND GRADE_POInT >= 60 16 | THEN 17 | 'C' 18 | ELSE 19 | 'D' 20 | EnD As GRADE 21 | FROM 22 | RISYU 23 | WHERe 24 | SUBJECT_NUMBEr = '005' 25 | ; 26 | SELECt 27 | Id 28 | , CAse 29 | GRaDE 30 | WHeN 31 | 'A' 32 | ThEN 33 | 5 34 | WHEn 35 | 'B' 36 | THen 37 | 4 38 | WHen 39 | 'C' 40 | Then 41 | 3 42 | ELSE 43 | 0 44 | End AS P 45 | FROm 46 | RISyU 47 | WHere 48 | SUBJECT_NUMber = '006' 49 | ; 50 | SELECt 51 | cASe 52 | /*param*/A -- simple case cond 53 | WHeN 54 | /*a*/'a' 55 | THEn 56 | 'A' 57 | Else 58 | 'B' 59 | eND 60 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/cast.sql: -------------------------------------------------------------------------------- 1 | selecT 2 | cast('2023-01-01' As DaTE) 3 | , CaST(100 As CHaR(3)) 4 | , CaST((1 + 2) aS CHaR(1)) 5 | WHERe 6 | tesT = tEst 7 | 8 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | 123456789 -- hoge 3 | as 4 | col 5 | from 6 | tbl t; 7 | select 8 | 1 -- hoge 9 | as 10 | col1 11 | ,123456789-- fuga 12 | as 13 | col2 14 | from 15 | tbl t; 16 | SELECT a, 17 | CASE -- case trailing 18 | /* case */ 19 | WHEN -- cond_1 20 | a=1 -- a equals 1 21 | THEN -- cond_1 == true 22 | 'one' -- one 23 | WHEN -- cond_2 24 | a=2 -- a equals 2 25 | THEN -- cond_2 == true 26 | 'two' -- two 27 | ELSE -- forall i: cond_i == false 28 | 'other' -- other 29 | END -- comment 30 | as COL 31 | FROM test -- test table 32 | select 33 | 123456789 -- hoge 34 | col 35 | from 36 | tbl t; 37 | select 38 | 1 -- hoge 39 | col1 40 | ,123456789-- fuga 41 | col2 42 | from 43 | tbl t; 44 | SELECT a, 45 | CASE -- case trailing 46 | /* case */ 47 | WHEN -- cond_1 48 | a=1 -- a equals 1 49 | THEN -- cond_1 == true 50 | 'one' -- one 51 | WHEN -- cond_2 52 | a=2 -- a equals 2 53 | THEN -- cond_2 == true 54 | 'two' -- two 55 | ELSE -- forall i: cond_i == false 56 | 'other' -- other 57 | END -- comment 58 | COL 59 | FROM test -- test table 60 | where CASE 61 | WHEN 62 | a=1 63 | THEN 64 | 'one' 65 | ELSE 66 | 'other' 67 | END = CASE 68 | WHEN 69 | a=1 70 | THEN 71 | 'one' 72 | ELSE 73 | 'other' 74 | END 75 | ; 76 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/complement_as.sql: -------------------------------------------------------------------------------- 1 | selecT 2 | Identifier as iD, 3 | stuDent_name 4 | froM 5 | japanesE_student_table -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/japanese.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | "テーブルエイリアス".ID -- コメント1 3 | as ID -- コメント2 4 | , "テーブルエイリアス".column as japanese_column -- コメント3 5 | FROM 6 | TBL "テーブルエイリアス" -- コメント4 7 | WHERE 1 = 1 -- コメント5 8 | and "テーブルエイリアス".ID = 1 -- コメント6 9 | and "テーブルエイリアス"."カラムX" = 3 -- コメント7 10 | ; 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/join.sql: -------------------------------------------------------------------------------- 1 | select * from t1 inner join t2 on t1.num = t2.num; 2 | select * from t1 left join t2 on t1.num = t2.num; 3 | select * from t1 right join t2 on t1.num = t2.num; 4 | select * from t1 full join t2 on t1.num = t2.num; 5 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/keyword.sql: -------------------------------------------------------------------------------- 1 | select CASE 2 | when 3 | a=1 4 | THEN 5 | 'one' 6 | else 7 | 'other' 8 | END AS GRADE 9 | from student std 10 | whEre grade BeTWEEN /*start1*/60 AND /*end1*/100 11 | and grade NOT between /*start2*/70 and /*end2*/80 12 | ; 13 | UPDATE weAther SET (temp_lo, temp_hi, prcp) = (tEmp_lo+1, temp_lo+15, DEfAULT) 14 | WHeRE city = 'San Francisco'; 15 | DELeTE from products 16 | WHeRE obsoletion_date = 'today' 17 | RETURNING *; 18 | INSeRT into distributors (did, dname) VALUES (deFault, 'XYZ Widgets') 19 | RETURNING did; 20 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/long_func.sql: -------------------------------------------------------------------------------- 1 | select normal_func(COL1+COL2, PARAM2) 2 | ; 3 | select many_args_func(PARAM1, PARAM2, PARAM3, PARAM4) 4 | ; 5 | select long_args_func(COL1+LONGLONGLONGLONGLONGLONGLONG,PARAM2) 6 | ; 7 | select longlonglonglonglonglonglonglonglonglonglonglong_func(PARAM1,PARAM2,PARAM3) 8 | ; 9 | select 10 | func1( CASE WHEN Z = 1 11 | THEN func3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 12 | ELSE func2( 13 | CASE 14 | WHEN Z = 1 15 | THEN 'ONE' 16 | ELSE func3(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) 17 | END) 18 | END) 19 | 20 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/not_euqal.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM students 3 | WHERE student_id <> 2; 4 | 5 | SELECT * 6 | FROM students 7 | WHERE student_id != 2; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/order_by.sql: -------------------------------------------------------------------------------- 1 | SElECT 2 | COL 3 | FRoM 4 | TAB 5 | ORdER By 6 | CoL ASc -- 昇順 7 | , LoNG_COL DEsC NUllS FiRST -- 降順 8 | , NuLL_COL NULlS First -- NULL先 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/over.sql: -------------------------------------------------------------------------------- 1 | SELECt 2 | DEpNAME 3 | , EMPNo 4 | , SALARY 5 | , RANK() OVeR( 6 | PARtITiON By 7 | DEPNAME 8 | ORDeR By 9 | SALARY DESc 10 | ) 11 | FROm 12 | EMPSALARY 13 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | SELECT ''::JSONB from tbl; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/redundant_paren.sql: -------------------------------------------------------------------------------- 1 | select a 2 | from b 3 | where (((1 = 1))) 4 | and (((a = b)) or (a) = (((42)))) -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/trim_bind.sql: -------------------------------------------------------------------------------- 1 | SELeCT Identifier 2 | FrOM japanese_student_table 3 | WHeRE SBJ.grade > /* grade */50 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/where.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from tbl t 4 | where t.id = ( 5 | SELECT 6 | MAX(t2.id) 7 | FROM 8 | tbl t2 9 | ) 10 | and t.age < 100 11 | ; 12 | select 13 | * 14 | from tbl t 15 | where t.id = ( 16 | SELECT 17 | MAX(t2.id) 18 | FROM 19 | tbl t2 20 | ) 21 | or t.id = 2 22 | ; 23 | select 24 | * 25 | from tbl t 26 | where -- comment 27 | t.id = ( 28 | SELECT 29 | MAX(t2.id) 30 | FROM 31 | tbl t2 32 | ) 33 | and -- comment 34 | -- comment 35 | t.age < 100 36 | ; 37 | select 38 | * 39 | from tbl t 40 | where -- comment 41 | t.id = ( 42 | SELECT 43 | MAX(t2.id) 44 | FROM 45 | tbl t2 46 | ) 47 | or -- comment 48 | -- comment 49 | t.id = 2 50 | ; 51 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/config_test/src/window.sql: -------------------------------------------------------------------------------- 1 | SELEcT dePname, empno, sAlary, 2 | rank() OVER (PArTITION bY depname OrDER bY salary DEsC) 3 | FROM empsalary; 4 | -- 0 argument over 5 | SELECT salary -- salary 6 | , sUm(sAlary) OVeR () -- sum 7 | FrOM empsalaRy; 8 | -- frame_clause 9 | SELECT order_id, itEm, qty, 10 | SuM(qty) OVeR (OrDER By order_id ROWS BEtWEEN 1 PRECeDING AnD 1 FOLLOwING) result 11 | FROM test_orders; 12 | SELECT *, 13 | sTring_agg(v, ',') OVeR ( 14 | PARTiTION BY color 15 | /* partition by */ 16 | ORdER By v 17 | /* order by */ 18 | GROUPS BeTWEEN UNbOUNDED PREcEDING AnD CURRENT ROw 19 | EXCLUDE No OTHERS 20 | /* frame clause with exclusion */ 21 | /* over clause */ 22 | ) 23 | FROM t; 24 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(doma)/else.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | /*%else*/ 9 | emp.birth_date < /*birth_date_to*/'1999-12-31' 10 | /*%end*/ 11 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(doma)/elseif.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 8 | -- domaはelifではなくelseif 9 | limit all 10 | offset 10 11 | /*%elseif SF.isNotEmpty(birth_date_from)*/ 12 | limit all 13 | offset 5 14 | /*%end*/ 15 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(doma)/if.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 8 | limit all 9 | offset 5 10 | /*%end*/ 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(doma)/multiple.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /*%if hoge*/ 5 | employee emp 6 | /*%elseif huga*/ 7 | student std 8 | /*%elseif foo*/ 9 | teacher tcr 10 | /*%else*/ 11 | people ppl 12 | /*%end*/ 13 | where 14 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 15 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 16 | and emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 17 | /*%elseif SF.isNotEmpty(birth_date_from)*/ 18 | and emp.birth_date >= /*birth_date_from*/'1990-01-01' 19 | /*%else*/ 20 | /*%end*/ 21 | limit all 22 | offset 5 23 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(doma)/nest.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /*%if test*/ 5 | employee emp1 6 | /*%else*/ 7 | employee emp2 8 | /*%end*/ 9 | where 10 | /*%if test*/ 11 | emp.first_name = /*first_name*/'Bob1' 12 | /*%if SF.isNotEmpty(first_name)*/ 13 | and emp.first_name = /*first_name*/'Bob' 14 | /*%elseif SF.isNotEmpty(last_name1)*/ 15 | and emp.last_name = /*last_name*/'Smith1' 16 | /*%elseif SF.isNotEmpty(last_name2)*/ 17 | and emp.last_name = /*last_name*/'Smith2' 18 | /*%elseif SF.isNotEmpty(last_name3)*/ 19 | and emp.last_name = /*last_name*/'Smith3' 20 | /*%else*/ 21 | and emp.last_name = /*last_name*/'Smith4' 22 | /*%end*/ 23 | /*%else*/ 24 | emp.last_name = /*last_name*/'Smith4' 25 | /*%end*/ 26 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(go-twowaysql)/elif.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 8 | limit all 9 | offset 10 10 | /* ELIF SF.isNotEmpty(birth_date_from) */ 11 | limit all 12 | offset 5 13 | /* END */ 14 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(go-twowaysql)/else.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | /* ELSE */ 9 | emp.birth_date < /*birth_date_to*/'1999-12-31' 10 | /* END */ 11 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(go-twowaysql)/if.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 8 | limit all 9 | offset 5 10 | /* END */ 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(go-twowaysql)/multiple.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /* IF hoge */ 5 | employee emp 6 | /* ELIF huga */ 7 | student std 8 | /* ELIF foo */ 9 | teacher tcr 10 | /* ELSE */ 11 | people ppl 12 | /* END */ 13 | where 14 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 15 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 16 | and emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 17 | /* ELIF SF.isNotEmpty(birth_date_from) */ 18 | and emp.birth_date >= /*birth_date_from*/'1990-01-01' 19 | /* ELSE */ 20 | /* END */ 21 | limit all 22 | offset 5 23 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql(go-twowaysql)/nest.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /* IF test */ 5 | employee emp1 6 | /* ELSE */ 7 | employee emp2 8 | /* END */ 9 | where 10 | /* IF test */ 11 | emp.first_name = /*first_name*/'Bob1' 12 | /* IF SF.isNotEmpty(first_name) */ 13 | and emp.first_name = /*first_name*/'Bob' 14 | /* ELIF SF.isNotEmpty(last_name1) */ 15 | and emp.last_name = /*last_name*/'Smith1' 16 | /* ELIF SF.isNotEmpty(last_name2) */ 17 | and emp.last_name = /*last_name*/'Smith2' 18 | /* ELIF SF.isNotEmpty(last_name3) */ 19 | and emp.last_name = /*last_name*/'Smith3' 20 | /* ELSE */ 21 | and emp.last_name = /*last_name*/'Smith4' 22 | /* END */ 23 | /* ELSE */ 24 | emp.last_name = /*last_name*/'Smith4' 25 | /* END */ 26 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/align.sql: -------------------------------------------------------------------------------- 1 | select 2 | '' as a 3 | /*IF true*/ 4 | , 'b' as b 5 | /*ELSE*/ 6 | , 'ccccccccccccccc' as c 7 | /*END*/ 8 | ; 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/begin.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | /*BEGIN*/ 6 | where 7 | emp.first_name = /*first_name*/'Bob' 8 | /*IF SF.isNotEmpty(first_name)*/ 9 | and emp.first_name = /*first_name*/'Bob' 10 | /*END*/ 11 | /*IF SF.isNotEmpty(last_name)*/ 12 | and emp.last_name = /*last_name*/'Smith' 13 | /*END*/ 14 | /*END*/ 15 | ; 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | foo f 5 | order by 6 | /*IF true*/ 7 | f.bar1 8 | , 9 | /*END*/ 10 | f.bar2 11 | , f.bar3 12 | select 13 | * 14 | from 15 | foo f 16 | order by 17 | /*IF true*/ 18 | f.bar1 19 | , 20 | /*END*/ 21 | f.bar2 22 | , f.bar3 23 | select 24 | * 25 | from 26 | foo f 27 | order by 28 | /*IF true*/ 29 | f.bar1 30 | , 31 | /*END*/ 32 | -- comment 33 | f.bar2 34 | , f.bar3 35 | select 36 | * 37 | from 38 | foo f 39 | order by 40 | /*IF true*/ 41 | f.bar1 42 | , /*prev*/ 43 | /*END*/ 44 | /*next*/ 45 | -- some 46 | f.bar2 47 | , f.bar3 48 | select 49 | * 50 | from 51 | ( 52 | select 53 | * 54 | from 55 | foo f 56 | order by 57 | /*IF true*/ 58 | f.bar1 59 | , 60 | /*END*/ 61 | -- comment 62 | f.bar2 63 | , f.bar3 64 | ) 65 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/elif.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 8 | limit all 9 | offset 10 10 | /*ELIF SF.isNotEmpty(birth_date_from)*/ 11 | limit all 12 | offset 5 13 | /*END*/ 14 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/else.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | /*ELSE*/ 9 | emp.birth_date < /*birth_date_to*/'1999-12-31' 10 | /*END*/ 11 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/if.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 8 | limit all 9 | offset 5 10 | /*END*/ 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/multiple.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /*IF hoge*/ 5 | employee emp 6 | /*ELIF huga*/ 7 | student std 8 | /*ELIF foo*/ 9 | teacher tcr 10 | /*ELSE*/ 11 | people ppl 12 | /*END*/ 13 | where 14 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 15 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 16 | and emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 17 | /*ELIF SF.isNotEmpty(birth_date_from)*/ 18 | and emp.birth_date >= /*birth_date_from*/'1990-01-01' 19 | /*ELSE*/ 20 | /*END*/ 21 | limit all 22 | offset 5 23 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/2way_sql/nest.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /*IF test*/ 5 | employee emp1 6 | /*ELSE*/ 7 | employee emp2 8 | /*END*/ 9 | /*BEGIN*/ 10 | where 11 | /*IF test*/ 12 | emp.first_name = /*first_name*/'Bob1' 13 | /*IF SF.isNotEmpty(first_name)*/ 14 | and emp.first_name = /*first_name*/'Bob' 15 | /*ELIF SF.isNotEmpty(last_name1)*/ 16 | and emp.last_name = /*last_name*/'Smith1' 17 | /*ELIF SF.isNotEmpty(last_name2)*/ 18 | and emp.last_name = /*last_name*/'Smith2' 19 | /*ELIF SF.isNotEmpty(last_name3)*/ 20 | and emp.last_name = /*last_name*/'Smith3' 21 | /*ELSE*/ 22 | and emp.last_name = /*last_name*/'Smith4' 23 | /*END*/ 24 | /*ELSE*/ 25 | emp.last_name = /*last_name*/'Smith4' 26 | /*END*/ 27 | /*END*/ 28 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/align_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a -- c 3 | , aaaaaaa as aaaaaaa -- c 4 | ; 5 | select 6 | aa as a -- c 7 | , b as b -- c 8 | ; 9 | select 10 | a as a -- c 11 | , func(b, c) as f -- c 12 | ; 13 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/case_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | , case 4 | -- case trailing 5 | /* case */ 6 | when 7 | -- cond_1 8 | a = 1 -- a equals 1 9 | then 10 | -- cond_1 == true 11 | 'one' -- one 12 | when 13 | -- cond_2 14 | a = 2 -- a equals 2 15 | then 16 | -- cond_2 == true 17 | 'two' -- two 18 | else 19 | -- forall i: cond_i == false 20 | 'other' -- other 21 | end 22 | from 23 | test -- test table 24 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/col_list_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | tbl 5 | where 6 | tbl.a in ( 7 | 'AAA' -- a 8 | , 'bbbbb' -- b 9 | , 'c' -- c 10 | ) 11 | ; 12 | select 13 | * 14 | from 15 | tbl 16 | where 17 | tbl.ab in (/*var_a*/'A', /*var_b*/'B') 18 | ; 19 | select 20 | * 21 | from 22 | tbl 23 | where 24 | tbl.xy in /*var*/('X', 'Y') 25 | ; 26 | select 27 | * 28 | from 29 | tbl 30 | where 31 | tbl.xy in (/*var_a*/'A', /*var_b*/'B') -- ab 32 | and tbl.xy in /*var*/('X', 'Y') -- xy 33 | and tbl.st in ( 34 | 'S' -- s 35 | , 'T' -- t 36 | ) -- st 37 | ; 38 | select 39 | * 40 | from 41 | tbl t 42 | where 43 | t.id in ( 44 | -- after opening paren 45 | -- another comment 46 | /*firstId*/0 47 | , /*secondId*/1 48 | ) 49 | ; 50 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/head_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | , /*param*/'1' as b 4 | from 5 | t 6 | where 7 | t.a = /*var*/1 8 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/hint_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | /*+ 3 | FULL(c) FULL(b) FULL(a) LEADING(a b c) USE_HASH(b c) 4 | */ 5 | * 6 | from 7 | departments a 8 | , employees b 9 | , locations c 10 | where 11 | a.manager_id = b.manager_id 12 | and a.location_id = c.location_id 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/many_comments.sql: -------------------------------------------------------------------------------- 1 | /* discription */ 2 | -- hoge 3 | select /* _SQL_ID_ */ 4 | /* select body */ 5 | -- comment 6 | std.id as id -- identifier 7 | , std.grade as grade 8 | -- single line comment 9 | /* 10 | multi lines comment 11 | hoge hoge fuga 12 | */ 13 | , std.age as age -- age 14 | /* end select */ 15 | -- from clause 16 | from 17 | /* table lists */ 18 | student std 19 | , professor prof 20 | where 21 | /* conditions */ 22 | id = 5 -- check id 23 | /* others */ 24 | and age >= 18 25 | /* hoge */ 26 | /* huga */ 27 | and -- this comment follows "AND" 28 | grade > 50 29 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/multi_line_block_comment.sql: -------------------------------------------------------------------------------- 1 | /* 2 | comment 3 | */ 4 | select 5 | 1 6 | ; 7 | /* 8 | comment 9 | comment with space 10 | */ 11 | select 12 | 1 13 | ; 14 | /* 15 | * will 16 | not 17 | * aligned 18 | */ 19 | select 20 | 1 21 | ; 22 | -- aligned with asterisk 23 | /* 24 | * a 25 | * b 26 | */ 27 | select 28 | 1 29 | ; 30 | /* 31 | * a 32 | * b 33 | */ 34 | select 35 | 1 36 | ; 37 | /* 38 | * a 39 | * b 40 | */ 41 | select 42 | 1 43 | ; 44 | /* 45 | * a 46 | * b 47 | */ 48 | select 49 | 1 50 | ; 51 | /* 52 | * a 53 | * b 54 | * c 55 | */ 56 | select 57 | 1 58 | ; 59 | -- nested 60 | select 61 | * 62 | from 63 | ( 64 | /* 65 | * a 66 | * b 67 | */ 68 | select 69 | * 70 | from 71 | foo f 72 | ) 73 | ; 74 | select 75 | * 76 | from 77 | ( 78 | /* 79 | * a 80 | * b 81 | */ 82 | select 83 | * 84 | from 85 | foo f 86 | ) 87 | ; 88 | select 89 | * 90 | from 91 | ( 92 | /* 93 | * a 94 | * b 95 | * c 96 | */ 97 | select 98 | * 99 | from 100 | foo f 101 | ) 102 | ; 103 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/paren_with_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | tb 5 | where 6 | 1 = 22222222222222 -- comment0 7 | or ( 8 | -- start 9 | test1 = 1 -- comment1 10 | and ( 11 | test2 = 2 -- comment2 12 | and test3 = 3 -- comment3 13 | /* multi comment3 */ 14 | ) -- comment4 15 | or ( 16 | test4 = 4 -- comment5 17 | /* 18 | multi comment5 19 | */ 20 | or test5 = 5 -- comment6 21 | ) -- comment7 22 | -- end 23 | ) -- comment8 24 | and ( 25 | test6 = 6 -- comment9 26 | ) 27 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/sql_id.sql: -------------------------------------------------------------------------------- 1 | select /* _SQL_ID_ */ 2 | dept.dept_no as dept_no 3 | from 4 | department dept 5 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/comment/tail_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | longlongtable l -- so long 5 | , tab -- no alias 6 | , table1 t1 -- normal 7 | , sososolonglonglong -- so long and no alias 8 | where 9 | l.a = l.b -- normal 10 | and sososolonglonglong.a = 1 -- so long 11 | or t1.x + t1.y = 42 -- long lhs 12 | and tab.a = 1 + 2 + 3 + 5 -- long rhs 13 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/delete/delete.sql: -------------------------------------------------------------------------------- 1 | delete 2 | from 3 | table1 tbl1 -- テーブル1 4 | where 5 | tbl1.value = 1 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/delete/delete_returning.sql: -------------------------------------------------------------------------------- 1 | delete 2 | from 3 | products 4 | where 5 | obsoletion_date = 'today' 6 | returning 7 | * 8 | ; 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/delete/using.sql: -------------------------------------------------------------------------------- 1 | delete 2 | from 3 | tbl_a a 4 | using 5 | tbl_b b 6 | , tbl_c c 7 | where 8 | a.col1 = b.col1 9 | and b.col2 > 10 10 | and c.col3 = 'abc' 11 | ; 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/delete/with.sql: -------------------------------------------------------------------------------- 1 | with /* _SQL_ID_ */ 2 | t -- with句 3 | as not materialized ( 4 | --internal_comment 5 | select 6 | * 7 | from 8 | foo 9 | ) -- test 10 | , t2 ( 11 | a -- カラム1 12 | , b -- カラム2 13 | , c -- カラム3 14 | , d -- カラム4 15 | ) as ( 16 | --internal_comment 17 | update 18 | products 19 | set 20 | price = price * 1.10 21 | where 22 | price <= 99.99 23 | returning 24 | name as name 25 | , price as new_price 26 | ) 27 | , t3 ( 28 | a -- カラム1 29 | , b -- カラム2 30 | , c -- カラム3 31 | , d -- カラム4 32 | ) -- with句 33 | as materialized ( 34 | --internal_comment 35 | delete 36 | from 37 | products 38 | where 39 | obsoletion_date = 'today' 40 | returning 41 | * 42 | ) 43 | , t4 as ( 44 | --internal_comment 45 | insert 46 | into 47 | distributors 48 | ( 49 | did 50 | ) values ( 51 | default 52 | ) 53 | returning 54 | did 55 | ) 56 | delete 57 | from 58 | table1 tbl1 -- テーブル1 59 | where 60 | tbl1.value = 1 61 | ; 62 | with recursive 63 | t4 as not materialized ( 64 | --internal_comment 65 | insert 66 | into 67 | distributors 68 | ( 69 | did 70 | ) values ( 71 | default 72 | ) 73 | returning 74 | did -- test 75 | ) -- comment 76 | delete 77 | from 78 | table1 tbl1 -- テーブル1 79 | where 80 | tbl1.value = 1 81 | ; 82 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/insert/insert.sql: -------------------------------------------------------------------------------- 1 | insert 2 | into 3 | table1 -- table1 4 | ( 5 | column1 -- col1 6 | , column2 -- col2 7 | ) values ( 8 | value1 9 | , value2 10 | ) 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/insert/insert2.sql: -------------------------------------------------------------------------------- 1 | insert 2 | into 3 | films 4 | ( 5 | code 6 | , title 7 | , did 8 | , date_prod 9 | , kind 10 | ) values 11 | ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy') 12 | , ('HG120', 'The Dinner Game', 140, default, 'Comedy') 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/insert/insert_on_conflict.sql: -------------------------------------------------------------------------------- 1 | insert 2 | into 3 | distributors as d 4 | ( 5 | did 6 | , dname 7 | ) values ( 8 | 8 9 | , 'Anvil Distribution' 10 | ) 11 | on 12 | conflict ( 13 | did 14 | ) 15 | do 16 | update 17 | set 18 | dname = excluded.dname || ' (formerly ' || d.dname || ')' 19 | where 20 | d.zipcode != '21201' 21 | ; 22 | insert 23 | into 24 | distributors 25 | ( 26 | did 27 | , dname 28 | ) values ( 29 | 9 30 | , 'Antwerp Design' 31 | ) 32 | on 33 | conflict 34 | on 35 | constraint DISTRIBUTORS_PKEY 36 | do 37 | nothing 38 | ; 39 | insert 40 | into 41 | distributors 42 | ( 43 | did 44 | , dname 45 | ) values ( 46 | 9 47 | , 'Antwerp Design' 48 | ) 49 | on 50 | conflict ( 51 | did1 52 | , did2 53 | , did3 54 | ) 55 | do 56 | nothing 57 | ; 58 | insert 59 | into 60 | distributors 61 | ( 62 | did 63 | , dname 64 | ) values ( 65 | 9 66 | , 'Antwerp Design' 67 | ) 68 | on 69 | conflict ( 70 | did1 collate "x" int4_ops 71 | , did2 collate "x" int4_ops 72 | ) 73 | do 74 | nothing 75 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/insert/insert_returning.sql: -------------------------------------------------------------------------------- 1 | insert 2 | into 3 | distributors 4 | ( 5 | did 6 | , dname 7 | ) values ( 8 | default 9 | , 'XYZ Widgets' 10 | ) 11 | returning 12 | did 13 | ; 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/insert/insert_select.sql: -------------------------------------------------------------------------------- 1 | insert 2 | into 3 | stafflist 4 | ( 5 | name 6 | , address 7 | , staff_cls 8 | ) 9 | select 10 | name as name 11 | , address as address 12 | , /*#CLS_STAFF_CLS_NEW_COMER*/'0' 13 | from 14 | newcomer 15 | where 16 | flag = 'TRUE' 17 | ; 18 | insert 19 | into 20 | stafflist 21 | ( 22 | name 23 | , address 24 | , staff_cls 25 | ) 26 | ( 27 | select 28 | name as name 29 | , address as address 30 | , /*#CLS_STAFF_CLS_NEW_COMER*/'0' 31 | from 32 | newcomer 33 | where 34 | flag = 'TRUE' 35 | ); 36 | insert 37 | into 38 | tbl 39 | ( 40 | id 41 | ) 42 | select 43 | id as id 44 | from 45 | tbl2 46 | where 47 | id = 1 -- trailing comment 48 | ; 49 | insert 50 | into 51 | tbl 52 | ( 53 | id 54 | ) 55 | select 56 | id as id 57 | from 58 | tbl2 59 | where 60 | id = 1 -- trailing comment 61 | on 62 | conflict 63 | do 64 | nothing 65 | ; 66 | insert 67 | into 68 | tbl 69 | ( 70 | id 71 | ) 72 | -- comments 73 | -- before select 74 | select 75 | id as id 76 | from 77 | tbl2 78 | where 79 | id = 1 80 | ; 81 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/insert/insert_sql_id.sql: -------------------------------------------------------------------------------- 1 | insert /* _SQL_ID_ */ 2 | into 3 | table1 as tbl1 4 | ( 5 | col1 6 | , col2 7 | ) values 8 | (val11, val12) 9 | , (val21, val22) 10 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/insert/with.sql: -------------------------------------------------------------------------------- 1 | with /* _SQL_ID_ */ 2 | t -- with句 3 | as not materialized ( 4 | --internal_comment 5 | select 6 | * 7 | from 8 | foo 9 | ) -- test 10 | , t2 ( 11 | a -- カラム1 12 | , b -- カラム2 13 | , c -- カラム3 14 | , d -- カラム4 15 | ) -- with句 16 | as ( 17 | --internal_comment 18 | update 19 | products 20 | set 21 | price = price * 1.10 22 | where 23 | price <= 99.99 24 | returning 25 | name as name 26 | , price as new_price 27 | ) 28 | , t3 as materialized ( 29 | --internal_comment 30 | delete 31 | from 32 | products 33 | where 34 | obsoletion_date = 'today' 35 | returning 36 | * 37 | ) 38 | , t4 ( 39 | a -- カラム1 40 | , b -- カラム2 41 | , c -- カラム3 42 | , d -- カラム4 43 | ) as ( 44 | --internal_comment 45 | insert 46 | into 47 | distributors 48 | ( 49 | did 50 | ) values ( 51 | default 52 | ) 53 | returning 54 | did 55 | ) 56 | insert 57 | into 58 | table1 -- table1 59 | ( 60 | column1 -- col1 61 | , column2 -- col2 62 | ) values ( 63 | value1 64 | , value2 65 | ) 66 | ; 67 | with recursive 68 | t4 as not materialized ( 69 | --internal_comment 70 | insert 71 | into 72 | distributors 73 | ( 74 | did 75 | ) values ( 76 | default 77 | ) 78 | returning 79 | did -- test 80 | ) -- comment 81 | insert 82 | into 83 | table1 -- table1 84 | ( 85 | column1 -- col1 86 | , column2 -- col2 87 | ) values ( 88 | value1 89 | , value2 90 | ) 91 | ; 92 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/absense-of-select-clause-body.sql: -------------------------------------------------------------------------------- 1 | select 2 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/aggregate_function.sql: -------------------------------------------------------------------------------- 1 | select 2 | count( 3 | distinct 4 | tbl.col1 5 | ) 6 | ; 7 | select 8 | count( 9 | all 10 | tbl.col1 11 | ) 12 | ; 13 | select 14 | string_agg( 15 | distinct 16 | tbl.column1 17 | , ',' 18 | order by 19 | tbl.column2 20 | , tbl.column3 21 | ) 22 | ; 23 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/all_distinct.sql: -------------------------------------------------------------------------------- 1 | select 2 | distinct on 3 | ( 4 | quantity 5 | , itemname 6 | , area 7 | ) 8 | itemid as itemid 9 | , itemname as itemname 10 | ; 11 | select 12 | distinct 13 | itemid as itemid 14 | , itemname as itemname 15 | ; 16 | select 17 | all 18 | itemid as itemid 19 | , itemname as itemname 20 | ; 21 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/all_some_any_subquery.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | students 5 | where 6 | student_id <> all ( 7 | select 8 | student_id as student_id 9 | from 10 | exam_results 11 | where 12 | student_id is not null 13 | ) 14 | and longlonglonglonglonglong = test 15 | ; 16 | select 17 | * 18 | from 19 | students 20 | where 21 | student_id != some ( 22 | select 23 | student_id as student_id 24 | from 25 | exam_results 26 | where 27 | student_id is not null 28 | ) 29 | and longlonglonglonglonglong = test 30 | ; 31 | select 32 | * 33 | from 34 | students 35 | where 36 | student_id = any ( 37 | select 38 | student_id as student_id 39 | from 40 | exam_results 41 | where 42 | student_id is not null 43 | ) 44 | and longlonglonglonglonglong = test 45 | ; 46 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/as_in_from.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | , b as b 4 | from 5 | tab1 t 6 | , solonglongtab l 7 | , tab 8 | where 9 | t.a = l.b 10 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/asterisk.sql: -------------------------------------------------------------------------------- 1 | select 2 | tab.* -- asterisk 3 | , tab2.hoge as hoge -- hoge 4 | from 5 | tab 6 | , tab2 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/between.sql: -------------------------------------------------------------------------------- 1 | select 2 | std.grade as grade 3 | from 4 | student std 5 | where 6 | grade between /*start1*/60 and /*end1*/100 -- between 7 | and grade not between /*start2*/70 and /*end2*/80 -- not between 8 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/bind_param.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | , /*param*/'1' as b 4 | from 5 | t 6 | where 7 | t.a = /*var*/1 8 | and /*var2*/1 = t.c 9 | ; 10 | select /* _SQL_ID_ */ 11 | /*x*/'x' as x 12 | , /*y*/'y' as y 13 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/case.sql: -------------------------------------------------------------------------------- 1 | select 2 | id as id 3 | , case 4 | when 5 | grade_point >= 80 6 | then 7 | 'A' 8 | when 9 | grade_point < 80 10 | and grade_point >= 70 11 | then 12 | 'B' 13 | when 14 | grade_point < 70 15 | and grade_point >= 60 16 | then 17 | 'C' 18 | else 19 | 'D' 20 | end 21 | as grade 22 | from 23 | risyu 24 | where 25 | subject_number = '005' 26 | ; 27 | select 28 | id as id 29 | , case 30 | grade 31 | when 32 | 'A' 33 | then 34 | 5 35 | when 36 | 'B' 37 | then 38 | 4 39 | when 40 | 'C' 41 | then 42 | 3 43 | else 44 | 0 45 | end 46 | as p 47 | from 48 | risyu 49 | where 50 | subject_number = '006' 51 | ; 52 | select 53 | case 54 | /*param*/a -- simple case cond 55 | when 56 | /*a*/'a' 57 | then 58 | 'A' 59 | else 60 | 'B' 61 | end 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/case_rhs.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | , ( 4 | select 5 | z as z 6 | , case 7 | when 8 | z = 1 9 | then 10 | 'ONE' 11 | else 12 | 'OTHER' 13 | end 14 | from 15 | tab2 16 | ) 17 | from 18 | tab1 19 | ; 20 | select 21 | * 22 | from 23 | tbl 24 | where 25 | tbl.col = 26 | case 27 | when 28 | col is null 29 | then 30 | 0 31 | else 32 | 1 33 | end 34 | and case 35 | when 36 | col is null 37 | then 38 | 0 39 | else 40 | 1 41 | end 42 | > func(hoge) 43 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/cast.sql: -------------------------------------------------------------------------------- 1 | select 2 | cast('2023-01-01' as date) 3 | , cast(100 as char(3)) 4 | , cast((1 + 2) as char(1)) 5 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/comma_and_trailing_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | col1 as col1 -- column 1 3 | , col2 as col2 -- column 2 4 | from 5 | tbl1 -- table 1 6 | , tbl2 -- table 2 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/comp_op.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | tab1 5 | where 6 | tab1.num = 1 7 | and tab1.nuuuuuuuuuuuum = 2 8 | and tab1.a = 3 9 | and not (tab1.b = 5) 10 | and tab.a + func1(tab.s, tab.t) + func2(tab.u) = 2 11 | and tab.t is true 12 | and tab.f is not false 13 | and tab.n is null 14 | and tbl.ab in (/*param_a*/'A', /*param_b*/'B') 15 | and tbl.bc not in ('D', 'E') 16 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/complement_alias.sql: -------------------------------------------------------------------------------- 1 | select 2 | tbl.a as a -- aliased 3 | , tbl.b as b -- complement 4 | , 100 -- number 5 | , "str" -- string 6 | , count(1) -- count() 7 | from 8 | tbl 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/exists_subquery.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | department 5 | where 6 | exists( 7 | select 8 | department_id as department_id 9 | from 10 | user 11 | where 12 | address = 'TOKYO' 13 | ) 14 | and test = test 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/for_update.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee 5 | where 6 | id = '1' 7 | for update 8 | ; 9 | select 10 | * 11 | from 12 | employee 13 | where 14 | id = '1' 15 | for update of 16 | tbl 17 | , tbl2 18 | ; 19 | select 20 | * 21 | from 22 | employee 23 | where 24 | id = '1' 25 | for update 26 | nowait 27 | ; 28 | select 29 | * 30 | from 31 | employee 32 | where 33 | id = '1' 34 | for update of 35 | tbl 36 | , tbl2 37 | nowait 38 | ; 39 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/from.sql: -------------------------------------------------------------------------------- 1 | select 2 | hoge as hoge 3 | , fuga as fuga 4 | from 5 | table1 6 | , table2 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/function.sql: -------------------------------------------------------------------------------- 1 | select 2 | id as id 3 | , avg(grade) 4 | from 5 | student 6 | group by 7 | id 8 | ; 9 | select 10 | concat_lower_or_upper( 11 | 'Hello' -- hello 12 | , 'World' -- world 13 | , true -- true 14 | ) 15 | ; 16 | select 17 | func( 18 | case 19 | when 20 | flag 21 | then 22 | a 23 | else 24 | b 25 | end 26 | , c 27 | ) 28 | ; 29 | select 30 | city as city 31 | , max(temp_lo) 32 | from 33 | weather 34 | group by 35 | city 36 | having 37 | max(temp_lo) < 40 38 | ; 39 | select 40 | func((a - b), c) 41 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/group_by.sql: -------------------------------------------------------------------------------- 1 | select 2 | id as id 3 | , sum(cnt) 4 | from 5 | tbl 6 | group by 7 | id 8 | having 9 | /* comment */ 10 | sum(cnt) > 1 11 | and avg(cnt) < 10 12 | ; 13 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/in_subquery.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | department 5 | where 6 | id in ( 7 | select 8 | department_id as department_id 9 | from 10 | user 11 | where 12 | address = 'TOKYO' 13 | ) 14 | and test = test 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/join.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | t1 5 | inner join 6 | t2 7 | on 8 | t1.num = t2.num 9 | ; 10 | select 11 | * 12 | from 13 | t1 14 | left outer join 15 | t2 16 | on 17 | t1.num = t2.num 18 | ; 19 | select 20 | * 21 | from 22 | t1 23 | right outer join 24 | t2 25 | on 26 | t1.num = t2.num 27 | ; 28 | select 29 | * 30 | from 31 | t1 32 | full outer join 33 | t2 34 | on 35 | t1.num = t2.num 36 | ; 37 | select 38 | * 39 | from 40 | t1 41 | inner join 42 | t2 43 | on 44 | t1.num = t2.num 45 | inner join 46 | t3 47 | on 48 | t2.num = t3.num 49 | ; 50 | select 51 | * 52 | from 53 | t1 54 | left outer join 55 | t2 56 | on 57 | t1.num = t2.num 58 | ; 59 | select 60 | * 61 | from 62 | t1 63 | right outer join 64 | t2 65 | on 66 | t1.num = t2.num 67 | ; 68 | select 69 | * 70 | from 71 | t1 72 | full outer join 73 | t2 74 | on 75 | t1.num = t2.num 76 | ; 77 | select 78 | * 79 | from 80 | t1 81 | cross join 82 | t2 83 | ; 84 | select 85 | * 86 | from 87 | t1 88 | natural inner join 89 | t2 90 | ; 91 | select 92 | * 93 | from 94 | t1 -- table 1 95 | cross join 96 | t2 -- table 2 97 | ; 98 | select 99 | * 100 | from 101 | t1 102 | inner join 103 | t2 -- tbl 104 | on 105 | t1.num = t2.num -- cond 106 | ; 107 | select 108 | * 109 | from 110 | t1 -- after table 111 | inner join 112 | -- after keyword 113 | -- another comment 114 | t2 -- after table 115 | on 116 | t1.num = t2.num -- cond 117 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/like.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | t 5 | where 6 | 1 = 1 7 | and t.age_loooooooooooooooooooooooooooooong > 10 -- hoge 8 | and -- fuga 9 | t.name like '%' -- trailing1 10 | and -- foo 11 | t.name like '%' escape '$' -- trailing2 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/limit_offset.sql: -------------------------------------------------------------------------------- 1 | select 2 | tbl1.column1 as column1 3 | from 4 | table1 tbl1 5 | order by 6 | tbl1.column2 desc 7 | limit 5 8 | offset 5 9 | ; 10 | select 11 | tbl1.column1 as column1 12 | from 13 | table1 tbl1 14 | order by 15 | tbl1.column2 desc 16 | limit /*$hoge*/5 17 | offset 5 18 | ; 19 | select 20 | tbl1.column1 as column1 21 | from 22 | table1 tbl1 23 | order by 24 | tbl1.column2 desc 25 | limit all 26 | offset 5 27 | ; 28 | select 29 | tbl1.column1 as column1 30 | from 31 | table1 tbl1 32 | order by 33 | tbl1.column2 desc 34 | limit /*$hoge*/all 35 | offset 5 36 | ; 37 | select 38 | tbl1.column1 as column1 39 | from 40 | table1 tbl1 41 | order by 42 | tbl1.column2 desc 43 | limit 1 + 2 44 | offset 5 45 | ; 46 | select 47 | tbl1.column1 as column1 48 | from 49 | table1 tbl1 50 | order by 51 | tbl1.column2 desc 52 | limit /*$hoge*/100 + 1 53 | offset 5 54 | ; 55 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/long_bind_param.sql: -------------------------------------------------------------------------------- 1 | select 2 | id as data_id -- ID 3 | , code as data_code -- コード 4 | , name as data_name -- 名称 5 | , value1 as valueaaaaaaaaaaaaaaaa 6 | , value2 as value2 -- 値2 7 | , ( 8 | select 9 | value3 as value3 10 | from 11 | table2 12 | ) -- サブクエリ 13 | from 14 | table1 15 | where 16 | id = 'DUMMY' -- IDが'DUMMY' 17 | and val1 = 1 -- VAL1が1 18 | and code = 42 -- CODEが42 19 | or value2 = /*LONGLONGLONGLONG_BIND_PARAMETER*/42 20 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/multi_statement.sql: -------------------------------------------------------------------------------- 1 | -- セミコロンあり 2 | select 3 | a as a 4 | from 5 | tbl1 6 | ; 7 | -- セミコロンなし 8 | select 9 | b as b 10 | from 11 | tbl2 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/null_type_cast.sql: -------------------------------------------------------------------------------- 1 | select /* _SQL_ID_ */ 2 | cast(null as text) as "test" 3 | , cast('Y' as text) 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/or_and.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | tab1 5 | where 6 | l.a = 2 7 | or t.solonglong = 42 8 | or t.a = 433 9 | and aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 2 10 | and test = 1 11 | or test = 2 12 | and test = 3 13 | or test = 2 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/order_by.sql: -------------------------------------------------------------------------------- 1 | select 2 | col as col 3 | from 4 | tab 5 | order by 6 | col asc -- 昇順 7 | , long_col desc nulls first -- 降順 8 | , null_col nulls first -- NULL先 9 | ; 10 | select 11 | * 12 | from 13 | foo t 14 | order by 15 | t.bar1 16 | , /* after comma */ 17 | t.bar2 18 | , t.bar3 19 | ; 20 | select 21 | * 22 | from 23 | foo t 24 | order by 25 | t.bar1 26 | /* before comma */ 27 | , t.bar2 28 | , t.bar3 29 | ; 30 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/paren.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | t 5 | where 6 | (t.a + 2) = 3 7 | and t.b = 3 8 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | select 2 | cast('' as jsonb) 3 | from 4 | tbl 5 | ; 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/select.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | , b as b 4 | , c as c 5 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/select_sub_lhs.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | , ( 4 | -- comm1 5 | /* comm2 */ 6 | select 7 | z as z 8 | /* z */ 9 | from 10 | tab2 11 | /* comm3*/ 12 | ) 13 | from 14 | longlongtable l 15 | , ( 16 | select 17 | b as b 18 | , c as c 19 | from 20 | tab1 21 | ) -- trailing 22 | bc 23 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/string_literal.sql: -------------------------------------------------------------------------------- 1 | select 2 | col1 as col1 3 | from 4 | tab 5 | where 6 | tab.col2 = "String" 7 | and tab.col3 = 'Character' 8 | and tab.col4 = $Tag$Dollar$Tag$ 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/unary.sql: -------------------------------------------------------------------------------- 1 | select 2 | +5 as positive_value 3 | ; 4 | select 5 | +5 as positive_value 6 | ; 7 | select 8 | -10 as negative_value 9 | ; 10 | select 11 | -10 as negative_value 12 | ; 13 | select 14 | not true as not_true 15 | ; 16 | select 17 | ~5 as bitwise_not 18 | ; 19 | select 20 | ~5 as bitwise_not 21 | ; 22 | select 23 | |/25 as square_root 24 | ; 25 | select 26 | |/25 as square_root 27 | ; 28 | -- select @-5 as absolute_value; : PostgreSQLでは、`@-5` と書くと `@-` が一つのトークンとして扱われるため無効なSQLになる 29 | select 30 | @-5 as absolute_value 31 | ; 32 | select 33 | ||/8 as cube_root 34 | ; 35 | select 36 | ||/8 as cube_root 37 | ; 38 | -- 単項演算子がある場合の縦揃え 39 | select 40 | 1 as positive_value -- 式 41 | , -2 as negative_value -- 1文字 42 | , |/4 as square_root -- 2文字 43 | , ||/8 as cube_root -- 3文字 44 | ; 45 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/union.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | b 5 | /* select - union */ 6 | union 7 | -- union 8 | /* union - subselect */ 9 | select 10 | c as c 11 | from 12 | b 13 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/where.sql: -------------------------------------------------------------------------------- 1 | select 2 | a as a 3 | from 4 | t 5 | where 6 | t.n = 1 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/window.sql: -------------------------------------------------------------------------------- 1 | select 2 | depname as depname 3 | , empno as empno 4 | , salary as salary 5 | , rank() over( 6 | partition by 7 | depname 8 | order by 9 | salary desc 10 | ) 11 | from 12 | empsalary 13 | ; 14 | -- 0 argument over 15 | select 16 | salary as salary -- salary 17 | , sum(salary) over() -- sum 18 | from 19 | empsalary 20 | ; 21 | -- frame_clause 22 | select 23 | order_id as order_id 24 | , item as item 25 | , qty as qty 26 | , sum(qty) over( 27 | order by 28 | order_id 29 | rows between 1 preceding and 1 following 30 | ) as result 31 | from 32 | test_orders 33 | ; 34 | select 35 | * 36 | , string_agg(v, ',') over( 37 | partition by 38 | color 39 | /* partition by */ 40 | order by 41 | v 42 | /* order by */ 43 | groups between unbounded preceding and current row exclude no others 44 | /* frame clause with exclusion */ 45 | /* over clause */ 46 | ) 47 | from 48 | t 49 | ; 50 | -- filter clause 51 | select 52 | city as city 53 | , count(*) filter( 54 | where 55 | temp_lo < 45 56 | ) 57 | , max(temp_lo) 58 | from 59 | weather 60 | group by 61 | city 62 | ; 63 | -- filter clause with comments 64 | select 65 | city as city 66 | , count(*) filter( 67 | where 68 | temp_lo < 45 -- comment 69 | /* filter where */ 70 | ) 71 | from 72 | weather 73 | group by 74 | city 75 | ; 76 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/select/with.sql: -------------------------------------------------------------------------------- 1 | with /* _SQL_ID_ */ 2 | t -- with句 3 | as not materialized ( 4 | --internal_comment 5 | select 6 | * 7 | from 8 | foo -- foo 9 | -- end 10 | ) -- test 11 | , t2 as ( 12 | --internal_comment 13 | update 14 | products 15 | set 16 | price = price * 1.10 17 | where 18 | price <= 99.99 19 | returning 20 | name as name 21 | , price as new_price 22 | ) 23 | , t3 ( 24 | a -- カラム1 25 | , b -- カラム2 26 | , c -- カラム3 27 | , d -- カラム4 28 | ) as materialized ( 29 | --internal_comment 30 | delete 31 | from 32 | products 33 | where 34 | obsoletion_date = 'today' 35 | returning 36 | * 37 | ) 38 | , t4 ( 39 | a -- カラム1 40 | , b -- カラム2 41 | , c -- カラム3 42 | , d -- カラム4 43 | ) -- with句 44 | as ( 45 | --internal_comment 46 | insert 47 | into 48 | distributors 49 | ( 50 | did 51 | ) values ( 52 | default 53 | ) 54 | returning 55 | did 56 | ) 57 | select 58 | * 59 | from 60 | t1 61 | ; 62 | with recursive 63 | t4 as not materialized ( 64 | --internal_comment 65 | insert 66 | into 67 | distributors 68 | ( 69 | did 70 | ) values ( 71 | default 72 | ) 73 | returning 74 | did -- test 75 | ) -- comment 76 | select 77 | * 78 | from 79 | t1 80 | ; 81 | with recursive /* _SQL_ID_ */ 82 | /* block */ 83 | -- line 84 | t as ( 85 | select 86 | 1 87 | ) 88 | select 89 | 1 90 | ; 91 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/update/column_list_syntax.sql: -------------------------------------------------------------------------------- 1 | update 2 | weather 3 | set 4 | (temp_lo, temp_hi, prcp) = (temp_lo + 1, temp_lo + 15, default) 5 | where 6 | city = 'San Francisco' 7 | and date = '2003-07-03' 8 | ; 9 | update 10 | accounts 11 | set 12 | (contact_first_name, contact_last_name) = ( 13 | select 14 | first_name as first_name 15 | , last_name as last_name 16 | from 17 | salesmen 18 | where 19 | salesmen.id = accounts.sales_id 20 | ) 21 | ; 22 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/update/join.sql: -------------------------------------------------------------------------------- 1 | update /* _SQL_ID_ */ 2 | tbl t 3 | set 4 | t.col2 = a.col2 5 | , t.col3 = a.col3 6 | from 7 | tbl_a a 8 | left outer join 9 | tbl_b b 10 | on 11 | a.col1 = b.col1 12 | where 13 | t.id = a.id 14 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/update/update.sql: -------------------------------------------------------------------------------- 1 | update 2 | table1 tbl1 -- テーブル1 3 | set 4 | tbl1.column2 = 100 -- カラム2 5 | , tbl1.column3 = 100 -- カラム3 6 | where 7 | tbl1.column1 = 10 8 | ; 9 | update 10 | t t 11 | set 12 | -- after set keyword 13 | -- another comment 14 | c = c + 1 15 | where 16 | id = 1 17 | ; 18 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/update/update_from.sql: -------------------------------------------------------------------------------- 1 | update 2 | table1 tbl1 -- テーブル1 3 | set 4 | tbl1.column2 = tbl2.columnx -- カラム2 5 | , tbl1.column3 = 100 -- カラム3 6 | -- コメント 7 | from 8 | table2 tbl2 -- テーブル2 9 | where 10 | tbl1.column1 = 10 11 | and tbl1.column4 = tbl2.columny 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/update/update_returning.sql: -------------------------------------------------------------------------------- 1 | update 2 | products 3 | set 4 | price = price * 1.10 5 | where 6 | price <= 99.99 7 | returning 8 | name 9 | , price as new_price 10 | ; 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/dst/update/with.sql: -------------------------------------------------------------------------------- 1 | with /* _SQL_ID_ */ 2 | t -- with句 3 | as not materialized ( 4 | --internal_comment 5 | select 6 | * 7 | from 8 | foo 9 | ) -- test 10 | , t2 as ( 11 | --internal_comment 12 | update 13 | products 14 | set 15 | price = price * 1.10 16 | where 17 | price <= 99.99 18 | returning 19 | name as name 20 | , price as new_price 21 | ) 22 | , t3 ( 23 | a -- カラム1 24 | , b -- カラム2 25 | , c -- カラム3 26 | , d -- カラム4 27 | ) as materialized ( 28 | --internal_comment 29 | delete 30 | from 31 | products 32 | where 33 | obsoletion_date = 'today' 34 | returning 35 | * 36 | ) 37 | , t4 ( 38 | a -- カラム1 39 | , b -- カラム2 40 | , c -- カラム3 41 | , d -- カラム4 42 | ) -- with句 43 | as ( 44 | --internal_comment 45 | insert 46 | into 47 | distributors 48 | ( 49 | did 50 | ) values ( 51 | default 52 | ) 53 | returning 54 | did 55 | ) 56 | update 57 | table1 tbl1 -- テーブル1 58 | set 59 | tbl1.column2 = 100 -- カラム2 60 | , tbl1.column3 = 100 -- カラム3 61 | where 62 | tbl1.column1 = 10 63 | ; 64 | with recursive 65 | t4 as not materialized ( 66 | --internal_comment 67 | insert 68 | into 69 | distributors 70 | ( 71 | did 72 | ) values ( 73 | default 74 | ) 75 | returning 76 | did -- test 77 | ) -- comment 78 | update 79 | table1 tbl1 -- テーブル1 80 | set 81 | tbl1.column2 = 100 -- カラム2 82 | , tbl1.column3 = 100 -- カラム3 83 | where 84 | tbl1.column1 = 10 85 | ; 86 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/readme.md: -------------------------------------------------------------------------------- 1 | # uroborosql-fmt/testfiles 2 | 3 | 以下のコマンドでフォーマッタのテストを行う。 4 | ```console 5 | cargo test 6 | ``` 7 | 8 | テストファイルは`./testfiles/src/`下に置く。 9 | テストが実行されたら、`./testfiles/src/`下にあるすべての`.sql`に対してフォーマットを行い、`./testfiles/dst/`の対応するパスにフォーマット後の`.sql`ファイルが生成される。 10 | 11 | テストの追加・変更・移動を行う際には、`./testfiles/src/`を変更すれば、テスト実行時に自動的に`./testfiles/dst/`ディレクトリも変更される。 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(doma)/else.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | /*%else*/ 9 | emp.birth_date < /*birth_date_to*/'1999-12-31' 10 | /*%end*/ 11 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(doma)/elseif.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | 8 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ -- domaはelifではなくelseif 9 | 10 | limit 11 | all 12 | OFFSET 10 13 | /*%elseif SF.isNotEmpty(birth_date_from)*/ 14 | limit 15 | all 16 | OFFSET 5 17 | /*%end*/ 18 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(doma)/if.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | 9 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 10 | limit 11 | all 12 | OFFSET 5 13 | /*%end*/ 14 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(doma)/multiple.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /*%if hoge*/ 5 | employee emp 6 | /*%elseif huga*/ 7 | student std 8 | /*%elseif foo*/ 9 | teacher tcr 10 | /*%else*/ 11 | people ppl 12 | /*%end*/ 13 | where 14 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 15 | /*%if SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 16 | and emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 17 | /*%elseif SF.isNotEmpty(birth_date_from)*/ 18 | and emp.birth_date >= /*birth_date_from*/'1990-01-01' 19 | /*%else*/ 20 | /*%end*/ 21 | limit 22 | all 23 | OFFSET 5; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(doma)/nest.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | /*%if test*/ 5 | EMPLOYEE EMP1 6 | /*%else*/ 7 | EMPLOYEE EMP2 8 | /*%end*/ 9 | WHERE 10 | /*%if test*/ 11 | EMP.FIRST_NAME = /*first_name*/'Bob1' 12 | /*%if SF.isNotEmpty(first_name)*/ 13 | AND EMP.FIRST_NAME = /*first_name*/'Bob' 14 | /*%elseif SF.isNotEmpty(last_name1)*/ 15 | AND EMP.LAST_NAME = /*last_name*/'Smith1' 16 | /*%elseif SF.isNotEmpty(last_name2)*/ 17 | AND EMP.LAST_NAME = 18 | /*last_name*/'Smith2' 19 | /*%elseif SF.isNotEmpty(last_name3)*/ 20 | AND EMP.LAST_NAME = /*last_name*/'Smith3' 21 | /*%else*/ 22 | AND EMP.LAST_NAME = /*last_name*/'Smith4' 23 | /*%end*/ 24 | /*%else*/ 25 | EMP.LAST_NAME = /*last_name*/'Smith4' 26 | /*%end*/ 27 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(go-twowaysql)/elif.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | 8 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 9 | 10 | limit 11 | all 12 | OFFSET 10 13 | /* ELIF SF.isNotEmpty(birth_date_from) */ 14 | limit 15 | all 16 | OFFSET 5 17 | /* END */ 18 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(go-twowaysql)/else.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | /* ELSE */ 9 | emp.birth_date < /*birth_date_to*/'1999-12-31' 10 | /* END */ 11 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(go-twowaysql)/if.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | 9 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 10 | limit 11 | all 12 | OFFSET 5 13 | /* END */ 14 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(go-twowaysql)/multiple.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /* IF hoge */ 5 | employee emp 6 | /* ELIF huga */ 7 | student std 8 | /* ELIF foo */ 9 | teacher tcr 10 | /* ELSE */ 11 | people ppl 12 | /* END */ 13 | where 14 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 15 | /* IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to) */ 16 | and emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 17 | /* ELIF SF.isNotEmpty(birth_date_from) */ 18 | and emp.birth_date >= /*birth_date_from*/'1990-01-01' 19 | /* ELSE */ 20 | /* END */ 21 | limit 22 | all 23 | OFFSET 5; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql(go-twowaysql)/nest.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | /* IF test */ 5 | EMPLOYEE EMP1 6 | /* ELSE */ 7 | EMPLOYEE EMP2 8 | /* END */ 9 | WHERE 10 | /* IF test */ 11 | EMP.FIRST_NAME = /*first_name*/'Bob1' 12 | /* IF SF.isNotEmpty(first_name) */ 13 | AND EMP.FIRST_NAME = /*first_name*/'Bob' 14 | /* ELIF SF.isNotEmpty(last_name1) */ 15 | AND EMP.LAST_NAME = /*last_name*/'Smith1' 16 | /* ELIF SF.isNotEmpty(last_name2) */ 17 | AND EMP.LAST_NAME = 18 | /*last_name*/'Smith2' 19 | /* ELIF SF.isNotEmpty(last_name3) */ 20 | AND EMP.LAST_NAME = /*last_name*/'Smith3' 21 | /* ELSE */ 22 | AND EMP.LAST_NAME = /*last_name*/'Smith4' 23 | /* END */ 24 | /* ELSE */ 25 | EMP.LAST_NAME = /*last_name*/'Smith4' 26 | /* END */ 27 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/align.sql: -------------------------------------------------------------------------------- 1 | select 2 | '' as a 3 | /*IF true*/ 4 | ,'b' as b 5 | /*ELSE*/ 6 | ,'ccccccccccccccc' as c 7 | /*END*/ 8 | ; 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/begin.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | /*BEGIN*/ 6 | where 7 | emp.first_name = /*first_name*/'Bob' 8 | /*IF SF.isNotEmpty(first_name)*/ 9 | and emp.first_name = /*first_name*/'Bob' 10 | /*END*/ 11 | /*IF SF.isNotEmpty(last_name)*/ 12 | and emp.last_name = /*last_name*/'Smith' 13 | /*END*/ 14 | /*END*/ 15 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/comment.sql: -------------------------------------------------------------------------------- 1 | select * from foo f 2 | order by 3 | /*IF true*/ 4 | f.bar1 5 | ,/*END*/ 6 | f.bar2 7 | , f.bar3 8 | 9 | select * from foo f 10 | order by /*IF true*/ 11 | f.bar1, 12 | /*END*/ 13 | f.bar2 14 | , f.bar3 15 | 16 | select 17 | * 18 | from 19 | foo f 20 | order by 21 | /*IF true*/ 22 | f.bar1 23 | ,/*END*/ -- comment 24 | f.bar2 25 | , f.bar3 26 | 27 | 28 | select 29 | * 30 | from 31 | foo f 32 | order by 33 | /*IF true*/ 34 | f.bar1 35 | ,/*prev*//*END*//*next*/ -- some 36 | f.bar2 37 | , f.bar3 38 | 39 | select * 40 | from ( 41 | select 42 | * 43 | from 44 | foo f 45 | order by 46 | /*IF true*/ 47 | f.bar1 48 | ,/*END*/ -- comment 49 | f.bar2 50 | , f.bar3 51 | ) 52 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/elif.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 7 | 8 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 9 | 10 | limit 11 | all 12 | OFFSET 10 13 | /*ELIF SF.isNotEmpty(birth_date_from)*/ 14 | limit 15 | all 16 | OFFSET 5 17 | /*END*/ 18 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/else.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | /*ELSE*/ 9 | emp.birth_date < /*birth_date_to*/'1999-12-31' 10 | /*END*/ 11 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/if.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | employee emp 5 | where 6 | 7 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 8 | 9 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 10 | limit 11 | all 12 | OFFSET 5 13 | /*END*/ 14 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/multiple.sql: -------------------------------------------------------------------------------- 1 | select 2 | * 3 | from 4 | /*IF hoge*/ 5 | employee emp 6 | /*ELIF huga*/ 7 | student std 8 | /*ELIF foo*/ 9 | teacher tcr 10 | /*ELSE*/ 11 | people ppl 12 | /*END*/ 13 | where 14 | emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 15 | /*IF SF.isNotEmpty(birth_date_from) and SF.isNotEmpty(birth_date_to)*/ 16 | and emp.birth_date between /*birth_date_from*/'1990-01-01' and /*birth_date_to*/'1999-12-31' 17 | /*ELIF SF.isNotEmpty(birth_date_from)*/ 18 | and emp.birth_date >= /*birth_date_from*/'1990-01-01' 19 | /*ELSE*/ 20 | /*END*/ 21 | limit 22 | all 23 | OFFSET 5; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/2way_sql/nest.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | /*IF test*/ 5 | EMPLOYEE EMP1 6 | /*ELSE*/ 7 | EMPLOYEE EMP2 8 | /*END*/ 9 | /*BEGIN*/ 10 | WHERE 11 | /*IF test*/ 12 | EMP.FIRST_NAME = /*first_name*/'Bob1' 13 | /*IF SF.isNotEmpty(first_name)*/ 14 | AND EMP.FIRST_NAME = /*first_name*/'Bob' 15 | /*ELIF SF.isNotEmpty(last_name1)*/ 16 | AND EMP.LAST_NAME = /*last_name*/'Smith1' 17 | /*ELIF SF.isNotEmpty(last_name2)*/ 18 | AND EMP.LAST_NAME = 19 | /*last_name*/'Smith2' 20 | /*ELIF SF.isNotEmpty(last_name3)*/ 21 | AND EMP.LAST_NAME = /*last_name*/'Smith3' 22 | /*ELSE*/ 23 | AND EMP.LAST_NAME = /*last_name*/'Smith4' 24 | /*END*/ 25 | /*ELSE*/ 26 | EMP.LAST_NAME = /*last_name*/'Smith4' 27 | /*END*/ 28 | /*END*/ 29 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/align_comment.sql: -------------------------------------------------------------------------------- 1 | SELECT a -- c 2 | , aaaaaaa -- c 3 | ; 4 | SELECT aa as a -- c 5 | , b -- c 6 | ; 7 | SELECT a -- c 8 | , func(b, c) as f -- c 9 | ; 10 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/case_comment.sql: -------------------------------------------------------------------------------- 1 | SELECT a, 2 | CASE -- case trailing 3 | /* case */ 4 | WHEN -- cond_1 5 | a=1 -- a equals 1 6 | THEN -- cond_1 == true 7 | 'one' -- one 8 | WHEN -- cond_2 9 | a=2 -- a equals 2 10 | THEN -- cond_2 == true 11 | 'two' -- two 12 | ELSE -- forall i: cond_i == false 13 | 'other' -- other 14 | END 15 | FROM test -- test table -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/col_list_comment.sql: -------------------------------------------------------------------------------- 1 | select * 2 | from tbl 3 | where tbl.a in ( 4 | 'AAA' -- a 5 | , 'bbbbb' -- b 6 | , 'c' -- c 7 | ); 8 | select * from tbl 9 | where tbl.ab in (/*var_a*/'A', /*var_b*/'B'); 10 | select * from tbl 11 | where tbl.xy in /*var*/('X', 'Y'); 12 | select * from tbl 13 | where tbl.xy in (/*var_a*/'A', /*var_b*/'B') -- ab 14 | and tbl.xy in /*var*/('X', 'Y') -- xy 15 | and tbl.st in ('S' -- s 16 | , 'T' -- t 17 | ) -- st 18 | ; 19 | select * from tbl t 20 | where t.id in ( -- after opening paren 21 | -- another comment 22 | /*firstId*/0, /*secondId*/1 23 | ); 24 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/head_comment.sql: -------------------------------------------------------------------------------- 1 | select a, /*param*/'1' as b 2 | from t 3 | where t.a = /*var*/1 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/hint_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | /*+ 3 | FULL(c) FULL(b) FULL(a) LEADING(a b c) USE_HASH(b c) 4 | */ * 5 | from departments a, 6 | employees b, 7 | locations c 8 | where a.manager_id = b.manager_id 9 | and a.location_id = c.location_id; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/many_comments.sql: -------------------------------------------------------------------------------- 1 | /* discription */ 2 | -- hoge 3 | SELECT /* _SQL_ID_ */ 4 | /* select body */ -- comment 5 | STD.ID AS ID -- identifier 6 | , STD.GRADE AS GRADE 7 | -- single line comment 8 | /* 9 | multi lines comment 10 | hoge hoge fuga 11 | */ 12 | , STD.AGE AS AGE -- age 13 | /* end select */ 14 | -- from clause 15 | FROM /* table lists */ 16 | STUDENT STD 17 | , PROFESSOR PROF 18 | WHERE /* conditions */ 19 | ID = 5 -- check id 20 | /* others */ 21 | and age >= 18 22 | /* hoge */ 23 | /* huga */ 24 | and -- this comment follows "AND" 25 | grade > 50 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/multi_line_block_comment.sql: -------------------------------------------------------------------------------- 1 | /* 2 | comment 3 | */ 4 | select 1; 5 | 6 | /* 7 | comment 8 | comment with space 9 | */ 10 | select 1; 11 | 12 | /* 13 | * will 14 | not 15 | * aligned 16 | */ 17 | select 1; 18 | 19 | -- aligned with asterisk 20 | /* 21 | * a 22 | * b 23 | */ 24 | select 1; 25 | 26 | /* 27 | * a 28 | * b 29 | */ 30 | select 1; 31 | 32 | /* 33 | *a 34 | *b 35 | */ 36 | select 1; 37 | 38 | /* 39 | * a 40 | * b 41 | */ 42 | select 1; 43 | 44 | /* 45 | *a 46 | * b 47 | * c */ 48 | select 1; 49 | 50 | -- nested 51 | select * 52 | from ( 53 | /* 54 | * a 55 | * b 56 | */ 57 | select 58 | * 59 | from 60 | foo f 61 | ); 62 | 63 | select * 64 | from ( 65 | /* 66 | * a 67 | * b 68 | */ 69 | select 70 | * 71 | from 72 | foo f 73 | ); 74 | 75 | select * 76 | from ( 77 | /* 78 | * a 79 | *b 80 | * c 81 | */ 82 | select 83 | * 84 | from 85 | foo f 86 | ); 87 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/paren_with_comment.sql: -------------------------------------------------------------------------------- 1 | SELECT A 2 | from tb 3 | WHERE 4 | 1=22222222222222 --comment0 5 | OR 6 | ( -- start 7 | test1 = 1 --comment1 8 | and 9 | (test2 = 2 --comment2 10 | and 11 | test3 = 3 --comment3 12 | /* multi comment3 */ 13 | ) --comment4 14 | or (((test4 = 4 --comment5 15 | /* 16 | multi comment5 17 | */ 18 | or test5 = 5 --comment6 19 | )) 20 | ) --comment7 21 | -- end 22 | ) --comment8 23 | and (test6 = 6 -- comment9 24 | ) -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/sql_id.sql: -------------------------------------------------------------------------------- 1 | select /* _SQL_ID_ */ 2 | dept.dept_no as dept_no 3 | from 4 | department dept -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/comment/tail_comment.sql: -------------------------------------------------------------------------------- 1 | select a 2 | from longlongtable as l -- so long 3 | , tab -- no alias 4 | , table1 as t1 -- normal 5 | , sososolonglonglong -- so long and no alias 6 | where l.a = l.b -- normal 7 | and sososolonglonglong.a = 1 -- so long 8 | or t1.x + t1.y = 42 -- long lhs 9 | and tab.a = 1 + 2 + 3 + 5 -- long rhs 10 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/delete/delete.sql: -------------------------------------------------------------------------------- 1 | delete from table1 tbl1 -- テーブル1 2 | where tbl1.value = 1 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/delete/delete_returning.sql: -------------------------------------------------------------------------------- 1 | DELETE FROM products 2 | WHERE obsoletion_date = 'today' 3 | RETURNING *; 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/delete/using.sql: -------------------------------------------------------------------------------- 1 | delete from tbl_a a 2 | using tbl_b b, tbl_c c 3 | where a.col1 = b.col1 and b.col2 > 10 and c.col3 = 'abc'; 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/delete/with.sql: -------------------------------------------------------------------------------- 1 | WITH/* _SQL_ID_ */ t -- with句 2 | AS not materialized ( --internal_comment 3 | SELECT * FROM foo 4 | ), --test 5 | 6 | t2( 7 | a --カラム1 8 | ,b --カラム2 9 | ,c --カラム3 10 | , d --カラム4 11 | ) AS ( --internal_comment 12 | UPDATE 13 | PRODUCTS 14 | SET 15 | PRICE = PRICE * 1.10 16 | WHERE 17 | PRICE <= 99.99 18 | RETURNING 19 | NAME AS NAME 20 | , PRICE AS NEW_PRICE 21 | 22 | 23 | ), 24 | t3 ( 25 | a --カラム1 26 | ,b --カラム2 27 | ,c --カラム3 28 | , d --カラム4 29 | ) -- with句 30 | as materialized( --internal_comment 31 | DELETE 32 | FROM 33 | products 34 | WHERE 35 | obsoletion_date = 'today' 36 | RETURNING 37 | * 38 | ), 39 | t4 as (--internal_comment 40 | INSERT 41 | INTO 42 | DISTRIBUTORS 43 | ( 44 | DID 45 | ) VALUES ( 46 | DEFAULT 47 | ) 48 | RETURNING 49 | DID 50 | ) 51 | delete from table1 tbl1 -- テーブル1 52 | where tbl1.value = 1 53 | ; 54 | 55 | with recursive t4 as not materialized (--internal_comment 56 | INSERT 57 | INTO 58 | DISTRIBUTORS 59 | ( 60 | DID 61 | ) VALUES ( 62 | DEFAULT 63 | ) 64 | RETURNING 65 | DID -- test 66 | ) --comment 67 | delete from table1 tbl1 -- テーブル1 68 | where tbl1.value = 1 69 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/insert/insert.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO TABLE1 -- table1 2 | ( 3 | COLUMN1 -- col1 4 | , COLUMN2 -- col2 5 | ) 6 | VALUES (VALUE1,VALUE2) -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/insert/insert2.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO films (code, title, did, date_prod, kind) VALUES 2 | ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'), 3 | ('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy'); -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/insert/insert_on_conflict.sql: -------------------------------------------------------------------------------- 1 | INSERT 2 | INTO 3 | DISTRIBUTORS AS D(DID, DNAME) VALUES ( 4 | 8 5 | , 'Anvil Distribution' 6 | ) 7 | ON CONFLICT (DID) 8 | DO UPDATE 9 | SET 10 | DNAME = EXCLUDED.DNAME || ' (formerly ' || D.DNAME || ')' 11 | WHERE 12 | D.ZIPCODE != '21201' 13 | ; 14 | 15 | INSERT 16 | INTO 17 | DISTRIBUTORS 18 | ( 19 | DID 20 | , DNAME 21 | ) VALUES ( 22 | 9 23 | , 'Antwerp Design' 24 | ) 25 | ON CONFLICT 26 | ON CONSTRAINT 27 | DISTRIBUTORS_PKEY 28 | DO NOTHING 29 | ; 30 | 31 | INSERT 32 | INTO 33 | DISTRIBUTORS 34 | ( 35 | DID 36 | , DNAME 37 | ) VALUES ( 38 | 9 39 | , 'Antwerp Design' 40 | ) 41 | ON CONFLICT (DID1, DID2, DID3) 42 | DO 43 | NOTHING; 44 | 45 | INSERT 46 | INTO 47 | DISTRIBUTORS 48 | ( 49 | DID 50 | , DNAME 51 | ) VALUES ( 52 | 9 53 | , 'Antwerp Design' 54 | ) 55 | ON 56 | CONFLICT ( 57 | DID1 COLLATE "x" INT4_OPS 58 | , DID2 COLLATE "x" INT4_OPS 59 | ) 60 | DO 61 | NOTHING 62 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/insert/insert_returning.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets') 2 | RETURNING did; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/insert/insert_select.sql: -------------------------------------------------------------------------------- 1 | insert into stafflist (name, address, staff_cls) 2 | select name, address, /*#CLS_STAFF_CLS_NEW_COMER*/'0' from newcomer where flag = 'TRUE'; 3 | 4 | insert into stafflist (name, address, staff_cls) 5 | (select name, address, /*#CLS_STAFF_CLS_NEW_COMER*/'0' from newcomer where flag = 'TRUE'); 6 | 7 | insert into tbl (id) 8 | select id from tbl2 where id = 1 -- trailing comment 9 | ; 10 | 11 | insert into tbl (id) 12 | select id from tbl2 where id = 1 -- trailing comment 13 | on conflict do nothing 14 | ; 15 | 16 | insert into tbl (id) 17 | -- comments 18 | -- before select 19 | select id from tbl2 where id = 1; 20 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/insert/insert_sql_id.sql: -------------------------------------------------------------------------------- 1 | insert /* _SQL_ID_ */ 2 | into table1 as tbl1 3 | (col1, col2) values (val11, val12), (val21, val22) 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/insert/with.sql: -------------------------------------------------------------------------------- 1 | WITH /* _SQL_ID_ */ t-- with句 2 | AS not materialized( --internal_comment 3 | SELECT * FROM foo 4 | ), --test 5 | 6 | t2 ( 7 | a --カラム1 8 | ,b --カラム2 9 | ,c --カラム3 10 | , d --カラム4 11 | ) -- with句 12 | AS ( --internal_comment 13 | UPDATE 14 | PRODUCTS 15 | SET 16 | PRICE = PRICE * 1.10 17 | WHERE 18 | PRICE <= 99.99 19 | RETURNING 20 | NAME AS NAME 21 | , PRICE AS NEW_PRICE 22 | 23 | 24 | ), 25 | t3 as materialized( --internal_comment 26 | DELETE 27 | FROM 28 | products 29 | WHERE 30 | obsoletion_date = 'today' 31 | RETURNING 32 | * 33 | ), 34 | t4 ( 35 | a --カラム1 36 | ,b --カラム2 37 | ,c --カラム3 38 | , d --カラム4 39 | ) as (--internal_comment 40 | INSERT 41 | INTO 42 | DISTRIBUTORS 43 | ( 44 | DID 45 | ) VALUES ( 46 | DEFAULT 47 | ) 48 | RETURNING 49 | DID 50 | ) 51 | INSERT INTO TABLE1 -- table1 52 | ( 53 | COLUMN1 -- col1 54 | , COLUMN2 -- col2 55 | ) 56 | VALUES (VALUE1,VALUE2); 57 | 58 | with recursive t4 as not materialized (--internal_comment 59 | INSERT 60 | INTO 61 | DISTRIBUTORS 62 | ( 63 | DID 64 | ) VALUES ( 65 | DEFAULT 66 | ) 67 | RETURNING 68 | DID -- test 69 | ) --comment 70 | INSERT INTO TABLE1 -- table1 71 | ( 72 | COLUMN1 -- col1 73 | , COLUMN2 -- col2 74 | ) 75 | VALUES (VALUE1,VALUE2); -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/absense-of-select-clause-body.sql: -------------------------------------------------------------------------------- 1 | select -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/aggregate_function.sql: -------------------------------------------------------------------------------- 1 | select 2 | count(distinct tbl.col1); 3 | 4 | select 5 | count(all tbl.col1); 6 | 7 | select 8 | string_agg(distinct tbl.column1, ',' order by tbl.column2, tbl.column3); -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/all_distinct.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DISTINCT ON ( 3 | quantity 4 | , itemname 5 | , area 6 | ) 7 | itemid 8 | , itemname 9 | ; 10 | 11 | SELECT 12 | DISTINCT 13 | itemid 14 | , itemname 15 | ; 16 | 17 | SELECT 18 | ALL 19 | itemid 20 | , itemname 21 | ; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/all_some_any_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM students 3 | WHERE student_id <> ALL 4 | (SELECT student_id 5 | FROM exam_results 6 | WHERE student_id IS NOT NULL) 7 | AND 8 | longlonglonglonglonglong = test 9 | ; 10 | 11 | SELECT * 12 | FROM students 13 | WHERE student_id != SOME 14 | (SELECT student_id 15 | FROM exam_results 16 | WHERE student_id IS NOT NULL) 17 | AND 18 | longlonglonglonglonglong = test 19 | ; 20 | 21 | SELECT * 22 | FROM students 23 | WHERE student_id = ANY 24 | (SELECT student_id 25 | FROM exam_results 26 | WHERE student_id IS NOT NULL) 27 | AND 28 | longlonglonglonglonglong = test 29 | ; 30 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/as_in_from.sql: -------------------------------------------------------------------------------- 1 | select a, b 2 | from tab1 as t, 3 | solonglongtab as l, 4 | tab 5 | where t.a = l.b 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/asterisk.sql: -------------------------------------------------------------------------------- 1 | select tab.* -- asterisk 2 | , tab2.hoge AS hoge -- hoge 3 | from tab, tab2 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/between.sql: -------------------------------------------------------------------------------- 1 | select std.grade as grade 2 | from student std 3 | where grade between /*start1*/60 and /*end1*/100 -- between 4 | and grade not between /*start2*/70 and /*end2*/80 -- not between -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/bind_param.sql: -------------------------------------------------------------------------------- 1 | select a, /*param*/'1' as b 2 | from t 3 | where t.a = /*var*/1 4 | and /*var2*/1 = t.c; 5 | 6 | select /* _SQL_ID_ */ 7 | /*x*/'x' as x 8 | , /*y*/'y' as y 9 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/case.sql: -------------------------------------------------------------------------------- 1 | select id, case when grade_point >= 80 then 'A' 2 | when grade_point < 80 and grade_point >= 70 then 'B' 3 | when grade_point < 70 and grade_point >= 60 then 'C' 4 | else 'D' end as grade 5 | from risyu 6 | where subject_number = '005'; 7 | select id, case grade 8 | when 'A' then 5 9 | when 'B' then 4 10 | when 'C' then 3 11 | else 0 end as p 12 | 13 | from risyu 14 | where subject_number = '006'; 15 | select case /*param*/a -- simple case cond 16 | when /*a*/'a' then 'A' 17 | else 'B' 18 | end -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/case_rhs.sql: -------------------------------------------------------------------------------- 1 | SELECT A, 2 | (SELECT Z, CASE WHEN Z = 1 THEN 'ONE' ELSE 'OTHER' END FROM TAB2) 3 | FROM TAB1; 4 | SELECT * FROM TBL 5 | WHERE TBl.COL = CASE WHEN COL IS NULL THEN 0 ELSE 1 END 6 | AND CASE WHEN COL IS NULL THEN 0 ELSE 1 END > FUNC(HOGE) 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/cast.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | cast('2023-01-01' 3 | AS date) , 4 | cast(100 AS char(3)) 5 | , 6 | cast((1+ 2) AS char(1)) 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/comma_and_trailing_comment.sql: -------------------------------------------------------------------------------- 1 | select 2 | col1, -- column 1 3 | col2 -- column 2 4 | from 5 | tbl1, -- table 1 6 | tbl2 -- table 2 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/comp_op.sql: -------------------------------------------------------------------------------- 1 | select a from tab1 2 | where tab1.num = 1 and tab1.nuuuuuuuuuuuum = 2 3 | and tab1.a = 3 4 | and not (tab1.b = 5) 5 | and tab.a + func1(tab.s, tab.t) + func2(tab.u) = 2 6 | and tab.t is true 7 | and tab.f is not false 8 | and tab.n is null 9 | and tbl.ab in (/*param_a*/'A', /*param_b*/'B') 10 | and tbl.bc not in ('D', 'E') 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/complement_alias.sql: -------------------------------------------------------------------------------- 1 | select tbl.a as a -- aliased 2 | , tbl.b -- complement 3 | , 100 -- number 4 | , "str" -- string 5 | , count(1) -- count() 6 | from tbl 7 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/exists_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | department 5 | WHERE 6 | EXISTS( 7 | SELECT 8 | department_id 9 | FROM 10 | user 11 | WHERE 12 | address = 'TOKYO' 13 | ) 14 | AND 15 | test = test -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/for_update.sql: -------------------------------------------------------------------------------- 1 | select * from employee 2 | where ID = '1' 3 | for update; 4 | 5 | select * from employee 6 | where ID = '1' 7 | for update of tbl, tbl2; 8 | 9 | select * from employee 10 | where ID = '1' 11 | for update nowait; 12 | 13 | select * from employee 14 | where ID = '1' 15 | for update of tbl, tbl2 nowait; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/from.sql: -------------------------------------------------------------------------------- 1 | select hoge, fuga 2 | from table1, table2 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/function.sql: -------------------------------------------------------------------------------- 1 | SELECT id, avg(grade) FROM student GROUP BY id; 2 | SELECT concat_lower_or_upper('Hello' --hello 3 | , 'World' --world 4 | ,true --true 5 | ); 6 | SELECT func(CASE WHEN flag THEN a ELSE b end, c ); 7 | SELECT city, max(temp_lo) 8 | FROM weather 9 | GROUP BY city 10 | HAVING max(temp_lo) < 40; 11 | SELECT func((a - b), c) 12 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/group_by.sql: -------------------------------------------------------------------------------- 1 | select 2 | id, sum(cnt) 3 | from 4 | tbl 5 | group by 6 | id 7 | having 8 | /* comment */ 9 | sum(cnt) > 1 and avg(cnt) < 10 10 | ; 11 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/in_subquery.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | * 3 | FROM 4 | department 5 | WHERE 6 | id IN ( 7 | SELECT 8 | department_id 9 | FROM 10 | user 11 | WHERE 12 | address = 'TOKYO' 13 | ) 14 | AND 15 | test = test -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/join.sql: -------------------------------------------------------------------------------- 1 | select * from t1 inner join t2 on t1.num = t2.num; 2 | select * from t1 left join t2 on t1.num = t2.num; 3 | select * from t1 right join t2 on t1.num = t2.num; 4 | select * from t1 full join t2 on t1.num = t2.num; 5 | select * from t1 inner join t2 on t1.num = t2.num inner join t3 on t2.num = t3.num; 6 | select * from t1 left outer join t2 on t1.num = t2.num; 7 | select * from t1 right outer join t2 on t1.num = t2.num; 8 | select * from t1 full outer join t2 on t1.num = t2.num; 9 | select * from t1 cross join t2; 10 | select * from t1 natural inner join t2; 11 | select * from t1 -- table 1 12 | cross join t2 -- table 2 13 | ; 14 | select * from t1 inner join t2 -- tbl 15 | on t1.num = t2.num -- cond 16 | ; 17 | select 18 | * 19 | from 20 | t1 -- after table 21 | inner join -- after keyword 22 | -- another comment 23 | t2 -- after table 24 | on t1.num = t2.num -- cond 25 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/like.sql: -------------------------------------------------------------------------------- 1 | select * from t where 1=1 and t.age_loooooooooooooooooooooooooooooong > 10 -- hoge 2 | and 3 | -- fuga 4 | t.name like '%' --trailing1 5 | and 6 | -- foo 7 | t.name like '%' escape '$' --trailing2 8 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/limit_offset.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | TBL1.COLUMN1 3 | AS COLUMN1 4 | FROM 5 | TABLE1 TBL1 6 | ORDER BY 7 | TBL1.COLUMN2 8 | DESC 9 | limit 5 10 | OFFSET 5; 11 | 12 | SELECT 13 | TBL1.COLUMN1 14 | AS COLUMN1 15 | FROM 16 | TABLE1 TBL1 17 | ORDER BY 18 | TBL1.COLUMN2 19 | DESC 20 | limit /*$hoge*/5 21 | OFFSET 5; 22 | 23 | SELECT 24 | TBL1.COLUMN1 25 | AS COLUMN1 26 | FROM 27 | TABLE1 TBL1 28 | ORDER BY 29 | TBL1.COLUMN2 30 | DESC 31 | limit 32 | all 33 | OFFSET 5; 34 | 35 | SELECT 36 | TBL1.COLUMN1 37 | AS COLUMN1 38 | FROM 39 | TABLE1 TBL1 40 | ORDER BY 41 | TBL1.COLUMN2 42 | DESC 43 | limit /*$hoge*/all 44 | OFFSET 5; 45 | 46 | SELECT 47 | TBL1.COLUMN1 48 | AS COLUMN1 49 | FROM 50 | TABLE1 TBL1 51 | ORDER BY 52 | TBL1.COLUMN2 53 | DESC 54 | limit 1 + 2 55 | OFFSET 5; 56 | 57 | SELECT 58 | TBL1.COLUMN1 59 | AS COLUMN1 60 | FROM 61 | TABLE1 TBL1 62 | ORDER BY 63 | TBL1.COLUMN2 64 | DESC 65 | limit /*$hoge*/100 + 1 66 | OFFSET 5; 67 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/long_bind_param.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ID AS DATA_ID -- ID 3 | , CODE AS DATA_CODE -- コード 4 | , NAME AS DATA_NAME -- 名称 5 | , VALUE1 AS VALUEAAAAAAAAAAAAAAAA 6 | , VALUE2 -- 値2 7 | , ( 8 | SELECT 9 | VALUE3 10 | FROM 11 | TABLE2 12 | ) -- サブクエリ 13 | FROM 14 | TABLE1 15 | WHERE 16 | ID = 'DUMMY' -- IDが'DUMMY' 17 | AND VAL1 = 1 -- VAL1が1 18 | AND CODE = 42 -- CODEが42 19 | OR VALUE2 = /*LONGLONGLONGLONG_BIND_PARAMETER*/42 20 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/multi_statement.sql: -------------------------------------------------------------------------------- 1 | -- セミコロンあり 2 | SELECT A FROM TBL1; 3 | -- セミコロンなし 4 | SELECT B FROM TBL2 5 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/null_type_cast.sql: -------------------------------------------------------------------------------- 1 | select /* _SQL_ID_ */ 2 | null::text AS "test" 3 | , 'Y'::text -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/or_and.sql: -------------------------------------------------------------------------------- 1 | select a 2 | from tab1 3 | where l.a = 2 4 | or t.solonglong = 42 5 | or t.a = 433 6 | and aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 2 7 | and test = 1 8 | or test = 2 9 | and test = 3 10 | or test = 2 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/order_by.sql: -------------------------------------------------------------------------------- 1 | select col from tab 2 | order by col asc -- 昇順 3 | , long_col desc nulls first -- 降順 4 | , null_col nulls first -- NULL先 5 | ; 6 | 7 | select * from foo t 8 | order by 9 | t.bar1 10 | , 11 | /* after comma */ 12 | t.bar2 13 | , t.bar3; 14 | 15 | select * from foo t 16 | order by 17 | t.bar1 18 | /* before comma */ 19 | , t.bar2 20 | , t.bar3; 21 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/paren.sql: -------------------------------------------------------------------------------- 1 | SELECT a FROM t WHERE (t.a + 2) = 3 AND t.b = 3 2 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/postgre_cast.sql: -------------------------------------------------------------------------------- 1 | SELECT ''::JSONB from tbl; -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/select.sql: -------------------------------------------------------------------------------- 1 | select a, b, c 2 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/select_sub_lhs.sql: -------------------------------------------------------------------------------- 1 | SELECT A, 2 | ( -- comm1 3 | /* comm2 */ 4 | SELECT Z /* z */FROM TAB2 5 | /* comm3*/) 6 | FROM LONGLONGTABLE AS L, 7 | (SELECT B, C FROM TAB1) -- trailing 8 | AS BC -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/string_literal.sql: -------------------------------------------------------------------------------- 1 | select col1 2 | from tab 3 | where tab.col2 = "String" 4 | and tab.col3 = 'Character' 5 | and tab.col4 = $Tag$Dollar$Tag$ -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/unary.sql: -------------------------------------------------------------------------------- 1 | select +5 as positive_value; 2 | select + 5 as positive_value; 3 | 4 | select -10 as negative_value; 5 | select - 10 as negative_value; 6 | 7 | select not true as not_true; 8 | 9 | select ~5 as bitwise_not; 10 | select ~ 5 as bitwise_not; 11 | 12 | select |/25 as square_root; 13 | select |/ 25 as square_root; 14 | 15 | -- select @-5 as absolute_value; : PostgreSQLでは、`@-5` と書くと `@-` が一つのトークンとして扱われるため無効なSQLになる 16 | select @ -5 as absolute_value; 17 | 18 | select ||/8 as cube_root; 19 | select ||/ 8 as cube_root; 20 | 21 | -- 単項演算子がある場合の縦揃え 22 | select 23 | 1 as positive_value -- 式 24 | ,-2 as negative_value -- 1文字 25 | ,|/4 as square_root -- 2文字 26 | ,||/8 as cube_root -- 3文字 27 | ; 28 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/union.sql: -------------------------------------------------------------------------------- 1 | SELECT A 2 | FROM B 3 | /* select - union */ 4 | UNION -- union 5 | /* union - subselect */ 6 | SELECT C 7 | FROM B -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/where.sql: -------------------------------------------------------------------------------- 1 | select 2 | a from t where t.n = 1 -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/window.sql: -------------------------------------------------------------------------------- 1 | SELECT depname, empno, salary, 2 | rank() OVER (PARTITION BY depname ORDER BY salary DESC) 3 | FROM empsalary; 4 | -- 0 argument over 5 | SELECT salary -- salary 6 | , sum(salary) OVER () -- sum 7 | FROM empsalary; 8 | -- frame_clause 9 | SELECT order_id, item, qty, 10 | SUM(qty) OVER (ORDER BY order_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) result 11 | FROM test_orders; 12 | SELECT *, 13 | string_agg(v, ',') OVER ( 14 | PARTITION BY color 15 | /* partition by */ 16 | ORDER BY v 17 | /* order by */ 18 | GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW 19 | EXCLUDE NO OTHERS 20 | /* frame clause with exclusion */ 21 | /* over clause */ 22 | ) 23 | FROM t; 24 | -- filter clause 25 | SELECT city, count(*) FILTER (WHERE temp_lo < 45), max(temp_lo) 26 | FROM weather GROUP BY city; 27 | 28 | -- filter clause with comments 29 | SELECT city, count(*) FILTER ( 30 | WHERE temp_lo < 45 -- comment 31 | /* filter where */ 32 | ) 33 | FROM weather 34 | GROUP BY city; 35 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/select/with.sql: -------------------------------------------------------------------------------- 1 | WITH/* _SQL_ID_ */ t -- with句 2 | AS not materialized( --internal_comment 3 | SELECT * FROM foo -- foo 4 | -- end 5 | ), --test 6 | 7 | t2 AS ( --internal_comment 8 | UPDATE 9 | PRODUCTS 10 | SET 11 | PRICE = PRICE * 1.10 12 | WHERE 13 | PRICE <= 99.99 14 | RETURNING 15 | NAME AS NAME 16 | , PRICE AS NEW_PRICE 17 | 18 | 19 | ), 20 | t3( 21 | a --カラム1 22 | ,b --カラム2 23 | ,c --カラム3 24 | , d --カラム4 25 | ) as materialized ( --internal_comment 26 | DELETE 27 | FROM 28 | products 29 | WHERE 30 | obsoletion_date = 'today' 31 | RETURNING 32 | * 33 | ), 34 | t4 ( 35 | a --カラム1 36 | ,b --カラム2 37 | ,c --カラム3 38 | , d --カラム4 39 | ) -- with句 40 | as (--internal_comment 41 | INSERT 42 | INTO 43 | DISTRIBUTORS 44 | ( 45 | DID 46 | ) VALUES ( 47 | DEFAULT 48 | ) 49 | RETURNING 50 | DID 51 | ) 52 | SELECT * FROM t1; 53 | 54 | 55 | with recursive t4 as not materialized (--internal_comment 56 | INSERT 57 | INTO 58 | DISTRIBUTORS 59 | ( 60 | DID 61 | ) VALUES ( 62 | DEFAULT 63 | ) 64 | RETURNING 65 | DID -- test 66 | ) --comment 67 | SELECT * FROM t1; 68 | 69 | with recursive /* _SQL_ID_ */ /* block */ -- line 70 | t as ( 71 | select 72 | 1 73 | ) 74 | select 75 | 1; 76 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/update/column_list_syntax.sql: -------------------------------------------------------------------------------- 1 | UPDATE weather SET (temp_lo, temp_hi, prcp) = (temp_lo+1, temp_lo+15, DEFAULT) 2 | WHERE city = 'San Francisco' AND date = '2003-07-03'; 3 | UPDATE accounts SET (contact_first_name, contact_last_name) = 4 | (SELECT first_name, last_name FROM salesmen 5 | WHERE salesmen.id = accounts.sales_id); 6 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/update/join.sql: -------------------------------------------------------------------------------- 1 | update /* _SQL_ID_ */ 2 | tbl t set t.col2 = a.col2, t.col3 = a.col3 3 | from tbl_a a 4 | left outer join tbl_b b on a.col1 = b.col1 where t.id = a.id 5 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/update/update.sql: -------------------------------------------------------------------------------- 1 | UPDATE TABLE1 TBL1 -- テーブル1 2 | SET TBL1.COLUMN2 = 100 -- カラム2 3 | , TBL1.COLUMN3 = 100 -- カラム3 4 | WHERE TBL1.COLUMN1 = 10 5 | ; 6 | 7 | update 8 | T t 9 | set -- after set keyword 10 | -- another comment 11 | c = c + 1 12 | where 13 | id = 1 14 | ; 15 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/update/update_from.sql: -------------------------------------------------------------------------------- 1 | UPDATE TABLE1 TBL1-- テーブル1 2 | SET TBL1.COLUMN2 = TBL2.COLUMNX -- カラム2 3 | , TBL1.COLUMN3 = 100 -- カラム3 4 | -- コメント 5 | from 6 | TABLE2 TBL2-- テーブル2 7 | WHERE TBL1.COLUMN1 = 10 AND TBL1.COLUMN4 = TBL2.COLUMNY 8 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/update/update_returning.sql: -------------------------------------------------------------------------------- 1 | UPDATE products SET price = price * 1.10 2 | WHERE price <= 99.99 3 | RETURNING name, price AS new_price; 4 | -------------------------------------------------------------------------------- /crates/uroborosql-fmt/testfiles/src/update/with.sql: -------------------------------------------------------------------------------- 1 | WITH/* _SQL_ID_ */ t 2 | -- with句 3 | AS not materialized( --internal_comment 4 | SELECT * FROM foo 5 | ), --test 6 | 7 | t2 AS ( --internal_comment 8 | UPDATE 9 | PRODUCTS 10 | SET 11 | PRICE = PRICE * 1.10 12 | WHERE 13 | PRICE <= 99.99 14 | RETURNING 15 | NAME AS NAME 16 | , PRICE AS NEW_PRICE 17 | 18 | 19 | ), 20 | t3 ( 21 | a --カラム1 22 | ,b --カラム2 23 | ,c --カラム3 24 | , d --カラム4 25 | ) 26 | as materialized( --internal_comment 27 | DELETE 28 | FROM 29 | products 30 | WHERE 31 | obsoletion_date = 'today' 32 | RETURNING 33 | * 34 | ), 35 | t4( 36 | a --カラム1 37 | ,b --カラム2 38 | ,c --カラム3 39 | , d --カラム4 40 | ) -- with句 41 | as (--internal_comment 42 | INSERT 43 | INTO 44 | DISTRIBUTORS 45 | ( 46 | DID 47 | ) VALUES ( 48 | DEFAULT 49 | ) 50 | RETURNING 51 | DID 52 | ) 53 | UPDATE TABLE1 TBL1 -- テーブル1 54 | SET TBL1.COLUMN2 = 100 -- カラム2 55 | , TBL1.COLUMN3 = 100 -- カラム3 56 | WHERE TBL1.COLUMN1 = 10; 57 | 58 | 59 | with recursive t4 as not materialized (--internal_comment 60 | INSERT 61 | INTO 62 | DISTRIBUTORS 63 | ( 64 | DID 65 | ) VALUES ( 66 | DEFAULT 67 | ) 68 | RETURNING 69 | DID -- test 70 | ) --comment 71 | UPDATE TABLE1 TBL1 -- テーブル1 72 | SET TBL1.COLUMN2 = 100 -- カラム2 73 | , TBL1.COLUMN3 = 100 -- カラム3 74 | WHERE TBL1.COLUMN1 = 10; 75 | -------------------------------------------------------------------------------- /demo/for_blog.sql: -------------------------------------------------------------------------------- 1 | SELECT Identifier 2 | as 3 | id, --ID 4 | student_name -- 学生名 5 | FROM japanese_student_table 6 | AS JPN_STD --日本人学生 7 | , 8 | SUBJECT_TABLE AS 9 | SBJ --科目 10 | WHERE 11 | JPN_STD.sportId = (SELECT 12 | sportId FROM Sport WHERE 13 | Sport.sportname 14 | = 'baseball' 15 | ) -- 野球をしている生徒 16 | AND 17 | JPN_STD.ID = 18 | SBJ.ID 19 | AND SBJ.grade > 20 | /*grade*/50 --成績が50点以上 -------------------------------------------------------------------------------- /demo/for_readme.sql: -------------------------------------------------------------------------------- 1 | SElECT Identifier as id, --comment1 2 | student_name -- comment2 3 | FROM 4 | japanese_student_table AS 5 | JPN_STD -- japanese student 6 | , 7 | SUBJECT_TABLE AS 8 | SBJ --subject 9 | WHERE JPN_STD.sportId = (SELECT 10 | sportId FROM Sport WHERE 11 | Sport.sportname 12 | = 'baseball' 13 | ) -- student playing baseball 14 | AND JPN_STD.ID = 15 | SBJ.ID /*IF grade_flag*/ 16 | AND SBJ.grade > 17 | /*grade*/50 -- grade > 50 18 | /*END*/ 19 | /*IF limit_flag*/ 20 | limIt 5 21 | /*END*/ -------------------------------------------------------------------------------- /docs/options/complement_alias.md: -------------------------------------------------------------------------------- 1 | # complement_alias 2 | 3 | Complement aliases. Currently, column names are auto-completed with the same name. 4 | 5 | ## Options 6 | 7 | - `true` (default): Complements column name aliases with the same name. 8 | - `false` : Do not complement column name aliases. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | COL1 17 | FROM 18 | TAB1 19 | ``` 20 | 21 | result: 22 | 23 | ```sql 24 | SELECT 25 | COL1 AS COL1 26 | FROM 27 | TAB1 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/options/complement_column_as_keyword.md: -------------------------------------------------------------------------------- 1 | # complement_column_as_keyword 2 | 3 | Complement `AS` in column aliases. 4 | 5 | ## Options 6 | 7 | - `true` (default): Complement column alias `AS` if it is omitted. 8 | - `false` : Do not complement column alias `AS`. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | COLUMN1 COL1 17 | FROM 18 | TBL 19 | ``` 20 | 21 | after: 22 | 23 | ```sql 24 | SELECT 25 | COLUMN1 AS COL1 26 | FROM 27 | TBL 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/options/complement_outer_keyword.md: -------------------------------------------------------------------------------- 1 | # complement_outer_keyword 2 | 3 | Complement the optional OUTER. Specifically, `RIGHT OUTER JOIN`, `LEFT OUTER JOIN`, and `FULL OUTER JOIN`. 4 | 5 | ## Options 6 | 7 | - `true` (default): If an optional `OUTER` is omitted, complement it. 8 | - `false` : Do not complement `OUTER`. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | * 17 | FROM 18 | T1 19 | LEFT JOIN 20 | T2 21 | ON 22 | T1.NUM = T2.NUM 23 | ``` 24 | 25 | result: 26 | 27 | ```sql 28 | SELECT 29 | * 30 | FROM 31 | T1 32 | LEFT OUTER JOIN 33 | T2 34 | ON 35 | T1.NUM = T2.NUM 36 | ``` 37 | -------------------------------------------------------------------------------- /docs/options/complement_sql_id.md: -------------------------------------------------------------------------------- 1 | # complement_sql_id 2 | 3 | Complement [SQL ID](https://palette-doc.rtfa.as/coding-standards/forSQL/SQL%E3%82%B3%E3%83%BC%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0%E8%A6%8F%E7%B4%84%EF%BC%88uroboroSQL%EF%BC%89.html#sql-%E8%AD%98%E5%88%A5%E5%AD%90). 4 | 5 | ## Options 6 | 7 | - `true` : Complement SQL ID. 8 | - `false` (default): Do not complement SQL ID. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | COL1 17 | FROM 18 | TBL1 19 | ``` 20 | 21 | result: 22 | 23 | ```sql 24 | SELECT /* _SQL_ID_ */ 25 | COL1 26 | FROM 27 | TBL1 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/options/convert_double_colon_cast.md: -------------------------------------------------------------------------------- 1 | # convert_double_colon_cast 2 | 3 | Convert casts by `X::type` to the form `CAST(X AS type)`. 4 | 5 | ## Options 6 | 7 | - `true` (default): Convert casts by `X::type` to the form `CAST(X AS type)`. 8 | - `false` : Do not convert casts by `X::type`. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | ''::JSONB 17 | FROM 18 | TBL 19 | ``` 20 | 21 | result: 22 | 23 | ```sql 24 | SELECT 25 | CAST('' AS JSONB) 26 | FROM 27 | TBL 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/options/debug.md: -------------------------------------------------------------------------------- 1 | # debug 2 | 3 | Run in debug mode. 4 | 5 | Output the following information to standard error output. 6 | 7 | - Whether formatting was done in 2way-sql mode or normal mode. 8 | - Parsing results for tree-sitter-sql. 9 | - Unique structure generated from tree-sitter-sql parse results. 10 | - Formatting results for each SQL (only 2way-sql mode). 11 | 12 | ## Options 13 | 14 | - `true`: Debug output at runtime. 15 | - `false` (default): No debug output at runtime. 16 | -------------------------------------------------------------------------------- /docs/options/identifier_case.md: -------------------------------------------------------------------------------- 1 | # identifier_case 2 | 3 | Unify the case of identifiers. 4 | 5 | ## Options 6 | 7 | - `"upper"` (default): Unify identifiers with upper cases. 8 | - `"lower"`: Unify identifiers with lower cases. 9 | - `"preserve"`: Preserves the original case of identifiers. 10 | 11 | ## Example 12 | 13 | before: 14 | 15 | ```sql 16 | SELECT 17 | coL1 18 | FROM 19 | Department 20 | WHERE 21 | DEPT_no = 10 22 | ``` 23 | 24 | ### upper 25 | 26 | ```sql 27 | SELECT 28 | COL1 29 | FROM 30 | DEPARTMENT 31 | WHERE 32 | DEPT_NO = 10 33 | ``` 34 | 35 | ### lower 36 | 37 | ```sql 38 | SELECT 39 | col1 40 | FROM 41 | department 42 | WHERE 43 | dept_no = 10 44 | ``` 45 | 46 | ### preserve 47 | 48 | ```sql 49 | SELECT 50 | coL1 51 | FROM 52 | Department 53 | WHERE 54 | DEPT_no = 10 55 | ``` 56 | -------------------------------------------------------------------------------- /docs/options/indent_tab.md: -------------------------------------------------------------------------------- 1 | # indent_tab 2 | 3 | Switch the indentation style between tabs and spaces. 4 | 5 | ## Options 6 | 7 | - `true` (default): Indent with tabs. 8 | - `false` : Indent with spaces. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | * 17 | FROM 18 | STUDENTS 19 | ``` 20 | 21 | result: 22 | 23 | ```sql 24 | SELECT 25 | * 26 | FROM 27 | STUDENTS 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/options/keyword_case.md: -------------------------------------------------------------------------------- 1 | # keyword_case 2 | 3 | Unify the case of keywords. 4 | 5 | ## Options 6 | 7 | - `"upper"` (default): Unify keywords with upper cases. 8 | - `"lower"`: Unify keywords with lower cases. 9 | - `"preserve"`: Preserves the original case of keywords. 10 | 11 | ## Example 12 | 13 | before: 14 | 15 | ```sql 16 | Select 17 | * 18 | FroM 19 | DEPARTMENT 20 | wheRE 21 | DEPT_NO = 10 22 | ``` 23 | 24 | ### upper 25 | 26 | ```sql 27 | SELECT 28 | * 29 | FROM 30 | DEPARTMENT 31 | WHERE 32 | DEPT_NO = 10 33 | ``` 34 | 35 | ### lower 36 | 37 | ```sql 38 | select 39 | * 40 | from 41 | DEPARTMENT 42 | where 43 | DEPT_NO = 10 44 | ``` 45 | 46 | ### preserve 47 | 48 | ```sql 49 | Select 50 | * 51 | FroM 52 | DEPARTMENT 53 | wheRE 54 | DEPT_NO = 10 55 | ``` 56 | -------------------------------------------------------------------------------- /docs/options/max_char_per_line.md: -------------------------------------------------------------------------------- 1 | # max_char_per_line 2 | 3 | If the total number of characters in the function name and arguments exceeds max_char_per_line, the arguments are formatted with new lines. 4 | 5 | Default value is 50. 6 | 7 | ## Example 8 | 9 | before: 10 | 11 | ```sql 12 | SELECT 13 | NORMAL_FUNC(COL1 + COL2, PARAM2) 14 | , LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC(PARAM1, PARAM2, PARAM3) 15 | ``` 16 | 17 | ### max_char_per_line = 100 18 | 19 | ```sql 20 | SELECT 21 | NORMAL_FUNC(COL1 + COL2, PARAM2) 22 | , LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC(PARAM1, PARAM2, PARAM3) 23 | ``` 24 | 25 | ### max_char_per_line = 50 26 | 27 | ```sql 28 | SELECT 29 | NORMAL_FUNC(COL1 + COL2, PARAM2) 30 | , LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC( 31 | PARAM1 32 | , PARAM2 33 | , PARAM3 34 | ) 35 | ``` 36 | 37 | ### max_char_per_line = 10 38 | 39 | ```sql 40 | SELECT 41 | NORMAL_FUNC( 42 | COL1 + COL2 43 | , PARAM2 44 | ) 45 | , LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG_FUNC( 46 | PARAM1 47 | , PARAM2 48 | , PARAM3 49 | ) 50 | ``` 51 | -------------------------------------------------------------------------------- /docs/options/remove_redundant_nest.md: -------------------------------------------------------------------------------- 1 | # OptionName 2 | 3 | Remove redundant parentheses. 4 | 5 | ## Options 6 | 7 | - `true` (default): Remove redundant parentheses. 8 | - `false` : Preserve redundant parentheses. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | A 17 | FROM 18 | B 19 | WHERE 20 | (((1 = 1))) 21 | AND ( 22 | ((A = B)) 23 | OR (A) = (((42))) 24 | ) 25 | ``` 26 | 27 | result: 28 | 29 | ```sql 30 | SELECT 31 | A 32 | FROM 33 | B 34 | WHERE 35 | (1 = 1) 36 | AND ( 37 | (A = B) 38 | OR (A) = (42) 39 | ) 40 | ``` 41 | -------------------------------------------------------------------------------- /docs/options/remove_table_as_keyword.md: -------------------------------------------------------------------------------- 1 | # remove_table_as_keyword 2 | 3 | Remove `AS` in table aliases. 4 | 5 | ## Options 6 | 7 | - `true` (default): Remove table aliases `AS` if present. 8 | - `false` : Do not remove table alias `AS`. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | COL1 17 | FROM 18 | TABLE1 AS TBL1 19 | ``` 20 | 21 | result: 22 | 23 | ```sql 24 | SELECT 25 | COL1 26 | FROM 27 | TABLE1 TBL1 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/options/tab_size.md: -------------------------------------------------------------------------------- 1 | # tab_size 2 | 3 | Tab size used for formatting. 4 | 5 | All indentation is done by tabs. 6 | By setting the appropriate tab size for your environment, you can align operators, etc. 7 | 8 | The default tab size is 4. 9 | -------------------------------------------------------------------------------- /docs/options/trim_bind_param.md: -------------------------------------------------------------------------------- 1 | # trim_bind_param 2 | 3 | Trim the contents of the [bind parameters](https://future-architect.github.io/uroborosql-doc/background/#%E3%83%8F%E3%82%99%E3%82%A4%E3%83%B3%E3%83%88%E3%82%99%E3%83%8F%E3%82%9A%E3%83%A9%E3%83%A1%E3%83%BC%E3%82%BF). 4 | 5 | ## Options 6 | 7 | - `true` : Trim blanks before and after bind parameters. 8 | - `false` (default): Do not trim blanks before and after bind parameters. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | * 17 | FROM 18 | DEPARTMENT 19 | WHERE 20 | DEPT_NO = /* dept_no */10 21 | ``` 22 | 23 | result: 24 | 25 | ```sql 26 | SELECT 27 | * 28 | FROM 29 | DEPARTMENT 30 | WHERE 31 | DEPT_NO = /*dept_no*/10 32 | ``` 33 | -------------------------------------------------------------------------------- /docs/options/unify_not_equal.md: -------------------------------------------------------------------------------- 1 | # unify_not_equal 2 | 3 | Convert comparison operator `<>` to `!=`. 4 | 5 | ## Options 6 | 7 | - `true` (default): Convert `<>` to `!=`. 8 | - `false` : Do not convert `<>` to `!=`. 9 | 10 | ## Example 11 | 12 | before: 13 | 14 | ```sql 15 | SELECT 16 | * 17 | FROM 18 | STUDENTS 19 | WHERE 20 | STUDENT_ID <> 2 21 | ``` 22 | 23 | result: 24 | 25 | ```sql 26 | SELECT 27 | * 28 | FROM 29 | STUDENTS 30 | WHERE 31 | STUDENT_ID != 2 32 | ``` 33 | -------------------------------------------------------------------------------- /docs/structure/how_to_format_2way_sql.md: -------------------------------------------------------------------------------- 1 | # How to format 2way-sql 2 | 3 | ![2way-sql_example](../../images/2way_sql.png) 4 | 5 | If the input SQL contains an IF branch, it is judged to be 2-way-sql and formatted in the following flow. 6 | 7 | 1. Generate multiple SQLs that can occur, taking into account all branches of the input SQL. 8 | 2. Format all SQL. 9 | 3. Merge all formatting results and output 10 | -------------------------------------------------------------------------------- /docs/structure/overview_of_the_process_flow.md: -------------------------------------------------------------------------------- 1 | # Overview of the process flow 2 | 3 | 4 | 5 | 1. Parse input SQL with tree-sitter-sql [tree-sitter-sql](https://github.com/future-architect/tree-sitter-sql) to get CST. 6 | 2. Parsing CSTs and converting them into their original tree structure. 7 | 3. Formatting and output using original tree structure. 8 | -------------------------------------------------------------------------------- /examples/as.sql: -------------------------------------------------------------------------------- 1 | 2 | --test 3 | /* test */ 4 | select 5 | --test 6 | a, --test 7 | b --test 8 | /* multi */ 9 | --test 10 | from tab1 /*ttesttestesttesetetssss */ 11 | AS t1 --test 12 | , tab2 AS t2, tabtabtabtabtab AS long --test 13 | where --test 14 | 1 = 2 + 1 --test 15 | AND ttesttestesttesetetssss = t1 --test tests 16 | --test 17 | -------------------------------------------------------------------------------- /examples/multi_content_lhs.sql: -------------------------------------------------------------------------------- 1 | select a, b 2 | from tab1 /* this table is table 1 */ as t1, tabtabtabtab as l 3 | where t.a + l.a = 2 4 | and t.solonglong = 42 5 | and t.n = 5 6 | and t.x + t.y + t.z + t.w = 57 7 | -------------------------------------------------------------------------------- /examples/or.sql: -------------------------------------------------------------------------------- 1 | select a 2 | from tab1 3 | where l.a = 2 4 | or t.solonglong = 42 5 | or t.a = 433 6 | and aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 2 7 | and test = 1 8 | or test = 2 9 | and test = 3 10 | or test = 2 -------------------------------------------------------------------------------- /examples/simple.sql: -------------------------------------------------------------------------------- 1 | select a, b 2 | from tab1, tab2 3 | where tab1.num = 1 4 | -------------------------------------------------------------------------------- /examples/target.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Identifier as id, --ID 3 | student_name -- 学生名 4 | FROM 5 | japanese_student_table 6 | AS JPN_STD --日本人学生 7 | , SUBJECT_TABLE AS SBJ --科目 8 | WHERE 9 | JPN_STD.sportId = (SELECT 10 | sportId FROM 11 | Sport 12 | WHERE 13 | Sport.sportname 14 | = 'baseball' 15 | ) -- 野球をしている生徒 16 | AND 17 | JPN_STD.ID = SBJ.ID 18 | AND SBJ.grade > 19 | /*grade*/50 --成績が50点以上 -------------------------------------------------------------------------------- /examples/test.sql: -------------------------------------------------------------------------------- 1 | SELECT A 2 | 3 | from tb 4 | WHERE 5 | 1=22222222222222 6 | OR 7 | (test = test and 8 | test = test and test = test --comment 9 | ) --test -------------------------------------------------------------------------------- /images/2way_sql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/future-architect/uroborosql-fmt/5231a6cd5811152c3b75bb13e879f3ed41f04924/images/2way_sql.png -------------------------------------------------------------------------------- /images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/future-architect/uroborosql-fmt/5231a6cd5811152c3b75bb13e879f3ed41f04924/images/demo.gif -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/future-architect/uroborosql-fmt/5231a6cd5811152c3b75bb13e879f3ed41f04924/images/logo.png -------------------------------------------------------------------------------- /images/process_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/future-architect/uroborosql-fmt/5231a6cd5811152c3b75bb13e879f3ed41f04924/images/process_flow.png -------------------------------------------------------------------------------- /images/wasm_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/future-architect/uroborosql-fmt/5231a6cd5811152c3b75bb13e879f3ed41f04924/images/wasm_demo.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uroborosql-fmt", 3 | "version": "1.0.0", 4 | "description": "To make it easy for you to get started with GitLab, here's a list of recommended next steps.", 5 | "devDependencies": { 6 | "http-server": "^14.1.1" 7 | }, 8 | "scripts": { 9 | "serve": "http-server -o ./wasm/index.html", 10 | "build-wasm": "bash build.sh" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /wasm/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: small; 3 | } 4 | 5 | code { 6 | font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace; 7 | } 8 | 9 | /* options */ 10 | #tab_size { 11 | width: 68px; 12 | } 13 | 14 | /* editor */ 15 | .editor_parent { 16 | display: flex; 17 | } 18 | 19 | .editor { 20 | height: 360px; 21 | width: 50%; 22 | border: 1px solid gray; 23 | } 24 | 25 | /* button */ 26 | .button_parent_center { 27 | display: flex; 28 | align-items: center; 29 | } 30 | 31 | .button_parent { 32 | display: flex; 33 | } 34 | 35 | .button { 36 | height: 40px; 37 | width: 100px; 38 | font-size: 20px; 39 | } 40 | 41 | .small_button { 42 | font-size: small; 43 | text-align: center; 44 | } 45 | 46 | .format_btn { 47 | margin-left: auto; 48 | } 49 | 50 | .copy_btn { 51 | margin-right: auto; 52 | } 53 | 54 | .option:hover .option_balloon { 55 | display: inline; 56 | } 57 | 58 | .option_balloon { 59 | display: none; 60 | position: absolute; 61 | left: 450px; 62 | padding: 16px; 63 | border-radius: 5px; 64 | background-color: gray; 65 | color: white; 66 | z-index: 10; 67 | } 68 | 69 | .format_btn:hover .format_balloon { 70 | display: inline; 71 | } 72 | 73 | .format_balloon { 74 | position: absolute; 75 | display: none; 76 | background-color: gray; 77 | color: white; 78 | } 79 | --------------------------------------------------------------------------------