diff --git a/README.md b/README.md index c01769f..8949ffb 100644 --- a/README.md +++ b/README.md @@ -58,14 +58,14 @@ More: [the generated code for every driver](docs/Examples.md) (it is the plugin' | Option | Default | What it does | |---|---|---| | `driver` | required | `pg`, `mysql2` or `sqlite3`. Must match the sqlc `engine:`. | -| `rubyVersion` | `3.3` | Oldest Ruby the code must run on, `3.1` – `4.0`. Rows are `Data` classes from 3.2 and `Struct`s below. | +| `rubyVersion` | `3.3` | Oldest Ruby the code must run on, `3.1` – `4.0`. Rows are `Data` classes from 3.2 and `Struct`s below; `3` means any 3.x, so it gets `Struct`s. | | `generateTypes` | `true` | Also generate `.rbs` type signatures. | | `generateGemfile` | `false` | Also generate a `Gemfile` with the gems the code needs. | | `moduleName` | `Codegen` | The module the code lives in, e.g. `MyApp::Db`. | | `overrides` | none | Change the type of columns / parameters, see [below](#overrides). | | `rename` | none | Rename tables (model class) and columns (attribute), e.g. `{authors: Writer, bio: biography}`; `schema.table` works too. | | `exactTableNames` | `false` | Keep table names as model names (`authors` → `Authors`) instead of singularizing them (`Author`). | -| `preparedStatements` | `true` | `pg` only (an error with other drivers). `false` sends the SQL with every call instead of preparing it (needed behind pgbouncer in transaction mode). Statements dropped by `DEALLOCATE ALL` / `DISCARD ALL` are prepared again by their next call outside a transaction (inside one, that call raises and the transaction rolls back). | +| `preparedStatements` | `true` | `pg` only (an error with other drivers). `false` sends the SQL with every call instead of preparing it (needed behind pgbouncer in transaction mode). Statements dropped by `DEALLOCATE ALL` / `DISCARD ALL` are prepared again by their next call outside a transaction (inside one, that call raises and the transaction rolls back). Statements are named `Module::Class#method` (with a hash when longer than PostgreSQL's 63 bytes), so classes sharing a pool never run each other's SQL. | Unknown or misspelled options are errors, with a hint for near misses (`generate_types` → `generateTypes`). Options shared by several `sql:` blocks can go in the top-level `options:` of `sqlc.yaml` under the plugin's name @@ -87,7 +87,8 @@ The first match wins in this order: `:`, `.`, `*:< Overrides only change the RBS types; the values are whatever the driver returns. Unknown keys are errors. ## The generated code -For each query file you get `query_sql.rb` with a `QuerySql` class (one method per query), plus `models.rb` (one class +For each query file you get `query_sql.rb` with a `QuerySql` class (one method per query; the file name in CamelCase: +`admin_users.sql` → `AdminUsersSql` in `admin_users_sql.rb`), plus `models.rb` (one class per table, one module of constants per enum), `connection.rb` (shared helpers) and the matching `.rbs` files. * **Arguments** are keywords named after the parameters (`get_author(id:)`); `sqlc.arg(name)` names them yourself. @@ -151,7 +152,7 @@ end | `:one` | the row or `nil` | plus a bang finder (`get_author!`) | | `:many` | `Array` of rows | | | `:exec` | `nil` | | -| `:execrows` | number of affected rows | | +| `:execrows` | number of affected rows | MySQL: rows changed, not rows matched; connect with `flags: Mysql2::Client::FOUND_ROWS` to count matched rows | | `:execlastid` | the new id | PostgreSQL / SQLite: needs `RETURNING id`; MySQL: the auto-increment id | | `:execresult` | `ExecResult` (`rows_affected`, `last_insert_id`) | `last_insert_id` is `nil` on PostgreSQL (use `RETURNING`) | | `:batchexec` / `:batchone` / `:batchmany` | `nil` / `Array` of rows or `nil` / `Array` of `Array`s of rows | take an `Array` of `Args` and run the query once per element, on one connection | @@ -184,6 +185,8 @@ server; duplicate keys and invalid values raise `Mysql2::Error` instead of being (`uuid[]`, enum arrays, ...) are `Array[String]`, also for types created after the connection was opened (a migration run while the application is up). Geometric, range, full-text, `hstore`, `ltree`, `timetz`, `reg*` and composite types are `String`s; domains and unknown types are `untyped`. +* A `String` passed to a PostgreSQL `json` / `jsonb` parameter is JSON text (`'{"a":1}'`): pass `'"hi"'` or + `'hi'.to_json` for a JSON string. Hashes, Arrays, numbers, `true` / `false` and `nil` are encoded for you. * Enums are `String`s, with constants in `models.rb` (`ExtendedBioType::MEMOIR`, `ExtendedBioType::ALL`). Values that are not valid constant names still get one: `'end'` → `END_`, `'all'` → `ALL_`, `'2x'` → `VALUE_2X`, `'a b'` → `A_B`; values that end up with the same name get `_2`, `_3`, ... @@ -194,7 +197,7 @@ server; duplicate keys and invalid values raise `Mysql2::Error` instead of being ### Names * Query methods and keyword arguments are snake_cased, with acronyms kept together (`MIN_ID` → `min_id`, `HTTPServer` → `http_server`); Ruby keywords get a trailing `_` (`end_:`). Row members use the column spelling - reported by sqlc for the engine, except names that conflict with generated row methods (`class_`, `hash_`): + reported by sqlc for the engine, except names that conflict with row methods, including the private ones `Data` / `Struct` call while building and copying rows (`class_`, `hash_`, `initialize_`): PostgreSQL and SQLite keep `"camelCase"` as `:camelCase`, while MySQL reports it as `:camelcase`. A column named `end` is the row member `:end` but the argument `end_:`. * A parameter used twice is one keyword when named with `sqlc.arg`; repeated `?` / `$n` of one column become `id:`, `id_2:`. @@ -210,6 +213,8 @@ server; duplicate keys and invalid values raise `Mysql2::Error` instead of being * SQLite: sqlc does not see parameters in `ON CONFLICT ... DO UPDATE SET` (it leaves `sqlc.arg(...)` in the SQL or reports fewer parameters than there are `?`), so such queries are generation errors. Use `excluded.` (`DO UPDATE SET n = counters.n + excluded.n`) or move the value into `VALUES`. +* SQLite: `busy_timeout=` makes the sqlite3 gem wait for a locked database while holding Ruby's GVL, so other threads + and fibers stop too; `busy_handler_timeout=` waits without blocking them. * SQLite transactions belong to the thread that opened them; fibers sharing the same database take turns, and a transaction holds it until it ends. Only the yielded `tx` runs inside the transaction from other fibers / threads. * Not applicable to Ruby (they exist in the C# plugin): `withAsyncSuffix` / `withCancellationToken` (use the Fiber diff --git a/docs/Coverage.md b/docs/Coverage.md index 653bcd9..3b2c0ea 100644 --- a/docs/Coverage.md +++ b/docs/Coverage.md @@ -5,11 +5,11 @@ only when the behavior is rejected or decided during generation and generated co | README claim / feature | PostgreSQL | MySQL | SQLite | Unit-only checks | |---|---|---|---|---| -| Options: driver, Ruby target, types, Gemfile, module name, renames, exact names, overrides and global/local merge | [`test_generator_options_preserve_runtime_values_and_generate_expected_layouts`](../tests/end2end_options.rb#test_generator_options_preserve_runtime_values_and_generate_expected_layouts) | unit: MySQL-specific `preparedStatements` is rejected | [`test_generator_options_preserve_runtime_values_and_generate_expected_layouts`](../tests/end2end_options.rb#test_generator_options_preserve_runtime_values_and_generate_expected_layouts) | [`test_unknown_options_are_rejected_with_a_hint`](../test/options_test.rb#test_unknown_options_are_rejected_with_a_hint), [`test_override_forms`](../test/options_test.rb#test_override_forms) | +| Options: driver, Ruby target, types, Gemfile, module name, renames, exact names, overrides and global/local merge; CamelCase query file classes (`admin_users.sql` → `AdminUsersSql`); distinct prepared statements for modules sharing a pool (also names over 63 bytes) | [`test_generator_options_preserve_runtime_values_and_generate_expected_layouts`](../tests/end2end_options.rb#test_generator_options_preserve_runtime_values_and_generate_expected_layouts) | unit: MySQL-specific `preparedStatements` is rejected | [`test_generator_options_preserve_runtime_values_and_generate_expected_layouts`](../tests/end2end_options.rb#test_generator_options_preserve_runtime_values_and_generate_expected_layouts) | [`test_unknown_options_are_rejected_with_a_hint`](../test/options_test.rb#test_unknown_options_are_rejected_with_a_hint), [`test_override_forms`](../test/options_test.rb#test_override_forms), [`test_immutable_data_support`](../test/options_test.rb#test_immutable_data_support), [`test_query_file_names_become_camel_case_classes`](../test/features_test.rb#test_query_file_names_become_camel_case_classes), [`test_statement_names_of_different_classes_never_collide`](../test/features_test.rb#test_statement_names_of_different_classes_never_collide) | | `preparedStatements` disabled and configured `moduleName` | [`test_flow`](../tests/end2end_pg.rb#test_flow) (Ruby 4.0 variant) | [`test_flow`](../tests/end2end_mysql2.rb#test_flow) (Ruby 4.0 variant) | [`test_flow`](../tests/end2end_sqlite3.rb#test_flow) (Ruby 4.0 variant) | [`test_pg_can_skip_prepared_statements`](../test/features_test.rb#test_pg_can_skip_prepared_statements) | | Generated query/model/connection files and generated `.rbs`; runtime return/attribute checks | [`test_models_are_generated_for_every_table`](../tests/end2end_pg.rb#test_models_are_generated_for_every_table), [`test_declared_types_match_runtime_values`](../tests/end2end_pg.rb#test_declared_types_match_runtime_values) | [`test_models_are_generated_for_every_table`](../tests/end2end_mysql2.rb#test_models_are_generated_for_every_table), [`test_declared_types_match_runtime_values`](../tests/end2end_mysql2.rb#test_declared_types_match_runtime_values) | [`test_models_are_generated_for_every_table`](../tests/end2end_sqlite3.rb#test_models_are_generated_for_every_table), [`test_declared_types_match_runtime_values`](../tests/end2end_sqlite3.rb#test_declared_types_match_runtime_values) | [`test_unknown_types_in_queries_fall_back_to_untyped`](../test/features_test.rb#test_unknown_types_in_queries_fall_back_to_untyped), [`test_models_fall_back_to_untyped_for_unknown_types`](../test/features_test.rb#test_models_fall_back_to_untyped_for_unknown_types) | | `:one`, `:many`, `:exec`, nil for no row, bang finder methods and `NotFound` error | [`test_flow`](../tests/end2end_pg.rb#test_flow), [`test_one_on_empty_table_returns_nil`](../tests/end2end_pg.rb#test_one_on_empty_table_returns_nil), [`test_every_one_query_has_a_bang_method`](../tests/end2end_pg.rb#test_every_one_query_has_a_bang_method), [`test_bang_finder_raises_not_found`](../tests/end2end_pg.rb#test_bang_finder_raises_not_found) | [`test_flow`](../tests/end2end_mysql2.rb#test_flow), [`test_one_on_empty_table_returns_nil`](../tests/end2end_mysql2.rb#test_one_on_empty_table_returns_nil), [`test_every_one_query_has_a_bang_method`](../tests/end2end_mysql2.rb#test_every_one_query_has_a_bang_method), [`test_bang_finder_raises_not_found`](../tests/end2end_mysql2.rb#test_bang_finder_raises_not_found) | [`test_flow`](../tests/end2end_sqlite3.rb#test_flow), [`test_every_one_query_has_a_bang_method`](../tests/end2end_sqlite3.rb#test_every_one_query_has_a_bang_method), [`test_bang_finder_raises_not_found`](../tests/end2end_sqlite3.rb#test_bang_finder_raises_not_found) | [`test_command_signatures`](../test/features_test.rb#test_command_signatures) | -| `:execrows`, `:execlastid`, `:execresult` semantics | [`test_execrows_returns_affected_row_count`](../tests/end2end_pg.rb#test_execrows_returns_affected_row_count), [`test_execlastid_returns_the_returning_column`](../tests/end2end_pg.rb#test_execlastid_returns_the_returning_column), [`test_execresult_returns_rows_affected`](../tests/end2end_pg.rb#test_execresult_returns_rows_affected) | [`test_execrows_returns_affected_row_count`](../tests/end2end_mysql2.rb#test_execrows_returns_affected_row_count), [`test_execlastid_returns_the_new_id`](../tests/end2end_mysql2.rb#test_execlastid_returns_the_new_id), [`test_execresult_returns_rows_affected_and_last_id`](../tests/end2end_mysql2.rb#test_execresult_returns_rows_affected_and_last_id) | [`test_execrows_returns_affected_row_count`](../tests/end2end_sqlite3.rb#test_execrows_returns_affected_row_count), [`test_execlastid_returns_the_returning_column`](../tests/end2end_sqlite3.rb#test_execlastid_returns_the_returning_column), [`test_execresult_returns_rows_affected_and_last_id`](../tests/end2end_sqlite3.rb#test_execresult_returns_rows_affected_and_last_id) | [`test_pg_and_sqlite_execlastid_need_returning`](../test/features_test.rb#test_pg_and_sqlite_execlastid_need_returning) | +| `:execrows`, `:execlastid`, `:execresult` semantics | [`test_execrows_returns_affected_row_count`](../tests/end2end_pg.rb#test_execrows_returns_affected_row_count), [`test_execlastid_returns_the_returning_column`](../tests/end2end_pg.rb#test_execlastid_returns_the_returning_column), [`test_execresult_returns_rows_affected`](../tests/end2end_pg.rb#test_execresult_returns_rows_affected) | [`test_execrows_returns_affected_row_count`](../tests/end2end_mysql2.rb#test_execrows_returns_affected_row_count), [`test_execrows_counts_changed_rows_unless_found_rows_is_set`](../tests/end2end_mysql2.rb#test_execrows_counts_changed_rows_unless_found_rows_is_set), [`test_execlastid_returns_the_new_id`](../tests/end2end_mysql2.rb#test_execlastid_returns_the_new_id), [`test_execresult_returns_rows_affected_and_last_id`](../tests/end2end_mysql2.rb#test_execresult_returns_rows_affected_and_last_id) | [`test_execrows_returns_affected_row_count`](../tests/end2end_sqlite3.rb#test_execrows_returns_affected_row_count), [`test_execlastid_returns_the_returning_column`](../tests/end2end_sqlite3.rb#test_execlastid_returns_the_returning_column), [`test_execresult_returns_rows_affected_and_last_id`](../tests/end2end_sqlite3.rb#test_execresult_returns_rows_affected_and_last_id) | [`test_pg_and_sqlite_execlastid_need_returning`](../test/features_test.rb#test_pg_and_sqlite_execlastid_need_returning) | | `:batchexec`, `:batchone`, `:batchmany`; batches use one connection and are not atomic unless wrapped in a transaction | [`test_batch_commands_run_once_per_args`](../tests/end2end_pg.rb#test_batch_commands_run_once_per_args), [`test_batches_are_not_atomic_without_a_transaction`](../tests/end2end_pg.rb#test_batches_are_not_atomic_without_a_transaction) | [`test_batch_commands_run_once_per_args`](../tests/end2end_mysql2.rb#test_batch_commands_run_once_per_args), [`test_batches_are_not_atomic_without_a_transaction`](../tests/end2end_mysql2.rb#test_batches_are_not_atomic_without_a_transaction) | [`test_batch_commands_run_once_per_args`](../tests/end2end_sqlite3.rb#test_batch_commands_run_once_per_args), [`test_batches_are_not_atomic_without_a_transaction`](../tests/end2end_sqlite3.rb#test_batches_are_not_atomic_without_a_transaction) | [`test_batch_commands_take_an_array_of_args`](../test/features_test.rb#test_batch_commands_take_an_array_of_args) | | `:copyfrom` round trips, all-or-none behavior and conflict clauses | [`test_copyfrom_many_rows_and_none`](../tests/end2end_pg.rb#test_copyfrom_many_rows_and_none), [`test_seeded_random_copyfrom_round_trip_and_duplicate_is_atomic`](../tests/end2end_pg.rb#test_seeded_random_copyfrom_round_trip_and_duplicate_is_atomic) | [`test_copyfrom_loads_binary_values`](../tests/end2end_mysql2.rb#test_copyfrom_loads_binary_values), [`test_seeded_random_copyfrom_round_trip_and_duplicate_is_atomic`](../tests/end2end_mysql2.rb#test_seeded_random_copyfrom_round_trip_and_duplicate_is_atomic) | [`test_copyfrom_is_all_or_nothing`](../tests/end2end_sqlite3.rb#test_copyfrom_is_all_or_nothing), [`test_copyfrom_keeps_conflict_clauses`](../tests/end2end_sqlite3.rb#test_copyfrom_keeps_conflict_clauses) | [`test_copyfrom_keeps_or_rejects_conflict_clauses`](../test/features_test.rb#test_copyfrom_keeps_or_rejects_conflict_clauses) | | `sqlc.arg`, `sqlc.narg`, positional/named keyword args, optional nils and argument errors | [`test_named_nullable_arguments_are_optional`](../tests/end2end_pg.rb#test_named_nullable_arguments_are_optional), [`test_required_argument_after_optional_named_argument`](../tests/end2end_pg.rb#test_required_argument_after_optional_named_argument), [`test_missing_keyword_arguments_are_errors`](../tests/end2end_pg.rb#test_missing_keyword_arguments_are_errors) | [`test_nullable_named_arg`](../tests/end2end_mysql2.rb#test_nullable_named_arg), [`test_required_argument_after_optional_named_argument`](../tests/end2end_mysql2.rb#test_required_argument_after_optional_named_argument), [`test_missing_keyword_arguments_are_errors`](../tests/end2end_mysql2.rb#test_missing_keyword_arguments_are_errors) | [`test_nullable_named_arg`](../tests/end2end_sqlite3.rb#test_nullable_named_arg), [`test_required_argument_after_optional_named_argument`](../tests/end2end_sqlite3.rb#test_required_argument_after_optional_named_argument), [`test_missing_keyword_arguments_are_errors`](../tests/end2end_sqlite3.rb#test_missing_keyword_arguments_are_errors) | [`test_named_nullable_parameters_are_optional_keywords`](../test/features_test.rb#test_named_nullable_parameters_are_optional_keywords) | @@ -20,7 +20,8 @@ only when the behavior is rejected or decided during generation and generated co | PostgreSQL arrays, JSON/JSONB, type round trips and RBS | [`test_array_parameters`](../tests/end2end_pg.rb#test_array_parameters), [`test_remaining_postgresql_types_round_trip`](../tests/end2end_pg.rb#test_remaining_postgresql_types_round_trip), [`test_json_and_jsonb_parameters_round_trip_all_json_value_types`](../tests/end2end_pg.rb#test_json_and_jsonb_parameters_round_trip_all_json_value_types) | not PostgreSQL types | not PostgreSQL types | [`test_multi_dimensional_arrays`](../test/features_test.rb#test_multi_dimensional_arrays), [`test_more_postgres_types_composites_and_domains`](../test/features_test.rb#test_more_postgres_types_composites_and_domains) | | MySQL unsigned integers, BIT, YEAR, DATETIME/TIME, JSON, enums/SET and client quoting | not MySQL | [`test_client_side_quoting_round_trips_supported_values`](../tests/end2end_mysql2.rb#test_client_side_quoting_round_trips_supported_values), [`test_time_values_match_mysql2_prepared_statement_storage`](../tests/end2end_mysql2.rb#test_time_values_match_mysql2_prepared_statement_storage), [`test_declared_types_match_runtime_values`](../tests/end2end_mysql2.rb#test_declared_types_match_runtime_values) | not MySQL | [`test_mysql_uses_client_side_binding_and_sqlite_closes_prepared_statements`](../test/features_test.rb#test_mysql_uses_client_side_binding_and_sqlite_closes_prepared_statements) | | SQLite affinity, JSON/UUID, and NUMERIC integer/float results | not SQLite | not SQLite | [`test_declared_types_match_runtime_values`](../tests/end2end_sqlite3.rb#test_declared_types_match_runtime_values), [`test_declared_types_with_parameters`](../tests/end2end_sqlite3.rb#test_declared_types_with_parameters) | [`test_sqlite_declared_types_follow_type_affinity`](../test/features_test.rb#test_sqlite_declared_types_follow_type_affinity), [`test_sqlite_json_and_uuid_declarations_are_strings`](../test/features_test.rb#test_sqlite_json_and_uuid_declarations_are_strings) | -| Names: keywords, method collisions, acronyms, quoted mixed case, repeated `$n`, plural models | [`test_keyword_and_method_names_keep_distinct_row_and_argument_names`](../tests/end2end_pg.rb#test_keyword_and_method_names_keep_distinct_row_and_argument_names), [`test_repeated_column_parameters_get_distinct_names`](../tests/end2end_pg.rb#test_repeated_column_parameters_get_distinct_names) | [`test_keyword_and_method_names_keep_distinct_row_and_argument_names`](../tests/end2end_mysql2.rb#test_keyword_and_method_names_keep_distinct_row_and_argument_names), [`test_repeated_positional_parameters_get_distinct_names`](../tests/end2end_mysql2.rb#test_repeated_positional_parameters_get_distinct_names) | [`test_keyword_and_method_names_keep_distinct_row_and_argument_names`](../tests/end2end_sqlite3.rb#test_keyword_and_method_names_keep_distinct_row_and_argument_names) | [`test_snake_case_keeps_acronyms_together`](../test/features_test.rb#test_snake_case_keeps_acronyms_together), [`test_query_names_cannot_replace_generated_methods`](../test/features_test.rb#test_query_names_cannot_replace_generated_methods), [`test_tables_with_the_same_singular_get_distinct_models`](../test/features_test.rb#test_tables_with_the_same_singular_get_distinct_models) | +| SQLite `busy_handler_timeout=` waits for another connection without blocking other threads | not SQLite | not SQLite | [`test_busy_handler_timeout_waits_for_another_connection_without_blocking_threads`](../tests/end2end_sqlite3.rb#test_busy_handler_timeout_waits_for_another_connection_without_blocking_threads) | | +| Names: keywords, method collisions (also private row hooks such as `initialize`), acronyms, quoted mixed case, repeated `$n`, plural models | [`test_keyword_and_method_names_keep_distinct_row_and_argument_names`](../tests/end2end_pg.rb#test_keyword_and_method_names_keep_distinct_row_and_argument_names), [`test_repeated_column_parameters_get_distinct_names`](../tests/end2end_pg.rb#test_repeated_column_parameters_get_distinct_names) | [`test_keyword_and_method_names_keep_distinct_row_and_argument_names`](../tests/end2end_mysql2.rb#test_keyword_and_method_names_keep_distinct_row_and_argument_names), [`test_repeated_positional_parameters_get_distinct_names`](../tests/end2end_mysql2.rb#test_repeated_positional_parameters_get_distinct_names) | [`test_keyword_and_method_names_keep_distinct_row_and_argument_names`](../tests/end2end_sqlite3.rb#test_keyword_and_method_names_keep_distinct_row_and_argument_names) | [`test_snake_case_keeps_acronyms_together`](../test/features_test.rb#test_snake_case_keeps_acronyms_together), [`test_query_names_cannot_replace_generated_methods`](../test/features_test.rb#test_query_names_cannot_replace_generated_methods), [`test_tables_with_the_same_singular_get_distinct_models`](../test/features_test.rb#test_tables_with_the_same_singular_get_distinct_models), [`test_columns_named_like_row_methods_still_build_and_read_rows`](../test/features_test.rb#test_columns_named_like_row_methods_still_build_and_read_rows) | | Connections, injected pools, reconnect behavior and SQLite serialization | [`test_queries_can_share_an_injected_pool`](../tests/end2end_pg.rb#test_queries_can_share_an_injected_pool), [`test_a_connection_closed_by_the_server_is_reconnected`](../tests/end2end_pg.rb#test_a_connection_closed_by_the_server_is_reconnected), [`test_connection_lost_inside_transaction_is_not_reconnected_until_the_transaction_ends`](../tests/end2end_pg.rb#test_connection_lost_inside_transaction_is_not_reconnected_until_the_transaction_ends) | [`test_queries_can_share_an_injected_pool`](../tests/end2end_mysql2.rb#test_queries_can_share_an_injected_pool), [`test_a_connection_closed_by_the_server_is_replaced`](../tests/end2end_mysql2.rb#test_a_connection_closed_by_the_server_is_replaced), [`test_a_stopped_async_task_does_not_leave_a_closed_connection_in_the_pool`](../tests/end2end_mysql2.rb#test_a_stopped_async_task_does_not_leave_a_closed_connection_in_the_pool) | [`test_fibers_sharing_a_database_take_turns`](../tests/end2end_sqlite3.rb#test_fibers_sharing_a_database_take_turns), [`test_threads_sharing_a_database_take_turns_in_transactions`](../tests/end2end_sqlite3.rb#test_threads_sharing_a_database_take_turns_in_transactions), [`test_a_database_returning_hash_rows_still_builds_rows`](../tests/end2end_sqlite3.rb#test_a_database_returning_hash_rows_still_builds_rows) | [`test_engine_must_match_the_driver`](../test/features_test.rb#test_engine_must_match_the_driver) | | Transaction result, commit/rollback, nested savepoint, exit semantics and rescued PostgreSQL error | [`test_nested_savepoint_rolls_back_while_outer_transaction_commits`](../tests/end2end_pg.rb#test_nested_savepoint_rolls_back_while_outer_transaction_commits), [`test_transaction_nonlocal_exit_semantics_follow_timeout_version`](../tests/end2end_pg.rb#test_transaction_nonlocal_exit_semantics_follow_timeout_version), [`test_transaction_whose_failed_statement_was_rescued_raises_instead_of_committing`](../tests/end2end_pg.rb#test_transaction_whose_failed_statement_was_rescued_raises_instead_of_committing) | [`test_nested_savepoint_rolls_back_while_outer_transaction_commits`](../tests/end2end_mysql2.rb#test_nested_savepoint_rolls_back_while_outer_transaction_commits), [`test_transaction_nonlocal_exit_semantics_follow_timeout_version`](../tests/end2end_mysql2.rb#test_transaction_nonlocal_exit_semantics_follow_timeout_version) | [`test_nested_transaction_rolls_back_to_a_savepoint`](../tests/end2end_sqlite3.rb#test_nested_transaction_rolls_back_to_a_savepoint), [`test_transaction_nonlocal_exit_semantics_follow_timeout_version`](../tests/end2end_sqlite3.rb#test_transaction_nonlocal_exit_semantics_follow_timeout_version) | [`test_nested_transactions_reject_isolation_and_mode`](../test/features_test.rb#test_nested_transactions_reject_isolation_and_mode) | | Isolation applied; invalid isolation/mode rejected before begin; SQLite locks | [`test_transaction_isolation_level`](../tests/end2end_pg.rb#test_transaction_isolation_level) | [`test_transaction_isolation_level_is_applied`](../tests/end2end_mysql2.rb#test_transaction_isolation_level_is_applied) | [`test_transaction_mode`](../tests/end2end_sqlite3.rb#test_transaction_mode), [`test_immediate_and_exclusive_transactions_block_a_second_connection`](../tests/end2end_sqlite3.rb#test_immediate_and_exclusive_transactions_block_a_second_connection), [`test_unknown_transaction_mode_is_rejected_before_beginning`](../tests/end2end_sqlite3.rb#test_unknown_transaction_mode_is_rejected_before_beginning) | [`test_nested_transactions_reject_isolation_and_mode`](../test/features_test.rb#test_nested_transactions_reject_isolation_and_mode) | diff --git a/docs/Testing.md b/docs/Testing.md index 1d49c48..701f853 100644 --- a/docs/Testing.md +++ b/docs/Testing.md @@ -39,7 +39,8 @@ They `require` the generated code from `examples/` and run it against a real dat * They cover every query command (batches with encoded `bytea` / `json` values too), transactions (nested, isolation, `break` / `throw`, a rescued failed statement on PostgreSQL, SQLite threads sharing a database, the yielded `tx` used from other fibers / threads), models named like Ruby constants (`Exception`, `Data`, ...), pool - injection, logging, bang finders, `:copyfrom` with awkward and binary values and its all-or-nothing behaviour, + injection, logging, bang finders, row members named like row methods (`initialize`), MySQL changed vs. matched + rows, SQLite busy waiting, `:copyfrom` with awkward and binary values and its all-or-nothing behaviour, Fiber-scheduler concurrency (`async` gem) and statement-leak checks. ## CI workflows (`.github/workflows/`) diff --git a/examples/authors/mysql/query.sql b/examples/authors/mysql/query.sql index 3f492ba..c8c252d 100644 --- a/examples/authors/mysql/query.sql +++ b/examples/authors/mysql/query.sql @@ -190,15 +190,16 @@ SELECT * FROM mysql_binding_values WHERE id = sqlc.arg(id); TRUNCATE TABLE mysql_binding_values; -- name: InsertNameCase :exec -INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`) +INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`, `initialize`) VALUES (sqlc.arg(id), sqlc.arg(class), sqlc.arg(end_), sqlc.arg(hash), sqlc.arg(method), sqlc.arg(count), - sqlc.arg(camel_case), sqlc.arg(http_server)); + sqlc.arg(camel_case), sqlc.arg(http_server), sqlc.arg(initialize)); -- name: GetNameCase :one SELECT * FROM name_cases WHERE id = sqlc.arg(id) AND `class` = sqlc.arg(class) AND `end` = sqlc.arg(end_) AND `hash` = sqlc.arg(hash) AND `method` = sqlc.arg(method) AND `count` = sqlc.arg(count) - AND `HTTPServer` = sqlc.arg(http_server) AND `camelCase` = sqlc.arg(camel_case); + AND `HTTPServer` = sqlc.arg(http_server) AND `camelCase` = sqlc.arg(camel_case) + AND `initialize` = sqlc.arg(initialize); -- name: GetHTTPServer :one SELECT * FROM name_cases WHERE id = sqlc.arg(id); diff --git a/examples/authors/mysql/schema.sql b/examples/authors/mysql/schema.sql index 2fbf870..9d2fcc7 100644 --- a/examples/authors/mysql/schema.sql +++ b/examples/authors/mysql/schema.sql @@ -108,7 +108,8 @@ CREATE TABLE name_cases ( `method` TEXT NOT NULL, `count` INT NOT NULL, `camelCase` TEXT NOT NULL, - `HTTPServer` TEXT NOT NULL + `HTTPServer` TEXT NOT NULL, + `initialize` TEXT NOT NULL ); -- Tables whose models share their name with a Ruby core or library constant used by the generated code diff --git a/examples/authors/postgresql/query.sql b/examples/authors/postgresql/query.sql index e1a3377..f54b6f9 100644 --- a/examples/authors/postgresql/query.sql +++ b/examples/authors/postgresql/query.sql @@ -226,15 +226,16 @@ SELECT count(*) FROM batch_types WHERE id > sqlc.arg(MIN_ID); TRUNCATE TABLE batch_types; -- name: InsertNameCase :exec -INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") +INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES (sqlc.arg(id), sqlc.arg(class), sqlc.arg(end_), sqlc.arg(hash), sqlc.arg(method), sqlc.arg(count), - sqlc.arg(camel_case), sqlc.arg(http_server)); + sqlc.arg(camel_case), sqlc.arg(http_server), sqlc.arg(initialize)); -- name: GetNameCase :one SELECT * FROM name_cases WHERE id = sqlc.arg(id) AND "class" = sqlc.arg(class) AND "end" = sqlc.arg(end_) AND "hash" = sqlc.arg(hash) AND "method" = sqlc.arg(method) AND "count" = sqlc.arg(count) - AND "HTTPServer" = sqlc.arg(http_server) AND "camelCase" = sqlc.arg(camel_case); + AND "HTTPServer" = sqlc.arg(http_server) AND "camelCase" = sqlc.arg(camel_case) + AND "initialize" = sqlc.arg(initialize); -- name: GetHTTPServer :one SELECT * FROM name_cases WHERE id = sqlc.arg(id); diff --git a/examples/authors/postgresql/schema.sql b/examples/authors/postgresql/schema.sql index 5737c16..9108fde 100644 --- a/examples/authors/postgresql/schema.sql +++ b/examples/authors/postgresql/schema.sql @@ -145,7 +145,8 @@ CREATE TABLE name_cases ( "method" TEXT NOT NULL, "count" INTEGER NOT NULL, "camelCase" TEXT NOT NULL, - "HTTPServer" TEXT NOT NULL + "HTTPServer" TEXT NOT NULL, + "initialize" TEXT NOT NULL ); -- Tables whose models share their name with a Ruby core or library constant used by the generated code diff --git a/examples/authors/sqlite/query.sql b/examples/authors/sqlite/query.sql index 9ce396a..7a16031 100644 --- a/examples/authors/sqlite/query.sql +++ b/examples/authors/sqlite/query.sql @@ -183,15 +183,16 @@ LEFT JOIN books ON authors.id = books.author_id ORDER BY authors.id; -- name: InsertNameCase :exec -INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") +INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES (sqlc.arg(id), sqlc.arg(class), sqlc.arg(end_), sqlc.arg(hash), sqlc.arg(method), sqlc.arg(count), - sqlc.arg(camel_case), sqlc.arg(http_server)); + sqlc.arg(camel_case), sqlc.arg(http_server), sqlc.arg(initialize)); -- name: GetNameCase :one SELECT * FROM name_cases WHERE id = sqlc.arg(id) AND "class" = sqlc.arg(class) AND "end" = sqlc.arg(end_) AND "hash" = sqlc.arg(hash) AND "method" = sqlc.arg(method) AND "count" = sqlc.arg(count) - AND "HTTPServer" = sqlc.arg(http_server) AND "camelCase" = sqlc.arg(camel_case); + AND "HTTPServer" = sqlc.arg(http_server) AND "camelCase" = sqlc.arg(camel_case) + AND "initialize" = sqlc.arg(initialize); -- name: GetHTTPServer :one SELECT * FROM name_cases WHERE id = sqlc.arg(id); diff --git a/examples/authors/sqlite/schema.sql b/examples/authors/sqlite/schema.sql index faf9246..f7d1432 100644 --- a/examples/authors/sqlite/schema.sql +++ b/examples/authors/sqlite/schema.sql @@ -43,7 +43,8 @@ CREATE TABLE name_cases ( "method" TEXT NOT NULL, "count" INTEGER NOT NULL, "camelCase" TEXT NOT NULL, - "HTTPServer" TEXT NOT NULL + "HTTPServer" TEXT NOT NULL, + "initialize" TEXT NOT NULL ); -- Tables whose models share their name with a Ruby core or library constant used by the generated code diff --git a/examples/mysql2/models.rb b/examples/mysql2/models.rb index 0734a54..a15f694 100644 --- a/examples/mysql2/models.rb +++ b/examples/mysql2/models.rb @@ -125,7 +125,8 @@ class NameCase < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end diff --git a/examples/mysql2/models.rbs b/examples/mysql2/models.rbs index fe32ac9..b79b204 100644 --- a/examples/mysql2/models.rbs +++ b/examples/mysql2/models.rbs @@ -202,6 +202,7 @@ module Mysql2Codegen attr_reader count: ::Integer attr_reader camelcase: ::String attr_reader httpserver: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -210,7 +211,8 @@ module Mysql2Codegen ::String method_, ::Integer count, ::String camelcase, - ::String httpserver + ::String httpserver, + ::String initialize_ ) -> void end diff --git a/examples/mysql2/query_sql.rb b/examples/mysql2/query_sql.rb index 9d22ad2..9967f26 100644 --- a/examples/mysql2/query_sql.rb +++ b/examples/mysql2/query_sql.rb @@ -405,16 +405,17 @@ class GetMysqlBindingValuesRow < ::Data.define( SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`) + INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`, `initialize`) VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? AND `class` = ? AND `end` = ? AND `hash` = ? AND `method` = ? AND `count` = ? AND `HTTPServer` = ? AND `camelCase` = ? + AND `initialize` = ? SQL class GetNameCaseRow < ::Data.define( @@ -425,12 +426,13 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases WHERE id = ? + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? SQL class GetHTTPServerRow < ::Data.define( @@ -441,7 +443,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end @@ -1164,7 +1167,7 @@ def truncate_mysql_binding_values end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1174,14 +1177,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] client.query(bind_params(client, INSERT_NAME_CASE_SQL, query_params)) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1191,7 +1195,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] result = client.query(bind_params(client, GET_NAME_CASE_SQL, query_params), as: :array) row = result.first @@ -1203,7 +1208,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row[4], row[5], row[6], - row[7] + row[7], + row[8] ) end end @@ -1226,7 +1232,8 @@ def get_http_server(id:) row[4], row[5], row[6], - row[7] + row[7], + row[8] ) end end diff --git a/examples/mysql2/query_sql.rbs b/examples/mysql2/query_sql.rbs index 1bb66d0..73d3edf 100644 --- a/examples/mysql2/query_sql.rbs +++ b/examples/mysql2/query_sql.rbs @@ -455,6 +455,7 @@ module Mysql2Codegen attr_reader count: ::Integer attr_reader camelcase: ::String attr_reader httpserver: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -463,7 +464,8 @@ module Mysql2Codegen ::String method_, ::Integer count, ::String camelcase, - ::String httpserver + ::String httpserver, + ::String initialize_ ) -> void end @@ -478,6 +480,7 @@ module Mysql2Codegen attr_reader count: ::Integer attr_reader camelcase: ::String attr_reader httpserver: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -486,7 +489,8 @@ module Mysql2Codegen ::String method_, ::Integer count, ::String camelcase, - ::String httpserver + ::String httpserver, + ::String initialize_ ) -> void end @@ -653,11 +657,11 @@ module Mysql2Codegen def truncate_mysql_binding_values: -> void - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/examples/pg/models.rb b/examples/pg/models.rb index ed926d0..cec6c8f 100644 --- a/examples/pg/models.rb +++ b/examples/pg/models.rb @@ -138,7 +138,8 @@ class NameCase < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName diff --git a/examples/pg/models.rbs b/examples/pg/models.rbs index 46eabfb..b16eb80 100644 --- a/examples/pg/models.rbs +++ b/examples/pg/models.rbs @@ -223,6 +223,7 @@ module PgCodegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -231,7 +232,8 @@ module PgCodegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end diff --git a/examples/pg/query_sql.rb b/examples/pg/query_sql.rb index 0117487..bfa65cb 100644 --- a/examples/pg/query_sql.rb +++ b/examples/pg/query_sql.rb @@ -488,16 +488,17 @@ class CountBatchTypesAboveRow < ::Data.define(:count) SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES ($1, $2, $3, $4, $5, $6, - $7, $8) + $7, $8, $9) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 AND "class" = $2 AND "end" = $3 AND "hash" = $4 AND "method" = $5 AND "count" = $6 AND "HTTPServer" = $7 AND "camelCase" = $8 + AND "initialize" = $9 SQL # rubocop:disable Naming/MethodName @@ -509,13 +510,14 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases WHERE id = $1 + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 SQL # rubocop:disable Naming/MethodName @@ -527,7 +529,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName @@ -669,7 +672,7 @@ class ExecResult < ::Data.define(:rows_affected, :last_insert_id) def get_author(id:) with_client('get_author') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author', GET_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author', GET_AUTHOR_SQL, query_params) row = result.first row && GetAuthorRow.new(row['id'], row['name'], row['bio']) end @@ -682,7 +685,7 @@ def get_author!(...) def list_authors with_client('list_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors', LIST_AUTHORS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors', LIST_AUTHORS_SQL) result.map do |row| ListAuthorsRow.new(row['id'], row['name'], row['bio']) end @@ -692,7 +695,7 @@ def list_authors def create_author(name:, bio:) with_client('create_author') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author', CREATE_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author', CREATE_AUTHOR_SQL, query_params) row = result.first row && CreateAuthorRow.new(row['id'], row['name'], row['bio']) end @@ -706,14 +709,14 @@ def create_author!(...) def delete_author(id:) with_client('delete_author') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_delete_author', DELETE_AUTHOR_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#delete_author', DELETE_AUTHOR_SQL, query_params) nil end end def test with_client('test') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_test', TEST_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#test', TEST_SQL) row = result.first row && TestRow.new( row['c_bit'], @@ -746,7 +749,7 @@ def test!(...) def set_json_round_trip(id:, json_value:, jsonb_value:) with_client('set_json_round_trip') do |client| query_params = [id, encode_json(json_value), encode_json(jsonb_value)] - run_prepared(client, 'pg_codegen_query_sql_set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) nil end end @@ -754,7 +757,7 @@ def set_json_round_trip(id:, json_value:, jsonb_value:) def get_json_round_trip(id:) with_client('get_json_round_trip') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) row = result.first row && GetJSONRoundTripRow.new(row['json_value'], row['jsonb_value']) end @@ -768,14 +771,14 @@ def get_json_round_trip!(...) def toggle_jsonb_round_trip(id:) with_client('toggle_jsonb_round_trip') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) nil end end def truncate_json_round_trips with_client('truncate_json_round_trips') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) nil end end @@ -783,7 +786,7 @@ def truncate_json_round_trips def pause_query(seconds:) with_client('pause_query') do |client| query_params = [encode_float(seconds)] - run_prepared(client, 'pg_codegen_query_sql_pause_query', PAUSE_QUERY_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#pause_query', PAUSE_QUERY_SQL, query_params) nil end end @@ -791,7 +794,7 @@ def pause_query(seconds:) def list_authors_paged(offset:, limit:) with_client('list_authors_paged') do |client| query_params = [offset, limit] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) result.map do |row| ListAuthorsPagedRow.new(row['id'], row['name'], row['bio']) end @@ -801,7 +804,7 @@ def list_authors_paged(offset:, limit:) def get_author_by_name_pattern(name_pattern: nil) with_client('get_author_by_name_pattern') do |client| query_params = [name_pattern] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) result.map do |row| GetAuthorByNamePatternRow.new(row['id'], row['name'], row['bio']) end @@ -811,7 +814,7 @@ def get_author_by_name_pattern(name_pattern: nil) def get_authors_by_optional_name(lim:, name_filter: nil) with_client('get_authors_by_optional_name') do |client| query_params = [name_filter, lim] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) result.map do |row| GetAuthorsByOptionalNameRow.new(row['id'], row['name'], row['bio']) end @@ -821,7 +824,7 @@ def get_authors_by_optional_name(lim:, name_filter: nil) def create_author_return_id(name:, bio:) with_client('create_author_return_id') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) row = result.first row && row['id'] end @@ -831,7 +834,7 @@ def create_author_return_id(name:, bio:) def update_author_bios(bio:) with_client('update_author_bios') do |client| query_params = [bio] - result = run_prepared(client, 'pg_codegen_query_sql_update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) result.cmd_tuples end end @@ -839,7 +842,7 @@ def update_author_bios(bio:) def get_authors_by_ids(param1:) with_client('get_authors_by_ids') do |client| query_params = [encode_array(param1)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) result.map do |row| GetAuthorsByIdsRow.new(row['id'], row['name'], row['bio']) end @@ -849,7 +852,7 @@ def get_authors_by_ids(param1:) def get_authors_by_ids_and_names(param1:, param2:) with_client('get_authors_by_ids_and_names') do |client| query_params = [encode_array(param1), encode_array(param2)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) result.map do |row| GetAuthorsByIdsAndNamesRow.new(row['id'], row['name'], row['bio']) end @@ -871,7 +874,7 @@ def copy_authors(rows) def truncate_authors with_client('truncate_authors') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_authors', TRUNCATE_AUTHORS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_authors', TRUNCATE_AUTHORS_SQL) nil end end @@ -879,7 +882,7 @@ def truncate_authors def create_book(name:, author_id:) with_client('create_book') do |client| query_params = [name, author_id] - result = run_prepared(client, 'pg_codegen_query_sql_create_book', CREATE_BOOK_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_book', CREATE_BOOK_SQL, query_params) row = result.first row && row['id'] end @@ -888,21 +891,21 @@ def create_book(name:, author_id:) def create_deferred_book(author_id:) with_client('create_deferred_book') do |client| query_params = [author_id] - run_prepared(client, 'pg_codegen_query_sql_create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) nil end end def truncate_deferred_books with_client('truncate_deferred_books') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) nil end end def list_all_authors_books with_client('list_all_authors_books') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values result.map do |row| ListAllAuthorsBooksRow.new( Author.new(row[0], row[1], row[2]), @@ -914,7 +917,7 @@ def list_all_authors_books def get_duplicate_authors with_client('get_duplicate_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values result.map do |row| GetDuplicateAuthorsRow.new(Author.new(row[0], row[1], row[2]), Author.new(row[3], row[4], row[5])) end @@ -924,7 +927,7 @@ def get_duplicate_authors def get_authors_by_book_name(name:) with_client('get_authors_by_book_name') do |client| query_params = [name] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values result.map do |row| GetAuthorsByBookNameRow.new(row[0], row[1], row[2], Book.new(row[3], row[4], row[5], row[6])) end @@ -934,7 +937,7 @@ def get_authors_by_book_name(name:) def create_extended_bio(author_name:, name:, bio_type:) with_client('create_extended_bio') do |client| query_params = [author_name, name, bio_type] - run_prepared(client, 'pg_codegen_query_sql_create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) nil end end @@ -942,7 +945,7 @@ def create_extended_bio(author_name:, name:, bio_type:) def get_first_extended_bio_by_type(bio_type:) with_client('get_first_extended_bio_by_type') do |client| query_params = [bio_type] - result = run_prepared(client, 'pg_codegen_query_sql_get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) row = result.first row && GetFirstExtendedBioByTypeRow.new(row['author_name'], row['name'], row['bio_type']) end @@ -955,7 +958,7 @@ def get_first_extended_bio_by_type!(...) def truncate_extended_bios with_client('truncate_extended_bios') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) nil end end @@ -972,14 +975,14 @@ def insert_extra_types(c_uuid:, c_jsonb:, c_text_array:, c_integer_array:, c_tim c_money, c_not_null ] - run_prepared(client, 'pg_codegen_query_sql_insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) nil end end def get_extra_types with_client('get_extra_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_extra_types', GET_EXTRA_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_extra_types', GET_EXTRA_TYPES_SQL) row = result.first row && GetExtraTypesRow.new( row['c_uuid'], @@ -1001,7 +1004,7 @@ def get_extra_types!(...) def truncate_extra_types with_client('truncate_extra_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) nil end end @@ -1023,14 +1026,14 @@ def insert_remaining_types(c_hstore:, c_ltree:, c_regclass:, c_cidr:, c_macaddr: c_timestamptz, encode_array(c_text_matrix) ] - run_prepared(client, 'pg_codegen_query_sql_insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) nil end end def get_remaining_types with_client('get_remaining_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_remaining_types', GET_REMAINING_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_remaining_types', GET_REMAINING_TYPES_SQL) row = result.first row && GetRemainingTypesRow.new( row['c_hstore'], @@ -1057,7 +1060,7 @@ def get_remaining_types!(...) def truncate_remaining_types with_client('truncate_remaining_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) nil end end @@ -1065,14 +1068,14 @@ def truncate_remaining_types def insert_array_types(c_uuid_array:, c_bio_type_array:, c_integer_matrix:) with_client('insert_array_types') do |client| query_params = [encode_array(c_uuid_array), encode_array(c_bio_type_array), encode_array(c_integer_matrix)] - run_prepared(client, 'pg_codegen_query_sql_insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) nil end end def get_array_types with_client('get_array_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_array_types', GET_ARRAY_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_array_types', GET_ARRAY_TYPES_SQL) row = result.first row && GetArrayTypesRow.new(row['c_uuid_array'], row['c_bio_type_array'], row['c_integer_matrix']) end @@ -1085,14 +1088,14 @@ def get_array_types!(...) def truncate_array_types with_client('truncate_array_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) nil end end def list_authors_with_optional_book with_client('list_authors_with_optional_book') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values result.map do |row| ListAuthorsWithOptionalBookRow.new( row[0].nil? && row[1].nil? ? nil : Author.new(row[0], row[1], row[2]), @@ -1105,7 +1108,7 @@ def list_authors_with_optional_book def list_authors_between_ids(id:, id_2:) with_client('list_authors_between_ids') do |client| query_params = [id, id_2] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) result.map do |row| ListAuthorsBetweenIdsRow.new(row['id'], row['name'], row['bio']) end @@ -1123,14 +1126,14 @@ def insert_special_types(c_timetz:, c_tsvector:, c_point:, c_int4range:, c_oid:, c_dimensions, c_positive ] - run_prepared(client, 'pg_codegen_query_sql_insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) nil end end def get_special_types with_client('get_special_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_special_types', GET_SPECIAL_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_special_types', GET_SPECIAL_TYPES_SQL) row = result.first row && GetSpecialTypesRow.new( row['c_timetz'], @@ -1151,7 +1154,7 @@ def get_special_types!(...) def truncate_special_types with_client('truncate_special_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) nil end end @@ -1159,7 +1162,7 @@ def truncate_special_types def create_author_result(name:, bio:) with_client('create_author_result') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) ExecResult.new(result.cmd_tuples, nil) end end @@ -1168,7 +1171,7 @@ def create_authors_batch(rows) with_client('create_authors_batch') do |client| rows.each do |args| query_params = [args.name, args.bio] - run_prepared(client, 'pg_codegen_query_sql_create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) end nil end @@ -1178,7 +1181,7 @@ def get_author_batch(rows) with_client('get_author_batch') do |client| rows.map do |args| query_params = [args.id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) row = result.first row && GetAuthorBatchRow.new(row['id'], row['name'], row['bio']) end @@ -1189,7 +1192,7 @@ def list_authors_by_name_batch(rows) with_client('list_authors_by_name_batch') do |client| rows.map do |args| query_params = [args.name] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) result.map do |row| ListAuthorsByNameBatchRow.new(row['id'], row['name'], row['bio']) end @@ -1207,7 +1210,7 @@ def create_regression(id:, order:, payload:, doc:, bio_types:, uids:) encode_array(bio_types), encode_array(uids) ] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression', CREATE_REGRESSION_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression', CREATE_REGRESSION_SQL, query_params) row = result.first row && CreateRegressionRow.new( row['id'], @@ -1229,7 +1232,7 @@ def create_regression!(...) def create_regression_if_new(id:, order:) with_client('create_regression_if_new') do |client| query_params = [id, order] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) row = result.first row && row['id'] end @@ -1251,7 +1254,7 @@ def create_regressions_batch(rows) with_client('create_regressions_batch') do |client| rows.each do |args| query_params = [args.id, args.order, encode_bytea(args.payload), encode_json(args.doc)] - run_prepared(client, 'pg_codegen_query_sql_create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) end nil end @@ -1260,7 +1263,7 @@ def create_regressions_batch(rows) def list_regressions(order_name: nil) with_client('list_regressions') do |client| query_params = [order_name] - result = run_prepared(client, 'pg_codegen_query_sql_list_regressions', LIST_REGRESSIONS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_regressions', LIST_REGRESSIONS_SQL, query_params) result.map do |row| ListRegressionsRow.new( row['id'], @@ -1278,7 +1281,7 @@ def list_regressions(order_name: nil) def set_regression_step(id:, step:) with_client('set_regression_step') do |client| query_params = [id, step] - result = run_prepared(client, 'pg_codegen_query_sql_set_regression_step', SET_REGRESSION_STEP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#set_regression_step', SET_REGRESSION_STEP_SQL, query_params) row = result.first row && SetRegressionStepRow.new(row['step']) end @@ -1291,7 +1294,7 @@ def set_regression_step!(...) def truncate_regressions with_client('truncate_regressions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_regressions', TRUNCATE_REGRESSIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_regressions', TRUNCATE_REGRESSIONS_SQL) nil end end @@ -1309,7 +1312,7 @@ def create_batch_types_batch(rows) encode_array(args.amounts), encode_array(args.stamps) ] - run_prepared(client, 'pg_codegen_query_sql_create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) end nil end @@ -1329,7 +1332,7 @@ def copy_batch_types(rows) def list_batch_types with_client('list_batch_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_batch_types', LIST_BATCH_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_batch_types', LIST_BATCH_TYPES_SQL) result.map do |row| ListBatchTypesRow.new( row['id'], @@ -1348,7 +1351,7 @@ def list_batch_types def count_batch_types_above(min_id:) with_client('count_batch_types_above') do |client| query_params = [min_id] - result = run_prepared(client, 'pg_codegen_query_sql_count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) row = result.first row && CountBatchTypesAboveRow.new(row['count']) end @@ -1361,12 +1364,12 @@ def count_batch_types_above!(...) def truncate_batch_types with_client('truncate_batch_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) nil end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1376,14 +1379,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] - run_prepared(client, 'pg_codegen_query_sql_insert_name_case', INSERT_NAME_CASE_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_name_case', INSERT_NAME_CASE_SQL, query_params) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1393,9 +1397,10 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] - result = run_prepared(client, 'pg_codegen_query_sql_get_name_case', GET_NAME_CASE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_name_case', GET_NAME_CASE_SQL, query_params) row = result.first row && GetNameCaseRow.new( row['id'], @@ -1405,7 +1410,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row['method'], row['count'], row['camelCase'], - row['HTTPServer'] + row['HTTPServer'], + row['initialize'] ) end end @@ -1418,7 +1424,7 @@ def get_name_case!(...) def get_http_server(id:) with_client('get_http_server') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_http_server', GET_HTTP_SERVER_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_http_server', GET_HTTP_SERVER_SQL, query_params) row = result.first row && GetHTTPServerRow.new( row['id'], @@ -1428,7 +1434,8 @@ def get_http_server(id:) row['method'], row['count'], row['camelCase'], - row['HTTPServer'] + row['HTTPServer'], + row['initialize'] ) end end @@ -1440,14 +1447,14 @@ def get_http_server!(...) def truncate_name_cases with_client('truncate_name_cases') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_name_cases', TRUNCATE_NAME_CASES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_name_cases', TRUNCATE_NAME_CASES_SQL) nil end end def get_unnamed_columns with_client('get_unnamed_columns') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values row = result.first row && GetUnnamedColumnsRow.new(row[0], row[1]) end @@ -1460,7 +1467,7 @@ def get_unnamed_columns!(...) def get_quoted_alias with_client('get_quoted_alias') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_quoted_alias', GET_QUOTED_ALIAS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_quoted_alias', GET_QUOTED_ALIAS_SQL) row = result.first row && GetQuotedAliasRow.new(row['it\'s']) end @@ -1473,14 +1480,14 @@ def get_quoted_alias!(...) def create_exception with_client('create_exception') do |client| - run_prepared(client, 'pg_codegen_query_sql_create_exception', CREATE_EXCEPTION_SQL) + run_prepared(client, 'PgCodegen::QuerySql#create_exception', CREATE_EXCEPTION_SQL) nil end end def count_exceptions with_client('count_exceptions') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_count_exceptions', COUNT_EXCEPTIONS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#count_exceptions', COUNT_EXCEPTIONS_SQL) row = result.first row && CountExceptionsRow.new(row['n']) end @@ -1493,7 +1500,7 @@ def count_exceptions!(...) def truncate_exceptions with_client('truncate_exceptions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) nil end end @@ -1501,7 +1508,7 @@ def truncate_exceptions def create_late_feeling(id:, moods:) with_client('create_late_feeling') do |client| query_params = [id, encode_array(moods)] - run_prepared(client, 'pg_codegen_query_sql_create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) nil end end @@ -1509,7 +1516,7 @@ def create_late_feeling(id:, moods:) def get_late_feeling(id:) with_client('get_late_feeling') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_late_feeling', GET_LATE_FEELING_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_late_feeling', GET_LATE_FEELING_SQL, query_params) row = result.first row && GetLateFeelingRow.new(row['moods']) end diff --git a/examples/pg/query_sql.rbs b/examples/pg/query_sql.rbs index fb1f646..c9f59f8 100644 --- a/examples/pg/query_sql.rbs +++ b/examples/pg/query_sql.rbs @@ -527,6 +527,7 @@ module PgCodegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -535,7 +536,8 @@ module PgCodegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -550,6 +552,7 @@ module PgCodegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -558,7 +561,8 @@ module PgCodegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -755,11 +759,11 @@ module PgCodegen def truncate_batch_types: -> void - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/examples/sqlite3/models.rb b/examples/sqlite3/models.rb index 35771dd..3446141 100644 --- a/examples/sqlite3/models.rb +++ b/examples/sqlite3/models.rb @@ -35,7 +35,8 @@ class NameCase < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName diff --git a/examples/sqlite3/models.rbs b/examples/sqlite3/models.rbs index 1e54403..798625e 100644 --- a/examples/sqlite3/models.rbs +++ b/examples/sqlite3/models.rbs @@ -57,6 +57,7 @@ module Sqlite3Codegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -65,7 +66,8 @@ module Sqlite3Codegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end diff --git a/examples/sqlite3/query_sql.rb b/examples/sqlite3/query_sql.rb index 13d50a2..9d2b157 100644 --- a/examples/sqlite3/query_sql.rb +++ b/examples/sqlite3/query_sql.rb @@ -325,16 +325,17 @@ class ListAuthorsWithOptionalBookRow < ::Data.define(:author, :book) end INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? AND "class" = ? AND "end" = ? AND "hash" = ? AND "method" = ? AND "count" = ? AND "HTTPServer" = ? AND "camelCase" = ? + AND "initialize" = ? SQL # rubocop:disable Naming/MethodName @@ -346,13 +347,14 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases WHERE id = ? + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? SQL # rubocop:disable Naming/MethodName @@ -364,7 +366,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName @@ -1137,7 +1140,7 @@ def list_authors_with_optional_book end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1147,7 +1150,8 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] stmt = client.prepare(INSERT_NAME_CASE_SQL) begin @@ -1159,7 +1163,7 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1169,7 +1173,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] stmt = client.prepare(GET_NAME_CASE_SQL) begin @@ -1183,7 +1188,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row[4], row[5], row[6], - row[7] + row[7], + row[8] ) ensure stmt.close @@ -1211,7 +1217,8 @@ def get_http_server(id:) row[4], row[5], row[6], - row[7] + row[7], + row[8] ) ensure stmt.close diff --git a/examples/sqlite3/query_sql.rbs b/examples/sqlite3/query_sql.rbs index e165013..236fd42 100644 --- a/examples/sqlite3/query_sql.rbs +++ b/examples/sqlite3/query_sql.rbs @@ -334,6 +334,7 @@ module Sqlite3Codegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -342,7 +343,8 @@ module Sqlite3Codegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -357,6 +359,7 @@ module Sqlite3Codegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -365,7 +368,8 @@ module Sqlite3Codegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -521,11 +525,11 @@ module Sqlite3Codegen def list_authors_with_optional_book: -> ::Array[ListAuthorsWithOptionalBookRow] - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/lib/sqlc_gen_ruby/code.rb b/lib/sqlc_gen_ruby/code.rb index 411d70a..ce9a3ee 100644 --- a/lib/sqlc_gen_ruby/code.rb +++ b/lib/sqlc_gen_ruby/code.rb @@ -71,12 +71,18 @@ def param_name(name) LOCAL = /\A[\p{Ll}_][\p{Word}]*\z/.freeze - # Public methods of every row object (Object + Data): a column with one of these names would override it. - OBJECT_METHODS = %w[__id__ __send__ class clone deconstruct deconstruct_keys define_singleton_method display dup - enum_for eql? equal? extend freeze frozen? hash inspect instance_of? instance_variable_defined? - instance_variable_get instance_variable_set instance_variables is_a? itself kind_of? members - method methods nil? object_id public_method public_send respond_to? send singleton_class - singleton_method singleton_methods tap then to_enum to_h to_s with yield_self].freeze + # Private hooks that building, copying and cloning a row call: a member with one of these names breaks them + # (a column named `initialize` would make every row raise ArgumentError when it is built). + CONSTRUCTION_METHODS = %w[initialize initialize_clone initialize_copy initialize_dup method_missing + respond_to_missing?].freeze + + # Methods of every row object (Object + Data): a column with one of these names would override it. + OBJECT_METHODS = (%w[__id__ __send__ class clone deconstruct deconstruct_keys define_singleton_method display dup + enum_for eql? equal? extend freeze frozen? hash inspect instance_of? instance_variable_defined? + instance_variable_get instance_variable_set instance_variables is_a? itself kind_of? members + method methods nil? object_id public_method public_send respond_to? send singleton_class + singleton_method singleton_methods tap then to_enum to_h to_s with yield_self] + + CONSTRUCTION_METHODS).freeze KERNEL_METHODS = %w[format raise rand].freeze # Struct (rows on Ruby < 3.2) also has Enumerable and accessors such as #size / #values. @@ -122,14 +128,37 @@ def identifier(name) name.match?(/\A\p{Digit}/) ? "_#{name}" : name end - # 'user-queries' => User_queries is invalid; runs of characters that are not valid in a constant start a new word: - # 'user-queries' => UserQueries, 'my_queries' => My_queries (unchanged), '2024' => Q2024 + # A file name as a CamelCase constant: underscores and other characters that are not valid in a constant start a + # new word. 'admin_users' => AdminUsers, 'user-queries' => UserQueries, 'userQueries' => UserQueries, + # '2024' => Q2024 def constant_part(str) - words = str.split(/[^A-Za-z0-9_]+/).reject(&:empty?) - raise ArgumentError, "#{str.inspect} has no characters usable in a Ruby constant" if words.empty? + name = camelize(str) + raise ArgumentError, "#{str.inspect} has no characters usable in a Ruby constant" if name.empty? - name = words.map { |w| upcase_first(w) }.join - name.match?(/\A[0-9_]/) ? "Q#{name}" : name + name.match?(/\A[0-9]/) ? "Q#{name}" : name + end + + # PostgreSQL keeps the first 63 bytes of a prepared statement name (NAMEDATALEN - 1). + STATEMENT_NAME_BYTES = 63 + + # Prepared statement name of a generated method, unique for every method of every class that can share a + # connection: `Module::Class#method` cannot be spelled by another class or method (`::` and `#` never occur + # inside a constant or method name). Names PostgreSQL would truncate become a prefix plus a 64-bit FNV-1a hash of + # the full name after a `~`, which no full name contains. + def statement_name(class_name, method) + name = "#{class_name}##{method}" + return name if name.bytesize <= STATEMENT_NAME_BYTES + + prefix = name.byteslice(0, STATEMENT_NAME_BYTES - 17).scrub('') + "#{prefix}~#{fnv1a64(name)}" + end + + FNV_OFFSET = 0xcbf29ce484222325 + FNV_PRIME = 0x100000001b3 + UINT64 = 0xffff_ffff_ffff_ffff + + def fnv1a64(text) + text.each_byte.reduce(FNV_OFFSET) { |hash, byte| ((hash ^ byte) * FNV_PRIME) & UINT64 }.to_s(16).rjust(16, '0') end # "Line 1\nLine 2" => "# Line 1\n# Line 2" ('' for no comment) diff --git a/lib/sqlc_gen_ruby/generator.rb b/lib/sqlc_gen_ruby/generator.rb index 5543799..302ddb8 100644 --- a/lib/sqlc_gen_ruby/generator.rb +++ b/lib/sqlc_gen_ruby/generator.rb @@ -33,7 +33,7 @@ def generate(request) models = models_files connection = connection_files by_class = request.queries.group_by { |q| class_name_for(q.filename) } - reject_colliding_files(by_class.keys) + reject_colliding_files(by_class) files = by_class.flat_map do |class_name, queries| generate_files(queries, class_name, with_models: !models.empty?, with_connection: !connection.empty?) end @@ -102,10 +102,11 @@ def class_name_for(filename) Code.constant_part(File.basename(filename, ext)) + Code.constant_part(ext[1..]) end - # user-queries.sql and user_queries.sql would both write user_queries_sql.rb - def reject_colliding_files(class_names) - class_names.group_by { |c| Code.snake_case(c) }.each do |base, names| - raise ArgumentError, "query files #{names.join(' and ')} would both generate #{base}.rb" if names.size > 1 + # user-queries.sql and user_queries.sql would both be UserQueriesSql in user_queries_sql.rb + def reject_colliding_files(by_class) + by_class.group_by { |class_name, _| Code.snake_case(class_name) }.each do |base, classes| + files = classes.flat_map { |_, queries| queries.map(&:filename) }.uniq + raise ArgumentError, "query files #{files.join(' and ')} would both generate #{base}.rb" if files.size > 1 end end diff --git a/lib/sqlc_gen_ruby/method_gen.rb b/lib/sqlc_gen_ruby/method_gen.rb index b993f2f..eb1c8b1 100644 --- a/lib/sqlc_gen_ruby/method_gen.rb +++ b/lib/sqlc_gen_ruby/method_gen.rb @@ -24,13 +24,13 @@ class MethodGen # Locals of the generated query methods; parameters with these names get a trailing underscore. GENERATED_LOCALS = %w[client query_params sql stmt result row].freeze - # layout: RowLayout, types: TypeResolver, class_name: the generated query class with its module (prefixes - # statement names, which must differ between modules that share a connection) + # layout: RowLayout, types: TypeResolver, class_name: the generated query class with its module (names the + # prepared statements, which must differ between classes that share a connection) def initialize(driver, layout, types, class_name) @driver = driver @layout = layout @types = types - @statement_prefix = class_name.split('::').map { |part| Code.snake_case(part) }.join('_') + @class_name = class_name end # `created_at > $1 AND created_at < $2` -> created_at:, created_at_2: @@ -209,7 +209,7 @@ def query_statements(query, func, params) statements << slice_sql(const, params) const = 'sql' end - stmt_name = "#{@statement_prefix}_#{func}" + stmt_name = Code.statement_name(@class_name, func) prepare = @driver.prepare_stmt(stmt_name, const) statements << prepare if prepare commands = command_statements(query, stmt_name, const, !params.empty?) @@ -226,7 +226,7 @@ def batch_statements(query, func, params) raise ArgumentError, "#{query.name}: sqlc.slice cannot be used in #{query.cmd}" if slice?(query) const = Code.sql_constant(query.name) - stmt_name = "#{@statement_prefix}_#{func}" + stmt_name = Code.statement_name(@class_name, func) prepare = @driver.prepare_stmt(stmt_name, const) cmd = BATCH_COMMANDS.fetch(query.cmd) body = [] diff --git a/lib/sqlc_gen_ruby/ruby_version.rb b/lib/sqlc_gen_ruby/ruby_version.rb index a8006db..a44d1da 100644 --- a/lib/sqlc_gen_ruby/ruby_version.rb +++ b/lib/sqlc_gen_ruby/ruby_version.rb @@ -66,9 +66,10 @@ def ==(other) def hash = [major, minor, patch].hash - # Ruby 3.2 introduced Data.define; older versions have to fall back to Struct. + # Ruby 3.2 introduced Data.define; older versions have to fall back to Struct. A missing minor part means any + # release of that major ("3" includes 3.1), so it counts as .0 here. def immutable_data_supported? - self >= IMMUTABLE_DATA_MIN + RubyVersion.new(major, minor || 0, patch) >= IMMUTABLE_DATA_MIN end def to_s diff --git a/steep_expectations.yml b/steep_expectations.yml index 18661fa..6e2df01 100644 --- a/steep_expectations.yml +++ b/steep_expectations.yml @@ -3,90 +3,90 @@ diagnostics: - range: start: - line: 497 + line: 500 character: 12 end: - line: 497 + line: 500 character: 26 severity: WARNING message: 'Cannot find the declaration of constant: `ConnectionPool`' code: Ruby::UnknownConstant - range: start: - line: 497 + line: 500 character: 51 end: - line: 497 + line: 500 character: 57 severity: WARNING message: 'Cannot find the declaration of constant: `Mysql2`' code: Ruby::UnknownConstant - range: start: - line: 497 + line: 500 character: 70 end: - line: 497 + line: 500 character: 85 severity: WARNING message: Empty kwargs doesn't have type annotation code: Ruby::UnannotatedEmptyCollection - range: start: - line: 522 + line: 525 character: 54 end: - line: 570 + line: 573 character: 11 severity: WARNING message: The method cannot be called with a block code: Ruby::UnexpectedBlockGiven - range: start: - line: 534 + line: 537 character: 62 end: - line: 536 + line: 539 character: 15 severity: WARNING message: The method cannot be called with a block code: Ruby::UnexpectedBlockGiven - range: start: - line: 542 + line: 545 character: 21 end: - line: 542 + line: 545 character: 27 severity: WARNING message: 'Cannot find the declaration of constant: `Mysql2`' code: Ruby::UnknownConstant - range: start: - line: 545 + line: 548 character: 37 end: - line: 545 + line: 548 character: 43 severity: WARNING message: 'Cannot find the declaration of constant: `Mysql2`' code: Ruby::UnknownConstant - range: start: - line: 560 + line: 563 character: 27 end: - line: 560 + line: 563 character: 33 severity: WARNING message: 'Cannot find the declaration of constant: `Mysql2`' code: Ruby::UnknownConstant - range: start: - line: 1397 + line: 1404 character: 20 end: - line: 1397 + line: 1404 character: 38 severity: ERROR message: |- @@ -99,20 +99,20 @@ code: Ruby::ArgumentTypeMismatch - range: start: - line: 1398 + line: 1405 character: 78 end: - line: 1398 + line: 1405 character: 84 severity: ERROR message: Type `(::String | nil)` does not have method `match?` code: Ruby::NoMethod - range: start: - line: 1400 + line: 1407 character: 20 end: - line: 1400 + line: 1407 character: 39 severity: ERROR message: |- @@ -125,10 +125,10 @@ code: Ruby::ArgumentTypeMismatch - range: start: - line: 1404 + line: 1411 character: 20 end: - line: 1404 + line: 1411 character: 39 severity: ERROR message: |- @@ -141,10 +141,10 @@ code: Ruby::ArgumentTypeMismatch - range: start: - line: 1409 + line: 1416 character: 20 end: - line: 1409 + line: 1416 character: 39 severity: ERROR message: |- @@ -157,10 +157,10 @@ code: Ruby::ArgumentTypeMismatch - range: start: - line: 1418 + line: 1425 character: 20 end: - line: 1418 + line: 1425 character: 24 severity: ERROR message: |- @@ -173,10 +173,10 @@ code: Ruby::ArgumentTypeMismatch - range: start: - line: 1451 + line: 1458 character: 18 end: - line: 1451 + line: 1458 character: 24 severity: WARNING message: 'Cannot find the declaration of constant: `Mysql2`' @@ -247,380 +247,380 @@ diagnostics: - range: start: - line: 588 + line: 591 character: 12 end: - line: 588 + line: 591 character: 26 severity: WARNING message: 'Cannot find the declaration of constant: `ConnectionPool`' code: Ruby::UnknownConstant - range: start: - line: 588 + line: 591 character: 51 end: - line: 588 + line: 591 character: 53 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 588 + line: 591 character: 62 end: - line: 588 + line: 591 character: 73 severity: WARNING message: Empty kwargs doesn't have type annotation code: Ruby::UnannotatedEmptyCollection - range: start: - line: 604 + line: 607 character: 51 end: - line: 604 + line: 607 character: 53 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 617 + line: 620 character: 54 end: - line: 661 + line: 664 character: 11 severity: WARNING message: The method cannot be called with a block code: Ruby::UnexpectedBlockGiven - range: start: - line: 625 + line: 628 character: 62 end: - line: 627 + line: 630 character: 15 severity: WARNING message: The method cannot be called with a block code: Ruby::UnexpectedBlockGiven - range: start: - line: 631 + line: 634 character: 60 end: - line: 631 + line: 634 character: 62 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 633 + line: 636 character: 76 end: - line: 633 + line: 636 character: 78 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 634 + line: 637 character: 65 end: - line: 634 + line: 637 character: 67 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 641 + line: 644 character: 37 end: - line: 641 + line: 644 character: 39 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 643 + line: 646 character: 22 end: - line: 643 + line: 646 character: 24 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 646 + line: 649 character: 55 end: - line: 646 + line: 649 character: 57 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 652 + line: 655 character: 64 end: - line: 652 + line: 655 character: 66 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 653 + line: 656 character: 42 end: - line: 653 + line: 656 character: 44 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 653 + line: 656 character: 95 end: - line: 653 + line: 656 character: 97 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 658 + line: 661 character: 22 end: - line: 658 + line: 661 character: 24 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 862 + line: 865 character: 20 end: - line: 862 + line: 865 character: 22 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1240 + line: 1243 character: 20 end: - line: 1240 + line: 1243 character: 22 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1320 + line: 1323 character: 20 end: - line: 1320 + line: 1323 character: 22 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1540 + line: 1547 character: 32 end: - line: 1540 + line: 1547 character: 34 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1542 + line: 1549 character: 20 end: - line: 1542 + line: 1549 character: 22 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1551 + line: 1558 character: 60 end: - line: 1551 + line: 1558 character: 62 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1563 + line: 1570 character: 19 end: - line: 1563 + line: 1570 character: 21 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1566 + line: 1573 character: 18 end: - line: 1566 + line: 1573 character: 20 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1568 + line: 1575 character: 55 end: - line: 1568 + line: 1575 character: 57 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1575 + line: 1582 character: 18 end: - line: 1575 + line: 1582 character: 20 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1576 + line: 1583 character: 16 end: - line: 1576 + line: 1583 character: 18 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1577 + line: 1584 character: 68 end: - line: 1577 + line: 1584 character: 70 severity: WARNING message: Empty array doesn't have type annotation code: Ruby::UnannotatedEmptyCollection - range: start: - line: 1592 + line: 1599 character: 13 end: - line: 1592 + line: 1599 character: 15 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1594 + line: 1601 character: 50 end: - line: 1594 + line: 1601 character: 52 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1603 + line: 1610 character: 17 end: - line: 1603 + line: 1610 character: 19 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1610 + line: 1617 character: 53 end: - line: 1610 + line: 1617 character: 55 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1626 + line: 1633 character: 8 end: - line: 1626 + line: 1633 character: 10 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1626 + line: 1633 character: 52 end: - line: 1626 + line: 1633 character: 54 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1633 + line: 1640 character: 44 end: - line: 1633 + line: 1640 character: 46 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1634 + line: 1641 character: 27 end: - line: 1634 + line: 1641 character: 29 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1635 + line: 1642 character: 46 end: - line: 1635 + line: 1642 character: 48 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' code: Ruby::UnknownConstant - range: start: - line: 1636 + line: 1643 character: 27 end: - line: 1636 + line: 1643 character: 29 severity: WARNING message: 'Cannot find the declaration of constant: `PG`' @@ -629,30 +629,30 @@ diagnostics: - range: start: - line: 451 + line: 454 character: 56 end: - line: 479 + line: 482 character: 13 severity: WARNING message: The method cannot be called with a block code: Ruby::UnexpectedBlockGiven - range: start: - line: 457 + line: 460 character: 64 end: - line: 459 + line: 462 character: 17 severity: WARNING message: The method cannot be called with a block code: Ruby::UnexpectedBlockGiven - range: start: - line: 1371 + line: 1378 character: 17 end: - line: 1371 + line: 1378 character: 24 severity: WARNING message: 'Cannot find the declaration of constant: `SQLite3`' diff --git a/test/features_test.rb b/test/features_test.rb index 066f277..24ac095 100644 --- a/test/features_test.rb +++ b/test/features_test.rb @@ -256,9 +256,45 @@ def test_query_comments_become_doc_comments def test_statements_are_named_after_the_module_and_query_class rb = generate(load_request('pg')).fetch('query_sql.rb') - assert_includes rb, "run_prepared(client, 'pg_codegen_query_sql_get_author', GET_AUTHOR_SQL, query_params)" + assert_includes rb, "run_prepared(client, 'PgCodegen::QuerySql#get_author', GET_AUTHOR_SQL, query_params)" rb = generate(load_request('pg', moduleName: 'Shop::DB')).fetch('query_sql.rb') - assert_includes rb, "run_prepared(client, 'shop_db_query_sql_get_author', GET_AUTHOR_SQL, query_params)" + assert_includes rb, "run_prepared(client, 'Shop::DB::QuerySql#get_author', GET_AUTHOR_SQL, query_params)" + end + + def test_statement_names_of_different_classes_never_collide + names = [%w[App::DbV2::QSql get_thing], %w[AppDb::V2::QSql get_thing], %w[Shop::Db::AdminUsersSql get_thing], + %w[Shop::Db::Admin::UsersSql get_thing], %w[Shop::Db::Admin_usersSql get_thing], + %w[A::B c_d], %w[A::BC d], %w[A::B_c d]].map { |klass, method| SqlcGenRuby::Code.statement_name(klass, method) } + assert_equal names.size, names.uniq.size + long = "Options::PgLongModuleNameThatPushesStatementNamesPastTheLimit#{'X' * 20}" + a = SqlcGenRuby::Code.statement_name("#{long}A::FirstSql", 'get_pg_option_author') + b = SqlcGenRuby::Code.statement_name("#{long}B::FirstSql", 'get_pg_option_author') + refute_equal a, b + assert_operator a.bytesize, :<=, 63 + assert_operator SqlcGenRuby::Code.statement_name("Ünïcödé::#{'Ä' * 40}Sql", 'get').bytesize, :<=, 63 + assert SqlcGenRuby::Code.statement_name("Ünïcödé::#{'Ä' * 40}Sql", 'get').valid_encoding? + assert_equal a, SqlcGenRuby::Code.statement_name("#{long}A::FirstSql", 'get_pg_option_author') + end + + # Every method a row inherits (public or private) keeps working when a column has its name. + def test_columns_named_like_row_methods_still_build_and_read_rows + row_classes = [::Struct] + row_classes << ::Data if defined?(::Data) + names = row_classes.flat_map { |k| k.instance_methods + k.private_instance_methods }.map(&:to_s).uniq + names = names.grep(/\A[a-z_][a-zA-Z0-9_]*\z/) + row_classes.each do |base| + struct = base == ::Struct + names.each do |name| + member = SqlcGenRuby::Code.member_name(name, struct: struct).to_sym + klass = struct ? Class.new(::Struct.new(member, :other, keyword_init: true)) : Class.new(::Data.define(member, :other)) + row = klass.new(member => 'value', other: 1) + assert_equal ['value', 1], [row.public_send(member), row.other], "#{base} member #{member} (column #{name})" + assert_equal({ member => 'value', other: 1 }, row.to_h) + assert_equal row, row.dup + assert_equal row, row.clone + assert_equal 2, row.with(other: 2).other unless struct + end + end end def test_pg_can_skip_prepared_statements @@ -342,11 +378,23 @@ def test_query_file_names_become_valid_constants assert_equal 0, ruby_syntax_check(files.fetch('user_queries_sql.rb')) end + def test_query_file_names_become_camel_case_classes + { 'admin_users.sql' => %w[admin_users_sql AdminUsersSql], 'v2_api_queries.sql' => %w[v2_api_queries_sql V2ApiQueriesSql], + '2024_report.sql' => %w[q2024_report_sql Q2024ReportSql], 'userQueries.sql' => %w[user_queries_sql UserQueriesSql] } + .each do |filename, (file, klass)| + request = load_request('sqlite3') + request.queries.each { |q| q.filename = filename } + rb = generate(request).fetch("#{file}.rb") + assert_includes rb, "class #{klass}\n" + end + end + def test_query_files_writing_the_same_file_are_rejected request = load_request('sqlite3') request.queries.first.filename = 'user-queries.sql' request.queries.last.filename = 'user_queries.sql' - assert_raises(RuntimeError) { generate(request) } + error = assert_raises(RuntimeError) { generate(request) } + assert_includes error.message, 'query files user-queries.sql and user_queries.sql would both generate user_queries_sql.rb' end diff --git a/test/fixtures/mysql2.bin b/test/fixtures/mysql2.bin index f1a1fc4..210c6fc 100644 --- a/test/fixtures/mysql2.bin +++ b/test/fixtures/mysql2.bin @@ -1,7 +1,7 @@ -2mysql¦(public"›(public€ +2mysql×(public"Ì(public€ authors& id0ÿÿÿÿÿÿÿÿÿR authorsbbigint& name0ÿÿÿÿÿÿÿÿÿR authorsbtext# @@ -117,7 +117,7 @@ year_value0 time_value0 Rmysql_binding_valuesbtime9 - json_unicode0ÿÿÿÿÿÿÿÿÿRmysql_binding_valuesbjsonó + json_unicode0ÿÿÿÿÿÿÿÿÿRmysql_binding_valuesbjson¤  name_cases) id0ÿÿÿÿÿÿÿÿÿR  @@ -136,6 +136,9 @@ name_casesbint. name_casesbtext/ httpserver0ÿÿÿÿÿÿÿÿÿR  +name_casesbtext/ + +initialize0ÿÿÿÿÿÿÿÿÿR  name_casesbtext9  exceptions) @@ -543,10 +546,10 @@ Rmysql_binding_valuesbtimez time_value"G json_unicode0ÿÿÿÿÿÿÿÿÿRmysql_binding_valuesbjsonz json_unicode*=9 id0ÿÿÿÿÿÿÿÿÿ8Rmysql_binding_valuesbbigintzid: query.sqlS -#TRUNCATE TABLE mysql_binding_valuesTruncateMysqlBindingValues:exec: query.sqlÐ -‰INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`) +#TRUNCATE TABLE mysql_binding_valuesTruncateMysqlBindingValues:exec: query.sql¬ +šINSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`, `initialize`) VALUES (?, ?, ?, ?, ?, ?, - ?, ?)InsertNameCase:exec*;7 + ?, ?, ?)InsertNameCase:exec*;7 id0ÿÿÿÿÿÿÿÿÿ8Rpublic name_casesbbigintzid*?; class0ÿÿÿÿÿÿÿÿÿ8Rpublic @@ -564,12 +567,18 @@ camel_case0 name_casesbtextz camelcase*JF http_server0ÿÿÿÿÿÿÿÿÿ8Rpublic name_casesbtextz -httpserver: query.sqlB  -name_casesï -ÙSELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases +httpserver*I E + +initialize0ÿÿÿÿÿÿÿÿÿ8Rpublic +name_casesbtextz +initialize: query.sqlB  +name_cases’ + +üSELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? AND `class` = ? AND `end` = ? AND `hash` = ? AND `method` = ? AND `count` = ? - AND `HTTPServer` = ? AND `camelCase` = ? GetNameCase:one"- + AND `HTTPServer` = ? AND `camelCase` = ? + AND `initialize` = ? GetNameCase:one"- id0ÿÿÿÿÿÿÿÿÿR  name_casesbbigintzid"1 class0ÿÿÿÿÿÿÿÿÿR  @@ -587,7 +596,11 @@ name_casesbtextz camelcase"; httpserver0ÿÿÿÿÿÿÿÿÿR  name_casesbtextz -httpserver*3/ +httpserver"; + +initialize0ÿÿÿÿÿÿÿÿÿR  +name_casesbtextz +initialize*3/ id0ÿÿÿÿÿÿÿÿÿ8R  name_casesbbigintzid*73 class0ÿÿÿÿÿÿÿÿÿ8R  @@ -605,8 +618,12 @@ name_casesbtextz httpserver*@< camel_case0ÿÿÿÿÿÿÿÿÿ8R  -name_casesbtextz camelcase: query.sqlÖ -^SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases WHERE id = ? GetHTTPServer:one"- +name_casesbtextz camelcase*A = + +initialize0ÿÿÿÿÿÿÿÿÿ8R  +name_casesbtextz +initialize: query.sqlŸ +jSELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? GetHTTPServer:one"- id0ÿÿÿÿÿÿÿÿÿR  name_casesbbigintzid"1 class0ÿÿÿÿÿÿÿÿÿR  @@ -624,7 +641,11 @@ name_casesbtextz camelcase"; httpserver0ÿÿÿÿÿÿÿÿÿR  name_casesbtextz -httpserver*3/ +httpserver"; + +initialize0ÿÿÿÿÿÿÿÿÿR  +name_casesbtextz +initialize*3/ id0ÿÿÿÿÿÿÿÿÿ8R  name_casesbbigintzid: query.sql@ TRUNCATE TABLE name_casesTruncateNameCases:exec: query.sqlb diff --git a/test/fixtures/pg.bin b/test/fixtures/pg.bin index b653776..465941d 100644 --- a/test/fixtures/pg.bin +++ b/test/fixtures/pg.bin @@ -1,7 +1,7 @@  2 -postgresqlÕ3public"ì/publicÍ +postgresql†4public"�0publicÍ authors) id0ÿÿÿÿÿÿÿÿÿR authorsb  bigserial& name0ÿÿÿÿÿÿÿÿÿR authorsbtextH @@ -126,7 +126,7 @@ pg_catalogbool+ pg_catalogint4ˆ? amounts 0ÿÿÿÿÿÿÿÿÿR  batch_typesb pg_catalognumericˆ6 -stamps 0ÿÿÿÿÿÿÿÿÿR  batch_typesb  timestamptzˆŠ +stamps 0ÿÿÿÿÿÿÿÿÿR  batch_typesb  timestamptzˆ»  name_cases3 id0ÿÿÿÿÿÿÿÿÿR  @@ -147,6 +147,9 @@ pg_catalogint4. name_casesbtext/ HTTPServer0ÿÿÿÿÿÿÿÿÿR  +name_casesbtext/ + +initialize0ÿÿÿÿÿÿÿÿÿR  name_casesbtext<  exceptions, @@ -603,10 +606,10 @@ pg_catalognumericzamounts .SELECT count(*) FROM batch_types WHERE id > $1CountBatchTypesAbove:one" count0ÿÿÿÿÿÿÿÿÿ@bbigint*A= min_id0ÿÿÿÿÿÿÿÿÿ8R  batch_typesbpg_catalog.int8zid: query.sqlB -TRUNCATE TABLE batch_typesTruncateBatchTypes:exec: query.sqlí -‘INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") +TRUNCATE TABLE batch_typesTruncateBatchTypes:exec: query.sqlÊ +£INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES ($1, $2, $3, $4, $5, $6, - $7, $8)InsertNameCase:exec*D@ + $7, $8, $9)InsertNameCase:exec*D@ id0ÿÿÿÿÿÿÿÿÿ8Rpublic name_casesbpg_catalog.int8zid*?; class0ÿÿÿÿÿÿÿÿÿ8Rpublic @@ -624,12 +627,18 @@ camel_case0 name_casesbtextz camelCase*JF http_server0ÿÿÿÿÿÿÿÿÿ8Rpublic name_casesbtextz -HTTPServer: query.sqlB  -name_cases© -çSELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases +HTTPServer*I E + +initialize0ÿÿÿÿÿÿÿÿÿ8Rpublic +name_casesbtextz +initialize: query.sqlB  +name_casesÍ + +‹SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 AND "class" = $2 AND "end" = $3 AND "hash" = $4 AND "method" = $5 AND "count" = $6 - AND "HTTPServer" = $7 AND "camelCase" = $8 GetNameCase:one"7 + AND "HTTPServer" = $7 AND "camelCase" = $8 + AND "initialize" = $9 GetNameCase:one"7 id0ÿÿÿÿÿÿÿÿÿR  name_casesb pg_catalogint8zid"1 @@ -649,7 +658,11 @@ name_casesbtextz camelCase"; HTTPServer0ÿÿÿÿÿÿÿÿÿR  name_casesbtextz -HTTPServer*<8 +HTTPServer"; + +initialize0ÿÿÿÿÿÿÿÿÿR  +name_casesbtextz +initialize*<8 id0ÿÿÿÿÿÿÿÿÿ8R  name_casesbpg_catalog.int8zid*73 class0ÿÿÿÿÿÿÿÿÿ8R  @@ -667,8 +680,12 @@ name_casesbtextz HTTPServer*@< camel_case0ÿÿÿÿÿÿÿÿÿ8R  -name_casesbtextz camelCase: query.sqlý -eSELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases WHERE id = $1 GetHTTPServer:one"7 +name_casesbtextz camelCase*A = + +initialize0ÿÿÿÿÿÿÿÿÿ8R  +name_casesbtextz +initialize: query.sqlÆ +qSELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 GetHTTPServer:one"7 id0ÿÿÿÿÿÿÿÿÿR  name_casesb pg_catalogint8zid"1 @@ -688,7 +705,11 @@ name_casesbtextz camelCase"; HTTPServer0ÿÿÿÿÿÿÿÿÿR  name_casesbtextz -HTTPServer*<8 +HTTPServer"; + +initialize0ÿÿÿÿÿÿÿÿÿR  +name_casesbtextz +initialize*<8 id0ÿÿÿÿÿÿÿÿÿ8R  name_casesbpg_catalog.int8zid: query.sql@ TRUNCATE TABLE name_casesTruncateNameCases:exec: query.sqlb diff --git a/test/fixtures/sqlite3.bin b/test/fixtures/sqlite3.bin index 61de13e..4bec56f 100644 Binary files a/test/fixtures/sqlite3.bin and b/test/fixtures/sqlite3.bin differ diff --git a/test/golden/mysql2/default/models.rb b/test/golden/mysql2/default/models.rb index 0734a54..a15f694 100644 --- a/test/golden/mysql2/default/models.rb +++ b/test/golden/mysql2/default/models.rb @@ -125,7 +125,8 @@ class NameCase < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end diff --git a/test/golden/mysql2/default/models.rbs b/test/golden/mysql2/default/models.rbs index fe32ac9..b79b204 100644 --- a/test/golden/mysql2/default/models.rbs +++ b/test/golden/mysql2/default/models.rbs @@ -202,6 +202,7 @@ module Mysql2Codegen attr_reader count: ::Integer attr_reader camelcase: ::String attr_reader httpserver: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -210,7 +211,8 @@ module Mysql2Codegen ::String method_, ::Integer count, ::String camelcase, - ::String httpserver + ::String httpserver, + ::String initialize_ ) -> void end diff --git a/test/golden/mysql2/default/my_queries_sql.rb b/test/golden/mysql2/default/my_queries_sql.rb index 029db2e..b2cae4a 100644 --- a/test/golden/mysql2/default/my_queries_sql.rb +++ b/test/golden/mysql2/default/my_queries_sql.rb @@ -14,7 +14,7 @@ module Mysql2Codegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end diff --git a/test/golden/mysql2/default/my_queries_sql.rbs b/test/golden/mysql2/default/my_queries_sql.rbs index b1a5299..729a392 100644 --- a/test/golden/mysql2/default/my_queries_sql.rbs +++ b/test/golden/mysql2/default/my_queries_sql.rbs @@ -2,7 +2,7 @@ module Mysql2Codegen WITH_NUMBERS2_GO_SQL: ::String - class My_queriesSql + class MyQueriesSql class NotFound < ::StandardError end diff --git a/test/golden/mysql2/default/query_sql.rb b/test/golden/mysql2/default/query_sql.rb index 4d23aa3..c7ce92d 100644 --- a/test/golden/mysql2/default/query_sql.rb +++ b/test/golden/mysql2/default/query_sql.rb @@ -405,16 +405,17 @@ class GetMysqlBindingValuesRow < ::Data.define( SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`) + INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`, `initialize`) VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? AND `class` = ? AND `end` = ? AND `hash` = ? AND `method` = ? AND `count` = ? AND `HTTPServer` = ? AND `camelCase` = ? + AND `initialize` = ? SQL class GetNameCaseRow < ::Data.define( @@ -425,12 +426,13 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases WHERE id = ? + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? SQL class GetHTTPServerRow < ::Data.define( @@ -441,7 +443,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end @@ -1194,7 +1197,7 @@ def truncate_mysql_binding_values end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1204,14 +1207,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] client.query(bind_params(client, INSERT_NAME_CASE_SQL, query_params)) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1221,7 +1225,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] result = client.query(bind_params(client, GET_NAME_CASE_SQL, query_params), as: :array) row = result.first @@ -1233,7 +1238,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row[4], row[5], row[6], - row[7] + row[7], + row[8] ) end end @@ -1256,7 +1262,8 @@ def get_http_server(id:) row[4], row[5], row[6], - row[7] + row[7], + row[8] ) end end diff --git a/test/golden/mysql2/default/query_sql.rbs b/test/golden/mysql2/default/query_sql.rbs index 290b64b..1d5e3d7 100644 --- a/test/golden/mysql2/default/query_sql.rbs +++ b/test/golden/mysql2/default/query_sql.rbs @@ -455,6 +455,7 @@ module Mysql2Codegen attr_reader count: ::Integer attr_reader camelcase: ::String attr_reader httpserver: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -463,7 +464,8 @@ module Mysql2Codegen ::String method_, ::Integer count, ::String camelcase, - ::String httpserver + ::String httpserver, + ::String initialize_ ) -> void end @@ -478,6 +480,7 @@ module Mysql2Codegen attr_reader count: ::Integer attr_reader camelcase: ::String attr_reader httpserver: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -486,7 +489,8 @@ module Mysql2Codegen ::String method_, ::Integer count, ::String camelcase, - ::String httpserver + ::String httpserver, + ::String initialize_ ) -> void end @@ -688,11 +692,11 @@ module Mysql2Codegen def truncate_mysql_binding_values: -> void - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/test/golden/mysql2/ruby31_gemfile/models.rb b/test/golden/mysql2/ruby31_gemfile/models.rb index e70df14..ceb7f1c 100644 --- a/test/golden/mysql2/ruby31_gemfile/models.rb +++ b/test/golden/mysql2/ruby31_gemfile/models.rb @@ -135,6 +135,7 @@ module RegressionsStep :count_, :camelcase, :httpserver, + :initialize_, keyword_init: true ) diff --git a/test/golden/mysql2/ruby31_gemfile/models.rbs b/test/golden/mysql2/ruby31_gemfile/models.rbs index ddf2fac..e23802b 100644 --- a/test/golden/mysql2/ruby31_gemfile/models.rbs +++ b/test/golden/mysql2/ruby31_gemfile/models.rbs @@ -276,6 +276,7 @@ module Mysql2Codegen attr_accessor count_: ::Integer attr_accessor camelcase: ::String attr_accessor httpserver: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -284,7 +285,8 @@ module Mysql2Codegen method_: ::String, count_: ::Integer, camelcase: ::String, - httpserver: ::String + httpserver: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -294,7 +296,8 @@ module Mysql2Codegen method_: ::String, count_: ::Integer, camelcase: ::String, - httpserver: ::String + httpserver: ::String, + initialize_: ::String ) -> NameCase end diff --git a/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rb b/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rb index 1050094..2aea1a5 100644 --- a/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rb +++ b/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rb @@ -14,7 +14,7 @@ module Mysql2Codegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end diff --git a/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rbs b/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rbs index 351a560..c7b7e0c 100644 --- a/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rbs +++ b/test/golden/mysql2/ruby31_gemfile/my_queries_sql.rbs @@ -2,7 +2,7 @@ module Mysql2Codegen WITH_NUMBERS2_GO_SQL: ::String - class My_queriesSql + class MyQueriesSql class NotFound < ::StandardError end diff --git a/test/golden/mysql2/ruby31_gemfile/query_sql.rb b/test/golden/mysql2/ruby31_gemfile/query_sql.rb index da1ef86..ce8e8e4 100644 --- a/test/golden/mysql2/ruby31_gemfile/query_sql.rb +++ b/test/golden/mysql2/ruby31_gemfile/query_sql.rb @@ -402,16 +402,17 @@ module Mysql2Codegen SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`) + INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`, `initialize`) VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? AND `class` = ? AND `end` = ? AND `hash` = ? AND `method` = ? AND `count` = ? AND `HTTPServer` = ? AND `camelCase` = ? + AND `initialize` = ? SQL GetNameCaseRow = ::Struct.new( @@ -423,11 +424,12 @@ module Mysql2Codegen :count_, :camelcase, :httpserver, + :initialize_, keyword_init: true ) GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases WHERE id = ? + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? SQL GetHTTPServerRow = ::Struct.new( @@ -439,6 +441,7 @@ module Mysql2Codegen :count_, :camelcase, :httpserver, + :initialize_, keyword_init: true ) @@ -1208,7 +1211,7 @@ def truncate_mysql_binding_values end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1218,14 +1221,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] client.query(bind_params(client, INSERT_NAME_CASE_SQL, query_params)) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1235,7 +1239,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] result = client.query(bind_params(client, GET_NAME_CASE_SQL, query_params), as: :array) row = result.first @@ -1247,7 +1252,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method_: row[4], count_: row[5], camelcase: row[6], - httpserver: row[7] + httpserver: row[7], + initialize_: row[8] ) end end @@ -1270,7 +1276,8 @@ def get_http_server(id:) method_: row[4], count_: row[5], camelcase: row[6], - httpserver: row[7] + httpserver: row[7], + initialize_: row[8] ) end end diff --git a/test/golden/mysql2/ruby31_gemfile/query_sql.rbs b/test/golden/mysql2/ruby31_gemfile/query_sql.rbs index e604d39..88953a1 100644 --- a/test/golden/mysql2/ruby31_gemfile/query_sql.rbs +++ b/test/golden/mysql2/ruby31_gemfile/query_sql.rbs @@ -559,6 +559,7 @@ module Mysql2Codegen attr_accessor count_: ::Integer attr_accessor camelcase: ::String attr_accessor httpserver: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -567,7 +568,8 @@ module Mysql2Codegen method_: ::String, count_: ::Integer, camelcase: ::String, - httpserver: ::String + httpserver: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -577,7 +579,8 @@ module Mysql2Codegen method_: ::String, count_: ::Integer, camelcase: ::String, - httpserver: ::String + httpserver: ::String, + initialize_: ::String ) -> GetNameCaseRow end @@ -592,6 +595,7 @@ module Mysql2Codegen attr_accessor count_: ::Integer attr_accessor camelcase: ::String attr_accessor httpserver: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -600,7 +604,8 @@ module Mysql2Codegen method_: ::String, count_: ::Integer, camelcase: ::String, - httpserver: ::String + httpserver: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -610,7 +615,8 @@ module Mysql2Codegen method_: ::String, count_: ::Integer, camelcase: ::String, - httpserver: ::String + httpserver: ::String, + initialize_: ::String ) -> GetHTTPServerRow end @@ -826,11 +832,11 @@ module Mysql2Codegen def truncate_mysql_binding_values: -> void - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/test/golden/mysql2/ruby32_notypes/models.rb b/test/golden/mysql2/ruby32_notypes/models.rb index 0734a54..a15f694 100644 --- a/test/golden/mysql2/ruby32_notypes/models.rb +++ b/test/golden/mysql2/ruby32_notypes/models.rb @@ -125,7 +125,8 @@ class NameCase < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end diff --git a/test/golden/mysql2/ruby32_notypes/my_queries_sql.rb b/test/golden/mysql2/ruby32_notypes/my_queries_sql.rb index 1050094..2aea1a5 100644 --- a/test/golden/mysql2/ruby32_notypes/my_queries_sql.rb +++ b/test/golden/mysql2/ruby32_notypes/my_queries_sql.rb @@ -14,7 +14,7 @@ module Mysql2Codegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end diff --git a/test/golden/mysql2/ruby32_notypes/query_sql.rb b/test/golden/mysql2/ruby32_notypes/query_sql.rb index 576a38b..cc42278 100644 --- a/test/golden/mysql2/ruby32_notypes/query_sql.rb +++ b/test/golden/mysql2/ruby32_notypes/query_sql.rb @@ -405,16 +405,17 @@ class GetMysqlBindingValuesRow < ::Data.define( SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`) + INSERT INTO name_cases (id, `class`, `end`, `hash`, `method`, `count`, `camelCase`, `HTTPServer`, `initialize`) VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? AND `class` = ? AND `end` = ? AND `hash` = ? AND `method` = ? AND `count` = ? AND `HTTPServer` = ? AND `camelCase` = ? + AND `initialize` = ? SQL class GetNameCaseRow < ::Data.define( @@ -425,12 +426,13 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, end, hash, method, count, camelcase, httpserver FROM name_cases WHERE id = ? + SELECT id, class, end, hash, method, count, camelcase, httpserver, initialize FROM name_cases WHERE id = ? SQL class GetHTTPServerRow < ::Data.define( @@ -441,7 +443,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelcase, - :httpserver + :httpserver, + :initialize_ ) end @@ -1197,7 +1200,7 @@ def truncate_mysql_binding_values end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1207,14 +1210,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] client.query(bind_params(client, INSERT_NAME_CASE_SQL, query_params)) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1224,7 +1228,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] result = client.query(bind_params(client, GET_NAME_CASE_SQL, query_params), as: :array) row = result.first @@ -1236,7 +1241,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row[4], row[5], row[6], - row[7] + row[7], + row[8] ) end end @@ -1259,7 +1265,8 @@ def get_http_server(id:) row[4], row[5], row[6], - row[7] + row[7], + row[8] ) end end diff --git a/test/golden/pg/default/models.rb b/test/golden/pg/default/models.rb index ed926d0..cec6c8f 100644 --- a/test/golden/pg/default/models.rb +++ b/test/golden/pg/default/models.rb @@ -138,7 +138,8 @@ class NameCase < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName diff --git a/test/golden/pg/default/models.rbs b/test/golden/pg/default/models.rbs index 46eabfb..b16eb80 100644 --- a/test/golden/pg/default/models.rbs +++ b/test/golden/pg/default/models.rbs @@ -223,6 +223,7 @@ module PgCodegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -231,7 +232,8 @@ module PgCodegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end diff --git a/test/golden/pg/default/my_queries_sql.rb b/test/golden/pg/default/my_queries_sql.rb index 1e2d884..4fd107a 100644 --- a/test/golden/pg/default/my_queries_sql.rb +++ b/test/golden/pg/default/my_queries_sql.rb @@ -12,7 +12,7 @@ module PgCodegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end @@ -99,7 +99,7 @@ def transaction(isolation: nil) def with_numbers2_go(c0:) with_client('with_numbers2_go') do |client| query_params = [c0] - run_prepared(client, 'pg_codegen_my_queries_sql_with_numbers2_go', WITH_NUMBERS2_GO_SQL, query_params) + run_prepared(client, 'PgCodegen::MyQueriesSql#with_numbers2_go', WITH_NUMBERS2_GO_SQL, query_params) nil end end diff --git a/test/golden/pg/default/my_queries_sql.rbs b/test/golden/pg/default/my_queries_sql.rbs index 40982ea..7680864 100644 --- a/test/golden/pg/default/my_queries_sql.rbs +++ b/test/golden/pg/default/my_queries_sql.rbs @@ -2,7 +2,7 @@ module PgCodegen WITH_NUMBERS2_GO_SQL: ::String - class My_queriesSql + class MyQueriesSql class NotFound < ::StandardError end diff --git a/test/golden/pg/default/other_sql.rb b/test/golden/pg/default/other_sql.rb index f5829d1..564d872 100644 --- a/test/golden/pg/default/other_sql.rb +++ b/test/golden/pg/default/other_sql.rb @@ -118,14 +118,14 @@ def no_cols(c0:, c1:, c2:, c3:, c4:) encode_float(c3), encode_bytea(c4) ] - run_prepared(client, 'pg_codegen_other_sql_no_cols', NO_COLS_SQL, query_params) + run_prepared(client, 'PgCodegen::OtherSql#no_cols', NO_COLS_SQL, query_params) nil end end def other_one with_client('other_one') do |client| - result = run_prepared(client, 'pg_codegen_other_sql_other_one', OTHER_ONE_SQL) + result = run_prepared(client, 'PgCodegen::OtherSql#other_one', OTHER_ONE_SQL) row = result.first row && OtherOneRow.new(row['c0']) end @@ -139,7 +139,7 @@ def other_one!(...) def count_rows(c0:) with_client('count_rows') do |client| query_params = [c0] - result = run_prepared(client, 'pg_codegen_other_sql_count_rows', COUNT_ROWS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::OtherSql#count_rows', COUNT_ROWS_SQL, query_params) result.cmd_tuples end end diff --git a/test/golden/pg/default/query_sql.rb b/test/golden/pg/default/query_sql.rb index 9d96255..67248e9 100644 --- a/test/golden/pg/default/query_sql.rb +++ b/test/golden/pg/default/query_sql.rb @@ -488,16 +488,17 @@ class CountBatchTypesAboveRow < ::Data.define(:count) SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES ($1, $2, $3, $4, $5, $6, - $7, $8) + $7, $8, $9) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 AND "class" = $2 AND "end" = $3 AND "hash" = $4 AND "method" = $5 AND "count" = $6 AND "HTTPServer" = $7 AND "camelCase" = $8 + AND "initialize" = $9 SQL # rubocop:disable Naming/MethodName @@ -509,13 +510,14 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases WHERE id = $1 + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 SQL # rubocop:disable Naming/MethodName @@ -527,7 +529,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName @@ -699,7 +702,7 @@ class ExecResult < ::Data.define(:rows_affected, :last_insert_id) def get_author(id:) with_client('get_author') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author', GET_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author', GET_AUTHOR_SQL, query_params) row = result.first row && GetAuthorRow.new(row['id'], row['name'], row['bio']) end @@ -712,7 +715,7 @@ def get_author!(...) def list_authors with_client('list_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors', LIST_AUTHORS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors', LIST_AUTHORS_SQL) result.map do |row| ListAuthorsRow.new(row['id'], row['name'], row['bio']) end @@ -722,7 +725,7 @@ def list_authors def create_author(name:, bio:) with_client('create_author') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author', CREATE_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author', CREATE_AUTHOR_SQL, query_params) row = result.first row && CreateAuthorRow.new(row['id'], row['name'], row['bio']) end @@ -736,14 +739,14 @@ def create_author!(...) def delete_author(id:) with_client('delete_author') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_delete_author', DELETE_AUTHOR_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#delete_author', DELETE_AUTHOR_SQL, query_params) nil end end def test with_client('test') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_test', TEST_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#test', TEST_SQL) row = result.first row && TestRow.new( row['c_bit'], @@ -776,7 +779,7 @@ def test!(...) def set_json_round_trip(id:, json_value:, jsonb_value:) with_client('set_json_round_trip') do |client| query_params = [id, encode_json(json_value), encode_json(jsonb_value)] - run_prepared(client, 'pg_codegen_query_sql_set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) nil end end @@ -784,7 +787,7 @@ def set_json_round_trip(id:, json_value:, jsonb_value:) def get_json_round_trip(id:) with_client('get_json_round_trip') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) row = result.first row && GetJSONRoundTripRow.new(row['json_value'], row['jsonb_value']) end @@ -798,14 +801,14 @@ def get_json_round_trip!(...) def toggle_jsonb_round_trip(id:) with_client('toggle_jsonb_round_trip') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) nil end end def truncate_json_round_trips with_client('truncate_json_round_trips') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) nil end end @@ -813,7 +816,7 @@ def truncate_json_round_trips def pause_query(seconds:) with_client('pause_query') do |client| query_params = [encode_float(seconds)] - run_prepared(client, 'pg_codegen_query_sql_pause_query', PAUSE_QUERY_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#pause_query', PAUSE_QUERY_SQL, query_params) nil end end @@ -821,7 +824,7 @@ def pause_query(seconds:) def list_authors_paged(offset:, limit:) with_client('list_authors_paged') do |client| query_params = [offset, limit] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) result.map do |row| ListAuthorsPagedRow.new(row['id'], row['name'], row['bio']) end @@ -831,7 +834,7 @@ def list_authors_paged(offset:, limit:) def get_author_by_name_pattern(name_pattern: nil) with_client('get_author_by_name_pattern') do |client| query_params = [name_pattern] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) result.map do |row| GetAuthorByNamePatternRow.new(row['id'], row['name'], row['bio']) end @@ -841,7 +844,7 @@ def get_author_by_name_pattern(name_pattern: nil) def get_authors_by_optional_name(lim:, name_filter: nil) with_client('get_authors_by_optional_name') do |client| query_params = [name_filter, lim] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) result.map do |row| GetAuthorsByOptionalNameRow.new(row['id'], row['name'], row['bio']) end @@ -851,7 +854,7 @@ def get_authors_by_optional_name(lim:, name_filter: nil) def create_author_return_id(name:, bio:) with_client('create_author_return_id') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) row = result.first row && row['id'] end @@ -861,7 +864,7 @@ def create_author_return_id(name:, bio:) def update_author_bios(bio:) with_client('update_author_bios') do |client| query_params = [bio] - result = run_prepared(client, 'pg_codegen_query_sql_update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) result.cmd_tuples end end @@ -869,7 +872,7 @@ def update_author_bios(bio:) def get_authors_by_ids(param1:) with_client('get_authors_by_ids') do |client| query_params = [encode_array(param1)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) result.map do |row| GetAuthorsByIdsRow.new(row['id'], row['name'], row['bio']) end @@ -879,7 +882,7 @@ def get_authors_by_ids(param1:) def get_authors_by_ids_and_names(param1:, param2:) with_client('get_authors_by_ids_and_names') do |client| query_params = [encode_array(param1), encode_array(param2)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) result.map do |row| GetAuthorsByIdsAndNamesRow.new(row['id'], row['name'], row['bio']) end @@ -901,7 +904,7 @@ def copy_authors(rows) def truncate_authors with_client('truncate_authors') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_authors', TRUNCATE_AUTHORS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_authors', TRUNCATE_AUTHORS_SQL) nil end end @@ -909,7 +912,7 @@ def truncate_authors def create_book(name:, author_id:) with_client('create_book') do |client| query_params = [name, author_id] - result = run_prepared(client, 'pg_codegen_query_sql_create_book', CREATE_BOOK_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_book', CREATE_BOOK_SQL, query_params) row = result.first row && row['id'] end @@ -918,21 +921,21 @@ def create_book(name:, author_id:) def create_deferred_book(author_id:) with_client('create_deferred_book') do |client| query_params = [author_id] - run_prepared(client, 'pg_codegen_query_sql_create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) nil end end def truncate_deferred_books with_client('truncate_deferred_books') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) nil end end def list_all_authors_books with_client('list_all_authors_books') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values result.map do |row| ListAllAuthorsBooksRow.new( Author.new(row[0], row[1], row[2]), @@ -944,7 +947,7 @@ def list_all_authors_books def get_duplicate_authors with_client('get_duplicate_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values result.map do |row| GetDuplicateAuthorsRow.new(Author.new(row[0], row[1], row[2]), Author.new(row[3], row[4], row[5])) end @@ -954,7 +957,7 @@ def get_duplicate_authors def get_authors_by_book_name(name:) with_client('get_authors_by_book_name') do |client| query_params = [name] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values result.map do |row| GetAuthorsByBookNameRow.new(row[0], row[1], row[2], Book.new(row[3], row[4], row[5], row[6])) end @@ -964,7 +967,7 @@ def get_authors_by_book_name(name:) def create_extended_bio(author_name:, name:, bio_type:) with_client('create_extended_bio') do |client| query_params = [author_name, name, bio_type] - run_prepared(client, 'pg_codegen_query_sql_create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) nil end end @@ -972,7 +975,7 @@ def create_extended_bio(author_name:, name:, bio_type:) def get_first_extended_bio_by_type(bio_type:) with_client('get_first_extended_bio_by_type') do |client| query_params = [bio_type] - result = run_prepared(client, 'pg_codegen_query_sql_get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) row = result.first row && GetFirstExtendedBioByTypeRow.new(row['author_name'], row['name'], row['bio_type']) end @@ -985,7 +988,7 @@ def get_first_extended_bio_by_type!(...) def truncate_extended_bios with_client('truncate_extended_bios') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) nil end end @@ -1002,14 +1005,14 @@ def insert_extra_types(c_uuid:, c_jsonb:, c_text_array:, c_integer_array:, c_tim c_money, c_not_null ] - run_prepared(client, 'pg_codegen_query_sql_insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) nil end end def get_extra_types with_client('get_extra_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_extra_types', GET_EXTRA_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_extra_types', GET_EXTRA_TYPES_SQL) row = result.first row && GetExtraTypesRow.new( row['c_uuid'], @@ -1031,7 +1034,7 @@ def get_extra_types!(...) def truncate_extra_types with_client('truncate_extra_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) nil end end @@ -1053,14 +1056,14 @@ def insert_remaining_types(c_hstore:, c_ltree:, c_regclass:, c_cidr:, c_macaddr: c_timestamptz, encode_array(c_text_matrix) ] - run_prepared(client, 'pg_codegen_query_sql_insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) nil end end def get_remaining_types with_client('get_remaining_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_remaining_types', GET_REMAINING_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_remaining_types', GET_REMAINING_TYPES_SQL) row = result.first row && GetRemainingTypesRow.new( row['c_hstore'], @@ -1087,7 +1090,7 @@ def get_remaining_types!(...) def truncate_remaining_types with_client('truncate_remaining_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) nil end end @@ -1095,14 +1098,14 @@ def truncate_remaining_types def insert_array_types(c_uuid_array:, c_bio_type_array:, c_integer_matrix:) with_client('insert_array_types') do |client| query_params = [encode_array(c_uuid_array), encode_array(c_bio_type_array), encode_array(c_integer_matrix)] - run_prepared(client, 'pg_codegen_query_sql_insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) nil end end def get_array_types with_client('get_array_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_array_types', GET_ARRAY_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_array_types', GET_ARRAY_TYPES_SQL) row = result.first row && GetArrayTypesRow.new(row['c_uuid_array'], row['c_bio_type_array'], row['c_integer_matrix']) end @@ -1115,14 +1118,14 @@ def get_array_types!(...) def truncate_array_types with_client('truncate_array_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) nil end end def list_authors_with_optional_book with_client('list_authors_with_optional_book') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values result.map do |row| ListAuthorsWithOptionalBookRow.new( row[0].nil? && row[1].nil? ? nil : Author.new(row[0], row[1], row[2]), @@ -1135,7 +1138,7 @@ def list_authors_with_optional_book def list_authors_between_ids(id:, id_2:) with_client('list_authors_between_ids') do |client| query_params = [id, id_2] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) result.map do |row| ListAuthorsBetweenIdsRow.new(row['id'], row['name'], row['bio']) end @@ -1153,14 +1156,14 @@ def insert_special_types(c_timetz:, c_tsvector:, c_point:, c_int4range:, c_oid:, c_dimensions, c_positive ] - run_prepared(client, 'pg_codegen_query_sql_insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) nil end end def get_special_types with_client('get_special_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_special_types', GET_SPECIAL_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_special_types', GET_SPECIAL_TYPES_SQL) row = result.first row && GetSpecialTypesRow.new( row['c_timetz'], @@ -1181,7 +1184,7 @@ def get_special_types!(...) def truncate_special_types with_client('truncate_special_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) nil end end @@ -1189,7 +1192,7 @@ def truncate_special_types def create_author_result(name:, bio:) with_client('create_author_result') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) ExecResult.new(result.cmd_tuples, nil) end end @@ -1198,7 +1201,7 @@ def create_authors_batch(rows) with_client('create_authors_batch') do |client| rows.each do |args| query_params = [args.name, args.bio] - run_prepared(client, 'pg_codegen_query_sql_create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) end nil end @@ -1208,7 +1211,7 @@ def get_author_batch(rows) with_client('get_author_batch') do |client| rows.map do |args| query_params = [args.id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) row = result.first row && GetAuthorBatchRow.new(row['id'], row['name'], row['bio']) end @@ -1219,7 +1222,7 @@ def list_authors_by_name_batch(rows) with_client('list_authors_by_name_batch') do |client| rows.map do |args| query_params = [args.name] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) result.map do |row| ListAuthorsByNameBatchRow.new(row['id'], row['name'], row['bio']) end @@ -1237,7 +1240,7 @@ def create_regression(id:, order:, payload:, doc:, bio_types:, uids:) encode_array(bio_types), encode_array(uids) ] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression', CREATE_REGRESSION_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression', CREATE_REGRESSION_SQL, query_params) row = result.first row && CreateRegressionRow.new( row['id'], @@ -1259,7 +1262,7 @@ def create_regression!(...) def create_regression_if_new(id:, order:) with_client('create_regression_if_new') do |client| query_params = [id, order] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) row = result.first row && row['id'] end @@ -1281,7 +1284,7 @@ def create_regressions_batch(rows) with_client('create_regressions_batch') do |client| rows.each do |args| query_params = [args.id, args.order, encode_bytea(args.payload), encode_json(args.doc)] - run_prepared(client, 'pg_codegen_query_sql_create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) end nil end @@ -1290,7 +1293,7 @@ def create_regressions_batch(rows) def list_regressions(order_name: nil) with_client('list_regressions') do |client| query_params = [order_name] - result = run_prepared(client, 'pg_codegen_query_sql_list_regressions', LIST_REGRESSIONS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_regressions', LIST_REGRESSIONS_SQL, query_params) result.map do |row| ListRegressionsRow.new( row['id'], @@ -1308,7 +1311,7 @@ def list_regressions(order_name: nil) def set_regression_step(id:, step:) with_client('set_regression_step') do |client| query_params = [id, step] - result = run_prepared(client, 'pg_codegen_query_sql_set_regression_step', SET_REGRESSION_STEP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#set_regression_step', SET_REGRESSION_STEP_SQL, query_params) row = result.first row && SetRegressionStepRow.new(row['step']) end @@ -1321,7 +1324,7 @@ def set_regression_step!(...) def truncate_regressions with_client('truncate_regressions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_regressions', TRUNCATE_REGRESSIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_regressions', TRUNCATE_REGRESSIONS_SQL) nil end end @@ -1339,7 +1342,7 @@ def create_batch_types_batch(rows) encode_array(args.amounts), encode_array(args.stamps) ] - run_prepared(client, 'pg_codegen_query_sql_create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) end nil end @@ -1359,7 +1362,7 @@ def copy_batch_types(rows) def list_batch_types with_client('list_batch_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_batch_types', LIST_BATCH_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_batch_types', LIST_BATCH_TYPES_SQL) result.map do |row| ListBatchTypesRow.new( row['id'], @@ -1378,7 +1381,7 @@ def list_batch_types def count_batch_types_above(min_id:) with_client('count_batch_types_above') do |client| query_params = [min_id] - result = run_prepared(client, 'pg_codegen_query_sql_count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) row = result.first row && CountBatchTypesAboveRow.new(row['count']) end @@ -1391,12 +1394,12 @@ def count_batch_types_above!(...) def truncate_batch_types with_client('truncate_batch_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) nil end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1406,14 +1409,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] - run_prepared(client, 'pg_codegen_query_sql_insert_name_case', INSERT_NAME_CASE_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_name_case', INSERT_NAME_CASE_SQL, query_params) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1423,9 +1427,10 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] - result = run_prepared(client, 'pg_codegen_query_sql_get_name_case', GET_NAME_CASE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_name_case', GET_NAME_CASE_SQL, query_params) row = result.first row && GetNameCaseRow.new( row['id'], @@ -1435,7 +1440,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row['method'], row['count'], row['camelCase'], - row['HTTPServer'] + row['HTTPServer'], + row['initialize'] ) end end @@ -1448,7 +1454,7 @@ def get_name_case!(...) def get_http_server(id:) with_client('get_http_server') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_http_server', GET_HTTP_SERVER_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_http_server', GET_HTTP_SERVER_SQL, query_params) row = result.first row && GetHTTPServerRow.new( row['id'], @@ -1458,7 +1464,8 @@ def get_http_server(id:) row['method'], row['count'], row['camelCase'], - row['HTTPServer'] + row['HTTPServer'], + row['initialize'] ) end end @@ -1470,14 +1477,14 @@ def get_http_server!(...) def truncate_name_cases with_client('truncate_name_cases') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_name_cases', TRUNCATE_NAME_CASES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_name_cases', TRUNCATE_NAME_CASES_SQL) nil end end def get_unnamed_columns with_client('get_unnamed_columns') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values row = result.first row && GetUnnamedColumnsRow.new(row[0], row[1]) end @@ -1490,7 +1497,7 @@ def get_unnamed_columns!(...) def get_quoted_alias with_client('get_quoted_alias') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_quoted_alias', GET_QUOTED_ALIAS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_quoted_alias', GET_QUOTED_ALIAS_SQL) row = result.first row && GetQuotedAliasRow.new(row['it\'s']) end @@ -1503,14 +1510,14 @@ def get_quoted_alias!(...) def create_exception with_client('create_exception') do |client| - run_prepared(client, 'pg_codegen_query_sql_create_exception', CREATE_EXCEPTION_SQL) + run_prepared(client, 'PgCodegen::QuerySql#create_exception', CREATE_EXCEPTION_SQL) nil end end def count_exceptions with_client('count_exceptions') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_count_exceptions', COUNT_EXCEPTIONS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#count_exceptions', COUNT_EXCEPTIONS_SQL) row = result.first row && CountExceptionsRow.new(row['n']) end @@ -1523,7 +1530,7 @@ def count_exceptions!(...) def truncate_exceptions with_client('truncate_exceptions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) nil end end @@ -1531,7 +1538,7 @@ def truncate_exceptions def create_late_feeling(id:, moods:) with_client('create_late_feeling') do |client| query_params = [id, encode_array(moods)] - run_prepared(client, 'pg_codegen_query_sql_create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) nil end end @@ -1539,7 +1546,7 @@ def create_late_feeling(id:, moods:) def get_late_feeling(id:) with_client('get_late_feeling') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_late_feeling', GET_LATE_FEELING_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_late_feeling', GET_LATE_FEELING_SQL, query_params) row = result.first row && GetLateFeelingRow.new(row['moods']) end @@ -1559,7 +1566,7 @@ def many_params(c0:, c1:, c2:, c3:, c4:) encode_float(c3), encode_bytea(c4) ] - result = run_prepared(client, 'pg_codegen_query_sql_many_params', MANY_PARAMS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#many_params', MANY_PARAMS_SQL, query_params) row = result.first row && ManyParamsRow.new(row['c0'], row['c1']) end @@ -1573,7 +1580,7 @@ def many_params!(...) def many_rows(c0:) with_client('many_rows') do |client| query_params = [c0] - result = run_prepared(client, 'pg_codegen_query_sql_many_rows', MANY_ROWS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#many_rows', MANY_ROWS_SQL, query_params) result.map do |row| ManyRowsRow.new( row['c0'], @@ -1588,7 +1595,7 @@ def many_rows(c0:) def four_cols with_client('four_cols') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_four_cols', FOUR_COLS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#four_cols', FOUR_COLS_SQL) result.map do |row| FourColsRow.new(row['c0'], row['c1'], row['c2'], row['c3']) end diff --git a/test/golden/pg/default/query_sql.rbs b/test/golden/pg/default/query_sql.rbs index 5b4f59f..024b862 100644 --- a/test/golden/pg/default/query_sql.rbs +++ b/test/golden/pg/default/query_sql.rbs @@ -527,6 +527,7 @@ module PgCodegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -535,7 +536,8 @@ module PgCodegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -550,6 +552,7 @@ module PgCodegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -558,7 +561,8 @@ module PgCodegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -790,11 +794,11 @@ module PgCodegen def truncate_batch_types: -> void - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/test/golden/pg/ruby31_gemfile/models.rb b/test/golden/pg/ruby31_gemfile/models.rb index a3c0df3..93ff880 100644 --- a/test/golden/pg/ruby31_gemfile/models.rb +++ b/test/golden/pg/ruby31_gemfile/models.rb @@ -140,6 +140,7 @@ module LateMood :count_, :camelCase, :HTTPServer, + :initialize_, keyword_init: true ) # rubocop:enable Naming/MethodName diff --git a/test/golden/pg/ruby31_gemfile/models.rbs b/test/golden/pg/ruby31_gemfile/models.rbs index 47f8a04..fb8d3c5 100644 --- a/test/golden/pg/ruby31_gemfile/models.rbs +++ b/test/golden/pg/ruby31_gemfile/models.rbs @@ -301,6 +301,7 @@ module PgCodegen attr_accessor count_: ::Integer attr_accessor camelCase: ::String attr_accessor HTTPServer: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -309,7 +310,8 @@ module PgCodegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -319,7 +321,8 @@ module PgCodegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> NameCase end diff --git a/test/golden/pg/ruby31_gemfile/my_queries_sql.rb b/test/golden/pg/ruby31_gemfile/my_queries_sql.rb index c60c7c0..636d2c0 100644 --- a/test/golden/pg/ruby31_gemfile/my_queries_sql.rb +++ b/test/golden/pg/ruby31_gemfile/my_queries_sql.rb @@ -13,7 +13,7 @@ module PgCodegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end @@ -103,7 +103,7 @@ def transaction(isolation: nil) def with_numbers2_go(c0:) with_client('with_numbers2_go') do |client| query_params = [c0] - run_prepared(client, 'pg_codegen_my_queries_sql_with_numbers2_go', WITH_NUMBERS2_GO_SQL, query_params) + run_prepared(client, 'PgCodegen::MyQueriesSql#with_numbers2_go', WITH_NUMBERS2_GO_SQL, query_params) nil end end diff --git a/test/golden/pg/ruby31_gemfile/my_queries_sql.rbs b/test/golden/pg/ruby31_gemfile/my_queries_sql.rbs index e7a7ae1..1a9641c 100644 --- a/test/golden/pg/ruby31_gemfile/my_queries_sql.rbs +++ b/test/golden/pg/ruby31_gemfile/my_queries_sql.rbs @@ -2,7 +2,7 @@ module PgCodegen WITH_NUMBERS2_GO_SQL: ::String - class My_queriesSql + class MyQueriesSql class NotFound < ::StandardError end diff --git a/test/golden/pg/ruby31_gemfile/other_sql.rb b/test/golden/pg/ruby31_gemfile/other_sql.rb index 8d977fe..1375a0d 100644 --- a/test/golden/pg/ruby31_gemfile/other_sql.rb +++ b/test/golden/pg/ruby31_gemfile/other_sql.rb @@ -121,14 +121,14 @@ def no_cols(c0:, c1:, c2:, c3:, c4:) encode_float(c3), encode_bytea(c4) ] - run_prepared(client, 'pg_codegen_other_sql_no_cols', NO_COLS_SQL, query_params) + run_prepared(client, 'PgCodegen::OtherSql#no_cols', NO_COLS_SQL, query_params) nil end end def other_one with_client('other_one') do |client| - result = run_prepared(client, 'pg_codegen_other_sql_other_one', OTHER_ONE_SQL) + result = run_prepared(client, 'PgCodegen::OtherSql#other_one', OTHER_ONE_SQL) row = result.first row && OtherOneRow.new(c0: row['c0']) end @@ -142,7 +142,7 @@ def other_one!(...) def count_rows(c0:) with_client('count_rows') do |client| query_params = [c0] - result = run_prepared(client, 'pg_codegen_other_sql_count_rows', COUNT_ROWS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::OtherSql#count_rows', COUNT_ROWS_SQL, query_params) result.cmd_tuples end end diff --git a/test/golden/pg/ruby31_gemfile/query_sql.rb b/test/golden/pg/ruby31_gemfile/query_sql.rb index 41d9441..dde9022 100644 --- a/test/golden/pg/ruby31_gemfile/query_sql.rb +++ b/test/golden/pg/ruby31_gemfile/query_sql.rb @@ -477,16 +477,17 @@ module PgCodegen SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES ($1, $2, $3, $4, $5, $6, - $7, $8) + $7, $8, $9) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 AND "class" = $2 AND "end" = $3 AND "hash" = $4 AND "method" = $5 AND "count" = $6 AND "HTTPServer" = $7 AND "camelCase" = $8 + AND "initialize" = $9 SQL # rubocop:disable Naming/MethodName @@ -499,12 +500,13 @@ module PgCodegen :count_, :camelCase, :HTTPServer, + :initialize_, keyword_init: true ) # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases WHERE id = $1 + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 SQL # rubocop:disable Naming/MethodName @@ -517,6 +519,7 @@ module PgCodegen :count_, :camelCase, :HTTPServer, + :initialize_, keyword_init: true ) # rubocop:enable Naming/MethodName @@ -690,7 +693,7 @@ def transaction(isolation: nil) def get_author(id:) with_client('get_author') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author', GET_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author', GET_AUTHOR_SQL, query_params) row = result.first row && GetAuthorRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -703,7 +706,7 @@ def get_author!(...) def list_authors with_client('list_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors', LIST_AUTHORS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors', LIST_AUTHORS_SQL) result.map do |row| ListAuthorsRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -713,7 +716,7 @@ def list_authors def create_author(name:, bio:) with_client('create_author') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author', CREATE_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author', CREATE_AUTHOR_SQL, query_params) row = result.first row && CreateAuthorRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -727,14 +730,14 @@ def create_author!(...) def delete_author(id:) with_client('delete_author') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_delete_author', DELETE_AUTHOR_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#delete_author', DELETE_AUTHOR_SQL, query_params) nil end end def test with_client('test') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_test', TEST_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#test', TEST_SQL) row = result.first row && TestRow.new( c_bit: row['c_bit'], @@ -767,7 +770,7 @@ def test!(...) def set_json_round_trip(id:, json_value:, jsonb_value:) with_client('set_json_round_trip') do |client| query_params = [id, encode_json(json_value), encode_json(jsonb_value)] - run_prepared(client, 'pg_codegen_query_sql_set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) nil end end @@ -775,7 +778,7 @@ def set_json_round_trip(id:, json_value:, jsonb_value:) def get_json_round_trip(id:) with_client('get_json_round_trip') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) row = result.first row && GetJSONRoundTripRow.new(json_value: row['json_value'], jsonb_value: row['jsonb_value']) end @@ -789,14 +792,14 @@ def get_json_round_trip!(...) def toggle_jsonb_round_trip(id:) with_client('toggle_jsonb_round_trip') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) nil end end def truncate_json_round_trips with_client('truncate_json_round_trips') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) nil end end @@ -804,7 +807,7 @@ def truncate_json_round_trips def pause_query(seconds:) with_client('pause_query') do |client| query_params = [encode_float(seconds)] - run_prepared(client, 'pg_codegen_query_sql_pause_query', PAUSE_QUERY_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#pause_query', PAUSE_QUERY_SQL, query_params) nil end end @@ -812,7 +815,7 @@ def pause_query(seconds:) def list_authors_paged(offset:, limit:) with_client('list_authors_paged') do |client| query_params = [offset, limit] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) result.map do |row| ListAuthorsPagedRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -822,7 +825,7 @@ def list_authors_paged(offset:, limit:) def get_author_by_name_pattern(name_pattern: nil) with_client('get_author_by_name_pattern') do |client| query_params = [name_pattern] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) result.map do |row| GetAuthorByNamePatternRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -832,7 +835,7 @@ def get_author_by_name_pattern(name_pattern: nil) def get_authors_by_optional_name(lim:, name_filter: nil) with_client('get_authors_by_optional_name') do |client| query_params = [name_filter, lim] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) result.map do |row| GetAuthorsByOptionalNameRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -842,7 +845,7 @@ def get_authors_by_optional_name(lim:, name_filter: nil) def create_author_return_id(name:, bio:) with_client('create_author_return_id') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) row = result.first row && row['id'] end @@ -852,7 +855,7 @@ def create_author_return_id(name:, bio:) def update_author_bios(bio:) with_client('update_author_bios') do |client| query_params = [bio] - result = run_prepared(client, 'pg_codegen_query_sql_update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) result.cmd_tuples end end @@ -860,7 +863,7 @@ def update_author_bios(bio:) def get_authors_by_ids(param1:) with_client('get_authors_by_ids') do |client| query_params = [encode_array(param1)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) result.map do |row| GetAuthorsByIdsRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -870,7 +873,7 @@ def get_authors_by_ids(param1:) def get_authors_by_ids_and_names(param1:, param2:) with_client('get_authors_by_ids_and_names') do |client| query_params = [encode_array(param1), encode_array(param2)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) result.map do |row| GetAuthorsByIdsAndNamesRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -892,7 +895,7 @@ def copy_authors(rows) def truncate_authors with_client('truncate_authors') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_authors', TRUNCATE_AUTHORS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_authors', TRUNCATE_AUTHORS_SQL) nil end end @@ -900,7 +903,7 @@ def truncate_authors def create_book(name:, author_id:) with_client('create_book') do |client| query_params = [name, author_id] - result = run_prepared(client, 'pg_codegen_query_sql_create_book', CREATE_BOOK_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_book', CREATE_BOOK_SQL, query_params) row = result.first row && row['id'] end @@ -909,21 +912,21 @@ def create_book(name:, author_id:) def create_deferred_book(author_id:) with_client('create_deferred_book') do |client| query_params = [author_id] - run_prepared(client, 'pg_codegen_query_sql_create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) nil end end def truncate_deferred_books with_client('truncate_deferred_books') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) nil end end def list_all_authors_books with_client('list_all_authors_books') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values result.map do |row| ListAllAuthorsBooksRow.new( author: Author.new(id: row[0], name: row[1], bio: row[2]), @@ -935,7 +938,7 @@ def list_all_authors_books def get_duplicate_authors with_client('get_duplicate_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values result.map do |row| GetDuplicateAuthorsRow.new( author: Author.new(id: row[0], name: row[1], bio: row[2]), @@ -948,7 +951,7 @@ def get_duplicate_authors def get_authors_by_book_name(name:) with_client('get_authors_by_book_name') do |client| query_params = [name] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values result.map do |row| GetAuthorsByBookNameRow.new( id: row[0], @@ -963,7 +966,7 @@ def get_authors_by_book_name(name:) def create_extended_bio(author_name:, name:, bio_type:) with_client('create_extended_bio') do |client| query_params = [author_name, name, bio_type] - run_prepared(client, 'pg_codegen_query_sql_create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) nil end end @@ -971,7 +974,7 @@ def create_extended_bio(author_name:, name:, bio_type:) def get_first_extended_bio_by_type(bio_type:) with_client('get_first_extended_bio_by_type') do |client| query_params = [bio_type] - result = run_prepared(client, 'pg_codegen_query_sql_get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) row = result.first row && GetFirstExtendedBioByTypeRow.new( author_name: row['author_name'], @@ -988,7 +991,7 @@ def get_first_extended_bio_by_type!(...) def truncate_extended_bios with_client('truncate_extended_bios') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) nil end end @@ -1005,14 +1008,14 @@ def insert_extra_types(c_uuid:, c_jsonb:, c_text_array:, c_integer_array:, c_tim c_money, c_not_null ] - run_prepared(client, 'pg_codegen_query_sql_insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) nil end end def get_extra_types with_client('get_extra_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_extra_types', GET_EXTRA_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_extra_types', GET_EXTRA_TYPES_SQL) row = result.first row && GetExtraTypesRow.new( c_uuid: row['c_uuid'], @@ -1034,7 +1037,7 @@ def get_extra_types!(...) def truncate_extra_types with_client('truncate_extra_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) nil end end @@ -1056,14 +1059,14 @@ def insert_remaining_types(c_hstore:, c_ltree:, c_regclass:, c_cidr:, c_macaddr: c_timestamptz, encode_array(c_text_matrix) ] - run_prepared(client, 'pg_codegen_query_sql_insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) nil end end def get_remaining_types with_client('get_remaining_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_remaining_types', GET_REMAINING_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_remaining_types', GET_REMAINING_TYPES_SQL) row = result.first row && GetRemainingTypesRow.new( c_hstore: row['c_hstore'], @@ -1090,7 +1093,7 @@ def get_remaining_types!(...) def truncate_remaining_types with_client('truncate_remaining_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) nil end end @@ -1098,14 +1101,14 @@ def truncate_remaining_types def insert_array_types(c_uuid_array:, c_bio_type_array:, c_integer_matrix:) with_client('insert_array_types') do |client| query_params = [encode_array(c_uuid_array), encode_array(c_bio_type_array), encode_array(c_integer_matrix)] - run_prepared(client, 'pg_codegen_query_sql_insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) nil end end def get_array_types with_client('get_array_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_array_types', GET_ARRAY_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_array_types', GET_ARRAY_TYPES_SQL) row = result.first row && GetArrayTypesRow.new( c_uuid_array: row['c_uuid_array'], @@ -1122,14 +1125,14 @@ def get_array_types!(...) def truncate_array_types with_client('truncate_array_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) nil end end def list_authors_with_optional_book with_client('list_authors_with_optional_book') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values result.map do |row| ListAuthorsWithOptionalBookRow.new( author: row[0].nil? && row[1].nil? ? nil : Author.new(id: row[0], name: row[1], bio: row[2]), @@ -1142,7 +1145,7 @@ def list_authors_with_optional_book def list_authors_between_ids(id:, id_2:) with_client('list_authors_between_ids') do |client| query_params = [id, id_2] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) result.map do |row| ListAuthorsBetweenIdsRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -1160,14 +1163,14 @@ def insert_special_types(c_timetz:, c_tsvector:, c_point:, c_int4range:, c_oid:, c_dimensions, c_positive ] - run_prepared(client, 'pg_codegen_query_sql_insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) nil end end def get_special_types with_client('get_special_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_special_types', GET_SPECIAL_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_special_types', GET_SPECIAL_TYPES_SQL) row = result.first row && GetSpecialTypesRow.new( c_timetz: row['c_timetz'], @@ -1188,7 +1191,7 @@ def get_special_types!(...) def truncate_special_types with_client('truncate_special_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) nil end end @@ -1196,7 +1199,7 @@ def truncate_special_types def create_author_result(name:, bio:) with_client('create_author_result') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) ExecResult.new(rows_affected: result.cmd_tuples, last_insert_id: nil) end end @@ -1205,7 +1208,7 @@ def create_authors_batch(rows) with_client('create_authors_batch') do |client| rows.each do |args| query_params = [args.name, args.bio] - run_prepared(client, 'pg_codegen_query_sql_create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) end nil end @@ -1215,7 +1218,7 @@ def get_author_batch(rows) with_client('get_author_batch') do |client| rows.map do |args| query_params = [args.id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) row = result.first row && GetAuthorBatchRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -1226,7 +1229,7 @@ def list_authors_by_name_batch(rows) with_client('list_authors_by_name_batch') do |client| rows.map do |args| query_params = [args.name] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) result.map do |row| ListAuthorsByNameBatchRow.new(id: row['id'], name: row['name'], bio: row['bio']) end @@ -1244,7 +1247,7 @@ def create_regression(id:, order:, payload:, doc:, bio_types:, uids:) encode_array(bio_types), encode_array(uids) ] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression', CREATE_REGRESSION_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression', CREATE_REGRESSION_SQL, query_params) row = result.first row && CreateRegressionRow.new( id: row['id'], @@ -1266,7 +1269,7 @@ def create_regression!(...) def create_regression_if_new(id:, order:) with_client('create_regression_if_new') do |client| query_params = [id, order] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) row = result.first row && row['id'] end @@ -1288,7 +1291,7 @@ def create_regressions_batch(rows) with_client('create_regressions_batch') do |client| rows.each do |args| query_params = [args.id, args.order, encode_bytea(args.payload), encode_json(args.doc)] - run_prepared(client, 'pg_codegen_query_sql_create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) end nil end @@ -1297,7 +1300,7 @@ def create_regressions_batch(rows) def list_regressions(order_name: nil) with_client('list_regressions') do |client| query_params = [order_name] - result = run_prepared(client, 'pg_codegen_query_sql_list_regressions', LIST_REGRESSIONS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_regressions', LIST_REGRESSIONS_SQL, query_params) result.map do |row| ListRegressionsRow.new( id: row['id'], @@ -1315,7 +1318,7 @@ def list_regressions(order_name: nil) def set_regression_step(id:, step:) with_client('set_regression_step') do |client| query_params = [id, step] - result = run_prepared(client, 'pg_codegen_query_sql_set_regression_step', SET_REGRESSION_STEP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#set_regression_step', SET_REGRESSION_STEP_SQL, query_params) row = result.first row && SetRegressionStepRow.new(step: row['step']) end @@ -1328,7 +1331,7 @@ def set_regression_step!(...) def truncate_regressions with_client('truncate_regressions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_regressions', TRUNCATE_REGRESSIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_regressions', TRUNCATE_REGRESSIONS_SQL) nil end end @@ -1346,7 +1349,7 @@ def create_batch_types_batch(rows) encode_array(args.amounts), encode_array(args.stamps) ] - run_prepared(client, 'pg_codegen_query_sql_create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) end nil end @@ -1366,7 +1369,7 @@ def copy_batch_types(rows) def list_batch_types with_client('list_batch_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_batch_types', LIST_BATCH_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_batch_types', LIST_BATCH_TYPES_SQL) result.map do |row| ListBatchTypesRow.new( id: row['id'], @@ -1385,7 +1388,7 @@ def list_batch_types def count_batch_types_above(min_id:) with_client('count_batch_types_above') do |client| query_params = [min_id] - result = run_prepared(client, 'pg_codegen_query_sql_count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) row = result.first row && CountBatchTypesAboveRow.new(count_: row['count']) end @@ -1398,12 +1401,12 @@ def count_batch_types_above!(...) def truncate_batch_types with_client('truncate_batch_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) nil end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1413,14 +1416,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] - run_prepared(client, 'pg_codegen_query_sql_insert_name_case', INSERT_NAME_CASE_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_name_case', INSERT_NAME_CASE_SQL, query_params) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1430,9 +1434,10 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] - result = run_prepared(client, 'pg_codegen_query_sql_get_name_case', GET_NAME_CASE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_name_case', GET_NAME_CASE_SQL, query_params) row = result.first row && GetNameCaseRow.new( id: row['id'], @@ -1442,7 +1447,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method_: row['method'], count_: row['count'], camelCase: row['camelCase'], - HTTPServer: row['HTTPServer'] + HTTPServer: row['HTTPServer'], + initialize_: row['initialize'] ) end end @@ -1455,7 +1461,7 @@ def get_name_case!(...) def get_http_server(id:) with_client('get_http_server') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_http_server', GET_HTTP_SERVER_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_http_server', GET_HTTP_SERVER_SQL, query_params) row = result.first row && GetHTTPServerRow.new( id: row['id'], @@ -1465,7 +1471,8 @@ def get_http_server(id:) method_: row['method'], count_: row['count'], camelCase: row['camelCase'], - HTTPServer: row['HTTPServer'] + HTTPServer: row['HTTPServer'], + initialize_: row['initialize'] ) end end @@ -1477,7 +1484,7 @@ def get_http_server!(...) def truncate_name_cases with_client('truncate_name_cases') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_name_cases', TRUNCATE_NAME_CASES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_name_cases', TRUNCATE_NAME_CASES_SQL) nil end end @@ -1485,7 +1492,7 @@ def truncate_name_cases # rubocop:disable Naming/VariableNumber def get_unnamed_columns with_client('get_unnamed_columns') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values row = result.first row && GetUnnamedColumnsRow.new(column_1: row[0], column_2: row[1]) end @@ -1499,7 +1506,7 @@ def get_unnamed_columns!(...) def get_quoted_alias with_client('get_quoted_alias') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_quoted_alias', GET_QUOTED_ALIAS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_quoted_alias', GET_QUOTED_ALIAS_SQL) row = result.first row && GetQuotedAliasRow.new(it_s: row['it\'s']) end @@ -1512,14 +1519,14 @@ def get_quoted_alias!(...) def create_exception with_client('create_exception') do |client| - run_prepared(client, 'pg_codegen_query_sql_create_exception', CREATE_EXCEPTION_SQL) + run_prepared(client, 'PgCodegen::QuerySql#create_exception', CREATE_EXCEPTION_SQL) nil end end def count_exceptions with_client('count_exceptions') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_count_exceptions', COUNT_EXCEPTIONS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#count_exceptions', COUNT_EXCEPTIONS_SQL) row = result.first row && CountExceptionsRow.new(n: row['n']) end @@ -1532,7 +1539,7 @@ def count_exceptions!(...) def truncate_exceptions with_client('truncate_exceptions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) nil end end @@ -1540,7 +1547,7 @@ def truncate_exceptions def create_late_feeling(id:, moods:) with_client('create_late_feeling') do |client| query_params = [id, encode_array(moods)] - run_prepared(client, 'pg_codegen_query_sql_create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) nil end end @@ -1548,7 +1555,7 @@ def create_late_feeling(id:, moods:) def get_late_feeling(id:) with_client('get_late_feeling') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_late_feeling', GET_LATE_FEELING_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_late_feeling', GET_LATE_FEELING_SQL, query_params) row = result.first row && GetLateFeelingRow.new(moods: row['moods']) end @@ -1568,7 +1575,7 @@ def many_params(c0:, c1:, c2:, c3:, c4:) encode_float(c3), encode_bytea(c4) ] - result = run_prepared(client, 'pg_codegen_query_sql_many_params', MANY_PARAMS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#many_params', MANY_PARAMS_SQL, query_params) row = result.first row && ManyParamsRow.new(c0: row['c0'], c1: row['c1']) end @@ -1582,7 +1589,7 @@ def many_params!(...) def many_rows(c0:) with_client('many_rows') do |client| query_params = [c0] - result = run_prepared(client, 'pg_codegen_query_sql_many_rows', MANY_ROWS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#many_rows', MANY_ROWS_SQL, query_params) result.map do |row| ManyRowsRow.new( c0: row['c0'], @@ -1597,7 +1604,7 @@ def many_rows(c0:) def four_cols with_client('four_cols') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_four_cols', FOUR_COLS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#four_cols', FOUR_COLS_SQL) result.map do |row| FourColsRow.new(c0: row['c0'], c1: row['c1'], c2: row['c2'], c3: row['c3']) end diff --git a/test/golden/pg/ruby31_gemfile/query_sql.rbs b/test/golden/pg/ruby31_gemfile/query_sql.rbs index fa8480c..6386ee1 100644 --- a/test/golden/pg/ruby31_gemfile/query_sql.rbs +++ b/test/golden/pg/ruby31_gemfile/query_sql.rbs @@ -659,6 +659,7 @@ module PgCodegen attr_accessor count_: ::Integer attr_accessor camelCase: ::String attr_accessor HTTPServer: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -667,7 +668,8 @@ module PgCodegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -677,7 +679,8 @@ module PgCodegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> GetNameCaseRow end @@ -692,6 +695,7 @@ module PgCodegen attr_accessor count_: ::Integer attr_accessor camelCase: ::String attr_accessor HTTPServer: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -700,7 +704,8 @@ module PgCodegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -710,7 +715,8 @@ module PgCodegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> GetHTTPServerRow end @@ -956,11 +962,11 @@ module PgCodegen def truncate_batch_types: -> void - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/test/golden/pg/ruby32_notypes/models.rb b/test/golden/pg/ruby32_notypes/models.rb index ed926d0..cec6c8f 100644 --- a/test/golden/pg/ruby32_notypes/models.rb +++ b/test/golden/pg/ruby32_notypes/models.rb @@ -138,7 +138,8 @@ class NameCase < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName diff --git a/test/golden/pg/ruby32_notypes/my_queries_sql.rb b/test/golden/pg/ruby32_notypes/my_queries_sql.rb index a9233af..ddbf24c 100644 --- a/test/golden/pg/ruby32_notypes/my_queries_sql.rb +++ b/test/golden/pg/ruby32_notypes/my_queries_sql.rb @@ -12,7 +12,7 @@ module PgCodegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end @@ -102,7 +102,7 @@ def transaction(isolation: nil) def with_numbers2_go(c0:) with_client('with_numbers2_go') do |client| query_params = [c0] - run_prepared(client, 'pg_codegen_my_queries_sql_with_numbers2_go', WITH_NUMBERS2_GO_SQL, query_params) + run_prepared(client, 'PgCodegen::MyQueriesSql#with_numbers2_go', WITH_NUMBERS2_GO_SQL, query_params) nil end end diff --git a/test/golden/pg/ruby32_notypes/other_sql.rb b/test/golden/pg/ruby32_notypes/other_sql.rb index fb4c463..5b7fd27 100644 --- a/test/golden/pg/ruby32_notypes/other_sql.rb +++ b/test/golden/pg/ruby32_notypes/other_sql.rb @@ -121,14 +121,14 @@ def no_cols(c0:, c1:, c2:, c3:, c4:) encode_float(c3), encode_bytea(c4) ] - run_prepared(client, 'pg_codegen_other_sql_no_cols', NO_COLS_SQL, query_params) + run_prepared(client, 'PgCodegen::OtherSql#no_cols', NO_COLS_SQL, query_params) nil end end def other_one with_client('other_one') do |client| - result = run_prepared(client, 'pg_codegen_other_sql_other_one', OTHER_ONE_SQL) + result = run_prepared(client, 'PgCodegen::OtherSql#other_one', OTHER_ONE_SQL) row = result.first row && OtherOneRow.new(row['c0']) end @@ -142,7 +142,7 @@ def other_one!(...) def count_rows(c0:) with_client('count_rows') do |client| query_params = [c0] - result = run_prepared(client, 'pg_codegen_other_sql_count_rows', COUNT_ROWS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::OtherSql#count_rows', COUNT_ROWS_SQL, query_params) result.cmd_tuples end end diff --git a/test/golden/pg/ruby32_notypes/query_sql.rb b/test/golden/pg/ruby32_notypes/query_sql.rb index 602a0d7..2ba17b4 100644 --- a/test/golden/pg/ruby32_notypes/query_sql.rb +++ b/test/golden/pg/ruby32_notypes/query_sql.rb @@ -488,16 +488,17 @@ class CountBatchTypesAboveRow < ::Data.define(:count) SQL INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES ($1, $2, $3, $4, $5, $6, - $7, $8) + $7, $8, $9) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 AND "class" = $2 AND "end" = $3 AND "hash" = $4 AND "method" = $5 AND "count" = $6 AND "HTTPServer" = $7 AND "camelCase" = $8 + AND "initialize" = $9 SQL # rubocop:disable Naming/MethodName @@ -509,13 +510,14 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer" FROM name_cases WHERE id = $1 + SELECT id, class, "end", hash, method, count, "camelCase", "HTTPServer", initialize FROM name_cases WHERE id = $1 SQL # rubocop:disable Naming/MethodName @@ -527,7 +529,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName @@ -702,7 +705,7 @@ class ExecResult < ::Data.define(:rows_affected, :last_insert_id) def get_author(id:) with_client('get_author') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author', GET_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author', GET_AUTHOR_SQL, query_params) row = result.first row && GetAuthorRow.new(row['id'], row['name'], row['bio']) end @@ -715,7 +718,7 @@ def get_author!(...) def list_authors with_client('list_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors', LIST_AUTHORS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors', LIST_AUTHORS_SQL) result.map do |row| ListAuthorsRow.new(row['id'], row['name'], row['bio']) end @@ -725,7 +728,7 @@ def list_authors def create_author(name:, bio:) with_client('create_author') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author', CREATE_AUTHOR_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author', CREATE_AUTHOR_SQL, query_params) row = result.first row && CreateAuthorRow.new(row['id'], row['name'], row['bio']) end @@ -739,14 +742,14 @@ def create_author!(...) def delete_author(id:) with_client('delete_author') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_delete_author', DELETE_AUTHOR_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#delete_author', DELETE_AUTHOR_SQL, query_params) nil end end def test with_client('test') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_test', TEST_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#test', TEST_SQL) row = result.first row && TestRow.new( row['c_bit'], @@ -779,7 +782,7 @@ def test!(...) def set_json_round_trip(id:, json_value:, jsonb_value:) with_client('set_json_round_trip') do |client| query_params = [id, encode_json(json_value), encode_json(jsonb_value)] - run_prepared(client, 'pg_codegen_query_sql_set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#set_json_round_trip', SET_JSON_ROUND_TRIP_SQL, query_params) nil end end @@ -787,7 +790,7 @@ def set_json_round_trip(id:, json_value:, jsonb_value:) def get_json_round_trip(id:) with_client('get_json_round_trip') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_json_round_trip', GET_JSON_ROUND_TRIP_SQL, query_params) row = result.first row && GetJSONRoundTripRow.new(row['json_value'], row['jsonb_value']) end @@ -801,14 +804,14 @@ def get_json_round_trip!(...) def toggle_jsonb_round_trip(id:) with_client('toggle_jsonb_round_trip') do |client| query_params = [id] - run_prepared(client, 'pg_codegen_query_sql_toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#toggle_jsonb_round_trip', TOGGLE_JSONB_ROUND_TRIP_SQL, query_params) nil end end def truncate_json_round_trips with_client('truncate_json_round_trips') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_json_round_trips', TRUNCATE_JSON_ROUND_TRIPS_SQL) nil end end @@ -816,7 +819,7 @@ def truncate_json_round_trips def pause_query(seconds:) with_client('pause_query') do |client| query_params = [encode_float(seconds)] - run_prepared(client, 'pg_codegen_query_sql_pause_query', PAUSE_QUERY_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#pause_query', PAUSE_QUERY_SQL, query_params) nil end end @@ -824,7 +827,7 @@ def pause_query(seconds:) def list_authors_paged(offset:, limit:) with_client('list_authors_paged') do |client| query_params = [offset, limit] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_paged', LIST_AUTHORS_PAGED_SQL, query_params) result.map do |row| ListAuthorsPagedRow.new(row['id'], row['name'], row['bio']) end @@ -834,7 +837,7 @@ def list_authors_paged(offset:, limit:) def get_author_by_name_pattern(name_pattern: nil) with_client('get_author_by_name_pattern') do |client| query_params = [name_pattern] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_by_name_pattern', GET_AUTHOR_BY_NAME_PATTERN_SQL, query_params) result.map do |row| GetAuthorByNamePatternRow.new(row['id'], row['name'], row['bio']) end @@ -844,7 +847,7 @@ def get_author_by_name_pattern(name_pattern: nil) def get_authors_by_optional_name(lim:, name_filter: nil) with_client('get_authors_by_optional_name') do |client| query_params = [name_filter, lim] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_optional_name', GET_AUTHORS_BY_OPTIONAL_NAME_SQL, query_params) result.map do |row| GetAuthorsByOptionalNameRow.new(row['id'], row['name'], row['bio']) end @@ -854,7 +857,7 @@ def get_authors_by_optional_name(lim:, name_filter: nil) def create_author_return_id(name:, bio:) with_client('create_author_return_id') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_return_id', CREATE_AUTHOR_RETURN_ID_SQL, query_params) row = result.first row && row['id'] end @@ -864,7 +867,7 @@ def create_author_return_id(name:, bio:) def update_author_bios(bio:) with_client('update_author_bios') do |client| query_params = [bio] - result = run_prepared(client, 'pg_codegen_query_sql_update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#update_author_bios', UPDATE_AUTHOR_BIOS_SQL, query_params) result.cmd_tuples end end @@ -872,7 +875,7 @@ def update_author_bios(bio:) def get_authors_by_ids(param1:) with_client('get_authors_by_ids') do |client| query_params = [encode_array(param1)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids', GET_AUTHORS_BY_IDS_SQL, query_params) result.map do |row| GetAuthorsByIdsRow.new(row['id'], row['name'], row['bio']) end @@ -882,7 +885,7 @@ def get_authors_by_ids(param1:) def get_authors_by_ids_and_names(param1:, param2:) with_client('get_authors_by_ids_and_names') do |client| query_params = [encode_array(param1), encode_array(param2)] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_ids_and_names', GET_AUTHORS_BY_IDS_AND_NAMES_SQL, query_params) result.map do |row| GetAuthorsByIdsAndNamesRow.new(row['id'], row['name'], row['bio']) end @@ -904,7 +907,7 @@ def copy_authors(rows) def truncate_authors with_client('truncate_authors') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_authors', TRUNCATE_AUTHORS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_authors', TRUNCATE_AUTHORS_SQL) nil end end @@ -912,7 +915,7 @@ def truncate_authors def create_book(name:, author_id:) with_client('create_book') do |client| query_params = [name, author_id] - result = run_prepared(client, 'pg_codegen_query_sql_create_book', CREATE_BOOK_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_book', CREATE_BOOK_SQL, query_params) row = result.first row && row['id'] end @@ -921,21 +924,21 @@ def create_book(name:, author_id:) def create_deferred_book(author_id:) with_client('create_deferred_book') do |client| query_params = [author_id] - run_prepared(client, 'pg_codegen_query_sql_create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_deferred_book', CREATE_DEFERRED_BOOK_SQL, query_params) nil end end def truncate_deferred_books with_client('truncate_deferred_books') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_deferred_books', TRUNCATE_DEFERRED_BOOKS_SQL) nil end end def list_all_authors_books with_client('list_all_authors_books') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_all_authors_books', LIST_ALL_AUTHORS_BOOKS_SQL).values result.map do |row| ListAllAuthorsBooksRow.new( Author.new(row[0], row[1], row[2]), @@ -947,7 +950,7 @@ def list_all_authors_books def get_duplicate_authors with_client('get_duplicate_authors') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_duplicate_authors', GET_DUPLICATE_AUTHORS_SQL).values result.map do |row| GetDuplicateAuthorsRow.new(Author.new(row[0], row[1], row[2]), Author.new(row[3], row[4], row[5])) end @@ -957,7 +960,7 @@ def get_duplicate_authors def get_authors_by_book_name(name:) with_client('get_authors_by_book_name') do |client| query_params = [name] - result = run_prepared(client, 'pg_codegen_query_sql_get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_authors_by_book_name', GET_AUTHORS_BY_BOOK_NAME_SQL, query_params).values result.map do |row| GetAuthorsByBookNameRow.new(row[0], row[1], row[2], Book.new(row[3], row[4], row[5], row[6])) end @@ -967,7 +970,7 @@ def get_authors_by_book_name(name:) def create_extended_bio(author_name:, name:, bio_type:) with_client('create_extended_bio') do |client| query_params = [author_name, name, bio_type] - run_prepared(client, 'pg_codegen_query_sql_create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_extended_bio', CREATE_EXTENDED_BIO_SQL, query_params) nil end end @@ -975,7 +978,7 @@ def create_extended_bio(author_name:, name:, bio_type:) def get_first_extended_bio_by_type(bio_type:) with_client('get_first_extended_bio_by_type') do |client| query_params = [bio_type] - result = run_prepared(client, 'pg_codegen_query_sql_get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_first_extended_bio_by_type', GET_FIRST_EXTENDED_BIO_BY_TYPE_SQL, query_params) row = result.first row && GetFirstExtendedBioByTypeRow.new(row['author_name'], row['name'], row['bio_type']) end @@ -988,7 +991,7 @@ def get_first_extended_bio_by_type!(...) def truncate_extended_bios with_client('truncate_extended_bios') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extended_bios', TRUNCATE_EXTENDED_BIOS_SQL) nil end end @@ -1005,14 +1008,14 @@ def insert_extra_types(c_uuid:, c_jsonb:, c_text_array:, c_integer_array:, c_tim c_money, c_not_null ] - run_prepared(client, 'pg_codegen_query_sql_insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_extra_types', INSERT_EXTRA_TYPES_SQL, query_params) nil end end def get_extra_types with_client('get_extra_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_extra_types', GET_EXTRA_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_extra_types', GET_EXTRA_TYPES_SQL) row = result.first row && GetExtraTypesRow.new( row['c_uuid'], @@ -1034,7 +1037,7 @@ def get_extra_types!(...) def truncate_extra_types with_client('truncate_extra_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_extra_types', TRUNCATE_EXTRA_TYPES_SQL) nil end end @@ -1056,14 +1059,14 @@ def insert_remaining_types(c_hstore:, c_ltree:, c_regclass:, c_cidr:, c_macaddr: c_timestamptz, encode_array(c_text_matrix) ] - run_prepared(client, 'pg_codegen_query_sql_insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_remaining_types', INSERT_REMAINING_TYPES_SQL, query_params) nil end end def get_remaining_types with_client('get_remaining_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_remaining_types', GET_REMAINING_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_remaining_types', GET_REMAINING_TYPES_SQL) row = result.first row && GetRemainingTypesRow.new( row['c_hstore'], @@ -1090,7 +1093,7 @@ def get_remaining_types!(...) def truncate_remaining_types with_client('truncate_remaining_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_remaining_types', TRUNCATE_REMAINING_TYPES_SQL) nil end end @@ -1098,14 +1101,14 @@ def truncate_remaining_types def insert_array_types(c_uuid_array:, c_bio_type_array:, c_integer_matrix:) with_client('insert_array_types') do |client| query_params = [encode_array(c_uuid_array), encode_array(c_bio_type_array), encode_array(c_integer_matrix)] - run_prepared(client, 'pg_codegen_query_sql_insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_array_types', INSERT_ARRAY_TYPES_SQL, query_params) nil end end def get_array_types with_client('get_array_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_array_types', GET_ARRAY_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_array_types', GET_ARRAY_TYPES_SQL) row = result.first row && GetArrayTypesRow.new(row['c_uuid_array'], row['c_bio_type_array'], row['c_integer_matrix']) end @@ -1118,14 +1121,14 @@ def get_array_types!(...) def truncate_array_types with_client('truncate_array_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_array_types', TRUNCATE_ARRAY_TYPES_SQL) nil end end def list_authors_with_optional_book with_client('list_authors_with_optional_book') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_with_optional_book', LIST_AUTHORS_WITH_OPTIONAL_BOOK_SQL).values result.map do |row| ListAuthorsWithOptionalBookRow.new( row[0].nil? && row[1].nil? ? nil : Author.new(row[0], row[1], row[2]), @@ -1138,7 +1141,7 @@ def list_authors_with_optional_book def list_authors_between_ids(id:, id_2:) with_client('list_authors_between_ids') do |client| query_params = [id, id_2] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_between_ids', LIST_AUTHORS_BETWEEN_IDS_SQL, query_params) result.map do |row| ListAuthorsBetweenIdsRow.new(row['id'], row['name'], row['bio']) end @@ -1156,14 +1159,14 @@ def insert_special_types(c_timetz:, c_tsvector:, c_point:, c_int4range:, c_oid:, c_dimensions, c_positive ] - run_prepared(client, 'pg_codegen_query_sql_insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_special_types', INSERT_SPECIAL_TYPES_SQL, query_params) nil end end def get_special_types with_client('get_special_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_special_types', GET_SPECIAL_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_special_types', GET_SPECIAL_TYPES_SQL) row = result.first row && GetSpecialTypesRow.new( row['c_timetz'], @@ -1184,7 +1187,7 @@ def get_special_types!(...) def truncate_special_types with_client('truncate_special_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_special_types', TRUNCATE_SPECIAL_TYPES_SQL) nil end end @@ -1192,7 +1195,7 @@ def truncate_special_types def create_author_result(name:, bio:) with_client('create_author_result') do |client| query_params = [name, bio] - result = run_prepared(client, 'pg_codegen_query_sql_create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_author_result', CREATE_AUTHOR_RESULT_SQL, query_params) ExecResult.new(result.cmd_tuples, nil) end end @@ -1201,7 +1204,7 @@ def create_authors_batch(rows) with_client('create_authors_batch') do |client| rows.each do |args| query_params = [args.name, args.bio] - run_prepared(client, 'pg_codegen_query_sql_create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_authors_batch', CREATE_AUTHORS_BATCH_SQL, query_params) end nil end @@ -1211,7 +1214,7 @@ def get_author_batch(rows) with_client('get_author_batch') do |client| rows.map do |args| query_params = [args.id] - result = run_prepared(client, 'pg_codegen_query_sql_get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_author_batch', GET_AUTHOR_BATCH_SQL, query_params) row = result.first row && GetAuthorBatchRow.new(row['id'], row['name'], row['bio']) end @@ -1222,7 +1225,7 @@ def list_authors_by_name_batch(rows) with_client('list_authors_by_name_batch') do |client| rows.map do |args| query_params = [args.name] - result = run_prepared(client, 'pg_codegen_query_sql_list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_authors_by_name_batch', LIST_AUTHORS_BY_NAME_BATCH_SQL, query_params) result.map do |row| ListAuthorsByNameBatchRow.new(row['id'], row['name'], row['bio']) end @@ -1240,7 +1243,7 @@ def create_regression(id:, order:, payload:, doc:, bio_types:, uids:) encode_array(bio_types), encode_array(uids) ] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression', CREATE_REGRESSION_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression', CREATE_REGRESSION_SQL, query_params) row = result.first row && CreateRegressionRow.new( row['id'], @@ -1262,7 +1265,7 @@ def create_regression!(...) def create_regression_if_new(id:, order:) with_client('create_regression_if_new') do |client| query_params = [id, order] - result = run_prepared(client, 'pg_codegen_query_sql_create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#create_regression_if_new', CREATE_REGRESSION_IF_NEW_SQL, query_params) row = result.first row && row['id'] end @@ -1284,7 +1287,7 @@ def create_regressions_batch(rows) with_client('create_regressions_batch') do |client| rows.each do |args| query_params = [args.id, args.order, encode_bytea(args.payload), encode_json(args.doc)] - run_prepared(client, 'pg_codegen_query_sql_create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_regressions_batch', CREATE_REGRESSIONS_BATCH_SQL, query_params) end nil end @@ -1293,7 +1296,7 @@ def create_regressions_batch(rows) def list_regressions(order_name: nil) with_client('list_regressions') do |client| query_params = [order_name] - result = run_prepared(client, 'pg_codegen_query_sql_list_regressions', LIST_REGRESSIONS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#list_regressions', LIST_REGRESSIONS_SQL, query_params) result.map do |row| ListRegressionsRow.new( row['id'], @@ -1311,7 +1314,7 @@ def list_regressions(order_name: nil) def set_regression_step(id:, step:) with_client('set_regression_step') do |client| query_params = [id, step] - result = run_prepared(client, 'pg_codegen_query_sql_set_regression_step', SET_REGRESSION_STEP_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#set_regression_step', SET_REGRESSION_STEP_SQL, query_params) row = result.first row && SetRegressionStepRow.new(row['step']) end @@ -1324,7 +1327,7 @@ def set_regression_step!(...) def truncate_regressions with_client('truncate_regressions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_regressions', TRUNCATE_REGRESSIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_regressions', TRUNCATE_REGRESSIONS_SQL) nil end end @@ -1342,7 +1345,7 @@ def create_batch_types_batch(rows) encode_array(args.amounts), encode_array(args.stamps) ] - run_prepared(client, 'pg_codegen_query_sql_create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_batch_types_batch', CREATE_BATCH_TYPES_BATCH_SQL, query_params) end nil end @@ -1362,7 +1365,7 @@ def copy_batch_types(rows) def list_batch_types with_client('list_batch_types') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_list_batch_types', LIST_BATCH_TYPES_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#list_batch_types', LIST_BATCH_TYPES_SQL) result.map do |row| ListBatchTypesRow.new( row['id'], @@ -1381,7 +1384,7 @@ def list_batch_types def count_batch_types_above(min_id:) with_client('count_batch_types_above') do |client| query_params = [min_id] - result = run_prepared(client, 'pg_codegen_query_sql_count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#count_batch_types_above', COUNT_BATCH_TYPES_ABOVE_SQL, query_params) row = result.first row && CountBatchTypesAboveRow.new(row['count']) end @@ -1394,12 +1397,12 @@ def count_batch_types_above!(...) def truncate_batch_types with_client('truncate_batch_types') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_batch_types', TRUNCATE_BATCH_TYPES_SQL) nil end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1409,14 +1412,15 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] - run_prepared(client, 'pg_codegen_query_sql_insert_name_case', INSERT_NAME_CASE_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#insert_name_case', INSERT_NAME_CASE_SQL, query_params) nil end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1426,9 +1430,10 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] - result = run_prepared(client, 'pg_codegen_query_sql_get_name_case', GET_NAME_CASE_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_name_case', GET_NAME_CASE_SQL, query_params) row = result.first row && GetNameCaseRow.new( row['id'], @@ -1438,7 +1443,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row['method'], row['count'], row['camelCase'], - row['HTTPServer'] + row['HTTPServer'], + row['initialize'] ) end end @@ -1451,7 +1457,7 @@ def get_name_case!(...) def get_http_server(id:) with_client('get_http_server') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_http_server', GET_HTTP_SERVER_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_http_server', GET_HTTP_SERVER_SQL, query_params) row = result.first row && GetHTTPServerRow.new( row['id'], @@ -1461,7 +1467,8 @@ def get_http_server(id:) row['method'], row['count'], row['camelCase'], - row['HTTPServer'] + row['HTTPServer'], + row['initialize'] ) end end @@ -1473,14 +1480,14 @@ def get_http_server!(...) def truncate_name_cases with_client('truncate_name_cases') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_name_cases', TRUNCATE_NAME_CASES_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_name_cases', TRUNCATE_NAME_CASES_SQL) nil end end def get_unnamed_columns with_client('get_unnamed_columns') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values + result = run_prepared(client, 'PgCodegen::QuerySql#get_unnamed_columns', GET_UNNAMED_COLUMNS_SQL).values row = result.first row && GetUnnamedColumnsRow.new(row[0], row[1]) end @@ -1493,7 +1500,7 @@ def get_unnamed_columns!(...) def get_quoted_alias with_client('get_quoted_alias') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_get_quoted_alias', GET_QUOTED_ALIAS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#get_quoted_alias', GET_QUOTED_ALIAS_SQL) row = result.first row && GetQuotedAliasRow.new(row['it\'s']) end @@ -1506,14 +1513,14 @@ def get_quoted_alias!(...) def create_exception with_client('create_exception') do |client| - run_prepared(client, 'pg_codegen_query_sql_create_exception', CREATE_EXCEPTION_SQL) + run_prepared(client, 'PgCodegen::QuerySql#create_exception', CREATE_EXCEPTION_SQL) nil end end def count_exceptions with_client('count_exceptions') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_count_exceptions', COUNT_EXCEPTIONS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#count_exceptions', COUNT_EXCEPTIONS_SQL) row = result.first row && CountExceptionsRow.new(row['n']) end @@ -1526,7 +1533,7 @@ def count_exceptions!(...) def truncate_exceptions with_client('truncate_exceptions') do |client| - run_prepared(client, 'pg_codegen_query_sql_truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) + run_prepared(client, 'PgCodegen::QuerySql#truncate_exceptions', TRUNCATE_EXCEPTIONS_SQL) nil end end @@ -1534,7 +1541,7 @@ def truncate_exceptions def create_late_feeling(id:, moods:) with_client('create_late_feeling') do |client| query_params = [id, encode_array(moods)] - run_prepared(client, 'pg_codegen_query_sql_create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) + run_prepared(client, 'PgCodegen::QuerySql#create_late_feeling', CREATE_LATE_FEELING_SQL, query_params) nil end end @@ -1542,7 +1549,7 @@ def create_late_feeling(id:, moods:) def get_late_feeling(id:) with_client('get_late_feeling') do |client| query_params = [id] - result = run_prepared(client, 'pg_codegen_query_sql_get_late_feeling', GET_LATE_FEELING_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#get_late_feeling', GET_LATE_FEELING_SQL, query_params) row = result.first row && GetLateFeelingRow.new(row['moods']) end @@ -1562,7 +1569,7 @@ def many_params(c0:, c1:, c2:, c3:, c4:) encode_float(c3), encode_bytea(c4) ] - result = run_prepared(client, 'pg_codegen_query_sql_many_params', MANY_PARAMS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#many_params', MANY_PARAMS_SQL, query_params) row = result.first row && ManyParamsRow.new(row['c0'], row['c1']) end @@ -1576,7 +1583,7 @@ def many_params!(...) def many_rows(c0:) with_client('many_rows') do |client| query_params = [c0] - result = run_prepared(client, 'pg_codegen_query_sql_many_rows', MANY_ROWS_SQL, query_params) + result = run_prepared(client, 'PgCodegen::QuerySql#many_rows', MANY_ROWS_SQL, query_params) result.map do |row| ManyRowsRow.new( row['c0'], @@ -1591,7 +1598,7 @@ def many_rows(c0:) def four_cols with_client('four_cols') do |client| - result = run_prepared(client, 'pg_codegen_query_sql_four_cols', FOUR_COLS_SQL) + result = run_prepared(client, 'PgCodegen::QuerySql#four_cols', FOUR_COLS_SQL) result.map do |row| FourColsRow.new(row['c0'], row['c1'], row['c2'], row['c3']) end diff --git a/test/golden/sqlite3/default/models.rb b/test/golden/sqlite3/default/models.rb index 35771dd..3446141 100644 --- a/test/golden/sqlite3/default/models.rb +++ b/test/golden/sqlite3/default/models.rb @@ -35,7 +35,8 @@ class NameCase < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName diff --git a/test/golden/sqlite3/default/models.rbs b/test/golden/sqlite3/default/models.rbs index 1e54403..798625e 100644 --- a/test/golden/sqlite3/default/models.rbs +++ b/test/golden/sqlite3/default/models.rbs @@ -57,6 +57,7 @@ module Sqlite3Codegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -65,7 +66,8 @@ module Sqlite3Codegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end diff --git a/test/golden/sqlite3/default/my_queries_sql.rb b/test/golden/sqlite3/default/my_queries_sql.rb index 58e41cd..66ad867 100644 --- a/test/golden/sqlite3/default/my_queries_sql.rb +++ b/test/golden/sqlite3/default/my_queries_sql.rb @@ -13,7 +13,7 @@ module Sqlite3Codegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end diff --git a/test/golden/sqlite3/default/my_queries_sql.rbs b/test/golden/sqlite3/default/my_queries_sql.rbs index 1f43243..c373d81 100644 --- a/test/golden/sqlite3/default/my_queries_sql.rbs +++ b/test/golden/sqlite3/default/my_queries_sql.rbs @@ -2,7 +2,7 @@ module Sqlite3Codegen WITH_NUMBERS2_GO_SQL: ::String - class My_queriesSql + class MyQueriesSql class NotFound < ::StandardError end diff --git a/test/golden/sqlite3/default/query_sql.rb b/test/golden/sqlite3/default/query_sql.rb index 310e246..656152a 100644 --- a/test/golden/sqlite3/default/query_sql.rb +++ b/test/golden/sqlite3/default/query_sql.rb @@ -325,16 +325,17 @@ class ListAuthorsWithOptionalBookRow < ::Data.define(:author, :book) end INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? AND "class" = ? AND "end" = ? AND "hash" = ? AND "method" = ? AND "count" = ? AND "HTTPServer" = ? AND "camelCase" = ? + AND "initialize" = ? SQL # rubocop:disable Naming/MethodName @@ -346,13 +347,14 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases WHERE id = ? + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? SQL # rubocop:disable Naming/MethodName @@ -364,7 +366,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName @@ -1167,7 +1170,7 @@ def list_authors_with_optional_book end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1177,7 +1180,8 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] stmt = client.prepare(INSERT_NAME_CASE_SQL) begin @@ -1189,7 +1193,7 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1199,7 +1203,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] stmt = client.prepare(GET_NAME_CASE_SQL) begin @@ -1213,7 +1218,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row[4], row[5], row[6], - row[7] + row[7], + row[8] ) ensure stmt.close @@ -1241,7 +1247,8 @@ def get_http_server(id:) row[4], row[5], row[6], - row[7] + row[7], + row[8] ) ensure stmt.close diff --git a/test/golden/sqlite3/default/query_sql.rbs b/test/golden/sqlite3/default/query_sql.rbs index 7dd85f6..3894f2b 100644 --- a/test/golden/sqlite3/default/query_sql.rbs +++ b/test/golden/sqlite3/default/query_sql.rbs @@ -334,6 +334,7 @@ module Sqlite3Codegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -342,7 +343,8 @@ module Sqlite3Codegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -357,6 +359,7 @@ module Sqlite3Codegen attr_reader count: ::Integer attr_reader camelCase: ::String attr_reader HTTPServer: ::String + attr_reader initialize_: ::String def initialize: ( ::Integer id, ::String class_, @@ -365,7 +368,8 @@ module Sqlite3Codegen ::String method_, ::Integer count, ::String camelCase, - ::String HTTPServer + ::String HTTPServer, + ::String initialize_ ) -> void end @@ -556,11 +560,11 @@ module Sqlite3Codegen def list_authors_with_optional_book: -> ::Array[ListAuthorsWithOptionalBookRow] - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/test/golden/sqlite3/ruby31_gemfile/models.rb b/test/golden/sqlite3/ruby31_gemfile/models.rb index 4fd4141..d6674f8 100644 --- a/test/golden/sqlite3/ruby31_gemfile/models.rb +++ b/test/golden/sqlite3/ruby31_gemfile/models.rb @@ -44,6 +44,7 @@ module Sqlite3Codegen :count_, :camelCase, :HTTPServer, + :initialize_, keyword_init: true ) # rubocop:enable Naming/MethodName diff --git a/test/golden/sqlite3/ruby31_gemfile/models.rbs b/test/golden/sqlite3/ruby31_gemfile/models.rbs index ae49628..3c6516f 100644 --- a/test/golden/sqlite3/ruby31_gemfile/models.rbs +++ b/test/golden/sqlite3/ruby31_gemfile/models.rbs @@ -70,6 +70,7 @@ module Sqlite3Codegen attr_accessor count_: ::Integer attr_accessor camelCase: ::String attr_accessor HTTPServer: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -78,7 +79,8 @@ module Sqlite3Codegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -88,7 +90,8 @@ module Sqlite3Codegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> NameCase end diff --git a/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rb b/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rb index a10ea4c..e47c44c 100644 --- a/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rb +++ b/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rb @@ -13,7 +13,7 @@ module Sqlite3Codegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end diff --git a/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rbs b/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rbs index 3f29c8b..24afb24 100644 --- a/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rbs +++ b/test/golden/sqlite3/ruby31_gemfile/my_queries_sql.rbs @@ -2,7 +2,7 @@ module Sqlite3Codegen WITH_NUMBERS2_GO_SQL: ::String - class My_queriesSql + class MyQueriesSql class NotFound < ::StandardError end diff --git a/test/golden/sqlite3/ruby31_gemfile/query_sql.rb b/test/golden/sqlite3/ruby31_gemfile/query_sql.rb index b6a397c..64a2879 100644 --- a/test/golden/sqlite3/ruby31_gemfile/query_sql.rb +++ b/test/golden/sqlite3/ruby31_gemfile/query_sql.rb @@ -307,16 +307,17 @@ module Sqlite3Codegen ListAuthorsWithOptionalBookRow = ::Struct.new(:author, :book, keyword_init: true) INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? AND "class" = ? AND "end" = ? AND "hash" = ? AND "method" = ? AND "count" = ? AND "HTTPServer" = ? AND "camelCase" = ? + AND "initialize" = ? SQL # rubocop:disable Naming/MethodName @@ -329,12 +330,13 @@ module Sqlite3Codegen :count_, :camelCase, :HTTPServer, + :initialize_, keyword_init: true ) # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases WHERE id = ? + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? SQL # rubocop:disable Naming/MethodName @@ -347,6 +349,7 @@ module Sqlite3Codegen :count_, :camelCase, :HTTPServer, + :initialize_, keyword_init: true ) # rubocop:enable Naming/MethodName @@ -1158,7 +1161,7 @@ def list_authors_with_optional_book end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1168,7 +1171,8 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] stmt = client.prepare(INSERT_NAME_CASE_SQL) begin @@ -1180,7 +1184,7 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1190,7 +1194,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] stmt = client.prepare(GET_NAME_CASE_SQL) begin @@ -1204,7 +1209,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method_: row[4], count_: row[5], camelCase: row[6], - HTTPServer: row[7] + HTTPServer: row[7], + initialize_: row[8] ) ensure stmt.close @@ -1232,7 +1238,8 @@ def get_http_server(id:) method_: row[4], count_: row[5], camelCase: row[6], - HTTPServer: row[7] + HTTPServer: row[7], + initialize_: row[8] ) ensure stmt.close diff --git a/test/golden/sqlite3/ruby31_gemfile/query_sql.rbs b/test/golden/sqlite3/ruby31_gemfile/query_sql.rbs index 1579d6d..b93ab43 100644 --- a/test/golden/sqlite3/ruby31_gemfile/query_sql.rbs +++ b/test/golden/sqlite3/ruby31_gemfile/query_sql.rbs @@ -379,6 +379,7 @@ module Sqlite3Codegen attr_accessor count_: ::Integer attr_accessor camelCase: ::String attr_accessor HTTPServer: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -387,7 +388,8 @@ module Sqlite3Codegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -397,7 +399,8 @@ module Sqlite3Codegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> GetNameCaseRow end @@ -412,6 +415,7 @@ module Sqlite3Codegen attr_accessor count_: ::Integer attr_accessor camelCase: ::String attr_accessor HTTPServer: ::String + attr_accessor initialize_: ::String def initialize: ( id: ::Integer, class_: ::String, @@ -420,7 +424,8 @@ module Sqlite3Codegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> void def self.new: ( id: ::Integer, @@ -430,7 +435,8 @@ module Sqlite3Codegen method_: ::String, count_: ::Integer, camelCase: ::String, - HTTPServer: ::String + HTTPServer: ::String, + initialize_: ::String ) -> GetHTTPServerRow end @@ -636,11 +642,11 @@ module Sqlite3Codegen def list_authors_with_optional_book: -> ::Array[ListAuthorsWithOptionalBookRow] - def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String) -> void + def insert_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, camel_case: ::String, http_server: ::String, initialize: ::String) -> void - def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow? + def get_name_case: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow? - def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String) -> GetNameCaseRow + def get_name_case!: (id: ::Integer, class_: ::String, end_: ::String, hash: ::String, method: ::String, count: ::Integer, http_server: ::String, camel_case: ::String, initialize: ::String) -> GetNameCaseRow def get_http_server: (id: ::Integer) -> GetHTTPServerRow? diff --git a/test/golden/sqlite3/ruby32_notypes/models.rb b/test/golden/sqlite3/ruby32_notypes/models.rb index 35771dd..3446141 100644 --- a/test/golden/sqlite3/ruby32_notypes/models.rb +++ b/test/golden/sqlite3/ruby32_notypes/models.rb @@ -35,7 +35,8 @@ class NameCase < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName diff --git a/test/golden/sqlite3/ruby32_notypes/my_queries_sql.rb b/test/golden/sqlite3/ruby32_notypes/my_queries_sql.rb index a10ea4c..e47c44c 100644 --- a/test/golden/sqlite3/ruby32_notypes/my_queries_sql.rb +++ b/test/golden/sqlite3/ruby32_notypes/my_queries_sql.rb @@ -13,7 +13,7 @@ module Sqlite3Codegen WHERE a = ? SQL - class My_queriesSql + class MyQueriesSql # Raised by the bang variants (get_author!) when the query returns no row. class NotFound < ::StandardError; end diff --git a/test/golden/sqlite3/ruby32_notypes/query_sql.rb b/test/golden/sqlite3/ruby32_notypes/query_sql.rb index 173a4f3..4652633 100644 --- a/test/golden/sqlite3/ruby32_notypes/query_sql.rb +++ b/test/golden/sqlite3/ruby32_notypes/query_sql.rb @@ -325,16 +325,17 @@ class ListAuthorsWithOptionalBookRow < ::Data.define(:author, :book) end INSERT_NAME_CASE_SQL = <<~'SQL' - INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer") + INSERT INTO name_cases (id, "class", "end", "hash", "method", "count", "camelCase", "HTTPServer", "initialize") VALUES (?, ?, ?, ?, ?, ?, - ?, ?) + ?, ?, ?) SQL GET_NAME_CASE_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? AND "class" = ? AND "end" = ? AND "hash" = ? AND "method" = ? AND "count" = ? AND "HTTPServer" = ? AND "camelCase" = ? + AND "initialize" = ? SQL # rubocop:disable Naming/MethodName @@ -346,13 +347,14 @@ class GetNameCaseRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName GET_HTTP_SERVER_SQL = <<~'SQL' - SELECT id, class, "end", hash, method, count, camelCase, HTTPServer FROM name_cases WHERE id = ? + SELECT id, class, "end", hash, method, count, camelCase, HTTPServer, initialize FROM name_cases WHERE id = ? SQL # rubocop:disable Naming/MethodName @@ -364,7 +366,8 @@ class GetHTTPServerRow < ::Data.define( :method_, :count, :camelCase, - :HTTPServer + :HTTPServer, + :initialize_ ) end # rubocop:enable Naming/MethodName @@ -1170,7 +1173,7 @@ def list_authors_with_optional_book end end - def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:) + def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, http_server:, initialize:) with_client('insert_name_case') do |client| query_params = [ id, @@ -1180,7 +1183,8 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h method, count, camel_case, - http_server + http_server, + initialize ] stmt = client.prepare(INSERT_NAME_CASE_SQL) begin @@ -1192,7 +1196,7 @@ def insert_name_case(id:, class_:, end_:, hash:, method:, count:, camel_case:, h end end - def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:) + def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, camel_case:, initialize:) with_client('get_name_case') do |client| query_params = [ id, @@ -1202,7 +1206,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam method, count, http_server, - camel_case + camel_case, + initialize ] stmt = client.prepare(GET_NAME_CASE_SQL) begin @@ -1216,7 +1221,8 @@ def get_name_case(id:, class_:, end_:, hash:, method:, count:, http_server:, cam row[4], row[5], row[6], - row[7] + row[7], + row[8] ) ensure stmt.close @@ -1244,7 +1250,8 @@ def get_http_server(id:) row[4], row[5], row[6], - row[7] + row[7], + row[8] ) ensure stmt.close diff --git a/test/options_test.rb b/test/options_test.rb index f3f4be3..3b1fdc6 100644 --- a/test/options_test.rb +++ b/test/options_test.rb @@ -50,6 +50,8 @@ def test_immutable_data_support assert RubyVersion.parse('3.2').immutable_data_supported? assert RubyVersion.parse('3.3').immutable_data_supported? assert RubyVersion.parse(' 3.2 ').immutable_data_supported? + refute RubyVersion.parse('3').immutable_data_supported?, '"3" includes Ruby 3.1, which has no Data' + assert RubyVersion.parse('4').immutable_data_supported? end def test_option_types_are_validated diff --git a/tests/end2end_mysql2.rb b/tests/end2end_mysql2.rb index da1cfc7..2e6d056 100755 --- a/tests/end2end_mysql2.rb +++ b/tests/end2end_mysql2.rb @@ -192,6 +192,14 @@ def test_execrows_returns_affected_row_count assert_equal 2, @query_sql.update_author_bios(bio: 'new bio') end + def test_execrows_counts_changed_rows_unless_found_rows_is_set + create_author('same bio', 'same') + create_author('other bio', 'other') + assert_equal 1, @query_sql.update_author_bios(bio: 'same') + found_rows = QuerySql.connect(mysql2_params.merge('flags' => Mysql2::Client::FOUND_ROWS)) + assert_equal 2, found_rows.update_author_bios(bio: 'same') + end + # ---- sqlc.arg / sqlc.narg -------------------------------------------------------------------------------------- def test_positional_args_limit_and_offset @@ -628,12 +636,14 @@ def test_repeated_positional_parameters_get_distinct_names def test_keyword_and_method_names_keep_distinct_row_and_argument_names args = { id: 1, class_: 'class', end_: 'end', hash: 'hash', method: 'method', count: 7, - camel_case: 'camel', http_server: 'server' } + camel_case: 'camel', http_server: 'server', initialize: 'init' } @query_sql.insert_name_case(**args) row = @query_sql.get_name_case(**args) count_member = row.is_a?(::Struct) ? :count_ : :count - assert_equal %i[id class_ end hash_ method_].concat([count_member, :camelcase, :httpserver]), row.class.members + assert_equal %i[id class_ end hash_ method_].concat([count_member, :camelcase, :httpserver, :initialize_]), row.class.members assert_equal %w[class end hash method], %i[class_ end hash_ method_].map { |member| row.public_send(member) } + assert_equal 'init', row.initialize_ + assert_equal row, row.with(id: 1) unless row.is_a?(::Struct) assert_equal 7, row.public_send(count_member) assert_equal 'camel', row.public_send(:camelcase) assert_equal 'server', row.public_send(:httpserver) diff --git a/tests/end2end_options.rb b/tests/end2end_options.rb index 4233f6a..bc99f63 100644 --- a/tests/end2end_options.rb +++ b/tests/end2end_options.rb @@ -29,8 +29,8 @@ def test_generator_options_preserve_runtime_values_and_generate_expected_layouts assert system('sqlc', 'generate', '-f', config_path, chdir: ROOT) sqlite_dir = File.join(OUTPUT_DIR, 'sqlite3') pg_dir = File.join(OUTPUT_DIR, 'pg') - assert_equal %w[first_sql.rb first_sql.rbs second_sql.rb second_sql.rbs models.rb models.rbs connection.rb connection.rbs - Gemfile].sort, + assert_equal %w[admin_users_sql.rb admin_users_sql.rbs first_sql.rb first_sql.rbs second_sql.rb second_sql.rbs models.rb + models.rbs connection.rb connection.rbs Gemfile].sort, Dir.children(sqlite_dir).sort refute Dir.children(pg_dir).any? { |file| file.end_with?('.rbs') } assert File.file?(File.join(pg_dir, 'Gemfile')) @@ -47,6 +47,8 @@ def test_generator_options_preserve_runtime_values_and_generate_expected_layouts assert_match(/id: String\b/, rbs) assert_match(/class GetBothModelsRow\b/, rbs) assert File.file?(File.join(sqlite_dir, 'second_sql.rbs')) + admin = File.read(File.join(sqlite_dir, 'admin_users_sql.rb')) + assert_match(/^ *class AdminUsersSql$/, admin) assert_sqlite_runtime(sqlite_dir) assert_pg_runtime(pg_dir) @@ -77,6 +79,7 @@ def assert_sqlite_runtime(generated_dir) 'bundle', 'exec', RbConfig.ruby, '-e', <<~'RUBY' require File.join(ENV.fetch('OPTIONS_SQLITE_DIR'), 'first_sql') require File.join(ENV.fetch('OPTIONS_SQLITE_DIR'), 'second_sql') + require File.join(ENV.fetch('OPTIONS_SQLITE_DIR'), 'admin_users_sql') db = SQLite3::Database.new(':memory:') db.execute_batch(File.read(ENV.fetch('OPTIONS_SCHEMA'))) db.execute("INSERT INTO option_items VALUES (1, 'note', 'tag', 'extra')") @@ -90,6 +93,7 @@ def assert_sqlite_runtime(generated_dir) joined = options::FirstSql.new(db).get_both_models(id: 1) raise 'embedded models were not renamed as expected' unless [joined.author.name, joined.author2.name] == %w[singular plural] raise 'exactTableNames did not preserve the plural table model' unless options::FirstSql.new(db).list_option_articles.first.title == 'article' + raise 'admin_users.sql did not become AdminUsersSql' unless options::AdminUsersSql.new(db).count_option_articles.total == 1 RUBY ) assert status.success?, "generated-Gemfile SQLite run failed:\n#{stdout}\n#{stderr}" @@ -116,6 +120,18 @@ def assert_pg_runtime(generated_dir) assert_equal 1, first.get_pg_option_author(id: 1).id assert_equal 'second module', second.get_pg_option_author(id: 1).label end + long = 'Options::PgLongModuleNameThatPushesStatementNamesPastTheLimit' + [%w[pg_v2 pg_nested_v2 Options::PgV2 Options::Pg::V2], ['pg_long_a', 'pg_long_b', "#{long}A", "#{long}B"]] + .each do |first_dir, second_dir, first_module, second_module| + require File.join(OUTPUT_DIR, first_dir, 'first_sql.rb') + require File.join(OUTPUT_DIR, second_dir, 'first_sql.rb') + first = Object.const_get("#{first_module}::FirstSql").new(pool) + second = Object.const_get("#{second_module}::FirstSql").new(pool) + 2.times do + assert_equal 1, first.get_pg_option_author(id: 1).id, first_module + assert_equal 'second module', second.get_pg_option_author(id: 1).label, second_module + end + end ensure pool&.shutdown(&:close) conn&.exec('DROP SCHEMA IF EXISTS options_audit CASCADE') diff --git a/tests/end2end_pg.rb b/tests/end2end_pg.rb index ae5fed2..b3c5d3b 100755 --- a/tests/end2end_pg.rb +++ b/tests/end2end_pg.rb @@ -284,12 +284,14 @@ def test_repeated_column_parameters_get_distinct_names def test_keyword_and_method_names_keep_distinct_row_and_argument_names args = { id: 1, class_: 'class', end_: 'end', hash: 'hash', method: 'method', count: 7, - camel_case: 'camel', http_server: 'server' } + camel_case: 'camel', http_server: 'server', initialize: 'init' } @query_sql.insert_name_case(**args) row = @query_sql.get_name_case(**args) count_member = row.is_a?(::Struct) ? :count_ : :count - assert_equal %i[id class_ end hash_ method_].concat([count_member, :camelCase, :HTTPServer]), row.class.members + assert_equal %i[id class_ end hash_ method_].concat([count_member, :camelCase, :HTTPServer, :initialize_]), row.class.members assert_equal %w[class end hash method], %i[class_ end hash_ method_].map { |member| row.public_send(member) } + assert_equal 'init', row.initialize_ + assert_equal row, row.with(id: 1) unless row.is_a?(::Struct) assert_equal 7, row.public_send(count_member) assert_equal 'camel', row.public_send(:camelCase) assert_equal 'server', row.public_send(:HTTPServer) diff --git a/tests/end2end_sqlite3.rb b/tests/end2end_sqlite3.rb index f466f9b..79fc0e0 100644 --- a/tests/end2end_sqlite3.rb +++ b/tests/end2end_sqlite3.rb @@ -183,12 +183,14 @@ def test_required_argument_after_optional_named_argument def test_keyword_and_method_names_keep_distinct_row_and_argument_names args = { id: 1, class_: 'class', end_: 'end', hash: 'hash', method: 'method', count: 7, - camel_case: 'camel', http_server: 'server' } + camel_case: 'camel', http_server: 'server', initialize: 'init' } @query_sql.insert_name_case(**args) row = @query_sql.get_name_case(**args) count_member = row.is_a?(::Struct) ? :count_ : :count - assert_equal %i[id class_ end hash_ method_].concat([count_member, :camelCase, :HTTPServer]), row.class.members + assert_equal %i[id class_ end hash_ method_].concat([count_member, :camelCase, :HTTPServer, :initialize_]), row.class.members assert_equal %w[class end hash method], %i[class_ end hash_ method_].map { |member| row.public_send(member) } + assert_equal 'init', row.initialize_ + assert_equal row, row.with(id: 1) unless row.is_a?(::Struct) assert_equal 7, row.public_send(count_member) assert_equal 'camel', row.public_send(:camelCase) assert_equal 'server', row.public_send(:HTTPServer) @@ -407,6 +409,27 @@ def test_transaction_mode assert_equal 1, @query_sql.transaction(mode: :immediate) { 1 } end + def test_busy_handler_timeout_waits_for_another_connection_without_blocking_threads + Tempfile.create('sqlite-busy-test') do |file| + first = SQLite3::Database.new(file.path) + first.execute_batch(SCHEMA) + second = SQLite3::Database.new(file.path) + second.busy_handler_timeout = 10_000 + first.execute('BEGIN IMMEDIATE') + writer = ::Thread.new { QuerySql.new(second).create_author_return_id(name: 'waited', bio: nil) } + ticks = 0 + ticks += 1 while writer.join(0.01).nil? && ticks < 20 + assert_equal 20, ticks, 'other threads keep running while the write waits' + first.execute('COMMIT') + refute_nil writer.value + assert_equal 1, first.execute('SELECT COUNT(*) FROM authors').first.first + ensure + writer&.join + second&.close + first&.close + end + end + def test_immediate_and_exclusive_transactions_block_a_second_connection Tempfile.create('sqlite-lock-test') do |file| first = SQLite3::Database.new(file.path) diff --git a/tests/options/sqlc.yaml b/tests/options/sqlc.yaml index ee00194..6b2db85 100644 --- a/tests/options/sqlc.yaml +++ b/tests/options/sqlc.yaml @@ -37,6 +37,7 @@ sql: queries: - "sqlite_queries/first.sql" - "sqlite_queries/second.sql" + - "sqlite_queries/admin_users.sql" engine: "sqlite" codegen: - plugin: ruby @@ -92,3 +93,49 @@ sql: driver: pg moduleName: Options::PgSecond generateTypes: false +# Module paths that snake_case to the same name (options_pg_v2_first_sql) and module paths whose statement names +# share their first 63 bytes (PostgreSQL truncates longer names): their prepared statements must stay distinct. +- schema: "pg_schema.sql" + queries: + - "pg_queries/first.sql" + engine: "postgresql" + codegen: + - plugin: ruby + out: ".generated/pg_v2" + options: + driver: pg + moduleName: Options::PgV2 + generateTypes: false +- schema: "pg_schema.sql" + queries: + - "pg_second_queries/first.sql" + engine: "postgresql" + codegen: + - plugin: ruby + out: ".generated/pg_nested_v2" + options: + driver: pg + moduleName: Options::Pg::V2 + generateTypes: false +- schema: "pg_schema.sql" + queries: + - "pg_queries/first.sql" + engine: "postgresql" + codegen: + - plugin: ruby + out: ".generated/pg_long_a" + options: + driver: pg + moduleName: Options::PgLongModuleNameThatPushesStatementNamesPastTheLimitA + generateTypes: false +- schema: "pg_schema.sql" + queries: + - "pg_second_queries/first.sql" + engine: "postgresql" + codegen: + - plugin: ruby + out: ".generated/pg_long_b" + options: + driver: pg + moduleName: Options::PgLongModuleNameThatPushesStatementNamesPastTheLimitB + generateTypes: false diff --git a/tests/options/sqlite_queries/admin_users.sql b/tests/options/sqlite_queries/admin_users.sql new file mode 100644 index 0000000..ea620b6 --- /dev/null +++ b/tests/options/sqlite_queries/admin_users.sql @@ -0,0 +1,3 @@ +-- A snake_case file name: the class is AdminUsersSql. +-- name: CountOptionArticles :one +SELECT COUNT(*) AS total FROM articles;