From 22d698b68f3c2687c11451d69fdaa0dc2f54928a Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Tue, 11 Jul 2023 08:44:09 -0500 Subject: [PATCH] The Big Linq Overhaul of 2023! Revamped Linq baseline support. Closes GH-2684 Ability to use compiled queries even when the generated SQL uses containment operators or JSONPath queries. Closes GH-2702 WIP: Refactored the Contains() query logic to centralize it a bit Updated to Weasel 6.2, changed the shape of ICompiledQueryAwareFilter to get ready for containment filters Added some test helper for detecting with a Linq query uses a CTE prior to improving child collection queries Cleaning out some ununsed ContainmentWhereFragment code WIP: refactored compiled queries quite a bit to get ready to handle JSONPath & containment operators in compiled queries Revert "tweaking github builds" This reverts commit fdfe09022191923242ca802f0c8449709ec90f1b. maybe fixed some references to code snippets tweaking github builds removing older postgres versions removing older Postgres versions Fixed a likely merge problem w/ the duplicated field doc page Fixed a combination of soft deleted documents being part of an Include() operation Few more fixes for LINQ overhaul regressions Bug fixing for a couple v7 merge issues doc snippet change Fixed new parsers to the v7 linq model --- .../1.3/DocumentActions-report-default.md | 12 - .../results/LinqActions-report-github.md | 16 - build/build.cs | 8 +- docs/configuration/storeoptions.md | 10 +- docs/documents/deletes.md | 8 +- docs/documents/hierarchies.md | 13 +- docs/documents/indexing/foreign-keys.md | 149 --- docs/documents/indexing/metadata-indexes.md | 3 +- docs/documents/metadata.md | 2 +- docs/documents/multi-tenancy.md | 4 +- docs/documents/querying/compiled-queries.md | 25 +- .../querying/linq/async-enumerable.md | 2 +- .../querying/linq/child-collections.md | 20 +- docs/documents/querying/linq/extending.md | 65 +- docs/documents/querying/linq/include.md | 19 +- docs/documents/querying/linq/nulls.md | 19 - docs/documents/querying/linq/operators.md | 6 +- docs/documents/querying/linq/paging.md | 6 +- docs/documents/querying/linq/projections.md | 14 +- docs/documents/querying/linq/strings.md | 2 +- docs/documents/querying/query-json.md | 4 +- docs/documents/storage.md | 2 +- docs/events/projections/inline.md | 51 - docs/events/storage.md | 114 -- docs/migration-guide.md | 108 -- docs/postgres/casing/index.md | 15 - docs/postgres/casing/queries.md | 3 - docs/schema/index.md | 3 +- docs/troubleshoot.md | 2 +- ..._1258_cannot_derive_updates_for_objects.cs | 29 +- src/CoreTests/create_database_Tests.cs | 1 + ...g_1217_order_by_count_of_sub_collection.cs | 63 - .../Bug_2057_select_transform_dictionary.cs | 75 -- ...list_contains_any_generates_invalid_sql.cs | 114 -- ...ion_on_class_with_invalid_type_id_field.cs | 12 +- ...ug_849_not_node_not_correctly_evaluated.cs | 47 - .../Configuration/DocumentMappingTests.cs | 283 ++-- .../Configuration/MartenRegistryTests.cs | 10 +- src/DocumentDbTests/Deleting/soft_deletes.cs | 54 +- .../delete_by_where_for_hierarchy_Tests.cs | 2 + .../Indexes/duplicated_field.cs | 19 +- ...rByUsernameCompiledQuerySource661477123.cs | 68 - ...rByUsernameCompiledQuerySource661477123.cs | 68 - ...iledQuery1CompiledQuerySource2018461339.cs | 65 - ...iledQuery2CompiledQuerySource1615176812.cs | 65 - ...edQueryTargetCompiledQuerySource9758203.cs | 73 -- ...ByNameQueryCompiledQuerySource549815509.cs | 67 - ...ByUsernameCompiledQuerySource1607037309.cs | 67 - ...llTheThingsCompiledQuerySource878799577.cs | 74 -- ...nationQueryCompiledQuerySource323866534.cs | 71 - ...getsInOrderCompiledQuerySource468279698.cs | 70 - ...eTestQueryCompiledQuerySource2052986011.cs | 65 - ...rByUsernameCompiledQuerySource661477123.cs | 68 - ...gleOrDefaultCompiledQuerySource97871325.cs | 68 - ...meWithFieldsCompiledQuerySource92089138.cs | 68 - ...yFirstNameCompiledQuerySource1983785893.cs | 64 - ...meContainsCompiledQuerySource1056635770.cs | 67 - ...nsensitiveCompiledQuerySource2080514763.cs | 67 - ...meEndsWithCompiledQuerySource1088283705.cs | 67 - ...eStartsWithCompiledQuerySource515679394.cs | 67 - ...ginPayloadCompiledQuerySource1260512725.cs | 65 - ...ByFirstNameCompiledQuerySource314143719.cs | 67 - ...eWithFieldsCompiledQuerySource906880034.cs | 67 - ...NestedQueryCompiledQuerySource970855369.cs | 67 - ...argetQueryCompiledQuerySource1643467126.cs | 73 -- ...ithAssigneeCompiledQuerySource113072566.cs | 77 -- ...ersAndParamCompiledQuerySource813614947.cs | 77 -- ...thUsersByIdCompiledQuerySource591142956.cs | 74 -- ...eWithUsersCompiledQuerySource2026718760.cs | 74 -- ...ueWithUsersCompiledQuerySource272805147.cs | 74 -- ...rByUsernameCompiledQuerySource661477123.cs | 68 - ...eWithFieldsCompiledQuerySource906880034.cs | 67 - ...ameContainsCompiledQuerySource893470325.cs | 67 - ...ameEndsWithCompiledQuerySource628653900.cs | 67 - ...StartsWithCompiledQuerySource2116019653.cs | 67 - .../AccountProvider793732554.cs | 878 ------------- .../AttVersionedDocProvider506859367.cs | 1165 ----------------- .../DocumentStorage/BugProvider65166103.cs | 848 ------------ .../DocumentStorage/CarProvider343829114.cs | 848 ------------ .../CoffeeShopEmployeeProvider920305685.cs | 1137 ---------------- .../CoffeeShopProvider2130089093.cs | 1137 ---------------- .../CompanyProvider297217634.cs | 848 ------------ .../ContactProvider677813566.cs | 848 ------------ .../CustomerProvider728829122.cs | 848 ------------ .../DocHolderProvider1892370027.cs | 848 ------------ .../DocWithArraysProvider1391541541.cs | 848 ------------ .../DocWithNumberProvider210740905.cs | 848 ------------ .../DocWithUintProvider1372666391.cs | 848 ------------ .../FailureInLifeProvider461155494.cs | 848 ------------ .../DocumentStorage/GroupProvider994823898.cs | 848 ------------ .../GuidDocProvider400073224.cs | 848 ------------ .../GuyWithIntArrayProvider1326363224.cs | 886 ------------- .../IntDocProvider379264442.cs | 848 ------------ .../IssueProvider2074714110.cs | 848 ------------ .../LongDocProvider1431212005.cs | 848 ------------ .../MainEntityProvider1625545438.cs | 848 ------------ .../MartenStoredStateProvider1211396321.cs | 848 ------------ .../MyClassProvider52903863.cs | 878 ------------- .../MyTrackedDocProvider815737241.cs | 1001 -------------- .../MyVersionedDocProvider1489495374.cs | 1165 ----------------- .../NonStandardDocProvider1732698282.cs | 878 ------------- ...aginationTestDocumentProvider1855354059.cs | 878 ------------- .../PlayerProvider1707213853.cs | 848 ------------ .../ProductProvider1360380871.cs | 848 ------------ .../ProductWithListProvider1228310865.cs | 848 ------------ .../ProductWithNumbersProvider1463839245.cs | 848 ------------ .../QueryTargetProvider1217791244.cs | 848 ------------ .../QueryTargetProvider535117371.cs | 848 ------------ .../RecordDocumentProvider1196727384.cs | 847 ------------ .../DocumentStorage/RootProvider493946136.cs | 848 ------------ .../RouteDetailsProvider784762106.cs | 848 ------------ .../SimpleUserProvider652546491.cs | 848 ------------ .../StringDocProvider478514312.cs | 878 ------------- .../TargetGroupProvider723464596.cs | 848 ------------ .../TargetProvider1797031270.cs | 848 ------------ .../DocumentStorage/TaskProvider74835621.cs | 848 ------------ .../TestClassProvider2001772986.cs | 848 ------------ .../TestClassProvider2042192398.cs | 848 ------------ .../DocumentStorage/TopProvider102551794.cs | 848 ------------ ...JsonConverterAttributeProvider818716525.cs | 848 ------------ .../UserFromBaseDocumentProvider1216401712.cs | 848 ------------ .../UserNestedProvider527241557.cs | 848 ------------ .../DocumentStorage/UserProvider1415907724.cs | 848 ------------ .../UserWithInterfaceProvider16433597.cs | 848 ------------ .../UserWithPrivateIdProvider1408394226.cs | 848 ------------ .../UserWithoutIdSetterProvider1320849530.cs | 844 ------------ .../Generated/EventStore/EventStorage.cs | 286 ---- .../Metadata/created_timestamp_queries.cs | 2 + .../Metadata/last_modified_queries.cs | 1 + .../Reading/Json/streaming_json_results.cs | 36 +- .../Linq/Compatibility/select_transforms.cs | 33 - .../Linq/EqualsIgnoreCase_filtering.cs | 39 - .../Linq/Fields/FieldCollectionTests.cs | 151 --- .../Reading/Linq/Internals/StatementTests.cs | 127 -- .../Internals/SubQueryFilterParserTests.cs | 36 - .../InvariantCultureIgnoreCase_filtering.cs | 49 - .../MatchesSql/MatchesSqlExtensionsTests.cs | 19 - .../Linq/Omitting_zero_offset_Tests.cs | 39 - .../Parsing/IsNullAndNotNullFilterTests.cs | 26 - .../Reading/Linq/SimpleEqualsParserTests.cs | 140 -- .../Linq/SimpleNotEqualsParserTests.cs | 79 -- .../SoftDeletes/DeletedBeforeParserTests.cs | 49 - .../SoftDeletes/DeletedSinceParserTests.cs | 51 - .../Linq/invoking_query_with_statistics.cs | 212 --- .../Linq/invoking_queryable_any_Tests.cs | 72 - .../invoking_queryable_any_async_Tests.cs | 75 -- .../invoking_queryable_count_async_Tests.cs | 97 -- .../invoking_queryable_through_first_Tests.cs | 92 -- ...ing_queryable_through_first_async_Tests.cs | 97 -- .../invoking_queryable_through_last_Tests.cs | 30 - ...invoking_queryable_through_single_Tests.cs | 110 -- ...ng_queryable_through_single_async_Tests.cs | 113 -- ...wing_the_command_from_a_queryable_Tests.cs | 78 -- .../query_beginning_with_constant_Tests.cs | 95 -- .../Reading/Linq/query_for_sum_Tests.cs | 82 -- .../Linq/query_with_aggregate_functions.cs | 100 -- .../Reading/Linq/query_with_dates_Tests.cs | 35 - .../Reading/Linq/query_with_float_Tests.cs | 28 - ...ery_with_is_in_generic_enumerable_Tests.cs | 60 - ...ith_properties_from_document_comparison.cs | 43 - .../Linq/select_transformations_Tests.cs | 44 - ...ing_const_boolean_in_where_clause_Tests.cs | 52 - .../using_custom_Linq_parser_plugins_Tests.cs | 103 -- .../Support/DefaultQueryFixture.cs | 6 +- .../Acceptance}/Support/LinqTestCase.cs | 8 +- .../Acceptance}/Support/LinqTestContext.cs | 24 +- .../Support/OrderedSelectComparison.cs | 6 +- .../Acceptance}/Support/TargetComparison.cs | 24 +- .../Support/TargetSchemaFixture.cs | 2 +- .../Acceptance}/casing_support.cs | 17 +- .../Acceptance/chained_where_clauses.cs} | 9 +- .../Acceptance/child_collection_queries.cs | 45 + .../Acceptance/custom_identity_members.cs} | 7 +- .../Acceptance/custom_linq_extensions.cs | 101 ++ .../Acceptance/date_type_usage.cs} | 28 +- .../Acceptance/deep_searches.cs} | 7 +- .../Acceptance/diagnostic_methods.cs} | 73 +- .../Acceptance/dictionary_usage.cs} | 42 +- .../Acceptance/enum_usage.cs} | 13 +- .../equals_method_usage_validation.cs | 102 ++ .../Acceptance/identity_map_mechanics.cs} | 7 +- .../Acceptance/json_naming_attributes.cs} | 9 +- .../Acceptance}/matches_sql_queries.cs | 13 +- .../Acceptance/nested_boolean_logic.cs} | 9 +- .../Acceptance/null_or_not_null_querying.cs} | 16 +- .../Acceptance/nullable_types.cs} | 9 +- .../Acceptance/number_filtering.cs} | 49 +- .../Acceptance/order_by_clauses.cs} | 12 +- .../Acceptance}/query_with_inheritance.cs | 20 +- .../Acceptance/select_clause_usage.cs} | 12 +- .../Acceptance/select_many.cs} | 24 +- .../Acceptance/statistics_and_paged_list.cs} | 208 ++- .../Acceptance/string_filtering.cs} | 82 +- .../Acceptance}/take_and_skip.cs | 11 +- .../Acceptance/using_dynamic_props.cs} | 14 +- .../Acceptance/where_clauses.cs} | 44 +- ...1189_can_select_transform_without_an_id.cs | 5 +- .../Bug_118_bad_exception_message_Tests.cs | 7 +- ...g_1217_order_by_count_of_sub_collection.cs | 61 + .../Bugs/Bug_1219_ordering_by_attributes.cs | 3 +- .../Bug_1245_include_plus_full_text_search.cs | 3 +- .../Bug_1256_querying_against_a_uint_type.cs | 3 +- ...25_Any_with_contains_on_IList_of_string.cs | 3 +- ...nside_of_where_against_child_collection.cs | 3 +- ...3_warn_about_custom_value_types_in_linq.cs | 7 +- ...g_1683_query_against_dict_string_object.cs | 17 +- .../Bugs/Bug_1703_Equality_Not_Symmetric.cs | 11 +- ...ric_type_parameters_of_compiled_queries.cs | 3 +- .../Bug_1875_duplicated_array_field_test.cs | 7 +- .../Bug_1884_multi_tenancy_and_Any_query.cs | 5 +- ...Bug_1886_compiled_query_value_retention.cs | 3 +- .../Bugs/Bug_1891_compiled_query_problem.cs | 3 +- .../Bug_1951_querying_against_nested_enum.cs | 3 +- .../Bug_2057_select_transform_dictionary.cs | 72 + ...erying_against_UTC_DateTime_with_Npgsql.cs | 3 +- ..._usage_of_coalescing_operator_in_select.cs | 8 +- ...list_contains_any_generates_invalid_sql.cs | 98 ++ ...s_to_respect_Take_and_Skip_in_main_body.cs | 3 +- .../Bug_2282_SOE_on_hiearchical_usage.cs | 5 +- .../Bug_260_Take_Skip_with_Select_Tests.cs | 3 +- .../Bugs/Bug_261_double_take_or_skip.cs | 4 +- ...276_Query_by_abstract_type_in_hierarchy.cs | 4 +- ...searches_are_not_using_searchable_field.cs | 9 +- ..._365_compiled_query_with_constant_fails.cs | 4 +- ...432_querying_with_UTC_times_with_offset.cs | 5 +- .../Bug_449_IsOneOf_query_with_enum_types.cs | 3 +- .../Bugs/Bug_479_select_datetime_fields.cs | 3 +- .../Bug_484_Contains_on_IList_of_string.cs | 3 +- .../Bugs/Bug_490_hierarchy_and_include.cs | 4 +- .../Bug_503_query_on_null_complex_object.cs | 10 +- ...elect_not_applying_sort_or_where_clause.cs | 14 +- .../Bug_561_negation_of_query_on_contains.cs | 4 +- ...d_592_Skip_and_Take_in_compiled_queries.cs | 4 +- ...sions_in_where_clause_of_compiled_query.cs | 4 +- ...starts_or_ends_with_in_compiled_queries.cs | 3 +- ...g_634_include_against_soft_deleted_docs.cs | 15 +- .../Bug_717_permutation_of_Linq_queries.cs | 3 +- ...llection_Contains_within_compiled_query.cs | 8 +- ...34_querying_inside_of_child_collections.cs | 16 +- ...te_tenancy_filters_appended_incorrectly.cs | 3 +- ...out_of_order_when_types_use_inheritance.cs | 8 +- ...g_997_or_queries_with_hierarchical_docs.cs | 3 +- ..._with_includes_and_ICompiledQuery_reuse.cs | 3 +- ...ed_query_problem_with_nested_properties.cs | 3 +- .../Bugs/hashset_contains.cs | 3 +- .../Bugs/query_with_order_by.cs | 5 +- .../ChildCollections/ChildTestClasses.cs | 6 +- .../count_for_child_collections.cs | 39 +- .../query_against_child_collections.cs} | 22 +- ...llectionToArrayJsonConverter_onProperty.cs | 12 +- ...with_global_CollectionStorage_WithArray.cs | 3 +- ...querying_through_n_deep_sub_collections.cs | 19 +- .../Compiled/compiled_query_Tests.cs | 7 +- .../compiled_query_by_string_fragments.cs | 15 +- ...alidating_and_making_unique_query_class.cs | 3 +- .../end_to_end_query_with_compiled_include.cs | 5 +- .../Includes/end_to_end_query_with_include.cs | 19 +- .../Internals}/BoolNotVisitorTests.cs | 3 +- .../ComparisonBetweenFieldsFragmentTests.cs | 5 +- .../Internals}/ComparisonFilterTests.cs | 3 +- .../Internals}/DuplicatedFieldTests.cs | 7 +- .../Internals}/ExpressionExtensionsTests.cs | 5 +- .../Internals/IsNullAndNotNullFilterTests.cs | 25 + .../Internals}/NotWhereFragmentTests.cs | 4 +- .../Internals/SimpleExpressionTests.cs | 152 +++ src/LinqTests/LinqTests.csproj | 129 ++ .../Operators/aggregate_functions.cs | 234 ++++ .../Operators/all_operator.cs} | 27 +- src/LinqTests/Operators/any_operator.cs | 132 ++ .../Operators/async_enumerable.cs} | 9 +- .../Operators/count_operator.cs} | 67 +- .../Operators/custom_marten_operators.cs} | 25 +- .../Operators/distinct_operator.cs} | 15 +- src/LinqTests/Operators/first_operator.cs | 180 +++ .../Operators/is_empty_operator.cs} | 7 +- .../Operators/is_one_of_operator.cs} | 8 +- .../Operators/is_subset_of_operator.cs} | 27 +- .../Operators/is_super_set_of_operator.cs} | 9 +- src/LinqTests/Operators/last_operator.cs | 47 + .../Operators/modulo_operator.cs} | 5 +- .../Operators/negation_operator.cs} | 9 +- src/LinqTests/Operators/single_operator.cs | 214 +++ .../Operators/to_list_operator.cs} | 9 +- .../Reading/Linq => LinqTests}/SimpleUser.cs | 2 +- ...ere_clauses_and_soft_deletes_configured.cs | 3 +- src/LinqTests/TestSetup.cs | 17 + src/LinqTests/Usings.cs | 1 + src/LinqTests/playing.cs | 21 + ...sing_containment_operator_in_linq_Tests.cs | 3 +- .../Patching/PatchExpressionTests.cs | 2 +- src/Marten.PLv8/Patching/PatchExpression.cs | 8 +- src/Marten.PLv8/Patching/PatchOperation.cs | 12 +- .../Transforms/DocumentTransforms.cs | 16 +- .../Transforms/TransformExtensions.cs | 20 +- src/Marten.Testing/Documents/Target.cs | 18 +- src/Marten.Testing/Examples/CamelCasing.cs | 6 +- .../Harness/TestOutputMartenLogger.cs | 12 + src/Marten.sln | 7 + .../Events/Aggregation/AggregateVersioning.cs | 6 +- .../MaybeArchivedMethodCallParser.cs | 6 +- .../Progress/ProjectionProgressStatement.cs | 3 +- src/Marten/Events/EventDocumentStorage.cs | 28 +- src/Marten/Events/EventMapping.cs | 49 +- src/Marten/Events/EventQueryMapping.cs | 33 +- src/Marten/Events/EventStatement.cs | 7 +- .../Flattened/FlatTableProjection.cs | 5 +- .../Events/Projections/Flattened/MemberMap.cs | 2 +- .../Querying/SingleEventQueryHandler.cs | 2 +- src/Marten/Events/Schema/EventTableColumn.cs | 3 +- src/Marten/Events/Schema/StreamsTable.cs | 3 +- .../Exceptions/BadLinqExpressionException.cs | 5 + src/Marten/IReadOnlyStoreOptions.cs | 2 + .../FrameCollectionExtensions.cs | 10 +- .../CompiledQueries/ClonedCompiledQuery.cs | 4 +- .../CompiledQueries/CompiledQueryCodeFile.cs | 2 + .../CompiledQueries/CompiledQueryPlan.cs | 24 +- .../CompiledQuerySourceBuilder.cs | 5 +- .../CompiledQueries/FieldQueryMember.cs | 2 +- .../CompiledQueries/HardCodedParameters.cs | 4 +- .../ICompiledQueryAwareFilter.cs | 72 + .../Internal/CompiledQueries/IQueryMember.cs | 7 +- .../CompiledQueries/PropertyQueryMember.cs | 2 +- .../Internal/CompiledQueries/QueryCompiler.cs | 23 +- .../Internal/CompiledQueries/QueryMember.cs | 101 +- .../DocumentSessionBase.HardDeletes.cs | 2 +- .../Sessions/QuerySession.Querying.cs | 4 +- .../Internal/Storage/DocumentStorage.cs | 128 +- .../Internal/Storage/IDocumentStorage.cs | 19 +- .../Storage/SubClassDocumentStorage.cs | 37 +- .../Linq/CollectionUsage.Compilation.cs | 300 +++++ src/Marten/Linq/CollectionUsage.Parsing.cs | 51 + src/Marten/Linq/CollectionUsage.cs | 41 + .../Linq/CreatedAt/CreatedBeforeParser.cs | 5 +- .../Linq/CreatedAt/CreatedSinceParser.cs | 5 +- src/Marten/Linq/Fields/ArrayField.cs | 69 - .../Linq/Fields/CollectionLengthField.cs | 18 - src/Marten/Linq/Fields/DateTimeField.cs | 17 - src/Marten/Linq/Fields/DateTimeOffsetField.cs | 17 - src/Marten/Linq/Fields/DictionaryField.cs | 98 -- src/Marten/Linq/Fields/EnumAsIntegerField.cs | 27 - src/Marten/Linq/Fields/EnumAsStringField.cs | 44 - src/Marten/Linq/Fields/FieldBase.cs | 134 -- src/Marten/Linq/Fields/FieldCollection.cs | 219 ---- src/Marten/Linq/Fields/HasValueField.cs | 23 - src/Marten/Linq/Fields/IField.cs | 48 - src/Marten/Linq/Fields/IdField.cs | 68 - src/Marten/Linq/Fields/NotField.cs | 20 - src/Marten/Linq/Fields/NullableTypeField.cs | 97 -- src/Marten/Linq/Fields/SimpleCastField.cs | 17 - src/Marten/Linq/Fields/SimpleDataField.cs | 67 - src/Marten/Linq/Fields/StringField.cs | 16 - src/Marten/Linq/Filters/CollectionIsEmpty.cs | 29 - .../Linq/Filters/CollectionIsNotEmpty.cs | 34 - .../Linq/Filters/ContainmentWhereFragment.cs | 120 -- src/Marten/Linq/ILinqQuery.cs | 13 + src/Marten/Linq/IMethodCallMatcher.cs | 14 - .../Linq/Includes/DictionaryIncludePlan.cs | 25 + src/Marten/Linq/Includes/IIncludePlan.cs | 10 +- .../IdInIncludedDocumentIdentifierFilter.cs | 31 + .../Linq/Includes/InTempTableWhereFragment.cs | 50 - .../IncludeIdentitySelectorStatement.cs | 118 -- src/Marten/Linq/Includes/IncludePlan.cs | 62 +- src/Marten/Linq/Includes/ListIncludePlan.cs | 13 + .../Includes/PassthroughSelectStatement.cs | 24 + .../Linq/Includes/TemporaryTableStatement.cs | 31 + .../Linq/LastModified/ModifiedBeforeParser.cs | 5 +- .../Linq/LastModified/ModifiedSinceParser.cs | 5 +- src/Marten/Linq/MartenLinqQueryProvider.cs | 101 +- src/Marten/Linq/MartenLinqQueryable.cs | 106 +- .../Linq/MatchesSql/MatchesSqlParser.cs | 5 +- src/Marten/Linq/Members/BooleanMember.cs | 19 + .../Linq/Members/ChildCollectionCount.cs | 39 + .../ChildCollectionJsonPathCountFilter.cs | 106 ++ .../Linq/Members/ChildCollectionMember.cs | 301 +++++ .../Members/ChildCollectionWhereClause.cs | 70 + src/Marten/Linq/Members/ChildDocument.cs | 81 ++ .../Linq/Members/CollectionLengthMember.cs | 21 + src/Marten/Linq/Members/DateTimeMember.cs | 17 + .../Linq/Members/DateTimeOffsetMember.cs | 17 + src/Marten/Linq/Members/DictionaryMember.cs | 142 ++ .../DocumentQueryableMemberCollection.cs | 104 ++ .../Linq/Members/DuplicatedArrayField.cs | 121 ++ .../{Fields => Members}/DuplicatedField.cs | 102 +- .../Linq/Members/EnumAsIntegerMember.cs | 36 + src/Marten/Linq/Members/EnumAsStringMember.cs | 42 + src/Marten/Linq/Members/HasValueMember.cs | 101 ++ src/Marten/Linq/Members/IBooleanField.cs | 8 + src/Marten/Linq/Members/ICollectionMember.cs | 31 + .../IComparableMember.cs} | 6 +- .../Linq/Members/IHasChildrenMembers.cs | 9 + .../IMemberSource.cs} | 6 +- src/Marten/Linq/Members/IQueryableMember.cs | 71 + .../Members/IQueryableMemberCollection.cs | 9 + src/Marten/Linq/Members/IdMember.cs | 92 ++ .../ModuloComparison.cs} | 22 +- src/Marten/Linq/Members/NotMember.cs | 20 + src/Marten/Linq/Members/QueryableMember.cs | 156 +++ .../ScalarSelectManyStatement.cs | 7 +- .../ScalarSelectManyStringStatement.cs | 11 + src/Marten/Linq/Members/SimpleCastMember.cs | 14 + src/Marten/Linq/Members/StringMember.cs | 32 + .../Linq/Members/ValueCollectionMember.cs | 300 +++++ src/Marten/Linq/Members/WholeDataMember.cs | 114 ++ .../Linq/Operators/IncludeExpressionNode.cs | 44 - .../Linq/Operators/IncludeResultOperator.cs | 114 -- .../Linq/Operators/OrderByComparerClause.cs | 47 - .../OrderByComparerExpressionNode.cs | 83 -- .../Linq/Operators/StatsExpressionNode.cs | 39 - .../Linq/Operators/StatsResultOperator.cs | 41 - src/Marten/Linq/OrderingDirection.cs | 16 + .../Linq/Parsing/DictionaryExpressions.cs | 80 -- src/Marten/Linq/Parsing/EnumerableContains.cs | 38 - .../Linq/Parsing/ExpressionExtensions.cs | 38 - src/Marten/Linq/Parsing/FindMembers.cs | 84 -- src/Marten/Linq/Parsing/IExpressionParser.cs | 21 - src/Marten/Linq/Parsing/IMethodCallParser.cs | 10 +- src/Marten/Linq/Parsing/LinqHandlerBuilder.cs | 336 ----- .../Linq/Parsing/LinqInternalExtensions.cs | 296 +++++ src/Marten/Linq/Parsing/LinqQueryParser.cs | 313 +++++ src/Marten/Linq/Parsing/MartenQueryParser.cs | 61 - src/Marten/Linq/Parsing/MemberFinder.cs | 94 ++ src/Marten/Linq/Parsing/MethodCallParser.cs | 28 - .../Linq/Parsing/Methods/AllMethodParser.cs | 40 + .../Linq/Parsing/Methods/AnySubQueryParser.cs | 78 ++ src/Marten/Linq/Parsing/Methods/AnyTenant.cs | 7 +- .../Parsing/Methods/DictionaryContains.cs | 34 + .../Parsing/Methods/DictionaryContainsKey.cs | 34 + .../Parsing/Methods/EnumerableContains.cs | 38 + .../FullTextSearchMethodCallParser.cs | 11 +- .../Parsing/Methods/FullText/NgramSearch.cs | 26 + .../Methods/{ => FullText}/PhraseSearch.cs | 2 +- .../Methods/{ => FullText}/PlainTextSearch.cs | 2 +- .../Parsing/Methods/{ => FullText}/Search.cs | 2 +- .../Methods/{ => FullText}/WebStyleSearch.cs | 2 +- src/Marten/Linq/Parsing/Methods/IsEmpty.cs | 10 +- .../Parsing/Methods/IsInGenericEnumerable.cs | 26 - src/Marten/Linq/Parsing/Methods/IsNotOneOf.cs | 14 +- src/Marten/Linq/Parsing/Methods/IsOneOf.cs | 15 +- src/Marten/Linq/Parsing/Methods/IsSubsetOf.cs | 17 +- .../Linq/Parsing/Methods/IsSupersetOf.cs | 16 +- .../Linq/Parsing/Methods/NgramSearch.cs | 25 - .../Parsing/Methods/SimpleEqualsParser.cs | 86 +- .../Parsing/Methods/StringComparisonParser.cs | 137 -- .../Linq/Parsing/Methods/StringContains.cs | 31 - .../Linq/Parsing/Methods/StringEndsWith.cs | 41 - .../Linq/Parsing/Methods/StringEquals.cs | 21 - .../{ => Strings}/EqualsIgnoreCaseParser.cs | 9 +- .../Methods/Strings/StringComparisonParser.cs | 98 ++ .../Parsing/Methods/Strings/StringContains.cs | 93 ++ .../Parsing/Methods/Strings/StringEndsWith.cs | 92 ++ .../Parsing/Methods/Strings/StringEquals.cs | 51 + .../Methods/Strings/StringStartsWith.cs | 82 ++ .../Linq/Parsing/Methods/TenantIsOneOf.cs | 7 +- .../Linq/Parsing/Operators/AnyOperator.cs | 17 + .../Linq/Parsing/Operators/CasingRule.cs | 7 + .../Parsing/Operators/DistinctOperator.cs | 16 + .../Linq/Parsing/Operators/IncludeOperator.cs | 19 + .../Linq/Parsing/Operators/LastOperator.cs | 30 + .../Linq/Parsing/Operators/LinqOperator.cs | 15 + .../Linq/Parsing/Operators/OperatorLibrary.cs | 55 + src/Marten/Linq/Parsing/Operators/Ordering.cs | 26 + .../Parsing/Operators/OrderingOperator.cs | 32 + .../Parsing/Operators/SelectManyOperator.cs | 17 + .../Linq/Parsing/Operators/SelectOperator.cs | 28 + .../Parsing/Operators/SingleValueOperator.cs | 35 + .../Linq/Parsing/Operators/SkipOperator.cs | 18 + .../Linq/Parsing/Operators/TakeOperator.cs | 18 + .../Linq/Parsing/Operators/WhereOperator.cs | 37 + .../Linq/Parsing/SelectTransformBuilder.cs | 20 +- src/Marten/Linq/Parsing/SelectorVisitor.cs | 91 +- src/Marten/Linq/Parsing/SimpleExpression.cs | 314 +++++ src/Marten/Linq/Parsing/SingleValueMode.cs | 17 + src/Marten/Linq/Parsing/StringStartsWith.cs | 21 - ...ereClauseParser.BinaryExpressionVisitor.cs | 80 -- .../Parsing/WhereClauseParser.BinarySide.cs | 54 - src/Marten/Linq/Parsing/WhereClauseParser.cs | 329 +---- .../Linq/QueryHandlers/LinqConstants.cs | 18 +- .../Linq/QueryHandlers/ListQueryHandler.cs | 8 +- .../ListWithStatsQueryHandler.cs | 8 +- .../Linq/QueryHandlers/OneResultHandler.cs | 8 +- .../QueryHandlers/UserSuppliedQueryHandler.cs | 5 +- .../Linq/SoftDeletes/DeletedBeforeParser.cs | 13 +- .../Linq/SoftDeletes/DeletedSinceParser.cs | 13 +- .../Linq/SoftDeletes/IsDeletedParser.cs | 6 +- .../Linq/SoftDeletes/MaybeDeletedParser.cs | 7 +- .../Linq/SqlGeneration/AllComparisonFilter.cs | 114 -- .../SqlGeneration/AllIdSelectorStatement.cs | 20 - .../Linq/SqlGeneration/AnySelectClause.cs | 16 +- .../ContainsIdSelectorStatement.cs | 37 - src/Marten/Linq/SqlGeneration/CountClause.cs | 35 +- .../SqlGeneration/CountComparisonStatement.cs | 58 - .../Linq/SqlGeneration/CountStatement.cs | 33 - .../Linq/SqlGeneration/DataSelectClause.cs | 35 +- src/Marten/Linq/SqlGeneration/Deletion.cs | 6 + .../DistinctSelectionStatement.cs | 29 + .../Linq/SqlGeneration/DocumentStatement.cs | 118 -- .../ExplodeCollectionStatement.cs | 58 + .../Linq/SqlGeneration/FilterStatement.cs | 81 ++ .../Filters/AllValuesAreNullFilter.cs | 67 + .../Filters/AllValuesEqualFilter.cs | 31 + .../Filters/BooleanFieldIsFalse.cs | 18 +- .../Filters/BooleanFieldIsTrue.cs | 18 +- .../{ => SqlGeneration}/Filters/ByIdFilter.cs | 2 +- .../Filters/CollectionIsEmpty.cs | 34 + .../Filters/CollectionIsNotEmpty.cs | 80 ++ .../Filters/ContainmentWhereFilter.cs | 192 +++ .../Filters/CurrentTenantFilter.cs | 2 +- .../Filters/DeepCollectionIsNotEmpty.cs | 35 + .../SqlGeneration/Filters/EqualsFilter.cs | 19 + .../Filters/ExcludeSoftDeletedFilter.cs | 2 +- .../Filters/FullTextWhereFragment.cs | 4 +- .../SqlGeneration/Filters/ICollectionAware.cs | 30 + .../Filters/ITenantWhereFragment.cs | 2 +- .../Filters/IsNotNullFilter.cs | 16 +- .../Filters/IsNullFilter.cs | 16 +- .../Filters/MemberComparisonFilter.cs | 69 + .../Filters/SpecificTenantFilter.cs | 2 +- .../SqlGeneration/Filters/SubQueryFilter.cs | 71 + .../Filters/TenantIsOneOfWhereFragment.cs | 2 +- .../WriteSerializedJsonParameterFrame.cs | 160 +++ src/Marten/Linq/SqlGeneration/FromFragment.cs | 34 + .../Linq/SqlGeneration/IScalarSelectClause.cs | 2 +- .../Linq/SqlGeneration/ISelectClause.cs | 9 +- .../Linq/SqlGeneration/IdSelectorStatement.cs | 80 -- .../Linq/SqlGeneration/JsonStatement.cs | 42 - .../SqlGeneration/NewScalarSelectClause.cs | 146 +++ .../NewScalarStringSelectClause.cs | 106 ++ .../Linq/SqlGeneration/OrderByFragment.cs | 32 + .../Linq/SqlGeneration/ScalarSelectClause.cs | 40 +- .../ScalarSelectManyStringStatement.cs | 9 - .../SqlGeneration/ScalarStringSelectClause.cs | 37 +- .../Linq/SqlGeneration/SelectorStatement.cs | 192 ++- .../SqlGeneration/SqlFragmentExtensions.cs | 25 - .../SqlGeneration/Statement.WhereParsing.cs | 90 ++ src/Marten/Linq/SqlGeneration/Statement.cs | 249 +--- .../Linq/SqlGeneration/StatementMode.cs | 3 +- .../Linq/SqlGeneration/StatementOperation.cs | 54 +- .../Linq/SqlGeneration/StatsSelectClause.cs | 12 +- .../Linq/SqlGeneration/SubQueryStatement.cs | 50 - .../SqlGeneration/WhereFragmentExtensions.cs | 2 +- src/Marten/LinqExtensions.cs | 1 - src/Marten/LinqParsing.cs | 58 +- src/Marten/Marten.csproj | 14 +- src/Marten/MartenRegistry.cs | 9 +- src/Marten/Properties/AssemblyInfo.cs | 1 + src/Marten/Schema/ChildDocument.cs | 33 - src/Marten/Schema/ComputedIndex.cs | 12 +- src/Marten/Schema/DocumentMapping.cs | 103 +- src/Marten/Schema/FullTextIndex.cs | 4 +- src/Marten/Schema/IDocumentMapping.cs | 3 + src/Marten/Schema/NgramIndex.cs | 4 +- src/Marten/Schema/SubClassMapping.cs | 8 + .../Services/BatchQuerying/BatchedQuery.cs | 24 +- src/Marten/Storage/DocumentTable.cs | 2 + src/Marten/Storage/DuplicatedFieldColumn.cs | 2 +- .../Metadata/EntityMetadataQueryHandler.cs | 4 +- src/Marten/Storage/Metadata/MetadataColumn.cs | 4 +- src/Marten/StoreOptions.MemberFactory.cs | 99 ++ src/Marten/StoreOptions.cs | 40 +- src/Marten/Util/CommandExtensions.cs | 5 +- src/Marten/Util/StringExtensions.cs | 20 + 561 files changed, 10640 insertions(+), 56398 deletions(-) delete mode 100644 src/DocumentDbTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs delete mode 100644 src/DocumentDbTests/Bugs/Bug_2057_select_transform_dictionary.cs delete mode 100644 src/DocumentDbTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs delete mode 100644 src/DocumentDbTests/Bugs/Bug_849_not_node_not_correctly_evaluated.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/DirtyTrackingUserByUsernameCompiledQuerySource661477123.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/IdentityOnlyUserByUsernameCompiledQuerySource661477123.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery1CompiledQuerySource2018461339.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery2CompiledQuerySource1615176812.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQueryTargetCompiledQuerySource9758203.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindJsonUsersByUsernameCompiledQuerySource1607037309.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindUserByAllTheThingsCompiledQuerySource878799577.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetPaginationQueryCompiledQuerySource323866534.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetsInOrderCompiledQuerySource468279698.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTestQueryCompiledQuerySource2052986011.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameCompiledQuerySource661477123.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameWithFieldsCompiledQuerySource92089138.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserCountByFirstNameCompiledQuerySource1983785893.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsCompiledQuerySource1056635770.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsInsensitiveCompiledQuerySource2080514763.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameEndsWithCompiledQuerySource1088283705.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameStartsWithCompiledQuerySource515679394.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameCompiledQuerySource314143719.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyCompiledNestedQueryCompiledQuerySource970855369.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource2026718760.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource272805147.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUserByUsernameCompiledQuerySource661477123.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameContainsCompiledQuerySource893470325.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/AccountProvider793732554.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/AttVersionedDocProvider506859367.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/BugProvider65166103.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/CarProvider343829114.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopEmployeeProvider920305685.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopProvider2130089093.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/CompanyProvider297217634.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/ContactProvider677813566.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/CustomerProvider728829122.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/DocHolderProvider1892370027.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithArraysProvider1391541541.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithNumberProvider210740905.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithUintProvider1372666391.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/FailureInLifeProvider461155494.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/GroupProvider994823898.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/GuidDocProvider400073224.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/GuyWithIntArrayProvider1326363224.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/IntDocProvider379264442.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/IssueProvider2074714110.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/LongDocProvider1431212005.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/MainEntityProvider1625545438.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/MartenStoredStateProvider1211396321.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/MyClassProvider52903863.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/MyTrackedDocProvider815737241.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/MyVersionedDocProvider1489495374.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/NonStandardDocProvider1732698282.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/PaginationTestDocumentProvider1855354059.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/PlayerProvider1707213853.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductProvider1360380871.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithListProvider1228310865.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithNumbersProvider1463839245.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider1217791244.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider535117371.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/RecordDocumentProvider1196727384.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/RootProvider493946136.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/RouteDetailsProvider784762106.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/SimpleUserProvider652546491.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/StringDocProvider478514312.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetGroupProvider723464596.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetProvider1797031270.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/TaskProvider74835621.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2001772986.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2042192398.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/TopProvider102551794.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/UserFromBaseDocumentProvider1216401712.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/UserNestedProvider527241557.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/UserProvider1415907724.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithInterfaceProvider16433597.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithPrivateIdProvider1408394226.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithoutIdSetterProvider1320849530.cs delete mode 100644 src/DocumentDbTests/Internal/Generated/EventStore/EventStorage.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/Compatibility/select_transforms.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/EqualsIgnoreCase_filtering.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/Fields/FieldCollectionTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/Internals/StatementTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/Internals/SubQueryFilterParserTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/InvariantCultureIgnoreCase_filtering.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/MatchesSql/MatchesSqlExtensionsTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/Omitting_zero_offset_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/Parsing/IsNullAndNotNullFilterTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/SimpleEqualsParserTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/SimpleNotEqualsParserTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedBeforeParserTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedSinceParserTests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_query_with_statistics.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_any_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_any_async_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_count_async_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_async_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_through_last_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_async_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/previewing_the_command_from_a_queryable_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/query_beginning_with_constant_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/query_for_sum_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/query_with_aggregate_functions.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/query_with_dates_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/query_with_float_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/query_with_is_in_generic_enumerable_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/query_with_properties_from_document_comparison.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/select_transformations_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/using_const_boolean_in_where_clause_Tests.cs delete mode 100644 src/DocumentDbTests/Reading/Linq/using_custom_Linq_parser_plugins_Tests.cs rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/Support/DefaultQueryFixture.cs (91%) rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/Support/LinqTestCase.cs (67%) rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/Support/LinqTestContext.cs (82%) rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/Support/OrderedSelectComparison.cs (91%) rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/Support/TargetComparison.cs (67%) rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/Support/TargetSchemaFixture.cs (93%) rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/casing_support.cs (84%) rename src/{DocumentDbTests/Reading/Linq/using_multiple_where_clauses_Tests.cs => LinqTests/Acceptance/chained_where_clauses.cs} (88%) create mode 100644 src/LinqTests/Acceptance/child_collection_queries.cs rename src/{DocumentDbTests/Reading/Linq/query_by_different_id_member.cs => LinqTests/Acceptance/custom_identity_members.cs} (94%) create mode 100644 src/LinqTests/Acceptance/custom_linq_extensions.cs rename src/{DocumentDbTests/Reading/Linq/query_against_dateoffset_Tests.cs => LinqTests/Acceptance/date_type_usage.cs} (68%) rename src/{DocumentDbTests/Reading/Linq/deep_searches_Tests.cs => LinqTests/Acceptance/deep_searches.cs} (97%) rename src/{DocumentDbTests/Reading/Linq/explain_query.cs => LinqTests/Acceptance/diagnostic_methods.cs} (61%) rename src/{DocumentDbTests/Reading/Linq/dictionary_is_translated.cs => LinqTests/Acceptance/dictionary_usage.cs} (56%) rename src/{DocumentDbTests/Reading/Linq/query_with_enums_Tests.cs => LinqTests/Acceptance/enum_usage.cs} (97%) create mode 100644 src/LinqTests/Acceptance/equals_method_usage_validation.cs rename src/{DocumentDbTests/Reading/Linq/query_running_through_the_IdentityMap_Tests.cs => LinqTests/Acceptance/identity_map_mechanics.cs} (93%) rename src/{DocumentDbTests/Reading/Linq/recognizing_json_names_from_attributes.cs => LinqTests/Acceptance/json_naming_attributes.cs} (87%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/Acceptance}/matches_sql_queries.cs (84%) rename src/{DocumentDbTests/Reading/Linq/query_with_nested_boolean_logic_Tests.cs => LinqTests/Acceptance/nested_boolean_logic.cs} (80%) rename src/{DocumentDbTests/Reading/Linq/IsNullNotNullArbitraryDepthTests.cs => LinqTests/Acceptance/null_or_not_null_querying.cs} (78%) rename src/{DocumentDbTests/Reading/Linq/query_with_nullable_types_Tests.cs => LinqTests/Acceptance/nullable_types.cs} (93%) rename src/{DocumentDbTests/Reading/Linq/query_with_biginteger_tests.cs => LinqTests/Acceptance/number_filtering.cs} (51%) rename src/{DocumentDbTests/Reading/Linq/Compatibility/simple_order_by_clauses.cs => LinqTests/Acceptance/order_by_clauses.cs} (64%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/Acceptance}/query_with_inheritance.cs (93%) rename src/{DocumentDbTests/Reading/Linq/invoking_query_with_select_Tests.cs => LinqTests/Acceptance/select_clause_usage.cs} (98%) rename src/{DocumentDbTests/Reading/Linq/query_with_select_many.cs => LinqTests/Acceptance/select_many.cs} (96%) rename src/{DocumentDbTests/Reading/Linq/pagedlist_queryable_extension_Tests.cs => LinqTests/Acceptance/statistics_and_paged_list.cs} (67%) rename src/{DocumentDbTests/Reading/Linq/StringNotVisitorTests.cs => LinqTests/Acceptance/string_filtering.cs} (56%) rename src/{DocumentDbTests/Reading/Linq/Compatibility => LinqTests/Acceptance}/take_and_skip.cs (78%) rename src/{DocumentDbTests/Reading/Linq/query_with_order_by_dynamic_props_tests.cs => LinqTests/Acceptance/using_dynamic_props.cs} (95%) rename src/{DocumentDbTests/Reading/Linq/Compatibility/simple_where_clauses.cs => LinqTests/Acceptance/where_clauses.cs} (75%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1189_can_select_transform_without_an_id.cs (94%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_118_bad_exception_message_Tests.cs (86%) create mode 100644 src/LinqTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1219_ordering_by_attributes.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1245_include_plus_full_text_search.cs (98%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1256_querying_against_a_uint_type.cs (95%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1413_not_inside_of_where_against_child_collection.cs (93%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1473_warn_about_custom_value_types_in_linq.cs (87%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1683_query_against_dict_string_object.cs (76%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1703_Equality_Not_Symmetric.cs (94%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries.cs (92%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1875_duplicated_array_field_test.cs (91%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs (98%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1886_compiled_query_value_retention.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1891_compiled_query_problem.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_1951_querying_against_nested_enum.cs (98%) create mode 100644 src/LinqTests/Bugs/Bug_2057_select_transform_dictionary.cs rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select.cs (81%) create mode 100644 src/LinqTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body.cs (99%) rename src/{DocumentDbTests/HierarchicalStorage => LinqTests/Bugs}/Bug_2282_SOE_on_hiearchical_usage.cs (94%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/Bugs}/Bug_260_Take_Skip_with_Select_Tests.cs (94%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_261_double_take_or_skip.cs (94%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs (95%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_337_certain_boolean_searches_are_not_using_searchable_field.cs (92%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_365_compiled_query_with_constant_fails.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs (99%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_479_select_datetime_fields.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_484_Contains_on_IList_of_string.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_490_hierarchy_and_include.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_503_query_on_null_complex_object.cs (80%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause.cs (88%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_561_negation_of_query_on_contains.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_582_and_592_Skip_and_Take_in_compiled_queries.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_605_unary_expressions_in_where_clause_of_compiled_query.cs (98%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.cs (98%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_634_include_against_soft_deleted_docs.cs (83%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_717_permutation_of_Linq_queries.cs (98%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_784_Collection_Contains_within_compiled_query.cs (94%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_834_querying_inside_of_child_collections.cs (69%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs (97%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs (92%) rename src/{DocumentDbTests => LinqTests}/Bugs/Bug_997_or_queries_with_hierarchical_docs.cs (96%) rename src/{DocumentDbTests => LinqTests}/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs (98%) rename src/{DocumentDbTests => LinqTests}/Bugs/compiled_query_problem_with_nested_properties.cs (95%) rename src/{DocumentDbTests => LinqTests}/Bugs/hashset_contains.cs (94%) rename src/{DocumentDbTests => LinqTests}/Bugs/query_with_order_by.cs (99%) rename src/{DocumentDbTests/Reading/Linq => LinqTests}/ChildCollections/ChildTestClasses.cs (85%) rename src/{DocumentDbTests/Reading/Linq => LinqTests}/ChildCollections/count_for_child_collections.cs (75%) rename src/{DocumentDbTests/Reading/Linq/query_against_child_collections_integrated_Tests.cs => LinqTests/ChildCollections/query_against_child_collections.cs} (96%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/ChildCollections}/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs (93%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/ChildCollections}/query_with_inner_query_with_global_CollectionStorage_WithArray.cs (99%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/ChildCollections}/querying_through_n_deep_sub_collections.cs (90%) rename src/{DocumentDbTests/Reading/Linq => LinqTests}/Compiled/compiled_query_Tests.cs (99%) rename src/{DocumentDbTests/Reading/Linq => LinqTests}/Compiled/compiled_query_by_string_fragments.cs (94%) rename src/{DocumentDbTests/Reading/Linq => LinqTests}/Compiled/validating_and_making_unique_query_class.cs (97%) rename src/{DocumentDbTests/Reading => LinqTests}/Includes/end_to_end_query_with_compiled_include.cs (97%) rename src/{DocumentDbTests/Reading => LinqTests}/Includes/end_to_end_query_with_include.cs (98%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/Internals}/BoolNotVisitorTests.cs (97%) rename src/{DocumentDbTests/Reading/Linq/Parsing => LinqTests/Internals}/ComparisonBetweenFieldsFragmentTests.cs (88%) rename src/{DocumentDbTests/Reading/Linq/Parsing => LinqTests/Internals}/ComparisonFilterTests.cs (88%) rename src/{DocumentDbTests/Reading/Linq/Fields => LinqTests/Internals}/DuplicatedFieldTests.cs (98%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/Internals}/ExpressionExtensionsTests.cs (84%) create mode 100644 src/LinqTests/Internals/IsNullAndNotNullFilterTests.cs rename src/{DocumentDbTests/Reading/Linq/Parsing => LinqTests/Internals}/NotWhereFragmentTests.cs (91%) create mode 100644 src/LinqTests/Internals/SimpleExpressionTests.cs create mode 100644 src/LinqTests/LinqTests.csproj create mode 100644 src/LinqTests/Operators/aggregate_functions.cs rename src/{DocumentDbTests/Reading/Linq/invoking_queryable_all_operation_tests.cs => LinqTests/Operators/all_operator.cs} (90%) create mode 100644 src/LinqTests/Operators/any_operator.cs rename src/{DocumentDbTests/Reading/Linq/invoking_query_with_ToAsyncEnumerable.cs => LinqTests/Operators/async_enumerable.cs} (78%) rename src/{DocumentDbTests/Reading/Linq/invoking_queryable_count_Tests.cs => LinqTests/Operators/count_operator.cs} (62%) rename src/{DocumentDbTests/Reading/Linq/LinqExtensionsTests.cs => LinqTests/Operators/custom_marten_operators.cs} (86%) rename src/{DocumentDbTests/Reading/Linq/query_with_distinct_Tests.cs => LinqTests/Operators/distinct_operator.cs} (87%) create mode 100644 src/LinqTests/Operators/first_operator.cs rename src/{DocumentDbTests/Reading/Linq/query_with_is_empty.cs => LinqTests/Operators/is_empty_operator.cs} (82%) rename src/{DocumentDbTests/Reading/Linq/query_with_is_one_of_Tests.cs => LinqTests/Operators/is_one_of_operator.cs} (97%) rename src/{DocumentDbTests/Reading/Linq/query_with_IsSubsetOf_Tests.cs => LinqTests/Operators/is_subset_of_operator.cs} (77%) rename src/{DocumentDbTests/Reading/Linq/query_with_IsSuperSetOf_Tests.cs => LinqTests/Operators/is_super_set_of_operator.cs} (92%) create mode 100644 src/LinqTests/Operators/last_operator.cs rename src/{DocumentDbTests/Reading/Linq/query_with_modulo_Tests.cs => LinqTests/Operators/modulo_operator.cs} (96%) rename src/{DocumentDbTests/Reading/Linq/query_negating_predicate_with_binary_operator_tests.cs => LinqTests/Operators/negation_operator.cs} (87%) create mode 100644 src/LinqTests/Operators/single_operator.cs rename src/{DocumentDbTests/Reading/Linq/invoking_queryable_through_to_list_async_Tests.cs => LinqTests/Operators/to_list_operator.cs} (80%) rename src/{DocumentDbTests/Reading/Linq => LinqTests}/SimpleUser.cs (94%) rename src/{DocumentDbTests/Reading/Linq => LinqTests/SoftDeletes}/query_with_multiple_where_clauses_and_soft_deletes_configured.cs (97%) create mode 100644 src/LinqTests/TestSetup.cs create mode 100644 src/LinqTests/Usings.cs create mode 100644 src/LinqTests/playing.cs rename src/{DocumentDbTests/Reading/Linq => LinqTests}/using_containment_operator_in_linq_Tests.cs (98%) create mode 100644 src/Marten/Internal/CompiledQueries/ICompiledQueryAwareFilter.cs create mode 100644 src/Marten/Linq/CollectionUsage.Compilation.cs create mode 100644 src/Marten/Linq/CollectionUsage.Parsing.cs create mode 100644 src/Marten/Linq/CollectionUsage.cs delete mode 100644 src/Marten/Linq/Fields/ArrayField.cs delete mode 100644 src/Marten/Linq/Fields/CollectionLengthField.cs delete mode 100644 src/Marten/Linq/Fields/DateTimeField.cs delete mode 100644 src/Marten/Linq/Fields/DateTimeOffsetField.cs delete mode 100644 src/Marten/Linq/Fields/DictionaryField.cs delete mode 100644 src/Marten/Linq/Fields/EnumAsIntegerField.cs delete mode 100644 src/Marten/Linq/Fields/EnumAsStringField.cs delete mode 100644 src/Marten/Linq/Fields/FieldBase.cs delete mode 100644 src/Marten/Linq/Fields/FieldCollection.cs delete mode 100644 src/Marten/Linq/Fields/HasValueField.cs delete mode 100644 src/Marten/Linq/Fields/IField.cs delete mode 100644 src/Marten/Linq/Fields/IdField.cs delete mode 100644 src/Marten/Linq/Fields/NotField.cs delete mode 100644 src/Marten/Linq/Fields/NullableTypeField.cs delete mode 100644 src/Marten/Linq/Fields/SimpleCastField.cs delete mode 100644 src/Marten/Linq/Fields/SimpleDataField.cs delete mode 100644 src/Marten/Linq/Fields/StringField.cs delete mode 100644 src/Marten/Linq/Filters/CollectionIsEmpty.cs delete mode 100644 src/Marten/Linq/Filters/CollectionIsNotEmpty.cs delete mode 100644 src/Marten/Linq/Filters/ContainmentWhereFragment.cs create mode 100644 src/Marten/Linq/ILinqQuery.cs delete mode 100644 src/Marten/Linq/IMethodCallMatcher.cs create mode 100644 src/Marten/Linq/Includes/DictionaryIncludePlan.cs create mode 100644 src/Marten/Linq/Includes/IdInIncludedDocumentIdentifierFilter.cs delete mode 100644 src/Marten/Linq/Includes/InTempTableWhereFragment.cs delete mode 100644 src/Marten/Linq/Includes/IncludeIdentitySelectorStatement.cs create mode 100644 src/Marten/Linq/Includes/ListIncludePlan.cs create mode 100644 src/Marten/Linq/Includes/PassthroughSelectStatement.cs create mode 100644 src/Marten/Linq/Includes/TemporaryTableStatement.cs create mode 100644 src/Marten/Linq/Members/BooleanMember.cs create mode 100644 src/Marten/Linq/Members/ChildCollectionCount.cs create mode 100644 src/Marten/Linq/Members/ChildCollectionJsonPathCountFilter.cs create mode 100644 src/Marten/Linq/Members/ChildCollectionMember.cs create mode 100644 src/Marten/Linq/Members/ChildCollectionWhereClause.cs create mode 100644 src/Marten/Linq/Members/ChildDocument.cs create mode 100644 src/Marten/Linq/Members/CollectionLengthMember.cs create mode 100644 src/Marten/Linq/Members/DateTimeMember.cs create mode 100644 src/Marten/Linq/Members/DateTimeOffsetMember.cs create mode 100644 src/Marten/Linq/Members/DictionaryMember.cs create mode 100644 src/Marten/Linq/Members/DocumentQueryableMemberCollection.cs create mode 100644 src/Marten/Linq/Members/DuplicatedArrayField.cs rename src/Marten/Linq/{Fields => Members}/DuplicatedField.cs (59%) create mode 100644 src/Marten/Linq/Members/EnumAsIntegerMember.cs create mode 100644 src/Marten/Linq/Members/EnumAsStringMember.cs create mode 100644 src/Marten/Linq/Members/HasValueMember.cs create mode 100644 src/Marten/Linq/Members/IBooleanField.cs create mode 100644 src/Marten/Linq/Members/ICollectionMember.cs rename src/Marten/Linq/{Fields/IComparableFragment.cs => Members/IComparableMember.cs} (57%) create mode 100644 src/Marten/Linq/Members/IHasChildrenMembers.cs rename src/Marten/Linq/{Fields/IFieldSource.cs => Members/IMemberSource.cs} (69%) create mode 100644 src/Marten/Linq/Members/IQueryableMember.cs create mode 100644 src/Marten/Linq/Members/IQueryableMemberCollection.cs create mode 100644 src/Marten/Linq/Members/IdMember.cs rename src/Marten/Linq/{Parsing/ModuloFragment.cs => Members/ModuloComparison.cs} (56%) create mode 100644 src/Marten/Linq/Members/NotMember.cs create mode 100644 src/Marten/Linq/Members/QueryableMember.cs rename src/Marten/Linq/{SqlGeneration => Members}/ScalarSelectManyStatement.cs (67%) create mode 100644 src/Marten/Linq/Members/ScalarSelectManyStringStatement.cs create mode 100644 src/Marten/Linq/Members/SimpleCastMember.cs create mode 100644 src/Marten/Linq/Members/StringMember.cs create mode 100644 src/Marten/Linq/Members/ValueCollectionMember.cs create mode 100644 src/Marten/Linq/Members/WholeDataMember.cs delete mode 100644 src/Marten/Linq/Operators/IncludeExpressionNode.cs delete mode 100644 src/Marten/Linq/Operators/IncludeResultOperator.cs delete mode 100644 src/Marten/Linq/Operators/OrderByComparerClause.cs delete mode 100644 src/Marten/Linq/Operators/OrderByComparerExpressionNode.cs delete mode 100644 src/Marten/Linq/Operators/StatsExpressionNode.cs delete mode 100644 src/Marten/Linq/Operators/StatsResultOperator.cs create mode 100644 src/Marten/Linq/OrderingDirection.cs delete mode 100644 src/Marten/Linq/Parsing/DictionaryExpressions.cs delete mode 100644 src/Marten/Linq/Parsing/EnumerableContains.cs delete mode 100644 src/Marten/Linq/Parsing/ExpressionExtensions.cs delete mode 100644 src/Marten/Linq/Parsing/FindMembers.cs delete mode 100644 src/Marten/Linq/Parsing/IExpressionParser.cs delete mode 100644 src/Marten/Linq/Parsing/LinqHandlerBuilder.cs create mode 100644 src/Marten/Linq/Parsing/LinqInternalExtensions.cs create mode 100644 src/Marten/Linq/Parsing/LinqQueryParser.cs delete mode 100644 src/Marten/Linq/Parsing/MartenQueryParser.cs create mode 100644 src/Marten/Linq/Parsing/MemberFinder.cs delete mode 100644 src/Marten/Linq/Parsing/MethodCallParser.cs create mode 100644 src/Marten/Linq/Parsing/Methods/AllMethodParser.cs create mode 100644 src/Marten/Linq/Parsing/Methods/AnySubQueryParser.cs create mode 100644 src/Marten/Linq/Parsing/Methods/DictionaryContains.cs create mode 100644 src/Marten/Linq/Parsing/Methods/DictionaryContainsKey.cs create mode 100644 src/Marten/Linq/Parsing/Methods/EnumerableContains.cs rename src/Marten/Linq/Parsing/Methods/{ => FullText}/FullTextSearchMethodCallParser.cs (84%) create mode 100644 src/Marten/Linq/Parsing/Methods/FullText/NgramSearch.cs rename src/Marten/Linq/Parsing/Methods/{ => FullText}/PhraseSearch.cs (79%) rename src/Marten/Linq/Parsing/Methods/{ => FullText}/PlainTextSearch.cs (80%) rename src/Marten/Linq/Parsing/Methods/{ => FullText}/Search.cs (77%) rename src/Marten/Linq/Parsing/Methods/{ => FullText}/WebStyleSearch.cs (80%) delete mode 100644 src/Marten/Linq/Parsing/Methods/IsInGenericEnumerable.cs delete mode 100644 src/Marten/Linq/Parsing/Methods/NgramSearch.cs delete mode 100644 src/Marten/Linq/Parsing/Methods/StringComparisonParser.cs delete mode 100644 src/Marten/Linq/Parsing/Methods/StringContains.cs delete mode 100644 src/Marten/Linq/Parsing/Methods/StringEndsWith.cs delete mode 100644 src/Marten/Linq/Parsing/Methods/StringEquals.cs rename src/Marten/Linq/Parsing/Methods/{ => Strings}/EqualsIgnoreCaseParser.cs (65%) create mode 100644 src/Marten/Linq/Parsing/Methods/Strings/StringComparisonParser.cs create mode 100644 src/Marten/Linq/Parsing/Methods/Strings/StringContains.cs create mode 100644 src/Marten/Linq/Parsing/Methods/Strings/StringEndsWith.cs create mode 100644 src/Marten/Linq/Parsing/Methods/Strings/StringEquals.cs create mode 100644 src/Marten/Linq/Parsing/Methods/Strings/StringStartsWith.cs create mode 100644 src/Marten/Linq/Parsing/Operators/AnyOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/CasingRule.cs create mode 100644 src/Marten/Linq/Parsing/Operators/DistinctOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/IncludeOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/LastOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/LinqOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/OperatorLibrary.cs create mode 100644 src/Marten/Linq/Parsing/Operators/Ordering.cs create mode 100644 src/Marten/Linq/Parsing/Operators/OrderingOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/SelectManyOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/SelectOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/SingleValueOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/SkipOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/TakeOperator.cs create mode 100644 src/Marten/Linq/Parsing/Operators/WhereOperator.cs create mode 100644 src/Marten/Linq/Parsing/SimpleExpression.cs create mode 100644 src/Marten/Linq/Parsing/SingleValueMode.cs delete mode 100644 src/Marten/Linq/Parsing/StringStartsWith.cs delete mode 100644 src/Marten/Linq/Parsing/WhereClauseParser.BinaryExpressionVisitor.cs delete mode 100644 src/Marten/Linq/Parsing/WhereClauseParser.BinarySide.cs delete mode 100644 src/Marten/Linq/SqlGeneration/AllComparisonFilter.cs delete mode 100644 src/Marten/Linq/SqlGeneration/AllIdSelectorStatement.cs delete mode 100644 src/Marten/Linq/SqlGeneration/ContainsIdSelectorStatement.cs delete mode 100644 src/Marten/Linq/SqlGeneration/CountComparisonStatement.cs delete mode 100644 src/Marten/Linq/SqlGeneration/CountStatement.cs create mode 100644 src/Marten/Linq/SqlGeneration/DistinctSelectionStatement.cs delete mode 100644 src/Marten/Linq/SqlGeneration/DocumentStatement.cs create mode 100644 src/Marten/Linq/SqlGeneration/ExplodeCollectionStatement.cs create mode 100644 src/Marten/Linq/SqlGeneration/FilterStatement.cs create mode 100644 src/Marten/Linq/SqlGeneration/Filters/AllValuesAreNullFilter.cs create mode 100644 src/Marten/Linq/SqlGeneration/Filters/AllValuesEqualFilter.cs rename src/Marten/Linq/{ => SqlGeneration}/Filters/BooleanFieldIsFalse.cs (51%) rename src/Marten/Linq/{ => SqlGeneration}/Filters/BooleanFieldIsTrue.cs (51%) rename src/Marten/Linq/{ => SqlGeneration}/Filters/ByIdFilter.cs (96%) create mode 100644 src/Marten/Linq/SqlGeneration/Filters/CollectionIsEmpty.cs create mode 100644 src/Marten/Linq/SqlGeneration/Filters/CollectionIsNotEmpty.cs create mode 100644 src/Marten/Linq/SqlGeneration/Filters/ContainmentWhereFilter.cs rename src/Marten/Linq/{ => SqlGeneration}/Filters/CurrentTenantFilter.cs (94%) create mode 100644 src/Marten/Linq/SqlGeneration/Filters/DeepCollectionIsNotEmpty.cs create mode 100644 src/Marten/Linq/SqlGeneration/Filters/EqualsFilter.cs rename src/Marten/Linq/{ => SqlGeneration}/Filters/ExcludeSoftDeletedFilter.cs (86%) rename src/Marten/Linq/{ => SqlGeneration}/Filters/FullTextWhereFragment.cs (94%) create mode 100644 src/Marten/Linq/SqlGeneration/Filters/ICollectionAware.cs rename src/Marten/Linq/{ => SqlGeneration}/Filters/ITenantWhereFragment.cs (81%) rename src/Marten/Linq/{ => SqlGeneration}/Filters/IsNotNullFilter.cs (51%) rename src/Marten/Linq/{ => SqlGeneration}/Filters/IsNullFilter.cs (50%) create mode 100644 src/Marten/Linq/SqlGeneration/Filters/MemberComparisonFilter.cs rename src/Marten/Linq/{ => SqlGeneration}/Filters/SpecificTenantFilter.cs (92%) create mode 100644 src/Marten/Linq/SqlGeneration/Filters/SubQueryFilter.cs rename src/Marten/Linq/{ => SqlGeneration}/Filters/TenantIsOneOfWhereFragment.cs (94%) create mode 100644 src/Marten/Linq/SqlGeneration/Filters/WriteSerializedJsonParameterFrame.cs create mode 100644 src/Marten/Linq/SqlGeneration/FromFragment.cs delete mode 100644 src/Marten/Linq/SqlGeneration/IdSelectorStatement.cs delete mode 100644 src/Marten/Linq/SqlGeneration/JsonStatement.cs create mode 100644 src/Marten/Linq/SqlGeneration/NewScalarSelectClause.cs create mode 100644 src/Marten/Linq/SqlGeneration/NewScalarStringSelectClause.cs create mode 100644 src/Marten/Linq/SqlGeneration/OrderByFragment.cs delete mode 100644 src/Marten/Linq/SqlGeneration/ScalarSelectManyStringStatement.cs delete mode 100644 src/Marten/Linq/SqlGeneration/SqlFragmentExtensions.cs create mode 100644 src/Marten/Linq/SqlGeneration/Statement.WhereParsing.cs delete mode 100644 src/Marten/Linq/SqlGeneration/SubQueryStatement.cs delete mode 100644 src/Marten/Schema/ChildDocument.cs create mode 100644 src/Marten/StoreOptions.MemberFactory.cs diff --git a/benchmarks/1.3/DocumentActions-report-default.md b/benchmarks/1.3/DocumentActions-report-default.md index cab61a5d501..e69de29bb2d 100644 --- a/benchmarks/1.3/DocumentActions-report-default.md +++ b/benchmarks/1.3/DocumentActions-report-default.md @@ -1,12 +0,0 @@ - -BenchmarkDotNet=v0.10.1, OS=Microsoft Windows NT 6.1.7601 Service Pack 1 -Processor=Intel(R) Core(TM) i7-4980HQ CPU 2.80GHz, ProcessorCount=4 -Frequency=10000000 Hz, Resolution=100.0000 ns, Timer=UNKNOWN - [Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 - Job-DNINOD : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 - -WarmupCount=2 Gen 0=287.5000 Allocated=4.62 MB - - Method | Mean | StdDev | ----------------- |----------- |---------- | - InsertDocuments | 43.7957 ms | 2.6786 ms | diff --git a/benchmarks/2.0.baseline/results/LinqActions-report-github.md b/benchmarks/2.0.baseline/results/LinqActions-report-github.md index ec011c53152..e69de29bb2d 100644 --- a/benchmarks/2.0.baseline/results/LinqActions-report-github.md +++ b/benchmarks/2.0.baseline/results/LinqActions-report-github.md @@ -1,16 +0,0 @@ -``` ini - -BenchmarkDotNet=v0.10.1, OS=Microsoft Windows NT 6.1.7601 Service Pack 1 -Processor=Intel(R) Core(TM) i7-4980HQ CPU 2.80GHz, ProcessorCount=4 -Frequency=10000000 Hz, Resolution=100.0000 ns, Timer=UNKNOWN - [Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 - Job-DNINOD : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1076.0 - -WarmupCount=2 - -``` - Method | Mean | StdDev | Gen 0 | Gen 1 | Allocated | ------------------- |---------------- |-------------- |---------- |-------- |---------- | - CreateLinqCommand | 189.7593 us | 2.3160 us | - | - | 42.64 kB | - RunLinqQuery | 124,248.2148 us | 1,785.5957 us | 4975.0000 | - | 34.13 MB | - CompiledQueries | 29,998.1235 us | 719.6757 us | 958.3333 | 83.3333 | 8.71 MB | diff --git a/build/build.cs b/build/build.cs index 18112beb4c8..291348c4b7d 100644 --- a/build/build.cs +++ b/build/build.cs @@ -91,6 +91,12 @@ private static async Task Main(string[] args) Target("test-event-sourcing", DependsOn("compile-event-sourcing-tests"), () => RunTests("EventSourcingTests")); + + Target("compile-linq-tests", DependsOn("clean"), () => + Run("dotnet", $"build src/LinqTests/LinqTests.csproj --framework {_framework} --configuration {configuration}")); + + Target("test-linq", DependsOn("compile-linq-tests"), () => + RunTests("LinqTests")); Target("test-codegen", () => { @@ -112,7 +118,7 @@ private static async Task Main(string[] args) Target("test-plv8", DependsOn("compile", "compile-plv8"), () => RunTests("Marten.PLv8.Testing")); - Target("test", DependsOn("test-base-lib", "test-core", "test-document-db", "test-event-sourcing", "test-cli", "test-codegen")); + Target("test", DependsOn("test-base-lib", "test-core", "test-document-db", "test-event-sourcing", "test-cli", "test-linq", "test-codegen")); Target("test-extension-libs-without-plv8", DependsOn("test-noda-time", "test-aspnetcore")); diff --git a/docs/configuration/storeoptions.md b/docs/configuration/storeoptions.md index 55747186145..2654bc7d414 100644 --- a/docs/configuration/storeoptions.md +++ b/docs/configuration/storeoptions.md @@ -94,7 +94,7 @@ public class OrganizationRegistry: MartenRegistry } } ``` -snippet source | anchor +snippet source | anchor To apply your new `MartenRegistry`, just include it when you bootstrap the `IDocumentStore` as in this example: @@ -109,7 +109,7 @@ var store = DocumentStore.For(opts => opts.Connection(ConnectionSource.ConnectionString); }); ``` -snippet source | anchor +snippet source | anchor Do note that you could happily use multiple `MartenRegistry` classes in larger applications if that is advantageous. @@ -131,7 +131,7 @@ var store = DocumentStore.For(opts => .For().Duplicate(x => x.UserName); }); ``` -snippet source | anchor +snippet source | anchor ## Custom Attributes @@ -202,7 +202,7 @@ public class ConfiguresItself } } ``` -snippet source | anchor +snippet source | anchor The `DocumentMapping` type is the core configuration class representing how a document type is persisted or @@ -226,7 +226,7 @@ public class ConfiguresItselfSpecifically } } ``` -snippet source | anchor +snippet source | anchor ## Document Policies diff --git a/docs/documents/deletes.md b/docs/documents/deletes.md index dde6f4e0804..e074f4dcd9e 100644 --- a/docs/documents/deletes.md +++ b/docs/documents/deletes.md @@ -203,7 +203,7 @@ public void query_soft_deleted_docs() .ToList().Single().UserName.ShouldBe("foo"); } ``` -snippet source | anchor +snippet source | anchor The SQL generated for the first call to `Query()` above would be: @@ -247,7 +247,7 @@ public void query_maybe_soft_deleted_docs() .ShouldHaveTheSameElementsAs("bar", "baz", "foo"); } ``` -snippet source | anchor +snippet source | anchor ### Fetching Only Deleted Documents @@ -285,7 +285,7 @@ public void query_is_soft_deleted_docs() .Single().ShouldBe("bar"); } ``` -snippet source | anchor +snippet source | anchor ### Fetching Documents Deleted Before or After a Specific Time @@ -319,7 +319,7 @@ public void query_is_soft_deleted_since_docs() .ToList().ShouldHaveTheSameElementsAs("jack"); } ``` -snippet source | anchor +snippet source | anchor _Neither `DeletedSince` nor `DeletedBefore` are inclusive searches as shown_below: diff --git a/docs/documents/hierarchies.md b/docs/documents/hierarchies.md index 06ce3ddd3c3..5c665ffaae4 100644 --- a/docs/documents/hierarchies.md +++ b/docs/documents/hierarchies.md @@ -89,7 +89,7 @@ public class BrainySmurf: PapaSmurf { } ``` -snippet source | anchor +snippet source | anchor If you wish to query over one of hierarchy classes and be able to get all of its documents as well as its subclasses, @@ -98,8 +98,9 @@ first you will need to map the hierarchy like so: ```cs -public query_with_inheritance() +public query_with_inheritance(ITestOutputHelper output) { + _output = output; StoreOptions(_ => { _.Schema.For() @@ -119,7 +120,7 @@ public query_with_inheritance() }); } ``` -snippet source | anchor +snippet source | anchor Note that if you wish to use aliases on certain subclasses, you could pass a `MappedType`, which contains the type to map @@ -138,7 +139,7 @@ _.Schema.For() typeof(BrainySmurf) ); ``` -snippet source | anchor +snippet source | anchor Now you can query the "complex" hierarchy in the following ways: @@ -169,6 +170,8 @@ public void get_all_subclasses_of_a_subclass2() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query().Count().ShouldBe(2); } @@ -232,5 +235,5 @@ public void get_all_subclasses_of_an_interface() theSession.Query().Count().ShouldBe(3); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/indexing/foreign-keys.md b/docs/documents/indexing/foreign-keys.md index 74119f77e87..e69de29bb2d 100644 --- a/docs/documents/indexing/foreign-keys.md +++ b/docs/documents/indexing/foreign-keys.md @@ -1,149 +0,0 @@ -# Foreign Keys - -Marten **is** built on top of a relational database, so why not take advantage of those abilities -where they still add value? In this case, Marten allows for a special kind of "Searchable" column -that also adds a foreign key constraint to enforce referential integrity between document types. - -One of our sample document types in Marten is the `Issue` class that has -a couple properties that link to the id's of related `User` documents: - - - -```cs -public class Issue -{ - public Issue() - { - Id = Guid.NewGuid(); - } - - public string[] Tags { get; set; } - - public Guid Id { get; set; } - - public string Title { get; set; } - - public int Number { get; set; } - - public Guid? AssigneeId { get; set; } - - public Guid? ReporterId { get; set; } - - public Guid? BugId { get; set; } - public string Status { get; set; } -} -``` -snippet source | anchor - - -If I want to enforce referential integrity between the `Issue` document and the `User` documents, -I can use this syntax shown below to configure Marten: - - - -```cs -var store = DocumentStore - .For(_ => - { - _.Connection("some database connection"); - - // In the following line of code, I'm setting - // up a foreign key relationship to the User document - _.Schema.For().ForeignKey(x => x.AssigneeId); - }); -``` -snippet source | anchor - - -With the configuration above, Marten will make an `assignee_id` field in the database table and build a -foreign key constraint to the `User` document like so: - -```sql -ALTER TABLE public.mt_doc_issue -ADD CONSTRAINT mt_doc_issue_assignee_id_fkey FOREIGN KEY (assignee_id) -REFERENCES public.mt_doc_user (id); - -CREATE INDEX mt_doc_issue_idx_assignee_id ON public.mt_doc_issue ("assignee_id"); -``` - -And some other things you probably want to know about how this works internally: - -Marten is smart enough to order the "upsert" operations to make the dependent documents be updated last. -In the `Issue` referencing `User` example above, this means that if you create a new `User` and a new -`Issue` in the same session, when you call `IDocumentSession.SaveChanges()/SaveChangesAsync()`, Marten will know -to save the new user first so that the issue will not fail with referential integrity violations. - -## Foreign Keys to non-Marten tables - -Marten can also create a foreign key to tables that are not managed by Marten. Continuing the our sample -of `Issue`, we can create a foreign key from our `Issue` to our external bug tracking system: - - - -```cs -var store = DocumentStore - .For(_ => - { - _.Connection("some database connection"); - - // Here we create a foreign key to table that is not - // created or managed by marten - _.Schema.For().ForeignKey(i => i.BugId, "bugtracker", "bugs", "id"); - }); -``` -snippet source | anchor - - -With the configuration above, Marten will generate a foreign key constraint from the `Issue` to a table in the -`bug-tracker` schema called `bugs` on the `id` column. The constraint would be defined as: - -```sql -ALTER TABLE public.mt_doc_issue -ADD CONSTRAINT mt_doc_issue_bug_id_fkey FOREIGN KEY (bug_id) -REFERENCES bug-tracker.bugs (id); -``` - -## Cascading deletes - -Marten can also cascade deletes on the foreign keys that it creates. The `ForeignKeyDefinition` has a -`CascadeDeletes` property that indicates whether the foreign key should enable cascading deletes. One way -to enable this is to use a configuration function like: - - - -```cs -var store = DocumentStore - .For(_ => - { - _.Connection("some database connection"); - - _.Schema.For().ForeignKey(x => x.AssigneeId, fkd => fkd.OnDelete = CascadeAction.Cascade); - }); -``` -snippet source | anchor - - -## Configuring with Attributes - -You can optionally configure properties or fields as foreign key relationships with the `[ForeignKey]` attribute: - - - -```cs -public class Issue -{ - public Issue() - { - Id = Guid.NewGuid(); - } - - public Guid Id { get; set; } - - [ForeignKey(typeof(User))] - public Guid UserId { get; set; } - - public Guid? OtherUserId { get; set; } -} -``` -snippet source | anchor - diff --git a/docs/documents/indexing/metadata-indexes.md b/docs/documents/indexing/metadata-indexes.md index e52049357de..1661a6a28d0 100644 --- a/docs/documents/indexing/metadata-indexes.md +++ b/docs/documents/indexing/metadata-indexes.md @@ -14,9 +14,10 @@ an index on the document's `mt_last_modified` metadata column either using `Inde [IndexedLastModified] public class Customer { + public Guid Id { get; set; } } ``` -snippet source | anchor +snippet source | anchor Or by using the fluent interface: diff --git a/docs/documents/metadata.md b/docs/documents/metadata.md index 8b9044c9712..488a343fa01 100644 --- a/docs/documents/metadata.md +++ b/docs/documents/metadata.md @@ -215,7 +215,7 @@ public async Task sample_usage(IQuerySession session) .ToListAsync(); } ``` -snippet source | anchor +snippet source | anchor ## Indexing diff --git a/docs/documents/multi-tenancy.md b/docs/documents/multi-tenancy.md index c500f8666fd..77854e97763 100644 --- a/docs/documents/multi-tenancy.md +++ b/docs/documents/multi-tenancy.md @@ -21,7 +21,7 @@ using (var session = theStore.LightweightSession("tenant1")) session.SaveChanges(); } ``` -snippet source | anchor +snippet source | anchor ```cs // Write some User documents to tenant "tenant1" @@ -32,7 +32,7 @@ using (var session = theStore.LightweightSession("tenant1")) session.SaveChanges(); } ``` -snippet source | anchor +snippet source | anchor ```cs // Write some User documents to tenant "tenant1" diff --git a/docs/documents/querying/compiled-queries.md b/docs/documents/querying/compiled-queries.md index 5147c5e70d3..a2463ece5ff 100644 --- a/docs/documents/querying/compiled-queries.md +++ b/docs/documents/querying/compiled-queries.md @@ -129,7 +129,7 @@ public class CompiledTimeline : ICompiledListQuery, IQueryPlanning public QueryStatistics Statistics { get; } = new QueryStatistics(); } ``` -snippet source | anchor +snippet source | anchor Pay close attention to the `SetUniqueValuesForQueryPlanning()` method. That has absolutely no other purpose but to help Marten @@ -189,7 +189,7 @@ public class UsersByFirstName: ICompiledListQuery } } ``` -snippet source | anchor +snippet source | anchor If you do want to use a `Select()` transform, use this interface: @@ -221,7 +221,7 @@ public class UserNamesForFirstName: ICompiledListQuery public string FirstName { get; set; } } ``` -snippet source | anchor +snippet source | anchor ## Querying for Related Documents with Include() @@ -265,7 +265,7 @@ public class IssueByTitleWithAssignee: ICompiledQuery } } ``` -snippet source | anchor +snippet source | anchor In this example, the query has an `Included` property which will receive the included Assignee / `User`. The 'resulting' included property can only be @@ -314,6 +314,7 @@ public void compiled_include_to_list() using var querySession = theStore.QuerySession(); var compiledQuery = new IssueWithUsers(); + querySession.Logger = new TestOutputMartenLogger(_output); var issues = querySession.Query(compiledQuery).ToArray(); compiledQuery.Users.Count.ShouldBe(2); @@ -323,7 +324,7 @@ public void compiled_include_to_list() compiledQuery.Users.Any(x => x.Id == user2.Id); } ``` -snippet source | anchor +snippet source | anchor Note that you could either have the list instantiated or at least make sure the property has a setter as well as a getter (we've got your back). @@ -372,7 +373,7 @@ public void compiled_include_to_dictionary() compiledQuery.UsersById.ContainsKey(user2.Id).ShouldBeTrue(); } ``` -snippet source | anchor +snippet source | anchor ## Querying for Paginated Results @@ -405,7 +406,7 @@ public class TargetPaginationQuery: ICompiledListQuery } } ``` -snippet source | anchor +snippet source | anchor Note that the way to get the `QueryStatistics` out is done by having a property on the query, which we specify in the `Stats()` method, similarly to the way @@ -445,7 +446,7 @@ public class FindUserByAllTheThings: ICompiledQuery } } ``` -snippet source | anchor +snippet source | anchor ## Querying for Multiple Results as JSON @@ -467,7 +468,7 @@ public class FindJsonOrderedUsersByUsername: ICompiledListQuery } } ``` -snippet source | anchor +snippet source | anchor If you wish to do it asynchronously, you can use the `ToJsonArrayAsync()` method. @@ -496,7 +497,7 @@ public class FindJsonUserByUsername: ICompiledQuery } } ``` -snippet source | anchor +snippet source | anchor And an example: @@ -531,7 +532,7 @@ public class TargetsInOrder: ICompiledListQuery } } ``` -snippet source | anchor +snippet source | anchor And when used in the actual test: @@ -555,5 +556,5 @@ public async Task use_compiled_query_with_statistics() query.Statistics.TotalResults.ShouldBe(100); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/querying/linq/async-enumerable.md b/docs/documents/querying/linq/async-enumerable.md index 9fef069bb63..a82ec92c5c7 100644 --- a/docs/documents/querying/linq/async-enumerable.md +++ b/docs/documents/querying/linq/async-enumerable.md @@ -40,7 +40,7 @@ public async Task query_to_async_enumerable() } } ``` -snippet source | anchor +snippet source | anchor ::: warning diff --git a/docs/documents/querying/linq/child-collections.md b/docs/documents/querying/linq/child-collections.md index 9435bf8888e..c862f89319d 100644 --- a/docs/documents/querying/linq/child-collections.md +++ b/docs/documents/querying/linq/child-collections.md @@ -69,7 +69,7 @@ var results = theSession .Where(x => x.Children.Any(_ => _.Number == 6 && _.Double == -1)) .ToArray(); ``` -snippet source | anchor +snippet source | anchor Finally, you can query for child collections that do **not** contain a value: @@ -80,13 +80,13 @@ Finally, you can query for child collections that do **not** contain a value: theSession.Query().Count(x => !x.Strings.Contains("c")) .ShouldBe(2); ``` -snippet source | anchor +snippet source | anchor ```cs theSession.Query().Count(x => !x.Strings.Contains("c")) .ShouldBe(2); ``` -snippet source | anchor +snippet source | anchor ## Querying within Value IEnumerables @@ -112,7 +112,7 @@ public void query_against_string_array() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); } ``` -snippet source | anchor +snippet source | anchor Marten also allows you to query over IEnumerables using the Any method for equality (similar to Contains): @@ -132,6 +132,8 @@ public void query_against_number_list_with_any() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query().Where(x => x.Numbers.Any(_ => _ == 3)).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); @@ -140,7 +142,7 @@ public void query_against_number_list_with_any() .Count(x => x.Numbers.Any()).ShouldBe(3); } ``` -snippet source | anchor +snippet source | anchor As of 1.2, you can also query against the `Count()` or `Length` of a child collection with the normal comparison @@ -162,11 +164,13 @@ public void query_against_number_list_with_count_method() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query() .Single(x => x.Numbers.Count() == 4).Id.ShouldBe(doc3.Id); } ``` -snippet source | anchor +snippet source | anchor ## IsOneOf @@ -270,7 +274,7 @@ var users = session.Query() var posts = theSession.Query() .Where(x => x.Tags.IsSupersetOf("c#", "json", "postgres")); ``` -snippet source | anchor +snippet source | anchor ## IsSubsetOf @@ -283,5 +287,5 @@ var posts = theSession.Query() var posts = theSession.Query() .Where(x => x.Tags.IsSubsetOf("c#", "json", "postgres")); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/querying/linq/extending.md b/docs/documents/querying/linq/extending.md index e915084e17f..148a2a92ce0 100644 --- a/docs/documents/querying/linq/extending.md +++ b/docs/documents/querying/linq/extending.md @@ -8,7 +8,7 @@ Marten allows you to add Linq parsing and querying support for your own custom m Using the (admittedly contrived) example from Marten's tests, say that you want to reuse a small part of a `Where()` clause across different queries for "IsBlue()." First, write the method you want to be recognized by Marten's Linq support: -<<< @/../src/DocumentDbTests/Reading/Linq/using_custom_Linq_parser_plugins_Tests.cs#sample_IsBlue +snippet: sample_IsBlue Note a couple things here: @@ -18,7 +18,7 @@ Note a couple things here: Now, to create a custom Linq parser for the `IsBlue()` method, you need to create a custom implementation of the `IMethodCallParser` interface shown below: -<<< @/../src/Marten/Linq/Parsing/IMethodCallParser.cs#sample_IMethodCallParser +snippet: sample_IMethodCallParser The `IMethodCallParser` interface needs to match on method expressions that it could parse, and be able to turn the Linq expression into part of a Postgresql "where" clause. The custom Linq parser for `IsBlue()` is shown below: @@ -26,12 +26,12 @@ part of a Postgresql "where" clause. The custom Linq parser for `IsBlue()` is sh ```cs -public static bool IsBlue(this ColorTarget target) +public static bool IsBlue(this string value) { - return target.Color == "Blue"; + return value == "Blue"; } ``` -snippet source | anchor +snippet source | anchor Lastly, to plug in our new parser, we can add that to the `StoreOptions` object that we use to bootstrap a new `DocumentStore` as shown below: @@ -40,43 +40,40 @@ Lastly, to plug in our new parser, we can add that to the `StoreOptions` object ```cs [Fact] -public void query_with_custom_parser() +public async Task query_with_custom_parser() { - using (var store = DocumentStore.For(_ => - { - _.Connection(ConnectionSource.ConnectionString); + using var store = DocumentStore.For(opts => + { + opts.Connection(ConnectionSource.ConnectionString); - // IsBlue is a custom parser I used for testing this - _.Linq.MethodCallParsers.Add(new IsBlue()); - _.AutoCreateSchemaObjects = AutoCreate.All; + // IsBlue is a custom parser I used for testing this + opts.Linq.MethodCallParsers.Add(new IsBlue()); + opts.AutoCreateSchemaObjects = AutoCreate.All; - // This is just to isolate the test - _.DatabaseSchemaName = "isblue"; - })) - { - store.Advanced.Clean.CompletelyRemoveAll(); + // This is just to isolate the test + opts.DatabaseSchemaName = "isblue"; + }); + + await store.Advanced.Clean.CompletelyRemoveAllAsync(); - var targets = new List(); - for (var i = 0; i < 25; i++) - { - targets.Add(new ColorTarget {Color = "Blue"}); - targets.Add(new ColorTarget {Color = "Green"}); - targets.Add(new ColorTarget {Color = "Red"}); - } + var targets = new List(); + for (var i = 0; i < 25; i++) + { + targets.Add(new ColorTarget {Color = "Blue"}); + targets.Add(new ColorTarget {Color = "Green"}); + targets.Add(new ColorTarget {Color = "Red"}); + } - var count = targets.Where(x => x.IsBlue()).Count(); + var count = targets.Count(x => x.Color.IsBlue()); - targets.Each(x => x.Id = Guid.NewGuid()); + targets.Each(x => x.Id = Guid.NewGuid()); - store.BulkInsert(targets.ToArray()); + await store.BulkInsertAsync(targets.ToArray()); - using (var session = store.QuerySession()) - { - session.Query().Count(x => x.IsBlue()) - .ShouldBe(count); - } - } + using var session = store.QuerySession(); + session.Query().Count(x => x.Color.IsBlue()) + .ShouldBe(count); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/querying/linq/include.md b/docs/documents/querying/linq/include.md index ef0cf37059d..b1425655843 100644 --- a/docs/documents/querying/linq/include.md +++ b/docs/documents/querying/linq/include.md @@ -18,19 +18,21 @@ public void simple_include_for_a_single_document() session.SaveChanges(); using var query = theStore.QuerySession(); + query.Logger = new TestOutputMartenLogger(_output); + User included = null; var issue2 = query .Query() .Include(x => x.AssigneeId, x => included = x) .Single(x => x.Title == issue.Title); - SpecificationExtensions.ShouldNotBeNull(included); + included.ShouldNotBeNull(); included.Id.ShouldBe(user.Id); - SpecificationExtensions.ShouldNotBeNull(issue2); + issue2.ShouldNotBeNull(); } ``` -snippet source | anchor +snippet source | anchor The first parameter of the `Include()` method takes an expression that specifies the document properties on which the join will be done (`AssigneeId` in this case). The second parameter is the expression that will assign the fetched related document to a previously declared variable (`included` in our case). By default, Marten will use an inner join. This means that any `Issue` with no corresponding `User` (or no `AssigneeId`), will not be fetched. If you wish to override this behavior, you can add as a third parameter the enum `JoinType.LeftOuter`. @@ -69,7 +71,7 @@ public void include_to_dictionary() dict.ContainsKey(user2.Id).ShouldBeTrue(); } ``` -snippet source | anchor +snippet source | anchor ## Include Multiple Document Types @@ -82,8 +84,8 @@ Marten also allows you to chain multiple `Include()` calls: [Fact] public void multiple_includes() { - var assignee = new User(); - var reporter = new User(); + var assignee = new User{FirstName = "Assignee"}; + var reporter = new User{FirstName = "Reporter"}; var issue1 = new Issue { AssigneeId = assignee.Id, ReporterId = reporter.Id, Title = "Garage Door is busted" }; @@ -96,6 +98,7 @@ public void multiple_includes() User assignee2 = null; User reporter2 = null; + query.Logger = new TestOutputMartenLogger(_output); query .Query() .Include(x => x.AssigneeId, x => assignee2 = x) @@ -107,7 +110,7 @@ public void multiple_includes() reporter2.Id.ShouldBe(reporter.Id); } ``` -snippet source | anchor +snippet source | anchor ## Asynchronous Support @@ -131,5 +134,5 @@ var found = batch.Query() .Where(x => x.Title == issue1.Title) .Single(); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/querying/linq/nulls.md b/docs/documents/querying/linq/nulls.md index f0f22550ed7..e69de29bb2d 100644 --- a/docs/documents/querying/linq/nulls.md +++ b/docs/documents/querying/linq/nulls.md @@ -1,19 +0,0 @@ -# Searching for NULL Values - -Regardless of your feelings about _NULL_, they do exist in databases and Marten allows you to search for documents that have (or don't have) null values: - - - -```cs -public void query_by_nullable_type_nulls(IDocumentSession session) -{ - // You can use Nullable.HasValue in Linq queries - session.Query().Where(x => !x.NullableNumber.HasValue).ToArray(); - session.Query().Where(x => x.NullableNumber.HasValue).ToArray(); - - // You can always search by field is NULL - session.Query().Where(x => x.Inner == null); -} -``` -snippet source | anchor - diff --git a/docs/documents/querying/linq/operators.md b/docs/documents/querying/linq/operators.md index 6a6fe48686c..e4f267c7647 100644 --- a/docs/documents/querying/linq/operators.md +++ b/docs/documents/querying/linq/operators.md @@ -243,7 +243,7 @@ public void get_distinct_string() queryable.ToList().Count.ShouldBe(3); } ``` -snippet source | anchor +snippet source | anchor Do note that the `Distinct()` keyword can be used with `Select()` transforms as well: @@ -272,7 +272,7 @@ public void get_distinct_numbers() queryable.ToList().Count.ShouldBe(4); } ``` -snippet source | anchor +snippet source | anchor ## Modulo Queries @@ -299,5 +299,5 @@ public void use_modulo() .ShouldHaveTheSameElementsAs(2, 4); } ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/querying/linq/paging.md b/docs/documents/querying/linq/paging.md index aedecf722ff..8ff01ef775a 100644 --- a/docs/documents/querying/linq/paging.md +++ b/docs/documents/querying/linq/paging.md @@ -20,7 +20,7 @@ var hasPrevPage = pagedList.HasPreviousPage; // check if there is previous page var firstItemOnPage = pagedList.FirstItemOnPage; // one-based index of first item in current page var lastItemOnPage = pagedList.LastItemOnPage; // one-based index of last item in current page ``` -snippet source | anchor +snippet source | anchor @@ -31,7 +31,7 @@ var pageSize = 10; var pagedList = await theSession.Query().ToPagedListAsync(pageNumber, pageSize); ``` -snippet source | anchor +snippet source | anchor If you want to create you own paged queries, just use the `Take()` and `Skip()` Linq operators in combination with `Stats()` @@ -64,7 +64,7 @@ public void can_get_the_total_in_results() stats.TotalResults.ShouldBe(count); } ``` -snippet source | anchor +snippet source | anchor For the sake of completeness, the SQL generated in the operation above by Marten would be: diff --git a/docs/documents/querying/linq/projections.md b/docs/documents/querying/linq/projections.md index 5768629fea2..c6046735f07 100644 --- a/docs/documents/querying/linq/projections.md +++ b/docs/documents/querying/linq/projections.md @@ -21,7 +21,7 @@ public void use_select_in_query_for_one_field() .ShouldHaveTheSameElementsAs("Bill", "Hank", "Sam", "Tom"); } ``` -snippet source | anchor +snippet source | anchor When you wish to retrieve certain properties and transform them into another type: @@ -50,7 +50,7 @@ public void use_select_with_multiple_fields_to_other_type() }); } ``` -snippet source | anchor +snippet source | anchor When you wish to retrieve certain properties and transform them into an anonymous type: @@ -74,7 +74,7 @@ public void use_select_to_transform_to_an_anonymous_type() .ShouldHaveTheSameElementsAs("Bill", "Hank", "Sam", "Tom"); } ``` -snippet source | anchor +snippet source | anchor Marten also allows you to run projection queries on deep (nested) properties: @@ -96,7 +96,7 @@ public void transform_with_deep_properties() actual.ShouldHaveTheSameElementsAs(expected); } ``` -snippet source | anchor +snippet source | anchor ## Chaining other Linq Methods @@ -121,7 +121,7 @@ public void use_select_to_another_type_with_first() ?.Name.ShouldBe("Bill"); } ``` -snippet source | anchor +snippet source | anchor ## SelectMany() @@ -162,7 +162,7 @@ public void can_do_simple_select_many_against_simple_array() } } ``` -snippet source | anchor +snippet source | anchor Or against collections of child documents: @@ -178,7 +178,7 @@ var results = query.Query() .Take(15) .ToList(); ``` -snippet source | anchor +snippet source | anchor A few notes on the `SelectMany()` usage and limitations: diff --git a/docs/documents/querying/linq/strings.md b/docs/documents/querying/linq/strings.md index 369eef49900..404904a0d11 100644 --- a/docs/documents/querying/linq/strings.md +++ b/docs/documents/querying/linq/strings.md @@ -44,7 +44,7 @@ A shorthand for case-insensitive string matching is provided through `EqualsIgno query.Query().Single(x => x.UserName.EqualsIgnoreCase("abc")).Id.ShouldBe(user1.Id); query.Query().Single(x => x.UserName.EqualsIgnoreCase("aBc")).Id.ShouldBe(user1.Id); ``` -snippet source | anchor +snippet source | anchor This defaults to `String.Equals` with `StringComparison.CurrentCultureIgnoreCase` as comparison type. diff --git a/docs/documents/querying/query-json.md b/docs/documents/querying/query-json.md index d3c62cd2320..64b03ae56b3 100644 --- a/docs/documents/querying/query-json.md +++ b/docs/documents/querying/query-json.md @@ -105,7 +105,7 @@ var json = await theSession json.ShouldBe("{\"Name\": \"Bill\"}"); ``` -snippet source | anchor +snippet source | anchor And another example, but this time transforming to an anonymous type: @@ -124,5 +124,5 @@ And another example, but this time transforming to an anonymous type: .ToJsonFirstOrDefault()) .ShouldBe("{\"Name\": \"Bill\"}"); ``` -snippet source | anchor +snippet source | anchor diff --git a/docs/documents/storage.md b/docs/documents/storage.md index 55ff595336a..c4aa15b9fb6 100644 --- a/docs/documents/storage.md +++ b/docs/documents/storage.md @@ -55,7 +55,7 @@ public class Customer [Identity] public string Name { get; set; } } ``` -snippet source | anchor +snippet source | anchor ## Type Aliases diff --git a/docs/events/projections/inline.md b/docs/events/projections/inline.md index 9ab8c1dc553..e69de29bb2d 100644 --- a/docs/events/projections/inline.md +++ b/docs/events/projections/inline.md @@ -1,51 +0,0 @@ -# Inline Projections - -An "inline" projection just means that Marten will process the projection against new events being appended -to the event store at the time that `IDocumentSession.SaveChanges()` is called to commit a unit of work. Here's a small example projection: - - - -```cs -public class MonsterDefeatedTransform: EventProjection -{ - public MonsterDefeated Create(IEvent input) - { - return new MonsterDefeated { Id = input.Id, Monster = input.Data.Name }; - } -} - -public class MonsterDefeated -{ - public Guid Id { get; set; } - public string Monster { get; set; } -} -``` -snippet source | anchor - - -Note that the inline projection is able to use the [event metadata](/events/metadata) at the time the inline projection is executed. That was previously a limitation of Marten that was fixed in Marten V4. - - - -```cs -var store = DocumentStore.For(opts => -{ - opts.Connection("some connection string"); - - opts.Projections.Add(new MonsterDefeatedTransform(), - ProjectionLifecycle.Inline); -}); - -await using var session = store.LightweightSession(); - -var streamId = session.Events - .StartStream(started, joined, slayed1, slayed2, joined2).Id; - -// The projection is going to be applied right here during -// the call to SaveChangesAsync() and the resulting document update -// of the new MonsterDefeated document will happen in the same database -// transaction -await theSession.SaveChangesAsync(); -``` -snippet source | anchor - diff --git a/docs/events/storage.md b/docs/events/storage.md index a3979c2dc80..e69de29bb2d 100644 --- a/docs/events/storage.md +++ b/docs/events/storage.md @@ -1,114 +0,0 @@ -# Event Store Schema Objects - -## Overriding the Schema - -By default, the event store database objects are created in the default schema for the active `IDocumentStore`. If you wish, -you can segregate the event store objects into a separate schema with this syntax: - - - -```cs -var store = DocumentStore.For(_ => -{ - _.Connection("some connection string"); - - // Places all the Event Store schema objects - // into the "events" schema - _.Events.DatabaseSchemaName = "events"; -}); -``` -snippet source | anchor - - -## Database Tables - -The events are stored in the `mt_events` table, with these columns: - -* `seq_id` - A sequential identifier that acts as the primary key -* `id` - A Guid value uniquely identifying the event across databases -* `stream_id` - A foreign key to the event stream that contains the event -* `version` - A numerical version of the event's position within its event stream -* `data` - The actual event data stored as JSONB -* `type` - A string identifier for the event type that's derived from the event type name. For example, events of type `IssueResolved` would be identified as "issue_resolved." The `type` - column exists so that Marten can be effectively used without the underlying JSON serializer having to embed type metadata. -* `timestamp` - A database timestamp written by the database when events are committed. -* `tenant_id` - Identifies the tenancy of the event -* `mt_dotnet_type` - The full name of the underlying event type, including assembly name, e.g. "Marten.Testing.Events.IssueResolved, Marten.Testing" - -The "Async Daemon" projection supports keys off of the sequential id, but we retained the Guid id field for backward compatibility and to retain a potential way to uniquely identify events across databases. - -In addition, there are a couple other metadata tables you'll see in your schema: - -* `mt_streams` - Metadata about each event stream -* `mt_event_progression` - A durable record about the progress of each async projection through the event store - -A couple functions that Marten uses internally: - -* `mt_append_event` - Writes event data to the `mt_events` and `mt_streams` tables -* `mt_mark_event_progression` - Updates the `mt_event_progression` table - -And lastly, there's a document type called `DeadLetterEvent` that Marten adds automatically to record information about -"dead letter events" that are repeatedly erroring in the async daemon and are being skipped in accordance with -the error handling policies in your application's Marten configuration. - -## Event Metadata in Code - -Hopefully, it's relatively clear how the fields in `mt_events` map to the `IEvent` interface in Marten: - - - -```cs -/// -/// A reference to the stream that contains -/// this event -/// -public Guid StreamId { get; set; } - -/// -/// A reference to the stream if the stream -/// identifier mode is AsString -/// -public string? StreamKey { get; set; } - -/// -/// An alternative Guid identifier to identify -/// events across databases -/// -public Guid Id { get; set; } - -/// -/// An event's version position within its event stream -/// -public long Version { get; set; } - -/// -/// A global sequential number identifying the Event -/// -public long Sequence { get; set; } - -/// -/// The UTC time that this event was originally captured -/// -public DateTimeOffset Timestamp { get; set; } - -public string TenantId { get; set; } = Tenancy.DefaultTenantId; - -/// -/// Optional metadata describing the causation id -/// -public string? CausationId { get; set; } - -/// -/// Optional metadata describing the correlation id -/// -public string? CorrelationId { get; set; } - -/// -/// This is meant to be lazy created, and can be null -/// -public Dictionary? Headers { get; set; } -``` -snippet source | anchor - - -The full event data is available on `EventStream` and `IEvent` objects immediately after committing a transaction that involves event capture. See [diagnostics and instrumentation](/diagnostics) for more information on capturing event data in the instrumentation hooks. diff --git a/docs/migration-guide.md b/docs/migration-guide.md index 86b188888cf..e69de29bb2d 100644 --- a/docs/migration-guide.md +++ b/docs/migration-guide.md @@ -1,108 +0,0 @@ -# Migration Guide - -## Key Changes in 6.0.0 - -The V6 release lite motive is upgrading to .NET 7 and Npgsql 7. Besides that, we decided to align the event sourcing projections' naming and initializing document sessions. See the [full release notes](https://github.com/JasperFx/marten/releases/tag/6.0.0). - -We tried to limit the number of breaking changes and mark methods with obsolete attributes to promote the new recommended way. - -The scope of breaking changes is limited, but we highly encourage migrating from all obsolete usage to the new conventions. - -### Guide on migration from v5 to v6: - -- **We Dropped support of .NET Core 3.1 and .NET 5** following the [Official .NET Support Policy](https://dotnet.microsoft.com/en-us/platform/support/policy). That allowed us to benefit fully from recent .NET improvements around asynchronous code, performance etc. Plus made maintenance easier by removing branches of code. If you're using those .NET versions, you need to upgrade to .NET 6 or 7. -- **Upgraded Npgsql version to 7.** If your project uses an explicitly lower version of Npgsql than 7, you'll need to bump it. We didn't face substantial issues this time, so you might not need to do around it, but you can double-check in the [Npgsql 7 release notes](https://www.npgsql.org/doc/release-notes/7.0.html#breaking-changes) for detailed information about breaking changes on their side. -- **Generic `OpenSession` store options (`OpenSession(SessionOptions options)` does not track changes by default.** Previously, it was using [identity map](https://martendb.io/documents/sessions.md#identity-map-mechanics). Other overloads of `OpenSession` didn't change the default behavior but were made obsolete. We encourage using explicit session creation and `LightweightSession` by default, as in the next major version, we plan to do the full switch. Read more about the [Unit of Work mechanics](/documents/sessions.md#unit-of-work-mechanics). -- **Renamed asynchronous session creation to include explicit Serializable name.** `OpenSessionAsync` was misleading, as the intention behind it was to enable proper handling of Postgres' serialized transaction level. Renamed the method to `OpenSerializableSessionAsync` and added explicit methods for session types. Check more in [handling Transaction Isolation Level](/documents/sessions.md#enlisting-in-existing-transactions). -- **Removed obsolete methods marked as to be removed in the previous versions.**: - - Removed synchronous'BuildProjectionDaemon`from the`IDocumentStore` method. Use the asynchronous version instead. - - Removed `Schema` from `IDocumentStore`. Use `Storage` instead. - - Replaced `GroupEventRange` in `IAggregationRuntime` with `Slicer` reference. - - Removed unused `UseAppendEventForUpdateLock` setting. - - Removed the `Searchable` method from `MartenRegistry`. Use `Index` instead. - **[ASP.NET JSON streaming `WriteById`](/documents/aspnetcore.md#single-document) is now using correctly custom `onFoundStatus`.** We had the bug and always used the default status. It's enhancement but also technically a breaking change to the behavior. We also added `onFoundStatus` to other methods, so you could specify, e.g. `201 Created` status for creating a new record. -- **Added [Optimistic concurrency checks](/documents/concurrency.md#optimistic-concurrency) during documents' updates.** Previously, they were only handled when calling the `Store` method; now `Update` uses the same logic. -- **Base state passed as parameter is returned from `AggregateStreamAsync` instead of null when the stream is empty.** `AggregateStreamAsync` allows passing the default state on which we're applying events. When no events were found, we were always returning null. Now we'll return the passed value. It is helpful when you filter events from a certain version or timestamp. It'll also be useful in the future for archiving scenarios -- **Ensured events with both `Create` and `Apply` in stream aggregation were handled only once.** When you defined both Create and Apply methods for the specific event, both methods were called for the single event. That wasn't expected behavior. Now they'll be only handled once. -- **Added missing passing Cancellation Tokens in all async methods in public API.** That ensures that cancellation is handled correctly across the whole codebase. Added the static analysis to ensure we won't miss them in the future. -- **All the Critter Stack dependencies like `Weasel`, `Lamar`, `JasperFx.Core`, `Oakton`, and `JasperFx.CodeGeneration` were bumped to the latest major versions.** If you use them explicitly, you'll need to align the versions. - -### Besides that, non-breaking but important changes to upgrade are: - -- **Added explicit `LightweightSession` and `IdentitySession` creation methods to `DocumentStore`**. Previously you could create `DirtyTrackedSession` explicitly. Now you can create all types of sessions explicitly. We recommend using them explicitly instead of the generic `OpenSession` method. -- **Renamed aggregations into projections and `SelfAggregate` into `Snapshot` and `LiveStreamAggregation`.** The established terms in the Event Sourcing community are Projection and Snapshot. Even though our naming was more precise on the implementation behind the scenes, it could be confusing. We decided to align it with the common naming and be more explicit about the intention. Old methods were marked as obsolete and will be removed in the next major release. - -### Other notable new features: - -- **[Added support for reusing Documents in the same async projection batch](/events/projections/event-projections.md#reusing-documents-in-the-same-batch).** By default, Marten does batch to handle multiple events for the projection in one update. When using `EventProjection` and updating data manually using `IDocumentOperations`, this may cause changes made for previous batch items not to be visible. Now you can opt-in for tracking documents by an identity within a batch using the `EnableDocumentTrackingByIdentity` async projection option. Read more in [related docs](/events/projections/event-projections.md#reusing-documents-in-the-same-batch). -- **Enabled the possibility of applying projections with different Conjoined Tenancy scopes for projections.** Enabled global projection for events with a conjoined tenancy style. Read more in [multi-tenancy documentation](/documents/multi-tenancy.md) -- **Added automatic retries when schema updates are running in parallel.** Marten locks the schema update using advisory locks. Previously when acquiring lock failed, then schema update also failed. Now it will be retried, which enables easier parallel automated tests and running schema migration during the startup for the containerized environment. - -## Key Changes in 5.0.0 - -V5 was a much smaller release for Marten than V4, and should require much less effort to move from V4 to V5 as it did from V2/3 to V4. - -- The [async daemon](/events/projections/async-daemon) has to be explicitly added with a chained call to `AddAsyncDaemon(mode)` -- The [Marten integration with .Net bootstrapping](/getting-started) now has the ability to split the Marten configuration for testing overrides or modular configuration -- `IInitialData` services are executed within IHost bootstrapping. See [Initial Baseline Data](/documents/initial-data). -- New facility to [apply all detected database changes on application startup](/schema/migrations.html#apply-all-outstanding-changes-upfront). -- Ability to [register multiple Marten document stores in one .Net IHost](/configuration/hostbuilder.html#working-with-multiple-marten-databases) -- The ["pre-built code generation" feature](/configuration/prebuilding) has a new, easier to use option in V5 -- New ["Optimized Artifact Workflow"](/configuration/optimized_artifact_workflow) option -- Some administrative or diagnostic methods that were previously on `IDocumentStore.Advanced` migrated to database specific access [as shown here](/configuration/multitenancy.html#administering-multiple-databases). - -## Key Changes in 4.0.0 - -V4 was a very large release for Marten, and basically every subsystem was touched at some point. When you are upgrading from V2/3 to V4 -- and even -earlier alphas or RC releases of 4.0 -- you will need to run a [database migration](/schema/migrations) as part of your migration to V4. - -Other key, breaking changes: - -- All schema management methods, including assertions on the schema, are now asynchronous. We had to do this for Npgsql connection multiplexing. -- The [compiled query](/documents/querying/compiled-queries) syntax changed -- The [event store](/events/) support has quite a few additions -- [Projections](/events/projections/) in Marten have moved to an all new programming model. Some of it is at least similar, but read the documentation on projection types before moving a Marten application over -- The [async daemon](/events/projections/async-daemon) was completely rewritten, and is now about to run in application clusters and handle multi-tenancy -- A few diagnostic methods moved within the API -- Document types need to be public now, and Marten will alert you if document types are not public -- The dynamic code in Marten moved to a runtime code generation model. If this is causing you any issues with cold start times or memory usage due to Roslyn misbehaving (this is **not** consistent), there is the new ["generate ahead model"](/configuration/prebuilding) as a workaround. -- If an application bootstraps Marten through the `IServiceCollection.AddMarten()` extension methods, the default logging in Marten is through the standard - `ILogger` of the application -- In order to support more LINQ query permutations, LINQ queries are temporarily not using the GIN indexable operators on documents that have `GinIndexJsonData()` set. Support for this can be tracked [here](https://github.com/JasperFx/marten/issues/2051) -- PLV8 support is disabled by default and moved to a separate package. - If an application was setting `StoreOptions.PLV8Enabled = false` to disable PLV8, - that line should be removed as the setting no longer exists. If an application - had `StoreOptions.PLV8Enabled = true` and was using PLV8, you will need to add - the [Marten.PLv8 package](/documents/plv8). - -## Key Changes in 3.0.0 - -Main goal of this release was to accommodate the **Npgsql 4.\*** dependency. - -Besides the usage of Npgsql 4, our biggest change was making the **default schema object creation mode** to `CreateOrUpdate`. Meaning that Marten even in its default mode will not drop any existing tables, even in development mode. You can still opt into the full "sure, I’ll blow away a table and start over if it’s incompatible" mode, but we felt like this option was safer after a few user problems were reported with the previous rules. See [schema migration and patches](/schema/migrations) for more information. - -We also aligned usage of `EnumStorage`. Previously, [Enum duplicated fields](/documents/indexing/duplicated-fields) was always stored as `varchar`. Now it's using setting from `JsonSerializer` options - so by default it's `integer`. We felt that it's not consistent to have different default setting for Enums stored in json and in duplicated fields. - -See full list of the fixed issues on [GitHub](https://github.com/JasperFx/marten/milestone/26?closed=1). - -You can also read more in [Jeremy's blog post from](https://jeremydmiller.com/2018/09/27/marten-3-0-is-released-and-introducing-the-new-core-team/). - -## Migration from 2.\* - -- To keep Marten fully rebuilding your schema (so to allow Marten drop tables) set store options to: - -```csharp -AutoCreateSchemaObjects = AutoCreate.All -``` - -- To keep [enum fields](/documents/indexing/duplicated-fields) being stored as `varchar` set store options to: - -```csharp -DuplicatedFieldEnumStorage = EnumStorage.AsString; -``` - -- To keep [duplicated DateTime fields](/documents/indexing/duplicated-fields) being stored as `timestamp with time zone` set store options to: - -```csharp -DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime = false; -``` diff --git a/docs/postgres/casing/index.md b/docs/postgres/casing/index.md index 7fa084af0b3..e69de29bb2d 100644 --- a/docs/postgres/casing/index.md +++ b/docs/postgres/casing/index.md @@ -1,15 +0,0 @@ -# Case Sensitivity - -String comparisons in PostgreSQL are case sensitive* (unless a case-insensitive collation were to be introduced). To work around this, PostgreSQL has several methods to match strings in a case-insensitive manner. Consequently, Marten also makes use of these methods to translate case-insensitive queries to pgSQL. See [querying document with Linq](/documents/querying/linq/) for querying by strings. - -::: tip INFO -Databases, tables, fields and column names are case-independent, unless created with double quotes. -::: - -## Case-Insensitivity & Marten Internals - -Marten query parser recognizes case-insensitive comparisons from the use of `StringComparison.CurrentCultureIgnoreCase`. Such comparisons are translated to use the `ILIKE` (or its equivalent operator `~~*`) PostgreSQL extension that matches strings independent of case. - -The use of `ILIKE` pattern match in place of equality comparison has the consequence that matching on *%* wildcard literal needs to be escaped as *\\%*, e.g. *abc%* would match on *abc* followed by any characters, whereas *abc\\%* would only match the exact string of *abc%*. - -See [Postgresql documentation on pattern matching](https://www.postgresql.org/docs/current/static/functions-matching.html) for more. diff --git a/docs/postgres/casing/queries.md b/docs/postgres/casing/queries.md index 37d5eeea6f8..e69de29bb2d 100644 --- a/docs/postgres/casing/queries.md +++ b/docs/postgres/casing/queries.md @@ -1,3 +0,0 @@ -# Queries (under construction) - -//TODO diff --git a/docs/schema/index.md b/docs/schema/index.md index 08b66f34a4b..9cbb0a91155 100644 --- a/docs/schema/index.md +++ b/docs/schema/index.md @@ -99,6 +99,7 @@ storeOptions.CreateDatabasesForTenants(c => c.MaintenanceDatabase(cstring); c.ForTenant() .CheckAgainstPgDatabase() + .WithOwner("postgres") .WithEncoding("UTF-8") .ConnectionLimit(-1) @@ -108,7 +109,7 @@ storeOptions.CreateDatabasesForTenants(c => }); }); ``` -snippet source | anchor +snippet source | anchor Databases are checked for existence upon store initialization. By default, connection attempts are made against the databases specified for tenants. If a connection attempt results in an invalid catalog error (3D000), database creation is triggered. `ITenantDatabaseCreationExpressions.CheckAgainstPgDatabase` can be used to alter this behavior to check for database existence from `pg_database`. diff --git a/docs/troubleshoot.md b/docs/troubleshoot.md index cf3e05869d2..b6d14d57216 100644 --- a/docs/troubleshoot.md +++ b/docs/troubleshoot.md @@ -25,7 +25,7 @@ var store = DocumentStore.For(storeOptions => // Change default casing to CamelCase storeOptions.UseDefaultSerialization(casing: Casing.CamelCase); ``` -snippet source | anchor +snippet source | anchor ## More diagnostics data outside of Marten diff --git a/src/CoreTests/Bugs/Bug_1258_cannot_derive_updates_for_objects.cs b/src/CoreTests/Bugs/Bug_1258_cannot_derive_updates_for_objects.cs index 2c3db30a759..a4602301aeb 100644 --- a/src/CoreTests/Bugs/Bug_1258_cannot_derive_updates_for_objects.cs +++ b/src/CoreTests/Bugs/Bug_1258_cannot_derive_updates_for_objects.cs @@ -8,26 +8,37 @@ using Weasel.Core; using Weasel.Postgresql; using Xunit; +using Xunit.Abstractions; namespace CoreTests.Bugs; public class Bug_1258_cannot_derive_updates_for_objects: BugIntegrationContext { + private readonly ITestOutputHelper _output; + + public Bug_1258_cannot_derive_updates_for_objects(ITestOutputHelper output) + { + _output = output; + } + [Fact] + [Obsolete("Obsolete")] public async Task can_properly_detect_changes_when_user_defined_type() { - theStore.Advanced.Clean.CompletelyRemoveAll(); - StoreOptions(_ => + await theStore.Advanced.Clean.CompletelyRemoveAllAsync(); + StoreOptions(opts => { - _.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate; - _.Schema.For(); - _.Schema.For().ForeignKey(x => x.UserId); - _.Schema.For().GinIndexJsonData(); - _.Schema.For().Duplicate(u => u.Name, pgType: "cust_type", configure: idx => + opts.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate; + opts.Schema.For(); + opts.Schema.For().ForeignKey(x => x.UserId); + opts.Schema.For().GinIndexJsonData(); + opts.Schema.For().Duplicate(u => u.Name, pgType: "cust_type", configure: idx => { idx.IsUnique = true; }); - _.Schema.For().GinIndexJsonData(); + opts.Schema.For().GinIndexJsonData(); + + opts.Logger(new TestOutputMartenLogger(_output)); }); var guyWithCustomType1 = new UserWithCustomType { Id = Guid.NewGuid(), Name = "test_guy", CustomType = "test_cust_type" }; @@ -237,4 +248,4 @@ public class IssueForUserWithCustomType public string Title { get; set; } public Guid? UserId { get; set; } -} \ No newline at end of file +} diff --git a/src/CoreTests/create_database_Tests.cs b/src/CoreTests/create_database_Tests.cs index 53b5623cb9f..3653dad93df 100644 --- a/src/CoreTests/create_database_Tests.cs +++ b/src/CoreTests/create_database_Tests.cs @@ -46,6 +46,7 @@ await Should.ThrowAsync(async () => c.MaintenanceDatabase(cstring); c.ForTenant() .CheckAgainstPgDatabase() + .WithOwner("postgres") .WithEncoding("UTF-8") .ConnectionLimit(-1) diff --git a/src/DocumentDbTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs b/src/DocumentDbTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs deleted file mode 100644 index 8fb95666417..00000000000 --- a/src/DocumentDbTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Threading.Tasks; -using Marten; -using Marten.Linq.Parsing; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Xunit; -using Shouldly; - -namespace DocumentDbTests.Bugs; - -public class Bug_1217_order_by_count_of_sub_collection : IntegrationContext -{ - public Bug_1217_order_by_count_of_sub_collection(DefaultStoreFixture fixture) : base(fixture) - { - } - - [Fact] - public async Task can_order_by_array_length() - { - var targets = Target.GenerateRandomData(100).ToArray(); - theStore.BulkInsert(targets); - - Expression> expression = x => x.Children.Length; - var memberInfos = FindMembers.Determine(expression.Body); - memberInfos.Length.ShouldBe(2); - - (await theSession.Query().OrderBy(x => x.Children.Length).ToListAsync()).ShouldNotBeNull(); - } - - public class Root - { - public Guid Id { get; set; } - public string Name { get; set; } - - public ICollection ChildsLevel1 { get; set; } - } - - public class ChildLevel1 - { - public Guid Id { get; set; } - public string Name { get; set; } - - public ICollection ChildsLevel2 { get; set; } - } - - public class ChildLevel2 - { - public Guid Id { get; set; } - public string Name { get; set; } - } - - [Fact] - public async Task query_by_list_sub_collection_count() - { - // Just a smoke test here - var list = await theSession.Query().OrderBy(x => x.ChildsLevel1.Count()).ToListAsync(); - list.ShouldNotBeNull(); - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Bugs/Bug_2057_select_transform_dictionary.cs b/src/DocumentDbTests/Bugs/Bug_2057_select_transform_dictionary.cs deleted file mode 100644 index 6eedbf19ca9..00000000000 --- a/src/DocumentDbTests/Bugs/Bug_2057_select_transform_dictionary.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Bug2057; -using Marten; -using Marten.Testing.Harness; -using Shouldly; -using Weasel.Core; -using Xunit; - -namespace DocumentDbTests.Bugs -{ - public class Bug_2057_select_transform_dictionary: BugIntegrationContext - { - [Fact] - public async Task should_be_able_select_dictionary() - { - using var documentStore = SeparateStore(x => - { - x.AutoCreateSchemaObjects = AutoCreate.All; - x.Schema.For(); - }); - - await documentStore.Advanced.Clean.DeleteAllDocumentsAsync(); - - await using var session = documentStore.LightweightSession(); - session.Store(new TestEntity - { - Name = "Test", - Values = new Dictionary - { - { "Key", "Value" }, - { "Key2", "Value2" } - } - }); - - await session.SaveChangesAsync(); - - await using var querySession = documentStore.QuerySession(); - - var results = await querySession.Query() - .Select(x => new TestDto - { - Name = x.Name, - Values = x.Values - }) - .ToListAsync(); - - results.Count.ShouldBe(1); - results[0].Name.ShouldBe("Test"); - results[0].Values.Keys.ShouldContain("Key"); - results[0].Values["Key"].ShouldBe("Value"); - results[0].Values.Keys.ShouldContain("Key2"); - results[0].Values["Key2"].ShouldBe("Value2"); - } - } -} - -namespace Bug2057 -{ - public class TestEntity - { - public Guid Id { get; set; } - - public string Name { get; set; } - public Dictionary Values { get; set; } - } - - public class TestDto - { - public string Name { get; set; } - public Dictionary Values { get; set; } - } -} diff --git a/src/DocumentDbTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs b/src/DocumentDbTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs deleted file mode 100644 index 84ea9cb59be..00000000000 --- a/src/DocumentDbTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using Bug2223; - -using Marten; -using Marten.Testing.Harness; - -using Shouldly; - -using Weasel.Core; - -using Xunit; - -namespace DocumentDbTests.Bugs -{ - public class Bug_2223_list_contains_any_with_include_generates_invalid_sql: BugIntegrationContext - { - [Fact] - public async Task should_be_able_to_query_with_multiple_list_items_and_have_include() - { - using var documentStore = SeparateStore(x => - { - x.AutoCreateSchemaObjects = AutoCreate.All; - x.Schema.For(); - x.Schema.For(); - }); - - await documentStore.Advanced.Clean.DeleteAllDocumentsAsync(); - - var otherEntityTestId = Guid.NewGuid(); - await using (var session = documentStore.LightweightSession()) - { - var otherEntityOne = CreateOtherTestEntity(session, otherEntityTestId, "Other one"); - var otherEntityTwo = CreateOtherTestEntity(session, Guid.NewGuid(), "Other two"); - var otherEntityThree = CreateOtherTestEntity(session, Guid.NewGuid(), "Other three"); - - session.Store(new TestEntity - { - Name = "Test", - OtherIds = new List - { - otherEntityOne.Id, - otherEntityTwo.Id - } - }); - - session.Store(new TestEntity - { - Name = "Test 2", - OtherIds = new List - { - otherEntityTwo.Id, - otherEntityThree.Id - } - }); - - await session.SaveChangesAsync(); - } - - await using (var session = documentStore.QuerySession()) - { - var otherIdsQuery = new[] - { - otherEntityTestId, - Guid.NewGuid() - }; - - var otherTestEntityLookup = new Dictionary(); - var entities = await session.Query() - .Include(x => x.OtherIds, otherTestEntityLookup) - .Where(x => x.OtherIds.Any(id => otherIdsQuery.Contains(id))) - .ToListAsync(); - - entities.Count.ShouldBe(1); - entities[0].OtherIds.Count.ShouldBe(2); - entities[0].OtherIds.ShouldContain(otherEntityTestId); - - otherTestEntityLookup.Count.ShouldBe(2); - otherTestEntityLookup.ShouldContainKey(otherEntityTestId); - } - } - - private static OtherTestEntity CreateOtherTestEntity(IDocumentSession session, Guid id, string name) - { - var entity = new OtherTestEntity - { - Id = id, - Name = name - }; - - session.Store(entity); - return entity; - } - } -} - -namespace Bug2223 -{ - public class TestEntity - { - public Guid Id { get; set; } - public string Name { get; set; } - public List OtherIds { get; set; } - } - - public class OtherTestEntity - { - public Guid Id { get; set; } - public string Name { get; set; } - } -} diff --git a/src/DocumentDbTests/Bugs/Bug_2327_using_identity_extension_on_class_with_invalid_type_id_field.cs b/src/DocumentDbTests/Bugs/Bug_2327_using_identity_extension_on_class_with_invalid_type_id_field.cs index c494b1bece2..5dfe878d492 100644 --- a/src/DocumentDbTests/Bugs/Bug_2327_using_identity_extension_on_class_with_invalid_type_id_field.cs +++ b/src/DocumentDbTests/Bugs/Bug_2327_using_identity_extension_on_class_with_invalid_type_id_field.cs @@ -2,6 +2,7 @@ using Shouldly; using System; using System.Linq; +using Marten.Exceptions; using Marten.Schema; using Xunit; @@ -20,14 +21,11 @@ public void can_override_the_identity_member_when_there_is_id_field_with_invalid [Fact] public void should_not_set_id_member_property_when_new_value_has_invalid_type() { - var mapping = DocumentMapping.For(); - var fieldWithInvalidTypeForId = typeof(OverriddenIdWithInvalidTypeIdField) - .GetMember(nameof(OverriddenIdWithInvalidTypeIdField.Id)).First(); + Should.Throw(() => + { + var mapping = DocumentMapping.For(); + }); - Action action = () => mapping.IdMember = fieldWithInvalidTypeForId; - - action.ShouldThrow(); - mapping.IdMember.ShouldNotBe(fieldWithInvalidTypeForId); } public class OverriddenIdWithInvalidTypeIdField diff --git a/src/DocumentDbTests/Bugs/Bug_849_not_node_not_correctly_evaluated.cs b/src/DocumentDbTests/Bugs/Bug_849_not_node_not_correctly_evaluated.cs deleted file mode 100644 index c6125daf46d..00000000000 --- a/src/DocumentDbTests/Bugs/Bug_849_not_node_not_correctly_evaluated.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Linq; -using Marten.Services; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; -using Xunit.Abstractions; - -namespace DocumentDbTests.Bugs; - -public class Bug_849_not_node_not_correctly_evaluated: IntegrationContext -{ - private readonly ITestOutputHelper _output; - - public class TestClass - { - public TestClass() - { - Id = Guid.NewGuid(); - } - - public Guid Id { get; set; } - public bool Flag { get; set; } - } - - internal TestClass TestNullObject { get; set; } - - [Fact] - public void When_Property_Is_Null_Exception_Should_Be_Null_Reference_Exception() - { - var flagFalse = new TestClass { Flag = false }; - var flagTrue = new TestClass { Flag = true }; - - theSession.Store(flagFalse, flagTrue); - theSession.SaveChanges(); - - using var s = theStore.QuerySession(); - var items = s.Query().Where(x => !x.Flag == false).ToList(); - - items.Single().Id.ShouldBe(flagTrue.Id); - } - - public Bug_849_not_node_not_correctly_evaluated(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) - { - _output = output; - } -} diff --git a/src/DocumentDbTests/Configuration/DocumentMappingTests.cs b/src/DocumentDbTests/Configuration/DocumentMappingTests.cs index 6c4166305b9..3cc5187764d 100644 --- a/src/DocumentDbTests/Configuration/DocumentMappingTests.cs +++ b/src/DocumentDbTests/Configuration/DocumentMappingTests.cs @@ -2,18 +2,18 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Threading.Tasks; -using JasperFx.Core; using JasperFx.CodeGeneration; +using JasperFx.Core.Reflection; using Marten; using Marten.Exceptions; -using Marten.Linq.Fields; +using Marten.Linq; +using Marten.Linq.Members; +using Marten.Linq.Parsing; using Marten.Schema; using Marten.Schema.Identity; using Marten.Schema.Identity.Sequences; using Marten.Storage; using Marten.Storage.Metadata; -using Marten.Testing; using Marten.Testing.Documents; using Marten.Testing.Harness; using NpgsqlTypes; @@ -21,137 +21,11 @@ using Weasel.Core; using Weasel.Postgresql.Tables; using Xunit; -using CombGuidIdGeneration = Marten.Schema.Identity.CombGuidIdGeneration; namespace DocumentDbTests.Configuration; public class DocumentMappingTests { - public class FieldId - { - public string id; - } - - public abstract class AbstractDoc - { - public int id; - } - - public interface IDoc - { - string id { get; set; } - } - - [UseOptimisticConcurrency] - public class VersionedDoc - { - public Guid Id { get; set; } = Guid.NewGuid(); - } - - public class IntId - { - public int Id; - } - - public class LongId - { - public long Id; - } - - public class StringId - { - public string Id; - } - - public class UpperCaseProperty - { - public Guid Id { get; set; } - } - - public class LowerCaseProperty - { - public Guid id { get; set; } - } - - public class UpperCaseField - { - public int Id; - } - - public class LowerCaseField - { - public int id; - } - - public class MySpecialDocument - { - public Guid Id { get; set; } - } - - [GinIndexed] - public class BaseDocumentWithAttribute - { - public int Id; - } - - public class BaseDocumentSubClass: BaseDocumentWithAttribute - { - } - - [PropertySearching(PropertySearching.JSON_Locator_Only)] - public class Organization - { - [DuplicateField] public string OtherName; - - public string OtherProp; - public Guid Id { get; set; } - - [DuplicateField] public string Name { get; set; } - - public string OtherField { get; set; } - } - - public class CustomIdGeneration: IIdGeneration - { - public IEnumerable KeyTypes { get; } - - public bool RequiresSequences { get; } = false; - - public void GenerateCode(GeneratedMethod assign, DocumentMapping mapping) - { - throw new NotSupportedException(); - } - } - - #region sample_ConfigureMarten-generic - - public class ConfiguresItself - { - public Guid Id; - - public static void ConfigureMarten(DocumentMapping mapping) - { - mapping.Alias = "different"; - } - } - - #endregion - - #region sample_ConfigureMarten-specifically - - public class ConfiguresItselfSpecifically - { - public Guid Id; - public string Name; - - public static void ConfigureMarten(DocumentMapping mapping) - { - mapping.Duplicate(x => x.Name); - } - } - - #endregion - [Fact] public void can_replace_hilo_def_settings() { @@ -278,11 +152,11 @@ public void duplicate_a_field() mapping.DuplicateField(nameof(User.FirstName)); - mapping.FieldFor(nameof(User.FirstName)).ShouldBeOfType(); + mapping.QueryMembers.MemberFor(nameof(User.FirstName)).ShouldBeOfType(); // other fields are still the same - SpecificationExtensions.ShouldNotBeOfType(mapping.FieldFor(nameof(User.LastName))); + mapping.QueryMembers.MemberFor(nameof(User.LastName)).ShouldNotBeOfType(); } [Theory] @@ -337,8 +211,8 @@ public void public void find_field_for_immediate_field_that_is_not_duplicated() { var mapping = DocumentMapping.For(); - var field = mapping.FieldFor("Id"); - field.Members.Single().ShouldBeAssignableTo() + var field = mapping.QueryMembers.MemberFor("Id"); + field.As().Member.ShouldBeAssignableTo() .Name.ShouldBe("Id"); } @@ -346,18 +220,18 @@ public void find_field_for_immediate_field_that_is_not_duplicated() public void find_field_for_immediate_property_that_is_not_duplicated() { var mapping = DocumentMapping.For(); - var field = mapping.FieldFor("Id"); - field.Members.Single().ShouldBeAssignableTo() + var field = mapping.QueryMembers.MemberFor("Id"); + field.As().Member.ShouldBeAssignableTo() .Name.ShouldBe("Id"); } [Fact] public void get_the_sql_locator_for_the_Id_member() { - DocumentMapping.For().FieldFor("Id") + DocumentMapping.For().QueryMembers.MemberFor("Id") .TypedLocator.ShouldBe("d.id"); - DocumentMapping.For().FieldFor("id") + DocumentMapping.For().QueryMembers.MemberFor("id") .TypedLocator.ShouldBe("d.id"); } @@ -517,8 +391,8 @@ public void picks_up_searchable_attribute_on_fields() { var mapping = DocumentMapping.For(); - mapping.FieldFor("OtherName").ShouldBeOfType(); - SpecificationExtensions.ShouldNotBeOfType(mapping.FieldFor(nameof(Organization.OtherField))); + mapping.QueryMembers.MemberFor("OtherName").ShouldBeOfType(); + mapping.QueryMembers.MemberFor(nameof(Organization.OtherField)).ShouldNotBeOfType(); } [Fact] @@ -526,8 +400,8 @@ public void picks_up_searchable_attribute_on_properties() { var mapping = DocumentMapping.For(); - mapping.FieldFor(nameof(Organization.Name)).ShouldBeOfType(); - mapping.FieldFor(nameof(Organization.OtherProp)).ShouldNotBeOfType(); + mapping.QueryMembers.MemberFor(nameof(Organization.Name)).ShouldBeOfType(); + mapping.QueryMembers.MemberFor(nameof(Organization.OtherProp)).ShouldNotBeOfType(); } [Fact] @@ -815,6 +689,131 @@ public void use_the_default_pg_type_for_the_member_type_if_not_overridden() DocumentMapping.For().DatabaseSchemaName.ShouldBe("organization"); } + public class FieldId + { + public string id; + } + + public abstract class AbstractDoc + { + public int id; + } + + public interface IDoc + { + string id { get; set; } + } + + [UseOptimisticConcurrency] + public class VersionedDoc + { + public Guid Id { get; set; } = Guid.NewGuid(); + } + + public class IntId + { + public int Id; + } + + public class LongId + { + public long Id; + } + + public class StringId + { + public string Id; + } + + public class UpperCaseProperty + { + public Guid Id { get; set; } + } + + public class LowerCaseProperty + { + public Guid id { get; set; } + } + + public class UpperCaseField + { + public int Id; + } + + public class LowerCaseField + { + public int id; + } + + public class MySpecialDocument + { + public Guid Id { get; set; } + } + + [GinIndexed] + public class BaseDocumentWithAttribute + { + public int Id; + } + + public class BaseDocumentSubClass: BaseDocumentWithAttribute + { + } + + [PropertySearching(PropertySearching.JSON_Locator_Only)] + public class Organization + { + [DuplicateField] public string OtherName; + + public string OtherProp; + public Guid Id { get; set; } + + [DuplicateField] public string Name { get; set; } + + public string OtherField { get; set; } + } + + public class CustomIdGeneration: IIdGeneration + { + public IEnumerable KeyTypes { get; } + + public bool RequiresSequences { get; } = false; + + public void GenerateCode(GeneratedMethod assign, DocumentMapping mapping) + { + throw new NotSupportedException(); + } + } + + #region sample_ConfigureMarten-generic + + public class ConfiguresItself + { + public Guid Id; + + public static void ConfigureMarten(DocumentMapping mapping) + { + mapping.Alias = "different"; + } + } + + #endregion + + #region sample_ConfigureMarten-specifically + + public class ConfiguresItselfSpecifically + { + public Guid Id; + public string Name; + + public static void ConfigureMarten(DocumentMapping mapping) + { + mapping.Duplicate(x => x.Name); + } + } + + #endregion + #region sample_using_DatabaseSchemaName_attribute [DatabaseSchemaName("organization")] diff --git a/src/DocumentDbTests/Configuration/MartenRegistryTests.cs b/src/DocumentDbTests/Configuration/MartenRegistryTests.cs index fe16785f406..8e3f63d600e 100644 --- a/src/DocumentDbTests/Configuration/MartenRegistryTests.cs +++ b/src/DocumentDbTests/Configuration/MartenRegistryTests.cs @@ -3,7 +3,9 @@ using JasperFx.Core; using JasperFx.Core.Reflection; using Marten; -using Marten.Linq.Fields; +using Marten.Linq; +using Marten.Linq.Members; +using Marten.Linq.Parsing; using Marten.Schema; using Marten.Storage; using Marten.Testing.Documents; @@ -49,14 +51,16 @@ public void property_searching_override() public void picks_up_searchable_on_property() { theStorage.MappingFor(typeof (Organization)).As() - .FieldFor(nameof(Organization.Name)).ShouldBeOfType(); + .QueryMembers + .MemberFor(nameof(Organization.Name)).ShouldBeOfType(); } [Fact] public void picks_up_searchable_on_field() { theStorage.MappingFor(typeof(Organization)).As() - .FieldFor(nameof(Organization.OtherName)).ShouldBeOfType(); + .QueryMembers + .MemberFor(nameof(Organization.OtherName)).ShouldBeOfType(); } [Fact] diff --git a/src/DocumentDbTests/Deleting/soft_deletes.cs b/src/DocumentDbTests/Deleting/soft_deletes.cs index ee90efb4403..58d6740475c 100644 --- a/src/DocumentDbTests/Deleting/soft_deletes.cs +++ b/src/DocumentDbTests/Deleting/soft_deletes.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using JasperFx.Core; +using JasperFx.Core.Reflection; using Marten; using Marten.Linq.SoftDeletes; using Marten.Metadata; @@ -69,12 +71,15 @@ public async Task can_query_by_the_deleted_column_if_it_exists() await theSession.SaveChangesAsync(); await using var session2 = theStore.LightweightSession(); + + session2.Logger = new TestOutputMartenLogger(_output); + session2.Delete(doc1); session2.Delete(doc3); await session2.SaveChangesAsync(); await using var query = theStore.QuerySession(); - query.Logger = new TestOutputMartenLogger(_output); + var deleted = await query.Query().Where(x => x.Deleted) .CountAsync(); @@ -643,6 +648,53 @@ public async Task hard_delete_by_document_and_tenant_by_Guid() blueCount.ShouldBe(1); } + + [Fact] + public async Task throw_not_supported_when_trying_to_query_against_non_soft_deleted_docs_1() + { + var ex = await Should.ThrowAsync(async () => + { + var dateTimeOffset = DateTimeOffset.Now.Subtract(5.Days()); + await theSession.Query().Where(x => x.DeletedBefore(dateTimeOffset)).ToListAsync(); + }); + + ex.Message.ShouldBe($"Document type {typeof(Target).FullNameInCode()} is not configured as soft deleted"); + } + + [Fact] + public async Task throw_not_supported_when_trying_to_query_against_non_soft_deleted_docs_2() + { + var ex = await Should.ThrowAsync(async () => + { + var dateTimeOffset = DateTimeOffset.Now.Subtract(5.Days()); + await theSession.Query().Where(x => x.DeletedSince(dateTimeOffset)).ToListAsync(); + }); + + ex.Message.ShouldBe($"Document type {typeof(Target).FullNameInCode()} is not configured as soft deleted"); + } + + [Fact] + public async Task throw_not_supported_when_trying_to_query_against_non_soft_deleted_docs_3() + { + var ex = await Should.ThrowAsync(async () => + { + await theSession.Query().Where(x => x.MaybeDeleted()).ToListAsync(); + }); + + ex.Message.ShouldBe($"Document type {typeof(Target).FullNameInCode()} is not configured as soft deleted"); + } + + + [Fact] + public async Task throw_not_supported_when_trying_to_query_against_non_soft_deleted_docs_4() + { + var ex = await Should.ThrowAsync(async () => + { + await theSession.Query().Where(x => x.IsDeleted()).ToListAsync(); + }); + + ex.Message.ShouldBe($"Document type {typeof(Target).FullNameInCode()} is not configured as soft deleted"); + } } public class File diff --git a/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs b/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs index 796d19ed230..82076218571 100644 --- a/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs +++ b/src/DocumentDbTests/HierarchicalStorage/delete_by_where_for_hierarchy_Tests.cs @@ -1,7 +1,9 @@ using System.Linq; using Marten.Testing.Documents; +using Marten.Testing.Harness; using Shouldly; using Xunit; +using Xunit.Abstractions; namespace DocumentDbTests.HierarchicalStorage; diff --git a/src/DocumentDbTests/Indexes/duplicated_field.cs b/src/DocumentDbTests/Indexes/duplicated_field.cs index 79309660bde..c41d1b08983 100644 --- a/src/DocumentDbTests/Indexes/duplicated_field.cs +++ b/src/DocumentDbTests/Indexes/duplicated_field.cs @@ -202,7 +202,8 @@ public void can_override_with_MartenRegistry() _.Schema.For().Duplicate(x => x.Time2, pgType: "timestamp"); }); - theStore.StorageFeatures.MappingFor(typeof(Organization)).As().DuplicatedFields.Single(x => x.MemberName == "Time2") + var documentMapping = theStore.StorageFeatures.MappingFor(typeof(Organization)).As(); + documentMapping.DuplicatedFields.Single(x => x.MemberName == "Time2") .PgType.ShouldBe("timestamp"); } @@ -315,24 +316,26 @@ await theStore.BulkInsertDocumentsAsync(new Application[] [Fact] public async Task Bug_1931_duplicated_deep_enum_field_with_int_storage() { - StoreOptions(config => + StoreOptions(opts => { - config.Schema.For() + opts.Schema.For() .AddSubClassHierarchy( typeof(ApplicationSubclass) ); - config.Schema.For().GinIndexJsonData(); + opts.Schema.For().GinIndexJsonData(); - config.Schema.For() + opts.Schema.For() .Duplicate(a => a.ApplicationNumber) .Duplicate(a => a.Status.StatusType); - config.Schema.For().Identity(a => a.Id).HiloSettings(new HiloSettings {MaxLo = 100}); + opts.Schema.For().Identity(a => a.Id).HiloSettings(new HiloSettings {MaxLo = 100}); - config.Advanced.DuplicatedFieldEnumStorage = EnumStorage.AsInteger; - config.Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime = false; + opts.Advanced.DuplicatedFieldEnumStorage = EnumStorage.AsInteger; + opts.Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime = false; + + opts.AutoCreateSchemaObjects = AutoCreate.All; }); await theStore.Advanced.Clean.CompletelyRemoveAllAsync(); diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/DirtyTrackingUserByUsernameCompiledQuerySource661477123.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/DirtyTrackingUserByUsernameCompiledQuerySource661477123.cs deleted file mode 100644 index 742f570fdd4..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/DirtyTrackingUserByUsernameCompiledQuerySource661477123.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: DirtyTrackingUserByUsernameCompiledQuery661477123 - public class DirtyTrackingUserByUsernameCompiledQuery661477123 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserByUsername _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public DirtyTrackingUserByUsernameCompiledQuery661477123(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.UserName; - _hardcoded.Apply(parameters); - } - - } - - // END: DirtyTrackingUserByUsernameCompiledQuery661477123 - - - // START: DirtyTrackingUserByUsernameCompiledQuerySource661477123 - public class DirtyTrackingUserByUsernameCompiledQuerySource661477123 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public DirtyTrackingUserByUsernameCompiledQuerySource661477123(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.DirtyTrackingUserByUsernameCompiledQuery661477123(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: DirtyTrackingUserByUsernameCompiledQuerySource661477123 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/IdentityOnlyUserByUsernameCompiledQuerySource661477123.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/IdentityOnlyUserByUsernameCompiledQuerySource661477123.cs deleted file mode 100644 index 5a828b36fb1..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/IdentityOnlyUserByUsernameCompiledQuerySource661477123.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: IdentityOnlyUserByUsernameCompiledQuery661477123 - public class IdentityOnlyUserByUsernameCompiledQuery661477123 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserByUsername _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public IdentityOnlyUserByUsernameCompiledQuery661477123(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.UserName; - _hardcoded.Apply(parameters); - } - - } - - // END: IdentityOnlyUserByUsernameCompiledQuery661477123 - - - // START: IdentityOnlyUserByUsernameCompiledQuerySource661477123 - public class IdentityOnlyUserByUsernameCompiledQuerySource661477123 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public IdentityOnlyUserByUsernameCompiledQuerySource661477123(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.IdentityOnlyUserByUsernameCompiledQuery661477123(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: IdentityOnlyUserByUsernameCompiledQuerySource661477123 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery1CompiledQuerySource2018461339.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery1CompiledQuerySource2018461339.cs deleted file mode 100644 index 0eef0b1e2ad..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery1CompiledQuerySource2018461339.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneCompiledQuery1CompiledQuery2018461339 - public class NoneCompiledQuery1CompiledQuery2018461339 : Marten.Internal.CompiledQueries.StatelessCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IQueryHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.CompiledQuery1 _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneCompiledQuery1CompiledQuery2018461339(Marten.Linq.QueryHandlers.IQueryHandler inner, DocumentDbTests.Reading.Linq.Compiled.CompiledQuery1 query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select TRUE as result from public.mt_doc_target as d where d.data ->> 'String' ~~* ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.StringValue; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneCompiledQuery1CompiledQuery2018461339 - - - // START: NoneCompiledQuery1CompiledQuerySource2018461339 - public class NoneCompiledQuery1CompiledQuerySource2018461339 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IQueryHandler _queryHandler; - - public NoneCompiledQuery1CompiledQuerySource2018461339(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IQueryHandler queryHandler) - { - _hardcoded = hardcoded; - _queryHandler = queryHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.CompiledQuery1 query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneCompiledQuery1CompiledQuery2018461339(_queryHandler, query, _hardcoded); - } - - } - - // END: NoneCompiledQuery1CompiledQuerySource2018461339 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery2CompiledQuerySource1615176812.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery2CompiledQuerySource1615176812.cs deleted file mode 100644 index d0f8881514d..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQuery2CompiledQuerySource1615176812.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneCompiledQuery2CompiledQuery1615176812 - public class NoneCompiledQuery2CompiledQuery1615176812 : Marten.Internal.CompiledQueries.StatelessCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IQueryHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.CompiledQuery2 _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneCompiledQuery2CompiledQuery1615176812(Marten.Linq.QueryHandlers.IQueryHandler inner, DocumentDbTests.Reading.Linq.Compiled.CompiledQuery2 query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select TRUE as result from public.mt_doc_target as d where d.id = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[0].Value = _query.IdValue; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneCompiledQuery2CompiledQuery1615176812 - - - // START: NoneCompiledQuery2CompiledQuerySource1615176812 - public class NoneCompiledQuery2CompiledQuerySource1615176812 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IQueryHandler _queryHandler; - - public NoneCompiledQuery2CompiledQuerySource1615176812(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IQueryHandler queryHandler) - { - _hardcoded = hardcoded; - _queryHandler = queryHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.CompiledQuery2 query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneCompiledQuery2CompiledQuery1615176812(_queryHandler, query, _hardcoded); - } - - } - - // END: NoneCompiledQuery2CompiledQuerySource1615176812 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQueryTargetCompiledQuerySource9758203.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQueryTargetCompiledQuerySource9758203.cs deleted file mode 100644 index 15905234179..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneCompiledQueryTargetCompiledQuerySource9758203.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneCompiledQueryTargetCompiledQuery9758203 - public class NoneCompiledQueryTargetCompiledQuery9758203 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.CompiledQueryTarget _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneCompiledQueryTargetCompiledQuery9758203(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.CompiledQueryTarget query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_simpleequalsparsertests_querytarget as d where (CAST(d.data ->> 'IntProp' as integer) = ? and d.id = ?) LIMIT ?"); - - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[1].Value = _query.IdProp; - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[0].Value = _query.IntProp; - - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = _query.IntProp; - } - - } - - // END: NoneCompiledQueryTargetCompiledQuery9758203 - - - // START: NoneCompiledQueryTargetCompiledQuerySource9758203 - public class NoneCompiledQueryTargetCompiledQuerySource9758203 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneCompiledQueryTargetCompiledQuerySource9758203(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.CompiledQueryTarget query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneCompiledQueryTargetCompiledQuery9758203(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneCompiledQueryTargetCompiledQuerySource9758203 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509.cs deleted file mode 100644 index 948b5a62a6b..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Json; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneFindCustomerJsonByNameQueryCompiledQuery549815509 - public class NoneFindCustomerJsonByNameQueryCompiledQuery549815509 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Json.streaming_json_results.FindCustomerJsonByNameQuery> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Json.streaming_json_results.FindCustomerJsonByNameQuery _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneFindCustomerJsonByNameQueryCompiledQuery549815509(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Json.streaming_json_results.FindCustomerJsonByNameQuery query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_streaming_json_results_customer as d where d.data ->> 'LastName' LIKE ? order by d.data ->> 'LastName'"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = EndsWith(_query.LastNamePrefix); - } - - } - - // END: NoneFindCustomerJsonByNameQueryCompiledQuery549815509 - - - // START: NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509 - public class NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Json.streaming_json_results.FindCustomerJsonByNameQuery> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Json.streaming_json_results.FindCustomerJsonByNameQuery query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneFindCustomerJsonByNameQueryCompiledQuery549815509(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneFindCustomerJsonByNameQueryCompiledQuerySource549815509 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindJsonUsersByUsernameCompiledQuerySource1607037309.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindJsonUsersByUsernameCompiledQuerySource1607037309.cs deleted file mode 100644 index 3fee3256941..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindJsonUsersByUsernameCompiledQuerySource1607037309.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneFindJsonUsersByUsernameCompiledQuery1607037309 - public class NoneFindJsonUsersByUsernameCompiledQuery1607037309 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.FindJsonUsersByUsername> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.FindJsonUsersByUsername _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneFindJsonUsersByUsernameCompiledQuery1607037309(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.FindJsonUsersByUsername query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'FirstName' = ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.FirstName; - } - - } - - // END: NoneFindJsonUsersByUsernameCompiledQuery1607037309 - - - // START: NoneFindJsonUsersByUsernameCompiledQuerySource1607037309 - public class NoneFindJsonUsersByUsernameCompiledQuerySource1607037309 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.FindJsonUsersByUsername> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneFindJsonUsersByUsernameCompiledQuerySource1607037309(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.FindJsonUsersByUsername query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneFindJsonUsersByUsernameCompiledQuery1607037309(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneFindJsonUsersByUsernameCompiledQuerySource1607037309 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindUserByAllTheThingsCompiledQuerySource878799577.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindUserByAllTheThingsCompiledQuerySource878799577.cs deleted file mode 100644 index 48245093c5d..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneFindUserByAllTheThingsCompiledQuerySource878799577.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneFindUserByAllTheThingsCompiledQuery878799577 - public class NoneFindUserByAllTheThingsCompiledQuery878799577 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.FindUserByAllTheThings _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneFindUserByAllTheThingsCompiledQuery878799577(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.FindUserByAllTheThings query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where ((d.data ->> 'FirstName' = ? and d.data ->> 'UserName' = ?) and d.data ->> 'LastName' = ?) LIMIT ?"); - - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[1].Value = _query.Username; - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.FirstName; - - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[2].Value = _query.LastName; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneFindUserByAllTheThingsCompiledQuery878799577 - - - // START: NoneFindUserByAllTheThingsCompiledQuerySource878799577 - public class NoneFindUserByAllTheThingsCompiledQuerySource878799577 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneFindUserByAllTheThingsCompiledQuerySource878799577(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.FindUserByAllTheThings query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneFindUserByAllTheThingsCompiledQuery878799577(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneFindUserByAllTheThingsCompiledQuerySource878799577 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetPaginationQueryCompiledQuerySource323866534.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetPaginationQueryCompiledQuerySource323866534.cs deleted file mode 100644 index 066cab07581..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetPaginationQueryCompiledQuerySource323866534.cs +++ /dev/null @@ -1,71 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneTargetPaginationQueryCompiledQuery323866534 - public class NoneTargetPaginationQueryCompiledQuery323866534 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.invoking_query_with_statistics.TargetPaginationQuery> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.invoking_query_with_statistics.TargetPaginationQuery _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneTargetPaginationQueryCompiledQuery323866534(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.invoking_query_with_statistics.TargetPaginationQuery query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data, count(1) OVER() as total_rows from public.mt_doc_target as d where CAST(d.data ->> 'Number' as integer) > ? OFFSET ? LIMIT ?"); - - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[1].Value = _query.PageNumber; - - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = _query.PageSize; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneTargetPaginationQueryCompiledQuery323866534 - - - // START: NoneTargetPaginationQueryCompiledQuerySource323866534 - public class NoneTargetPaginationQueryCompiledQuerySource323866534 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.invoking_query_with_statistics.TargetPaginationQuery> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneTargetPaginationQueryCompiledQuerySource323866534(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.invoking_query_with_statistics.TargetPaginationQuery query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneTargetPaginationQueryCompiledQuery323866534(_maybeStatefulHandler, query, query.Stats, _hardcoded); - } - - } - - // END: NoneTargetPaginationQueryCompiledQuerySource323866534 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetsInOrderCompiledQuerySource468279698.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetsInOrderCompiledQuerySource468279698.cs deleted file mode 100644 index ba12d2163c2..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTargetsInOrderCompiledQuerySource468279698.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneTargetsInOrderCompiledQuery468279698 - public class NoneTargetsInOrderCompiledQuery468279698 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.TargetsInOrder> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.TargetsInOrder _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneTargetsInOrderCompiledQuery468279698(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.TargetsInOrder query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data, count(1) OVER() as total_rows from public.mt_doc_target as d order by d.id OFFSET ? LIMIT ?"); - - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[1].Value = _query.PageSize; - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[0].Value = _query.Start; - } - - } - - // END: NoneTargetsInOrderCompiledQuery468279698 - - - // START: NoneTargetsInOrderCompiledQuerySource468279698 - public class NoneTargetsInOrderCompiledQuerySource468279698 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.TargetsInOrder> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneTargetsInOrderCompiledQuerySource468279698(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.TargetsInOrder query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneTargetsInOrderCompiledQuery468279698(_maybeStatefulHandler, query, query.Statistics, _hardcoded); - } - - } - - // END: NoneTargetsInOrderCompiledQuerySource468279698 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTestQueryCompiledQuerySource2052986011.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTestQueryCompiledQuerySource2052986011.cs deleted file mode 100644 index c90da774e30..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneTestQueryCompiledQuerySource2052986011.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneTestQueryCompiledQuery2052986011 - public class NoneTestQueryCompiledQuery2052986011 : Marten.Internal.CompiledQueries.StatelessCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IQueryHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.compiled_query_Tests.TestQuery _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneTestQueryCompiledQuery2052986011(Marten.Linq.QueryHandlers.IQueryHandler inner, DocumentDbTests.Reading.Linq.Compiled.compiled_query_Tests.TestQuery query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select TRUE as result from public.mt_doc_user as d where CAST(d.data ->> 'Age' as integer) = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[0].Value = _query.Age; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneTestQueryCompiledQuery2052986011 - - - // START: NoneTestQueryCompiledQuerySource2052986011 - public class NoneTestQueryCompiledQuerySource2052986011 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IQueryHandler _queryHandler; - - public NoneTestQueryCompiledQuerySource2052986011(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IQueryHandler queryHandler) - { - _hardcoded = hardcoded; - _queryHandler = queryHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.compiled_query_Tests.TestQuery query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneTestQueryCompiledQuery2052986011(_queryHandler, query, _hardcoded); - } - - } - - // END: NoneTestQueryCompiledQuerySource2052986011 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameCompiledQuerySource661477123.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameCompiledQuerySource661477123.cs deleted file mode 100644 index 01b72add4c3..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameCompiledQuerySource661477123.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserByUsernameCompiledQuery661477123 - public class NoneUserByUsernameCompiledQuery661477123 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserByUsername _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserByUsernameCompiledQuery661477123(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.UserName; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneUserByUsernameCompiledQuery661477123 - - - // START: NoneUserByUsernameCompiledQuerySource661477123 - public class NoneUserByUsernameCompiledQuerySource661477123 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUserByUsernameCompiledQuerySource661477123(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserByUsernameCompiledQuery661477123(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUserByUsernameCompiledQuerySource661477123 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325.cs deleted file mode 100644 index 127f0418398..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserByUsernameSingleOrDefaultCompiledQuery97871325 - public class NoneUserByUsernameSingleOrDefaultCompiledQuery97871325 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserByUsernameSingleOrDefault _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserByUsernameSingleOrDefaultCompiledQuery97871325(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserByUsernameSingleOrDefault query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.UserName; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneUserByUsernameSingleOrDefaultCompiledQuery97871325 - - - // START: NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325 - public class NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserByUsernameSingleOrDefault query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserByUsernameSingleOrDefaultCompiledQuery97871325(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUserByUsernameSingleOrDefaultCompiledQuerySource97871325 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameWithFieldsCompiledQuerySource92089138.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameWithFieldsCompiledQuerySource92089138.cs deleted file mode 100644 index 190842f5d57..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserByUsernameWithFieldsCompiledQuerySource92089138.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserByUsernameWithFieldsCompiledQuery92089138 - public class NoneUserByUsernameWithFieldsCompiledQuery92089138 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserByUsernameWithFields _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserByUsernameWithFieldsCompiledQuery92089138(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserByUsernameWithFields query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.UserName; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneUserByUsernameWithFieldsCompiledQuery92089138 - - - // START: NoneUserByUsernameWithFieldsCompiledQuerySource92089138 - public class NoneUserByUsernameWithFieldsCompiledQuerySource92089138 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUserByUsernameWithFieldsCompiledQuerySource92089138(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserByUsernameWithFields query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserByUsernameWithFieldsCompiledQuery92089138(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUserByUsernameWithFieldsCompiledQuerySource92089138 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserCountByFirstNameCompiledQuerySource1983785893.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserCountByFirstNameCompiledQuerySource1983785893.cs deleted file mode 100644 index 501b89ca895..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserCountByFirstNameCompiledQuerySource1983785893.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserCountByFirstNameCompiledQuery1983785893 - public class NoneUserCountByFirstNameCompiledQuery1983785893 : Marten.Internal.CompiledQueries.StatelessCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IQueryHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserCountByFirstName _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserCountByFirstNameCompiledQuery1983785893(Marten.Linq.QueryHandlers.IQueryHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserCountByFirstName query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select count(*) as number from public.mt_doc_user as d where d.data ->> 'FirstName' = ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.FirstName; - } - - } - - // END: NoneUserCountByFirstNameCompiledQuery1983785893 - - - // START: NoneUserCountByFirstNameCompiledQuerySource1983785893 - public class NoneUserCountByFirstNameCompiledQuerySource1983785893 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IQueryHandler _queryHandler; - - public NoneUserCountByFirstNameCompiledQuerySource1983785893(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IQueryHandler queryHandler) - { - _hardcoded = hardcoded; - _queryHandler = queryHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserCountByFirstName query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserCountByFirstNameCompiledQuery1983785893(_queryHandler, query, _hardcoded); - } - - } - - // END: NoneUserCountByFirstNameCompiledQuerySource1983785893 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsCompiledQuerySource1056635770.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsCompiledQuerySource1056635770.cs deleted file mode 100644 index 9b78690b8ac..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsCompiledQuerySource1056635770.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserNameContainsCompiledQuery1056635770 - public class NoneUserNameContainsCompiledQuery1056635770 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContains> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContains _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserNameContainsCompiledQuery1056635770(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContains query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' LIKE ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = ContainsString(_query.Fragment); - } - - } - - // END: NoneUserNameContainsCompiledQuery1056635770 - - - // START: NoneUserNameContainsCompiledQuerySource1056635770 - public class NoneUserNameContainsCompiledQuerySource1056635770 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContains> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUserNameContainsCompiledQuerySource1056635770(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContains query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserNameContainsCompiledQuery1056635770(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUserNameContainsCompiledQuerySource1056635770 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsInsensitiveCompiledQuerySource2080514763.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsInsensitiveCompiledQuerySource2080514763.cs deleted file mode 100644 index 16964a47a3e..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameContainsInsensitiveCompiledQuerySource2080514763.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserNameContainsInsensitiveCompiledQuery2080514763 - public class NoneUserNameContainsInsensitiveCompiledQuery2080514763 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContainsInsensitive> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContainsInsensitive _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserNameContainsInsensitiveCompiledQuery2080514763(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContainsInsensitive query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' ILIKE ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = ContainsString(_query.Fragment); - } - - } - - // END: NoneUserNameContainsInsensitiveCompiledQuery2080514763 - - - // START: NoneUserNameContainsInsensitiveCompiledQuerySource2080514763 - public class NoneUserNameContainsInsensitiveCompiledQuerySource2080514763 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContainsInsensitive> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUserNameContainsInsensitiveCompiledQuerySource2080514763(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameContainsInsensitive query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserNameContainsInsensitiveCompiledQuery2080514763(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUserNameContainsInsensitiveCompiledQuerySource2080514763 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameEndsWithCompiledQuerySource1088283705.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameEndsWithCompiledQuerySource1088283705.cs deleted file mode 100644 index 5d4740aa6fd..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameEndsWithCompiledQuerySource1088283705.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserNameEndsWithCompiledQuery1088283705 - public class NoneUserNameEndsWithCompiledQuery1088283705 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameEndsWith> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameEndsWith _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserNameEndsWithCompiledQuery1088283705(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameEndsWith query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' LIKE ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = StartsWith(_query.Suffix); - } - - } - - // END: NoneUserNameEndsWithCompiledQuery1088283705 - - - // START: NoneUserNameEndsWithCompiledQuerySource1088283705 - public class NoneUserNameEndsWithCompiledQuerySource1088283705 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameEndsWith> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUserNameEndsWithCompiledQuerySource1088283705(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameEndsWith query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserNameEndsWithCompiledQuery1088283705(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUserNameEndsWithCompiledQuerySource1088283705 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameStartsWithCompiledQuerySource515679394.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameStartsWithCompiledQuerySource515679394.cs deleted file mode 100644 index 2235996b2fb..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserNameStartsWithCompiledQuerySource515679394.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserNameStartsWithCompiledQuery515679394 - public class NoneUserNameStartsWithCompiledQuery515679394 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameStartsWith> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameStartsWith _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserNameStartsWithCompiledQuery515679394(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameStartsWith query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' LIKE ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = EndsWith(_query.Prefix); - } - - } - - // END: NoneUserNameStartsWithCompiledQuery515679394 - - - // START: NoneUserNameStartsWithCompiledQuerySource515679394 - public class NoneUserNameStartsWithCompiledQuerySource515679394 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameStartsWith> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUserNameStartsWithCompiledQuerySource515679394(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.compiled_query_by_string_fragments.UserNameStartsWith query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserNameStartsWithCompiledQuery515679394(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUserNameStartsWithCompiledQuerySource515679394 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725.cs deleted file mode 100644 index acb68181c34..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUserProjectionToLoginPayloadCompiledQuery1260512725 - public class NoneUserProjectionToLoginPayloadCompiledQuery1260512725 : Marten.Internal.CompiledQueries.StatelessCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IQueryHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserProjectionToLoginPayload _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUserProjectionToLoginPayloadCompiledQuery1260512725(Marten.Linq.QueryHandlers.IQueryHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserProjectionToLoginPayload query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select jsonb_build_object('Username', d.data ->> 'UserName') as data from public.mt_doc_user as d where d.data ->> 'UserName' = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.UserName; - _hardcoded.Apply(parameters); - } - - } - - // END: NoneUserProjectionToLoginPayloadCompiledQuery1260512725 - - - // START: NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725 - public class NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IQueryHandler _queryHandler; - - public NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IQueryHandler queryHandler) - { - _hardcoded = hardcoded; - _queryHandler = queryHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserProjectionToLoginPayload query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUserProjectionToLoginPayloadCompiledQuery1260512725(_queryHandler, query, _hardcoded); - } - - } - - // END: NoneUserProjectionToLoginPayloadCompiledQuerySource1260512725 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameCompiledQuerySource314143719.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameCompiledQuerySource314143719.cs deleted file mode 100644 index bd96f497718..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameCompiledQuerySource314143719.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUsersByFirstNameCompiledQuery314143719 - public class NoneUsersByFirstNameCompiledQuery314143719 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstName> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UsersByFirstName _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUsersByFirstNameCompiledQuery314143719(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstName query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'FirstName' = ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.FirstName; - } - - } - - // END: NoneUsersByFirstNameCompiledQuery314143719 - - - // START: NoneUsersByFirstNameCompiledQuerySource314143719 - public class NoneUsersByFirstNameCompiledQuerySource314143719 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstName> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUsersByFirstNameCompiledQuerySource314143719(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UsersByFirstName query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUsersByFirstNameCompiledQuery314143719(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUsersByFirstNameCompiledQuerySource314143719 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs deleted file mode 100644 index c9ca6ec6111..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: NoneUsersByFirstNameWithFieldsCompiledQuery906880034 - public class NoneUsersByFirstNameWithFieldsCompiledQuery906880034 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public NoneUsersByFirstNameWithFieldsCompiledQuery906880034(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.id, d.data from public.mt_doc_user as d where d.data ->> 'FirstName' = ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.FirstName; - } - - } - - // END: NoneUsersByFirstNameWithFieldsCompiledQuery906880034 - - - // START: NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034 - public class NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.NoneUsersByFirstNameWithFieldsCompiledQuery906880034(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: NoneUsersByFirstNameWithFieldsCompiledQuerySource906880034 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyCompiledNestedQueryCompiledQuerySource970855369.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyCompiledNestedQueryCompiledQuerySource970855369.cs deleted file mode 100644 index 721d55e19bc..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyCompiledNestedQueryCompiledQuerySource970855369.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyCompiledNestedQueryCompiledQuery970855369 - public class QueryOnlyCompiledNestedQueryCompiledQuery970855369 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Bugs.CompiledNestedQuery> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Bugs.CompiledNestedQuery _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyCompiledNestedQueryCompiledQuery970855369(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Bugs.CompiledNestedQuery query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.data from public.mt_doc_target as d where CAST(d.data -> 'Inner' ->> 'Number' as integer) = ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[0].Value = _query.Number; - } - - } - - // END: QueryOnlyCompiledNestedQueryCompiledQuery970855369 - - - // START: QueryOnlyCompiledNestedQueryCompiledQuerySource970855369 - public class QueryOnlyCompiledNestedQueryCompiledQuerySource970855369 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Bugs.CompiledNestedQuery> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyCompiledNestedQueryCompiledQuerySource970855369(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Bugs.CompiledNestedQuery query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyCompiledNestedQueryCompiledQuery970855369(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: QueryOnlyCompiledNestedQueryCompiledQuerySource970855369 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126.cs deleted file mode 100644 index b2ba5d3d930..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyFunnyTargetQueryCompiledQuery1643467126 - public class QueryOnlyFunnyTargetQueryCompiledQuery1643467126 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Bugs.Bug_784_Collection_Contains_within_compiled_query.FunnyTargetQuery> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Bugs.Bug_784_Collection_Contains_within_compiled_query.FunnyTargetQuery _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyFunnyTargetQueryCompiledQuery1643467126(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Bugs.Bug_784_Collection_Contains_within_compiled_query.FunnyTargetQuery query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"WITH mt_temp_id_list1CTE as ( - select ctid, unnest(CAST(ARRAY(SELECT jsonb_array_elements_text(CAST(d.data ->> 'NumberArray' as jsonb))) as integer[])) as data from public.mt_doc_target as d WHERE (d.data ->> 'Flag' is not null and CAST(d.data ->> 'Flag' as boolean) = True) - ) - , mt_temp_id_list2CTE as ( - select ctid from mt_temp_id_list1CTE where data = ? - ) - select d.data from public.mt_doc_target as d where ctid in (select ctid from mt_temp_id_list2CTE)"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[0].Value = _query.Number; - } - - } - - // END: QueryOnlyFunnyTargetQueryCompiledQuery1643467126 - - - // START: QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126 - public class QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Bugs.Bug_784_Collection_Contains_within_compiled_query.FunnyTargetQuery> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Bugs.Bug_784_Collection_Contains_within_compiled_query.FunnyTargetQuery query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyFunnyTargetQueryCompiledQuery1643467126(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: QueryOnlyFunnyTargetQueryCompiledQuerySource1643467126 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566.cs deleted file mode 100644 index 9dd18ad5b09..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566.cs +++ /dev/null @@ -1,77 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Includes; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyIssueByTitleWithAssigneeCompiledQuery113072566 - public class QueryOnlyIssueByTitleWithAssigneeCompiledQuery113072566 : Marten.Internal.CompiledQueries.ComplexCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueByTitleWithAssignee _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyIssueByTitleWithAssigneeCompiledQuery113072566(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueByTitleWithAssignee query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"drop table if exists mt_temp_id_list1; - create temp table mt_temp_id_list1 as ( - select id, CAST(d.data ->> 'AssigneeId' as uuid) as id1 from public.mt_doc_issue as d where d.data ->> 'Title' = ? - ); select d.data from public.mt_doc_user as d where id in (select id1 from mt_temp_id_list1); - select d.data from public.mt_doc_issue as d where id in (select id from mt_temp_id_list1)"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.Title; - } - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(Marten.Internal.IMartenSession session) - { - var cloned = _inner.CloneForSession(session, null); - var includeWriters = new Marten.Linq.Includes.IIncludeReader[]{Marten.Linq.Includes.Include.ReaderToList(session, _query.Included)}; - var included = new Marten.Linq.Includes.IncludeQueryHandler((Marten.Linq.QueryHandlers.IQueryHandler)cloned, includeWriters); - return included; - } - - } - - // END: QueryOnlyIssueByTitleWithAssigneeCompiledQuery113072566 - - - // START: QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566 - public class QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueByTitleWithAssignee query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyIssueByTitleWithAssigneeCompiledQuery113072566(_maybeStatefulHandler, query, _hardcoded); - } - - } - - // END: QueryOnlyIssueByTitleWithAssigneeCompiledQuerySource113072566 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947.cs deleted file mode 100644 index 31dae1246cb..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947.cs +++ /dev/null @@ -1,77 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyIssueWithUsersAndParamCompiledQuery813614947 - public class QueryOnlyIssueWithUsersAndParamCompiledQuery813614947 : Marten.Internal.CompiledQueries.ComplexCompiledQuery, DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsersAndParam> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsersAndParam _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyIssueWithUsersAndParamCompiledQuery813614947(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsersAndParam query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"drop table if exists mt_temp_id_list1; - create temp table mt_temp_id_list1 as ( - select id, CAST(d.data ->> 'AssigneeId' as uuid) as id1 from public.mt_doc_issue as d where CAST(d.data ->> 'AssigneeId' as uuid) = ? - ); select d.data from public.mt_doc_user as d where id in (select id1 from mt_temp_id_list1); - select d.data from public.mt_doc_issue as d where id in (select id from mt_temp_id_list1)"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[0].Value = _query.UserId; - } - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(Marten.Internal.IMartenSession session) - { - var cloned = _inner.CloneForSession(session, null); - var includeWriters = new Marten.Linq.Includes.IIncludeReader[]{Marten.Linq.Includes.Include.ReaderToList(session, _query.Users)}; - var included = new Marten.Linq.Includes.IncludeQueryHandler>((Marten.Linq.QueryHandlers.IQueryHandler>)cloned, includeWriters); - return included; - } - - } - - // END: QueryOnlyIssueWithUsersAndParamCompiledQuery813614947 - - - // START: QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947 - public class QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsersAndParam> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsersAndParam query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyIssueWithUsersAndParamCompiledQuery813614947(_maybeStatefulHandler, query, _hardcoded); - } - - } - - // END: QueryOnlyIssueWithUsersAndParamCompiledQuerySource813614947 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956.cs deleted file mode 100644 index bf925fd7fce..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Includes; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyIssueWithUsersByIdCompiledQuery591142956 - public class QueryOnlyIssueWithUsersByIdCompiledQuery591142956 : Marten.Internal.CompiledQueries.ComplexCompiledQuery, DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsersById> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsersById _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyIssueWithUsersByIdCompiledQuery591142956(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsersById query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"drop table if exists mt_temp_id_list1; - create temp table mt_temp_id_list1 as ( - select id, CAST(d.data ->> 'AssigneeId' as uuid) as id1 from public.mt_doc_issue as d - ); select d.data from public.mt_doc_user as d where id in (select id1 from mt_temp_id_list1); - select d.data from public.mt_doc_issue as d where id in (select id from mt_temp_id_list1)"); - } - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(Marten.Internal.IMartenSession session) - { - var cloned = _inner.CloneForSession(session, null); - var includeWriters = new Marten.Linq.Includes.IIncludeReader[]{Marten.Linq.Includes.Include.ReaderToDictionary(session, _query.UsersById)}; - var included = new Marten.Linq.Includes.IncludeQueryHandler>((Marten.Linq.QueryHandlers.IQueryHandler>)cloned, includeWriters); - return included; - } - - } - - // END: QueryOnlyIssueWithUsersByIdCompiledQuery591142956 - - - // START: QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956 - public class QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsersById> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsersById query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyIssueWithUsersByIdCompiledQuery591142956(_maybeStatefulHandler, query, _hardcoded); - } - - } - - // END: QueryOnlyIssueWithUsersByIdCompiledQuerySource591142956 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource2026718760.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource2026718760.cs deleted file mode 100644 index e0bfec02156..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource2026718760.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Includes; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyIssueWithUsersCompiledQuery2026718760 - public class QueryOnlyIssueWithUsersCompiledQuery2026718760 : Marten.Internal.CompiledQueries.ComplexCompiledQuery, DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsers> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsers _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyIssueWithUsersCompiledQuery2026718760(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsers query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"drop table if exists mt_temp_id_list1; - create temp table mt_temp_id_list1 as ( - select id, CAST(d.data ->> 'AssigneeId' as uuid) as id1 from public.mt_doc_issue as d - ); select d.data from public.mt_doc_user as d where id in (select id1 from mt_temp_id_list1); - select d.data from public.mt_doc_issue as d where id in (select id from mt_temp_id_list1)"); - } - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(Marten.Internal.IMartenSession session) - { - var cloned = _inner.CloneForSession(session, null); - var includeWriters = new Marten.Linq.Includes.IIncludeReader[]{Marten.Linq.Includes.Include.ReaderToList(session, _query.Users)}; - var included = new Marten.Linq.Includes.IncludeQueryHandler>((Marten.Linq.QueryHandlers.IQueryHandler>)cloned, includeWriters); - return included; - } - - } - - // END: QueryOnlyIssueWithUsersCompiledQuery2026718760 - - - // START: QueryOnlyIssueWithUsersCompiledQuerySource2026718760 - public class QueryOnlyIssueWithUsersCompiledQuerySource2026718760 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsers> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyIssueWithUsersCompiledQuerySource2026718760(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Includes.end_to_end_query_with_compiled_include_Tests.IssueWithUsers query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyIssueWithUsersCompiledQuery2026718760(_maybeStatefulHandler, query, _hardcoded); - } - - } - - // END: QueryOnlyIssueWithUsersCompiledQuerySource2026718760 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource272805147.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource272805147.cs deleted file mode 100644 index 9a4196c5037..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyIssueWithUsersCompiledQuerySource272805147.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal.CompiledQueries; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyIssueWithUsersCompiledQuery272805147 - public class QueryOnlyIssueWithUsersCompiledQuery272805147 : Marten.Internal.CompiledQueries.ComplexCompiledQuery, DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsers> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsers _query; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyIssueWithUsersCompiledQuery272805147(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsers query, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, hardcoded) - { - _inner = inner; - _query = query; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"drop table if exists mt_temp_id_list1; - create temp table mt_temp_id_list1 as ( - select id, CAST(d.data ->> 'AssigneeId' as uuid) as id1 from public.mt_doc_issue as d - ); select d.data from public.mt_doc_user as d where id in (select id1 from mt_temp_id_list1); - select d.data from public.mt_doc_issue as d where id in (select id from mt_temp_id_list1)"); - } - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(Marten.Internal.IMartenSession session) - { - var cloned = _inner.CloneForSession(session, null); - var includeWriters = new Marten.Linq.Includes.IIncludeReader[]{Marten.Linq.Includes.Include.ReaderToList(session, _query.Users)}; - var included = new Marten.Linq.Includes.IncludeQueryHandler>((Marten.Linq.QueryHandlers.IQueryHandler>)cloned, includeWriters); - return included; - } - - } - - // END: QueryOnlyIssueWithUsersCompiledQuery272805147 - - - // START: QueryOnlyIssueWithUsersCompiledQuerySource272805147 - public class QueryOnlyIssueWithUsersCompiledQuerySource272805147 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsers> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyIssueWithUsersCompiledQuerySource272805147(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Bugs.compiled_query_problem_with_includes_and_ICompiledQuery_reuse.IssueWithUsers query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyIssueWithUsersCompiledQuery272805147(_maybeStatefulHandler, query, _hardcoded); - } - - } - - // END: QueryOnlyIssueWithUsersCompiledQuerySource272805147 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUserByUsernameCompiledQuerySource661477123.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUserByUsernameCompiledQuerySource661477123.cs deleted file mode 100644 index ac100829455..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUserByUsernameCompiledQuerySource661477123.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyUserByUsernameCompiledQuery661477123 - public class QueryOnlyUserByUsernameCompiledQuery661477123 : Marten.Internal.CompiledQueries.ClonedCompiledQuery - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UserByUsername _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyUserByUsernameCompiledQuery661477123(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.data from public.mt_doc_user as d where d.data ->> 'UserName' = ? LIMIT ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.UserName; - _hardcoded.Apply(parameters); - } - - } - - // END: QueryOnlyUserByUsernameCompiledQuery661477123 - - - // START: QueryOnlyUserByUsernameCompiledQuerySource661477123 - public class QueryOnlyUserByUsernameCompiledQuerySource661477123 : Marten.Internal.CompiledQueries.CompiledQuerySource - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyUserByUsernameCompiledQuerySource661477123(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UserByUsername query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyUserByUsernameCompiledQuery661477123(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: QueryOnlyUserByUsernameCompiledQuerySource661477123 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs deleted file mode 100644 index 19ea2d7ef58..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq.Compiled; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyUsersByFirstNameWithFieldsCompiledQuery906880034 - public class QueryOnlyUsersByFirstNameWithFieldsCompiledQuery906880034 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyUsersByFirstNameWithFieldsCompiledQuery906880034(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.data from public.mt_doc_user as d where d.data ->> 'FirstName' = ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = _query.FirstName; - } - - } - - // END: QueryOnlyUsersByFirstNameWithFieldsCompiledQuery906880034 - - - // START: QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034 - public class QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Reading.Linq.Compiled.UsersByFirstNameWithFields query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyUsersByFirstNameWithFieldsCompiledQuery906880034(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: QueryOnlyUsersByFirstNameWithFieldsCompiledQuerySource906880034 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameContainsCompiledQuerySource893470325.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameContainsCompiledQuerySource893470325.cs deleted file mode 100644 index 4bf7b1c3604..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameContainsCompiledQuerySource893470325.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyWhereUsernameContainsCompiledQuery893470325 - public class QueryOnlyWhereUsernameContainsCompiledQuery893470325 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameContains> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameContains _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyWhereUsernameContainsCompiledQuery893470325(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameContains query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.data from public.mt_doc_user as d where d.data ->> 'UserName' LIKE ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = ContainsString(_query.Contains); - } - - } - - // END: QueryOnlyWhereUsernameContainsCompiledQuery893470325 - - - // START: QueryOnlyWhereUsernameContainsCompiledQuerySource893470325 - public class QueryOnlyWhereUsernameContainsCompiledQuerySource893470325 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameContains> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyWhereUsernameContainsCompiledQuerySource893470325(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameContains query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyWhereUsernameContainsCompiledQuery893470325(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: QueryOnlyWhereUsernameContainsCompiledQuerySource893470325 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900.cs deleted file mode 100644 index 7626f0ed43b..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyWhereUsernameEndsWithCompiledQuery628653900 - public class QueryOnlyWhereUsernameEndsWithCompiledQuery628653900 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameEndsWith> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameEndsWith _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyWhereUsernameEndsWithCompiledQuery628653900(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameEndsWith query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.data from public.mt_doc_user as d where d.data ->> 'UserName' LIKE ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = StartsWith(_query.EndsWith); - } - - } - - // END: QueryOnlyWhereUsernameEndsWithCompiledQuery628653900 - - - // START: QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900 - public class QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameEndsWith> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameEndsWith query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyWhereUsernameEndsWithCompiledQuery628653900(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: QueryOnlyWhereUsernameEndsWithCompiledQuerySource628653900 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653.cs b/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653.cs deleted file mode 100644 index a6524311ee8..00000000000 --- a/src/DocumentDbTests/Internal/Generated/CompiledQueries/QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal.CompiledQueries; -using Marten.Linq; -using Marten.Linq.QueryHandlers; -using System; - -namespace Marten.Generated.CompiledQueries -{ - // START: QueryOnlyWhereUsernameStartsWithCompiledQuery2116019653 - public class QueryOnlyWhereUsernameStartsWithCompiledQuery2116019653 : Marten.Internal.CompiledQueries.ClonedCompiledQuery, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameStartsWith> - { - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _inner; - private readonly DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameStartsWith _query; - private readonly Marten.Linq.QueryStatistics _statistics; - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - - public QueryOnlyWhereUsernameStartsWithCompiledQuery2116019653(Marten.Linq.QueryHandlers.IMaybeStatefulHandler inner, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameStartsWith query, Marten.Linq.QueryStatistics statistics, Marten.Internal.CompiledQueries.HardCodedParameters hardcoded) : base(inner, query, statistics, hardcoded) - { - _inner = inner; - _query = query; - _statistics = statistics; - _hardcoded = hardcoded; - } - - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(@"select d.data from public.mt_doc_user as d where d.data ->> 'UserName' LIKE ?"); - - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[0].Value = EndsWith(_query.StartsWith); - } - - } - - // END: QueryOnlyWhereUsernameStartsWithCompiledQuery2116019653 - - - // START: QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653 - public class QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653 : Marten.Internal.CompiledQueries.CompiledQuerySource, DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameStartsWith> - { - private readonly Marten.Internal.CompiledQueries.HardCodedParameters _hardcoded; - private readonly Marten.Linq.QueryHandlers.IMaybeStatefulHandler _maybeStatefulHandler; - - public QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653(Marten.Internal.CompiledQueries.HardCodedParameters hardcoded, Marten.Linq.QueryHandlers.IMaybeStatefulHandler maybeStatefulHandler) - { - _hardcoded = hardcoded; - _maybeStatefulHandler = maybeStatefulHandler; - } - - - - public override Marten.Linq.QueryHandlers.IQueryHandler> BuildHandler(DocumentDbTests.Bugs.Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.WhereUsernameStartsWith query, Marten.Internal.IMartenSession session) - { - return new Marten.Generated.CompiledQueries.QueryOnlyWhereUsernameStartsWithCompiledQuery2116019653(_maybeStatefulHandler, query, null, _hardcoded); - } - - } - - // END: QueryOnlyWhereUsernameStartsWithCompiledQuerySource2116019653 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/AccountProvider793732554.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/AccountProvider793732554.cs deleted file mode 100644 index 272408bbc62..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/AccountProvider793732554.cs +++ /dev/null @@ -1,878 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertAccountOperation793732554 - public class UpsertAccountOperation793732554 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Account _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertAccountOperation793732554(Marten.Testing.Documents.Account document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_account(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertAccountOperation793732554 - - - // START: InsertAccountOperation793732554 - public class InsertAccountOperation793732554 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Account _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertAccountOperation793732554(Marten.Testing.Documents.Account document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_account(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertAccountOperation793732554 - - - // START: UpdateAccountOperation793732554 - public class UpdateAccountOperation793732554 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Account _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateAccountOperation793732554(Marten.Testing.Documents.Account document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_account(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateAccountOperation793732554 - - - // START: QueryOnlyAccountSelector793732554 - public class QueryOnlyAccountSelector793732554 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyAccountSelector793732554(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Account Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.Account document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.Account document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyAccountSelector793732554 - - - // START: LightweightAccountSelector793732554 - public class LightweightAccountSelector793732554 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightAccountSelector793732554(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Account Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.Account document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.Account document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightAccountSelector793732554 - - - // START: IdentityMapAccountSelector793732554 - public class IdentityMapAccountSelector793732554 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapAccountSelector793732554(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Account Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Account document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Account document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapAccountSelector793732554 - - - // START: DirtyTrackingAccountSelector793732554 - public class DirtyTrackingAccountSelector793732554 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingAccountSelector793732554(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Account Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Account document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Account document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingAccountSelector793732554 - - - // START: QueryOnlyAccountDocumentStorage793732554 - public class QueryOnlyAccountDocumentStorage793732554 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyAccountDocumentStorage793732554(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.Account document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.Account document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyAccountSelector793732554(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyAccountDocumentStorage793732554 - - - // START: LightweightAccountDocumentStorage793732554 - public class LightweightAccountDocumentStorage793732554 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightAccountDocumentStorage793732554(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.Account document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.Account document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightAccountSelector793732554(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightAccountDocumentStorage793732554 - - - // START: IdentityMapAccountDocumentStorage793732554 - public class IdentityMapAccountDocumentStorage793732554 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapAccountDocumentStorage793732554(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.Account document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.Account document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapAccountSelector793732554(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapAccountDocumentStorage793732554 - - - // START: DirtyTrackingAccountDocumentStorage793732554 - public class DirtyTrackingAccountDocumentStorage793732554 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingAccountDocumentStorage793732554(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.Account document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertAccountOperation793732554 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Account document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.Account document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingAccountSelector793732554(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingAccountDocumentStorage793732554 - - - // START: AccountBulkLoader793732554 - public class AccountBulkLoader793732554 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public AccountBulkLoader793732554(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_account(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_account_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_account (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_account_temp.\"id\", mt_doc_account_temp.\"data\", mt_doc_account_temp.\"mt_version\", mt_doc_account_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_account_temp left join public.mt_doc_account on mt_doc_account_temp.id = public.mt_doc_account.id where public.mt_doc_account.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_account target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_account_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_account_temp as select * from public.mt_doc_account limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Account document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Text); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Account document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Text, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: AccountBulkLoader793732554 - - - // START: AccountProvider793732554 - public class AccountProvider793732554 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public AccountProvider793732554(Marten.Schema.DocumentMapping mapping) : base(new AccountBulkLoader793732554(new QueryOnlyAccountDocumentStorage793732554(mapping)), new QueryOnlyAccountDocumentStorage793732554(mapping), new LightweightAccountDocumentStorage793732554(mapping), new IdentityMapAccountDocumentStorage793732554(mapping), new DirtyTrackingAccountDocumentStorage793732554(mapping)) - { - _mapping = mapping; - } - - - } - - // END: AccountProvider793732554 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/AttVersionedDocProvider506859367.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/AttVersionedDocProvider506859367.cs deleted file mode 100644 index 2680fec51da..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/AttVersionedDocProvider506859367.cs +++ /dev/null @@ -1,1165 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Metadata; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertAttVersionedDocOperation506859367 - public class UpsertAttVersionedDocOperation506859367 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.AttVersionedDoc _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertAttVersionedDocOperation506859367(DocumentDbTests.Metadata.AttVersionedDoc document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_attversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertAttVersionedDocOperation506859367 - - - // START: InsertAttVersionedDocOperation506859367 - public class InsertAttVersionedDocOperation506859367 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.AttVersionedDoc _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertAttVersionedDocOperation506859367(DocumentDbTests.Metadata.AttVersionedDoc document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_attversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertAttVersionedDocOperation506859367 - - - // START: UpdateAttVersionedDocOperation506859367 - public class UpdateAttVersionedDocOperation506859367 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.AttVersionedDoc _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateAttVersionedDocOperation506859367(DocumentDbTests.Metadata.AttVersionedDoc document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_attversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateAttVersionedDocOperation506859367 - - - // START: QueryOnlyAttVersionedDocSelector506859367 - public class QueryOnlyAttVersionedDocSelector506859367 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyAttVersionedDocSelector506859367(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.AttVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = _serializer.FromJson(reader, 0); - var version = reader.GetFieldValue(1); - document.Version = version; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(1, token); - document.Version = version; - return document; - } - - } - - // END: QueryOnlyAttVersionedDocSelector506859367 - - - // START: LightweightAttVersionedDocSelector506859367 - public class LightweightAttVersionedDocSelector506859367 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightAttVersionedDocSelector506859367(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.AttVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightAttVersionedDocSelector506859367 - - - // START: IdentityMapAttVersionedDocSelector506859367 - public class IdentityMapAttVersionedDocSelector506859367 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapAttVersionedDocSelector506859367(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.AttVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapAttVersionedDocSelector506859367 - - - // START: DirtyTrackingAttVersionedDocSelector506859367 - public class DirtyTrackingAttVersionedDocSelector506859367 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingAttVersionedDocSelector506859367(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.AttVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.AttVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingAttVersionedDocSelector506859367 - - - // START: OverwriteAttVersionedDocOperation506859367 - public class OverwriteAttVersionedDocOperation506859367 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.AttVersionedDoc _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public OverwriteAttVersionedDocOperation506859367(DocumentDbTests.Metadata.AttVersionedDoc document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_overwrite_attversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: OverwriteAttVersionedDocOperation506859367 - - - // START: QueryOnlyAttVersionedDocDocumentStorage506859367 - public class QueryOnlyAttVersionedDocDocumentStorage506859367 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyAttVersionedDocDocumentStorage506859367(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Metadata.AttVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Metadata.AttVersionedDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override int Identity(DocumentDbTests.Metadata.AttVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyAttVersionedDocSelector506859367(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyAttVersionedDocDocumentStorage506859367 - - - // START: LightweightAttVersionedDocDocumentStorage506859367 - public class LightweightAttVersionedDocDocumentStorage506859367 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightAttVersionedDocDocumentStorage506859367(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Metadata.AttVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Metadata.AttVersionedDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override int Identity(DocumentDbTests.Metadata.AttVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightAttVersionedDocSelector506859367(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightAttVersionedDocDocumentStorage506859367 - - - // START: IdentityMapAttVersionedDocDocumentStorage506859367 - public class IdentityMapAttVersionedDocDocumentStorage506859367 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapAttVersionedDocDocumentStorage506859367(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Metadata.AttVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Metadata.AttVersionedDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override int Identity(DocumentDbTests.Metadata.AttVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapAttVersionedDocSelector506859367(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapAttVersionedDocDocumentStorage506859367 - - - // START: DirtyTrackingAttVersionedDocDocumentStorage506859367 - public class DirtyTrackingAttVersionedDocDocumentStorage506859367 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingAttVersionedDocDocumentStorage506859367(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Metadata.AttVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Metadata.AttVersionedDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteAttVersionedDocOperation506859367 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override int Identity(DocumentDbTests.Metadata.AttVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingAttVersionedDocSelector506859367(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingAttVersionedDocDocumentStorage506859367 - - - // START: AttVersionedDocBulkLoader506859367 - public class AttVersionedDocBulkLoader506859367 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public AttVersionedDocBulkLoader506859367(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_attversioneddoc(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_attversioneddoc_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_attversioneddoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_attversioneddoc_temp.\"id\", mt_doc_attversioneddoc_temp.\"data\", mt_doc_attversioneddoc_temp.\"mt_version\", mt_doc_attversioneddoc_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_attversioneddoc_temp left join public.mt_doc_attversioneddoc on mt_doc_attversioneddoc_temp.id = public.mt_doc_attversioneddoc.id where public.mt_doc_attversioneddoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_attversioneddoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_attversioneddoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_attversioneddoc_temp as select * from public.mt_doc_attversioneddoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Integer); - - var version = Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(); - writer.Write(version, NpgsqlTypes.NpgsqlDbType.Uuid); - document.Version = version; - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Metadata.AttVersionedDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Integer, cancellation); - - var version = Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(); - writer.Write(version, NpgsqlTypes.NpgsqlDbType.Uuid); - document.Version = version; - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: AttVersionedDocBulkLoader506859367 - - - // START: AttVersionedDocProvider506859367 - public class AttVersionedDocProvider506859367 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public AttVersionedDocProvider506859367(Marten.Schema.DocumentMapping mapping) : base(new AttVersionedDocBulkLoader506859367(new QueryOnlyAttVersionedDocDocumentStorage506859367(mapping)), new QueryOnlyAttVersionedDocDocumentStorage506859367(mapping), new LightweightAttVersionedDocDocumentStorage506859367(mapping), new IdentityMapAttVersionedDocDocumentStorage506859367(mapping), new DirtyTrackingAttVersionedDocDocumentStorage506859367(mapping)) - { - _mapping = mapping; - } - - - } - - // END: AttVersionedDocProvider506859367 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/BugProvider65166103.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/BugProvider65166103.cs deleted file mode 100644 index 1fae36d2392..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/BugProvider65166103.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertBugOperation65166103 - public class UpsertBugOperation65166103 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Bug _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertBugOperation65166103(Marten.Testing.Documents.Bug document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_bug(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertBugOperation65166103 - - - // START: InsertBugOperation65166103 - public class InsertBugOperation65166103 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Bug _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertBugOperation65166103(Marten.Testing.Documents.Bug document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_bug(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertBugOperation65166103 - - - // START: UpdateBugOperation65166103 - public class UpdateBugOperation65166103 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Bug _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateBugOperation65166103(Marten.Testing.Documents.Bug document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_bug(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateBugOperation65166103 - - - // START: QueryOnlyBugSelector65166103 - public class QueryOnlyBugSelector65166103 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyBugSelector65166103(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Bug Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.Bug document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.Bug document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyBugSelector65166103 - - - // START: LightweightBugSelector65166103 - public class LightweightBugSelector65166103 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightBugSelector65166103(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Bug Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.Bug document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.Bug document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightBugSelector65166103 - - - // START: IdentityMapBugSelector65166103 - public class IdentityMapBugSelector65166103 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapBugSelector65166103(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Bug Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Bug document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Bug document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapBugSelector65166103 - - - // START: DirtyTrackingBugSelector65166103 - public class DirtyTrackingBugSelector65166103 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingBugSelector65166103(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Bug Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Bug document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Bug document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingBugSelector65166103 - - - // START: QueryOnlyBugDocumentStorage65166103 - public class QueryOnlyBugDocumentStorage65166103 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyBugDocumentStorage65166103(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Bug document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Bug document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyBugSelector65166103(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyBugDocumentStorage65166103 - - - // START: LightweightBugDocumentStorage65166103 - public class LightweightBugDocumentStorage65166103 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightBugDocumentStorage65166103(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Bug document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Bug document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightBugSelector65166103(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightBugDocumentStorage65166103 - - - // START: IdentityMapBugDocumentStorage65166103 - public class IdentityMapBugDocumentStorage65166103 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapBugDocumentStorage65166103(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Bug document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Bug document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapBugSelector65166103(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapBugDocumentStorage65166103 - - - // START: DirtyTrackingBugDocumentStorage65166103 - public class DirtyTrackingBugDocumentStorage65166103 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingBugDocumentStorage65166103(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Bug document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertBugOperation65166103 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Bug document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Bug document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingBugSelector65166103(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingBugDocumentStorage65166103 - - - // START: BugBulkLoader65166103 - public class BugBulkLoader65166103 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public BugBulkLoader65166103(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_bug(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_bug_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_bug (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_bug_temp.\"id\", mt_doc_bug_temp.\"data\", mt_doc_bug_temp.\"mt_version\", mt_doc_bug_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_bug_temp left join public.mt_doc_bug on mt_doc_bug_temp.id = public.mt_doc_bug.id where public.mt_doc_bug.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_bug target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_bug_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_bug_temp as select * from public.mt_doc_bug limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Bug document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Bug document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: BugBulkLoader65166103 - - - // START: BugProvider65166103 - public class BugProvider65166103 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public BugProvider65166103(Marten.Schema.DocumentMapping mapping) : base(new BugBulkLoader65166103(new QueryOnlyBugDocumentStorage65166103(mapping)), new QueryOnlyBugDocumentStorage65166103(mapping), new LightweightBugDocumentStorage65166103(mapping), new IdentityMapBugDocumentStorage65166103(mapping), new DirtyTrackingBugDocumentStorage65166103(mapping)) - { - _mapping = mapping; - } - - - } - - // END: BugProvider65166103 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CarProvider343829114.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/CarProvider343829114.cs deleted file mode 100644 index 9bf89138d3b..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CarProvider343829114.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertCarOperation343829114 - public class UpsertCarOperation343829114 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertCarOperation343829114(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_bug_1219_ordering_by_attributes_car(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertCarOperation343829114 - - - // START: InsertCarOperation343829114 - public class InsertCarOperation343829114 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertCarOperation343829114(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_bug_1219_ordering_by_attributes_car(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertCarOperation343829114 - - - // START: UpdateCarOperation343829114 - public class UpdateCarOperation343829114 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateCarOperation343829114(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_bug_1219_ordering_by_attributes_car(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateCarOperation343829114 - - - // START: QueryOnlyCarSelector343829114 - public class QueryOnlyCarSelector343829114 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyCarSelector343829114(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyCarSelector343829114 - - - // START: LightweightCarSelector343829114 - public class LightweightCarSelector343829114 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightCarSelector343829114(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightCarSelector343829114 - - - // START: IdentityMapCarSelector343829114 - public class IdentityMapCarSelector343829114 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapCarSelector343829114(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapCarSelector343829114 - - - // START: DirtyTrackingCarSelector343829114 - public class DirtyTrackingCarSelector343829114 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingCarSelector343829114(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingCarSelector343829114 - - - // START: QueryOnlyCarDocumentStorage343829114 - public class QueryOnlyCarDocumentStorage343829114 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyCarDocumentStorage343829114(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyCarSelector343829114(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyCarDocumentStorage343829114 - - - // START: LightweightCarDocumentStorage343829114 - public class LightweightCarDocumentStorage343829114 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightCarDocumentStorage343829114(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightCarSelector343829114(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightCarDocumentStorage343829114 - - - // START: IdentityMapCarDocumentStorage343829114 - public class IdentityMapCarDocumentStorage343829114 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapCarDocumentStorage343829114(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapCarSelector343829114(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapCarDocumentStorage343829114 - - - // START: DirtyTrackingCarDocumentStorage343829114 - public class DirtyTrackingCarDocumentStorage343829114 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingCarDocumentStorage343829114(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCarOperation343829114 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingCarSelector343829114(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingCarDocumentStorage343829114 - - - // START: CarBulkLoader343829114 - public class CarBulkLoader343829114 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public CarBulkLoader343829114(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_bug_1219_ordering_by_attributes_car(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_bug_1219_ordering_by_attributes_car_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_bug_1219_ordering_by_attributes_car (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_bug_1219_ordering_by_attributes_car_temp.\"id\", mt_doc_bug_1219_ordering_by_attributes_car_temp.\"data\", mt_doc_bug_1219_ordering_by_attributes_car_temp.\"mt_version\", mt_doc_bug_1219_ordering_by_attributes_car_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_bug_1219_ordering_by_attributes_car_temp left join public.mt_doc_bug_1219_ordering_by_attributes_car on mt_doc_bug_1219_ordering_by_attributes_car_temp.id = public.mt_doc_bug_1219_ordering_by_attributes_car.id where public.mt_doc_bug_1219_ordering_by_attributes_car.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_bug_1219_ordering_by_attributes_car target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_bug_1219_ordering_by_attributes_car_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_bug_1219_ordering_by_attributes_car_temp as select * from public.mt_doc_bug_1219_ordering_by_attributes_car limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_1219_ordering_by_attributes.Car document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: CarBulkLoader343829114 - - - // START: CarProvider343829114 - public class CarProvider343829114 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public CarProvider343829114(Marten.Schema.DocumentMapping mapping) : base(new CarBulkLoader343829114(new QueryOnlyCarDocumentStorage343829114(mapping)), new QueryOnlyCarDocumentStorage343829114(mapping), new LightweightCarDocumentStorage343829114(mapping), new IdentityMapCarDocumentStorage343829114(mapping), new DirtyTrackingCarDocumentStorage343829114(mapping)) - { - _mapping = mapping; - } - - - } - - // END: CarProvider343829114 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopEmployeeProvider920305685.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopEmployeeProvider920305685.cs deleted file mode 100644 index 911520b5953..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopEmployeeProvider920305685.cs +++ /dev/null @@ -1,1137 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Concurrency; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertCoffeeShopEmployeeOperation920305685 - public class UpsertCoffeeShopEmployeeOperation920305685 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShopEmployee _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertCoffeeShopEmployeeOperation920305685(DocumentDbTests.Concurrency.CoffeeShopEmployee document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_coffeeshopemployee(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertCoffeeShopEmployeeOperation920305685 - - - // START: InsertCoffeeShopEmployeeOperation920305685 - public class InsertCoffeeShopEmployeeOperation920305685 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShopEmployee _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertCoffeeShopEmployeeOperation920305685(DocumentDbTests.Concurrency.CoffeeShopEmployee document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_coffeeshopemployee(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertCoffeeShopEmployeeOperation920305685 - - - // START: UpdateCoffeeShopEmployeeOperation920305685 - public class UpdateCoffeeShopEmployeeOperation920305685 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShopEmployee _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateCoffeeShopEmployeeOperation920305685(DocumentDbTests.Concurrency.CoffeeShopEmployee document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_coffeeshopemployee(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateCoffeeShopEmployeeOperation920305685 - - - // START: QueryOnlyCoffeeShopEmployeeSelector920305685 - public class QueryOnlyCoffeeShopEmployeeSelector920305685 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyCoffeeShopEmployeeSelector920305685(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShopEmployee Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyCoffeeShopEmployeeSelector920305685 - - - // START: LightweightCoffeeShopEmployeeSelector920305685 - public class LightweightCoffeeShopEmployeeSelector920305685 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightCoffeeShopEmployeeSelector920305685(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShopEmployee Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightCoffeeShopEmployeeSelector920305685 - - - // START: IdentityMapCoffeeShopEmployeeSelector920305685 - public class IdentityMapCoffeeShopEmployeeSelector920305685 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapCoffeeShopEmployeeSelector920305685(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShopEmployee Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapCoffeeShopEmployeeSelector920305685 - - - // START: DirtyTrackingCoffeeShopEmployeeSelector920305685 - public class DirtyTrackingCoffeeShopEmployeeSelector920305685 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingCoffeeShopEmployeeSelector920305685(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShopEmployee Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShopEmployee document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingCoffeeShopEmployeeSelector920305685 - - - // START: OverwriteCoffeeShopEmployeeOperation920305685 - public class OverwriteCoffeeShopEmployeeOperation920305685 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShopEmployee _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public OverwriteCoffeeShopEmployeeOperation920305685(DocumentDbTests.Concurrency.CoffeeShopEmployee document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_overwrite_coffeeshopemployee(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: OverwriteCoffeeShopEmployeeOperation920305685 - - - // START: QueryOnlyCoffeeShopEmployeeDocumentStorage920305685 - public class QueryOnlyCoffeeShopEmployeeDocumentStorage920305685 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyCoffeeShopEmployeeDocumentStorage920305685(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShopEmployee document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShopEmployee document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyCoffeeShopEmployeeSelector920305685(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyCoffeeShopEmployeeDocumentStorage920305685 - - - // START: LightweightCoffeeShopEmployeeDocumentStorage920305685 - public class LightweightCoffeeShopEmployeeDocumentStorage920305685 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightCoffeeShopEmployeeDocumentStorage920305685(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShopEmployee document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShopEmployee document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightCoffeeShopEmployeeSelector920305685(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightCoffeeShopEmployeeDocumentStorage920305685 - - - // START: IdentityMapCoffeeShopEmployeeDocumentStorage920305685 - public class IdentityMapCoffeeShopEmployeeDocumentStorage920305685 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapCoffeeShopEmployeeDocumentStorage920305685(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShopEmployee document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShopEmployee document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapCoffeeShopEmployeeSelector920305685(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapCoffeeShopEmployeeDocumentStorage920305685 - - - // START: DirtyTrackingCoffeeShopEmployeeDocumentStorage920305685 - public class DirtyTrackingCoffeeShopEmployeeDocumentStorage920305685 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingCoffeeShopEmployeeDocumentStorage920305685(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShopEmployee document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopEmployeeOperation920305685 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShopEmployee document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingCoffeeShopEmployeeSelector920305685(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingCoffeeShopEmployeeDocumentStorage920305685 - - - // START: CoffeeShopEmployeeBulkLoader920305685 - public class CoffeeShopEmployeeBulkLoader920305685 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public CoffeeShopEmployeeBulkLoader920305685(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_coffeeshopemployee(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_coffeeshopemployee_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_coffeeshopemployee (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", \"mt_deleted\", \"mt_deleted_at\", mt_last_modified) (select mt_doc_coffeeshopemployee_temp.\"id\", mt_doc_coffeeshopemployee_temp.\"data\", mt_doc_coffeeshopemployee_temp.\"mt_version\", mt_doc_coffeeshopemployee_temp.\"mt_dotnet_type\", mt_doc_coffeeshopemployee_temp.\"mt_deleted\", mt_doc_coffeeshopemployee_temp.\"mt_deleted_at\", transaction_timestamp() from mt_doc_coffeeshopemployee_temp left join public.mt_doc_coffeeshopemployee on mt_doc_coffeeshopemployee_temp.id = public.mt_doc_coffeeshopemployee.id where public.mt_doc_coffeeshopemployee.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_coffeeshopemployee target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_deleted = source.mt_deleted, mt_deleted_at = source.mt_deleted_at, mt_last_modified = transaction_timestamp() FROM mt_doc_coffeeshopemployee_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_coffeeshopemployee_temp as select * from public.mt_doc_coffeeshopemployee limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Concurrency.CoffeeShopEmployee document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: CoffeeShopEmployeeBulkLoader920305685 - - - // START: CoffeeShopEmployeeProvider920305685 - public class CoffeeShopEmployeeProvider920305685 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public CoffeeShopEmployeeProvider920305685(Marten.Schema.DocumentMapping mapping) : base(new CoffeeShopEmployeeBulkLoader920305685(new QueryOnlyCoffeeShopEmployeeDocumentStorage920305685(mapping)), new QueryOnlyCoffeeShopEmployeeDocumentStorage920305685(mapping), new LightweightCoffeeShopEmployeeDocumentStorage920305685(mapping), new IdentityMapCoffeeShopEmployeeDocumentStorage920305685(mapping), new DirtyTrackingCoffeeShopEmployeeDocumentStorage920305685(mapping)) - { - _mapping = mapping; - } - - - } - - // END: CoffeeShopEmployeeProvider920305685 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopProvider2130089093.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopProvider2130089093.cs deleted file mode 100644 index 4fa85b28fcf..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CoffeeShopProvider2130089093.cs +++ /dev/null @@ -1,1137 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Concurrency; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertCoffeeShopOperation2130089093 - public class UpsertCoffeeShopOperation2130089093 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShop _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertCoffeeShopOperation2130089093(DocumentDbTests.Concurrency.CoffeeShop document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_coffeeshop(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertCoffeeShopOperation2130089093 - - - // START: InsertCoffeeShopOperation2130089093 - public class InsertCoffeeShopOperation2130089093 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShop _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertCoffeeShopOperation2130089093(DocumentDbTests.Concurrency.CoffeeShop document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_coffeeshop(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertCoffeeShopOperation2130089093 - - - // START: UpdateCoffeeShopOperation2130089093 - public class UpdateCoffeeShopOperation2130089093 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShop _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateCoffeeShopOperation2130089093(DocumentDbTests.Concurrency.CoffeeShop document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_coffeeshop(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateCoffeeShopOperation2130089093 - - - // START: QueryOnlyCoffeeShopSelector2130089093 - public class QueryOnlyCoffeeShopSelector2130089093 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyCoffeeShopSelector2130089093(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShop Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Concurrency.CoffeeShop document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Concurrency.CoffeeShop document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyCoffeeShopSelector2130089093 - - - // START: LightweightCoffeeShopSelector2130089093 - public class LightweightCoffeeShopSelector2130089093 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightCoffeeShopSelector2130089093(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShop Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Concurrency.CoffeeShop document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Concurrency.CoffeeShop document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightCoffeeShopSelector2130089093 - - - // START: IdentityMapCoffeeShopSelector2130089093 - public class IdentityMapCoffeeShopSelector2130089093 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapCoffeeShopSelector2130089093(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShop Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShop document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShop document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapCoffeeShopSelector2130089093 - - - // START: DirtyTrackingCoffeeShopSelector2130089093 - public class DirtyTrackingCoffeeShopSelector2130089093 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingCoffeeShopSelector2130089093(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Concurrency.CoffeeShop Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShop document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Concurrency.CoffeeShop document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingCoffeeShopSelector2130089093 - - - // START: OverwriteCoffeeShopOperation2130089093 - public class OverwriteCoffeeShopOperation2130089093 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Concurrency.CoffeeShop _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public OverwriteCoffeeShopOperation2130089093(DocumentDbTests.Concurrency.CoffeeShop document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_overwrite_coffeeshop(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session) - { - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: OverwriteCoffeeShopOperation2130089093 - - - // START: QueryOnlyCoffeeShopDocumentStorage2130089093 - public class QueryOnlyCoffeeShopDocumentStorage2130089093 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyCoffeeShopDocumentStorage2130089093(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShop document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShop document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyCoffeeShopSelector2130089093(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyCoffeeShopDocumentStorage2130089093 - - - // START: LightweightCoffeeShopDocumentStorage2130089093 - public class LightweightCoffeeShopDocumentStorage2130089093 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightCoffeeShopDocumentStorage2130089093(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShop document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShop document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightCoffeeShopSelector2130089093(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightCoffeeShopDocumentStorage2130089093 - - - // START: IdentityMapCoffeeShopDocumentStorage2130089093 - public class IdentityMapCoffeeShopDocumentStorage2130089093 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapCoffeeShopDocumentStorage2130089093(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShop document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShop document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapCoffeeShopSelector2130089093(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapCoffeeShopDocumentStorage2130089093 - - - // START: DirtyTrackingCoffeeShopDocumentStorage2130089093 - public class DirtyTrackingCoffeeShopDocumentStorage2130089093 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingCoffeeShopDocumentStorage2130089093(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Concurrency.CoffeeShop document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Concurrency.CoffeeShop document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteCoffeeShopOperation2130089093 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Concurrency.CoffeeShop document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingCoffeeShopSelector2130089093(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingCoffeeShopDocumentStorage2130089093 - - - // START: CoffeeShopBulkLoader2130089093 - public class CoffeeShopBulkLoader2130089093 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public CoffeeShopBulkLoader2130089093(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_coffeeshop(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_coffeeshop_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_coffeeshop (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_coffeeshop_temp.\"id\", mt_doc_coffeeshop_temp.\"data\", mt_doc_coffeeshop_temp.\"mt_version\", mt_doc_coffeeshop_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_coffeeshop_temp left join public.mt_doc_coffeeshop on mt_doc_coffeeshop_temp.id = public.mt_doc_coffeeshop.id where public.mt_doc_coffeeshop.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_coffeeshop target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_coffeeshop_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_coffeeshop_temp as select * from public.mt_doc_coffeeshop limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Concurrency.CoffeeShop document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Concurrency.CoffeeShop document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: CoffeeShopBulkLoader2130089093 - - - // START: CoffeeShopProvider2130089093 - public class CoffeeShopProvider2130089093 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public CoffeeShopProvider2130089093(Marten.Schema.DocumentMapping mapping) : base(new CoffeeShopBulkLoader2130089093(new QueryOnlyCoffeeShopDocumentStorage2130089093(mapping)), new QueryOnlyCoffeeShopDocumentStorage2130089093(mapping), new LightweightCoffeeShopDocumentStorage2130089093(mapping), new IdentityMapCoffeeShopDocumentStorage2130089093(mapping), new DirtyTrackingCoffeeShopDocumentStorage2130089093(mapping)) - { - _mapping = mapping; - } - - - } - - // END: CoffeeShopProvider2130089093 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CompanyProvider297217634.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/CompanyProvider297217634.cs deleted file mode 100644 index 9bd996ad860..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CompanyProvider297217634.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertCompanyOperation297217634 - public class UpsertCompanyOperation297217634 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Company _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertCompanyOperation297217634(Marten.Testing.Documents.Company document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_company(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertCompanyOperation297217634 - - - // START: InsertCompanyOperation297217634 - public class InsertCompanyOperation297217634 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Company _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertCompanyOperation297217634(Marten.Testing.Documents.Company document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_company(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertCompanyOperation297217634 - - - // START: UpdateCompanyOperation297217634 - public class UpdateCompanyOperation297217634 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Company _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateCompanyOperation297217634(Marten.Testing.Documents.Company document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_company(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateCompanyOperation297217634 - - - // START: QueryOnlyCompanySelector297217634 - public class QueryOnlyCompanySelector297217634 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyCompanySelector297217634(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Company Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.Company document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.Company document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyCompanySelector297217634 - - - // START: LightweightCompanySelector297217634 - public class LightweightCompanySelector297217634 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightCompanySelector297217634(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Company Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.Company document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.Company document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightCompanySelector297217634 - - - // START: IdentityMapCompanySelector297217634 - public class IdentityMapCompanySelector297217634 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapCompanySelector297217634(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Company Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Company document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Company document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapCompanySelector297217634 - - - // START: DirtyTrackingCompanySelector297217634 - public class DirtyTrackingCompanySelector297217634 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingCompanySelector297217634(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Company Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Company document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Company document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingCompanySelector297217634 - - - // START: QueryOnlyCompanyDocumentStorage297217634 - public class QueryOnlyCompanyDocumentStorage297217634 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyCompanyDocumentStorage297217634(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Company document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Company document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyCompanySelector297217634(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyCompanyDocumentStorage297217634 - - - // START: LightweightCompanyDocumentStorage297217634 - public class LightweightCompanyDocumentStorage297217634 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightCompanyDocumentStorage297217634(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Company document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Company document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightCompanySelector297217634(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightCompanyDocumentStorage297217634 - - - // START: IdentityMapCompanyDocumentStorage297217634 - public class IdentityMapCompanyDocumentStorage297217634 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapCompanyDocumentStorage297217634(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Company document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Company document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapCompanySelector297217634(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapCompanyDocumentStorage297217634 - - - // START: DirtyTrackingCompanyDocumentStorage297217634 - public class DirtyTrackingCompanyDocumentStorage297217634 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingCompanyDocumentStorage297217634(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Company document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCompanyOperation297217634 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Company document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Company document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingCompanySelector297217634(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingCompanyDocumentStorage297217634 - - - // START: CompanyBulkLoader297217634 - public class CompanyBulkLoader297217634 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public CompanyBulkLoader297217634(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_company(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_company_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_company (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_company_temp.\"id\", mt_doc_company_temp.\"data\", mt_doc_company_temp.\"mt_version\", mt_doc_company_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_company_temp left join public.mt_doc_company on mt_doc_company_temp.id = public.mt_doc_company.id where public.mt_doc_company.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_company target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_company_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_company_temp as select * from public.mt_doc_company limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Company document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Company document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: CompanyBulkLoader297217634 - - - // START: CompanyProvider297217634 - public class CompanyProvider297217634 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public CompanyProvider297217634(Marten.Schema.DocumentMapping mapping) : base(new CompanyBulkLoader297217634(new QueryOnlyCompanyDocumentStorage297217634(mapping)), new QueryOnlyCompanyDocumentStorage297217634(mapping), new LightweightCompanyDocumentStorage297217634(mapping), new IdentityMapCompanyDocumentStorage297217634(mapping), new DirtyTrackingCompanyDocumentStorage297217634(mapping)) - { - _mapping = mapping; - } - - - } - - // END: CompanyProvider297217634 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ContactProvider677813566.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/ContactProvider677813566.cs deleted file mode 100644 index 656cb69429c..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ContactProvider677813566.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertContactOperation677813566 - public class UpsertContactOperation677813566 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertContactOperation677813566(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_bug_834_querying_inside_of_child_collections_contact(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertContactOperation677813566 - - - // START: InsertContactOperation677813566 - public class InsertContactOperation677813566 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertContactOperation677813566(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_bug_834_querying_inside_of_child_collections_contact(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertContactOperation677813566 - - - // START: UpdateContactOperation677813566 - public class UpdateContactOperation677813566 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateContactOperation677813566(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_bug_834_querying_inside_of_child_collections_contact(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateContactOperation677813566 - - - // START: QueryOnlyContactSelector677813566 - public class QueryOnlyContactSelector677813566 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyContactSelector677813566(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyContactSelector677813566 - - - // START: LightweightContactSelector677813566 - public class LightweightContactSelector677813566 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightContactSelector677813566(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightContactSelector677813566 - - - // START: IdentityMapContactSelector677813566 - public class IdentityMapContactSelector677813566 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapContactSelector677813566(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapContactSelector677813566 - - - // START: DirtyTrackingContactSelector677813566 - public class DirtyTrackingContactSelector677813566 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingContactSelector677813566(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingContactSelector677813566 - - - // START: QueryOnlyContactDocumentStorage677813566 - public class QueryOnlyContactDocumentStorage677813566 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyContactDocumentStorage677813566(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyContactSelector677813566(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyContactDocumentStorage677813566 - - - // START: LightweightContactDocumentStorage677813566 - public class LightweightContactDocumentStorage677813566 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightContactDocumentStorage677813566(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightContactSelector677813566(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightContactDocumentStorage677813566 - - - // START: IdentityMapContactDocumentStorage677813566 - public class IdentityMapContactDocumentStorage677813566 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapContactDocumentStorage677813566(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapContactSelector677813566(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapContactDocumentStorage677813566 - - - // START: DirtyTrackingContactDocumentStorage677813566 - public class DirtyTrackingContactDocumentStorage677813566 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingContactDocumentStorage677813566(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertContactOperation677813566 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingContactSelector677813566(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingContactDocumentStorage677813566 - - - // START: ContactBulkLoader677813566 - public class ContactBulkLoader677813566 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public ContactBulkLoader677813566(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_bug_834_querying_inside_of_child_collections_contact(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_bug_834_querying_inside_of_child_collections_contact_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_bug_834_querying_inside_of_child_collections_contact (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_bug_834_querying_inside_of_child_collections_contact_temp.\"id\", mt_doc_bug_834_querying_inside_of_child_collections_contact_temp.\"data\", mt_doc_bug_834_querying_inside_of_child_collections_contact_temp.\"mt_version\", mt_doc_bug_834_querying_inside_of_child_collections_contact_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_bug_834_querying_inside_of_child_collections_contact_temp left join public.mt_doc_bug_834_querying_inside_of_child_collections_contact on mt_doc_bug_834_querying_inside_of_child_collections_contact_temp.id = public.mt_doc_bug_834_querying_inside_of_child_collections_contact.id where public.mt_doc_bug_834_querying_inside_of_child_collections_contact.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_bug_834_querying_inside_of_child_collections_contact target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_bug_834_querying_inside_of_child_collections_contact_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_bug_834_querying_inside_of_child_collections_contact_temp as select * from public.mt_doc_bug_834_querying_inside_of_child_collections_contact limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_834_querying_inside_of_child_collections.Contact document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: ContactBulkLoader677813566 - - - // START: ContactProvider677813566 - public class ContactProvider677813566 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public ContactProvider677813566(Marten.Schema.DocumentMapping mapping) : base(new ContactBulkLoader677813566(new QueryOnlyContactDocumentStorage677813566(mapping)), new QueryOnlyContactDocumentStorage677813566(mapping), new LightweightContactDocumentStorage677813566(mapping), new IdentityMapContactDocumentStorage677813566(mapping), new DirtyTrackingContactDocumentStorage677813566(mapping)) - { - _mapping = mapping; - } - - - } - - // END: ContactProvider677813566 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CustomerProvider728829122.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/CustomerProvider728829122.cs deleted file mode 100644 index 11d5de1085d..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/CustomerProvider728829122.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Json; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertCustomerOperation728829122 - public class UpsertCustomerOperation728829122 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Json.streaming_json_results.Customer _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertCustomerOperation728829122(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_streaming_json_results_customer(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertCustomerOperation728829122 - - - // START: InsertCustomerOperation728829122 - public class InsertCustomerOperation728829122 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Json.streaming_json_results.Customer _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertCustomerOperation728829122(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_streaming_json_results_customer(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertCustomerOperation728829122 - - - // START: UpdateCustomerOperation728829122 - public class UpdateCustomerOperation728829122 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Json.streaming_json_results.Customer _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateCustomerOperation728829122(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_streaming_json_results_customer(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateCustomerOperation728829122 - - - // START: QueryOnlyCustomerSelector728829122 - public class QueryOnlyCustomerSelector728829122 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyCustomerSelector728829122(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Json.streaming_json_results.Customer Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyCustomerSelector728829122 - - - // START: LightweightCustomerSelector728829122 - public class LightweightCustomerSelector728829122 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightCustomerSelector728829122(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Json.streaming_json_results.Customer Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightCustomerSelector728829122 - - - // START: IdentityMapCustomerSelector728829122 - public class IdentityMapCustomerSelector728829122 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapCustomerSelector728829122(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Json.streaming_json_results.Customer Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapCustomerSelector728829122 - - - // START: DirtyTrackingCustomerSelector728829122 - public class DirtyTrackingCustomerSelector728829122 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingCustomerSelector728829122(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Json.streaming_json_results.Customer Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Json.streaming_json_results.Customer document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingCustomerSelector728829122 - - - // START: QueryOnlyCustomerDocumentStorage728829122 - public class QueryOnlyCustomerDocumentStorage728829122 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyCustomerDocumentStorage728829122(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyCustomerSelector728829122(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyCustomerDocumentStorage728829122 - - - // START: LightweightCustomerDocumentStorage728829122 - public class LightweightCustomerDocumentStorage728829122 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightCustomerDocumentStorage728829122(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightCustomerSelector728829122(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightCustomerDocumentStorage728829122 - - - // START: IdentityMapCustomerDocumentStorage728829122 - public class IdentityMapCustomerDocumentStorage728829122 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapCustomerDocumentStorage728829122(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapCustomerSelector728829122(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapCustomerDocumentStorage728829122 - - - // START: DirtyTrackingCustomerDocumentStorage728829122 - public class DirtyTrackingCustomerDocumentStorage728829122 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingCustomerDocumentStorage728829122(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertCustomerOperation728829122 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Json.streaming_json_results.Customer document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingCustomerSelector728829122(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingCustomerDocumentStorage728829122 - - - // START: CustomerBulkLoader728829122 - public class CustomerBulkLoader728829122 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public CustomerBulkLoader728829122(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_streaming_json_results_customer(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_streaming_json_results_customer_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_streaming_json_results_customer (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_streaming_json_results_customer_temp.\"id\", mt_doc_streaming_json_results_customer_temp.\"data\", mt_doc_streaming_json_results_customer_temp.\"mt_version\", mt_doc_streaming_json_results_customer_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_streaming_json_results_customer_temp left join public.mt_doc_streaming_json_results_customer on mt_doc_streaming_json_results_customer_temp.id = public.mt_doc_streaming_json_results_customer.id where public.mt_doc_streaming_json_results_customer.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_streaming_json_results_customer target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_streaming_json_results_customer_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_streaming_json_results_customer_temp as select * from public.mt_doc_streaming_json_results_customer limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Json.streaming_json_results.Customer document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: CustomerBulkLoader728829122 - - - // START: CustomerProvider728829122 - public class CustomerProvider728829122 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public CustomerProvider728829122(Marten.Schema.DocumentMapping mapping) : base(new CustomerBulkLoader728829122(new QueryOnlyCustomerDocumentStorage728829122(mapping)), new QueryOnlyCustomerDocumentStorage728829122(mapping), new LightweightCustomerDocumentStorage728829122(mapping), new IdentityMapCustomerDocumentStorage728829122(mapping), new DirtyTrackingCustomerDocumentStorage728829122(mapping)) - { - _mapping = mapping; - } - - - } - - // END: CustomerProvider728829122 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocHolderProvider1892370027.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocHolderProvider1892370027.cs deleted file mode 100644 index ef99e57fbd3..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocHolderProvider1892370027.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertDocHolderOperation1892370027 - public class UpsertDocHolderOperation1892370027 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.DocHolder _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertDocHolderOperation1892370027(DocumentDbTests.Bugs.DocHolder document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_docholder(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertDocHolderOperation1892370027 - - - // START: InsertDocHolderOperation1892370027 - public class InsertDocHolderOperation1892370027 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.DocHolder _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertDocHolderOperation1892370027(DocumentDbTests.Bugs.DocHolder document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_docholder(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertDocHolderOperation1892370027 - - - // START: UpdateDocHolderOperation1892370027 - public class UpdateDocHolderOperation1892370027 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.DocHolder _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateDocHolderOperation1892370027(DocumentDbTests.Bugs.DocHolder document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_docholder(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateDocHolderOperation1892370027 - - - // START: QueryOnlyDocHolderSelector1892370027 - public class QueryOnlyDocHolderSelector1892370027 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyDocHolderSelector1892370027(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocHolder Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.DocHolder document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.DocHolder document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyDocHolderSelector1892370027 - - - // START: LightweightDocHolderSelector1892370027 - public class LightweightDocHolderSelector1892370027 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightDocHolderSelector1892370027(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocHolder Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.DocHolder document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.DocHolder document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightDocHolderSelector1892370027 - - - // START: IdentityMapDocHolderSelector1892370027 - public class IdentityMapDocHolderSelector1892370027 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapDocHolderSelector1892370027(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocHolder Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocHolder document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocHolder document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapDocHolderSelector1892370027 - - - // START: DirtyTrackingDocHolderSelector1892370027 - public class DirtyTrackingDocHolderSelector1892370027 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingDocHolderSelector1892370027(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocHolder Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocHolder document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocHolder document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingDocHolderSelector1892370027 - - - // START: QueryOnlyDocHolderDocumentStorage1892370027 - public class QueryOnlyDocHolderDocumentStorage1892370027 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyDocHolderDocumentStorage1892370027(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocHolder document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocHolder document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyDocHolderSelector1892370027(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyDocHolderDocumentStorage1892370027 - - - // START: LightweightDocHolderDocumentStorage1892370027 - public class LightweightDocHolderDocumentStorage1892370027 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightDocHolderDocumentStorage1892370027(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocHolder document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocHolder document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightDocHolderSelector1892370027(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightDocHolderDocumentStorage1892370027 - - - // START: IdentityMapDocHolderDocumentStorage1892370027 - public class IdentityMapDocHolderDocumentStorage1892370027 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapDocHolderDocumentStorage1892370027(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocHolder document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocHolder document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapDocHolderSelector1892370027(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapDocHolderDocumentStorage1892370027 - - - // START: DirtyTrackingDocHolderDocumentStorage1892370027 - public class DirtyTrackingDocHolderDocumentStorage1892370027 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingDocHolderDocumentStorage1892370027(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocHolder document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocHolderOperation1892370027 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocHolder document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocHolder document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingDocHolderSelector1892370027(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingDocHolderDocumentStorage1892370027 - - - // START: DocHolderBulkLoader1892370027 - public class DocHolderBulkLoader1892370027 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public DocHolderBulkLoader1892370027(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_docholder(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_docholder_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_docholder (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_docholder_temp.\"id\", mt_doc_docholder_temp.\"data\", mt_doc_docholder_temp.\"mt_version\", mt_doc_docholder_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_docholder_temp left join public.mt_doc_docholder on mt_doc_docholder_temp.id = public.mt_doc_docholder.id where public.mt_doc_docholder.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_docholder target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_docholder_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_docholder_temp as select * from public.mt_doc_docholder limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.DocHolder document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.DocHolder document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: DocHolderBulkLoader1892370027 - - - // START: DocHolderProvider1892370027 - public class DocHolderProvider1892370027 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public DocHolderProvider1892370027(Marten.Schema.DocumentMapping mapping) : base(new DocHolderBulkLoader1892370027(new QueryOnlyDocHolderDocumentStorage1892370027(mapping)), new QueryOnlyDocHolderDocumentStorage1892370027(mapping), new LightweightDocHolderDocumentStorage1892370027(mapping), new IdentityMapDocHolderDocumentStorage1892370027(mapping), new DirtyTrackingDocHolderDocumentStorage1892370027(mapping)) - { - _mapping = mapping; - } - - - } - - // END: DocHolderProvider1892370027 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithArraysProvider1391541541.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithArraysProvider1391541541.cs deleted file mode 100644 index 2864a1ac5b3..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithArraysProvider1391541541.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertDocWithArraysOperation1391541541 - public class UpsertDocWithArraysOperation1391541541 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.DocWithArrays _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertDocWithArraysOperation1391541541(DocumentDbTests.Bugs.DocWithArrays document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_docwitharrays(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertDocWithArraysOperation1391541541 - - - // START: InsertDocWithArraysOperation1391541541 - public class InsertDocWithArraysOperation1391541541 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.DocWithArrays _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertDocWithArraysOperation1391541541(DocumentDbTests.Bugs.DocWithArrays document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_docwitharrays(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertDocWithArraysOperation1391541541 - - - // START: UpdateDocWithArraysOperation1391541541 - public class UpdateDocWithArraysOperation1391541541 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.DocWithArrays _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateDocWithArraysOperation1391541541(DocumentDbTests.Bugs.DocWithArrays document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_docwitharrays(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateDocWithArraysOperation1391541541 - - - // START: QueryOnlyDocWithArraysSelector1391541541 - public class QueryOnlyDocWithArraysSelector1391541541 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyDocWithArraysSelector1391541541(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocWithArrays Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.DocWithArrays document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.DocWithArrays document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyDocWithArraysSelector1391541541 - - - // START: LightweightDocWithArraysSelector1391541541 - public class LightweightDocWithArraysSelector1391541541 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightDocWithArraysSelector1391541541(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocWithArrays Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.DocWithArrays document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.DocWithArrays document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightDocWithArraysSelector1391541541 - - - // START: IdentityMapDocWithArraysSelector1391541541 - public class IdentityMapDocWithArraysSelector1391541541 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapDocWithArraysSelector1391541541(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocWithArrays Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocWithArrays document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocWithArrays document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapDocWithArraysSelector1391541541 - - - // START: DirtyTrackingDocWithArraysSelector1391541541 - public class DirtyTrackingDocWithArraysSelector1391541541 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingDocWithArraysSelector1391541541(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.DocWithArrays Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocWithArrays document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.DocWithArrays document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingDocWithArraysSelector1391541541 - - - // START: QueryOnlyDocWithArraysDocumentStorage1391541541 - public class QueryOnlyDocWithArraysDocumentStorage1391541541 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyDocWithArraysDocumentStorage1391541541(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocWithArrays document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocWithArrays document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyDocWithArraysSelector1391541541(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyDocWithArraysDocumentStorage1391541541 - - - // START: LightweightDocWithArraysDocumentStorage1391541541 - public class LightweightDocWithArraysDocumentStorage1391541541 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightDocWithArraysDocumentStorage1391541541(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocWithArrays document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocWithArrays document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightDocWithArraysSelector1391541541(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightDocWithArraysDocumentStorage1391541541 - - - // START: IdentityMapDocWithArraysDocumentStorage1391541541 - public class IdentityMapDocWithArraysDocumentStorage1391541541 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapDocWithArraysDocumentStorage1391541541(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocWithArrays document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocWithArrays document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapDocWithArraysSelector1391541541(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapDocWithArraysDocumentStorage1391541541 - - - // START: DirtyTrackingDocWithArraysDocumentStorage1391541541 - public class DirtyTrackingDocWithArraysDocumentStorage1391541541 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingDocWithArraysDocumentStorage1391541541(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.DocWithArrays document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithArraysOperation1391541541 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.DocWithArrays document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.DocWithArrays document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingDocWithArraysSelector1391541541(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingDocWithArraysDocumentStorage1391541541 - - - // START: DocWithArraysBulkLoader1391541541 - public class DocWithArraysBulkLoader1391541541 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public DocWithArraysBulkLoader1391541541(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_docwitharrays(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_docwitharrays_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_docwitharrays (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_docwitharrays_temp.\"id\", mt_doc_docwitharrays_temp.\"data\", mt_doc_docwitharrays_temp.\"mt_version\", mt_doc_docwitharrays_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_docwitharrays_temp left join public.mt_doc_docwitharrays on mt_doc_docwitharrays_temp.id = public.mt_doc_docwitharrays.id where public.mt_doc_docwitharrays.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_docwitharrays target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_docwitharrays_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_docwitharrays_temp as select * from public.mt_doc_docwitharrays limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.DocWithArrays document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.DocWithArrays document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: DocWithArraysBulkLoader1391541541 - - - // START: DocWithArraysProvider1391541541 - public class DocWithArraysProvider1391541541 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public DocWithArraysProvider1391541541(Marten.Schema.DocumentMapping mapping) : base(new DocWithArraysBulkLoader1391541541(new QueryOnlyDocWithArraysDocumentStorage1391541541(mapping)), new QueryOnlyDocWithArraysDocumentStorage1391541541(mapping), new LightweightDocWithArraysDocumentStorage1391541541(mapping), new IdentityMapDocWithArraysDocumentStorage1391541541(mapping), new DirtyTrackingDocWithArraysDocumentStorage1391541541(mapping)) - { - _mapping = mapping; - } - - - } - - // END: DocWithArraysProvider1391541541 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithNumberProvider210740905.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithNumberProvider210740905.cs deleted file mode 100644 index 388a97b640b..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithNumberProvider210740905.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertDocWithNumberOperation210740905 - public class UpsertDocWithNumberOperation210740905 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.DocWithNumber _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertDocWithNumberOperation210740905(DocumentDbTests.Reading.Linq.DocWithNumber document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_docwithnumber(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertDocWithNumberOperation210740905 - - - // START: InsertDocWithNumberOperation210740905 - public class InsertDocWithNumberOperation210740905 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.DocWithNumber _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertDocWithNumberOperation210740905(DocumentDbTests.Reading.Linq.DocWithNumber document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_docwithnumber(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertDocWithNumberOperation210740905 - - - // START: UpdateDocWithNumberOperation210740905 - public class UpdateDocWithNumberOperation210740905 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.DocWithNumber _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateDocWithNumberOperation210740905(DocumentDbTests.Reading.Linq.DocWithNumber document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_docwithnumber(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateDocWithNumberOperation210740905 - - - // START: QueryOnlyDocWithNumberSelector210740905 - public class QueryOnlyDocWithNumberSelector210740905 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyDocWithNumberSelector210740905(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.DocWithNumber Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyDocWithNumberSelector210740905 - - - // START: LightweightDocWithNumberSelector210740905 - public class LightweightDocWithNumberSelector210740905 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightDocWithNumberSelector210740905(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.DocWithNumber Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightDocWithNumberSelector210740905 - - - // START: IdentityMapDocWithNumberSelector210740905 - public class IdentityMapDocWithNumberSelector210740905 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapDocWithNumberSelector210740905(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.DocWithNumber Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapDocWithNumberSelector210740905 - - - // START: DirtyTrackingDocWithNumberSelector210740905 - public class DirtyTrackingDocWithNumberSelector210740905 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingDocWithNumberSelector210740905(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.DocWithNumber Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.DocWithNumber document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingDocWithNumberSelector210740905 - - - // START: QueryOnlyDocWithNumberDocumentStorage210740905 - public class QueryOnlyDocWithNumberDocumentStorage210740905 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyDocWithNumberDocumentStorage210740905(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.DocWithNumber document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.DocWithNumber document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyDocWithNumberSelector210740905(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyDocWithNumberDocumentStorage210740905 - - - // START: LightweightDocWithNumberDocumentStorage210740905 - public class LightweightDocWithNumberDocumentStorage210740905 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightDocWithNumberDocumentStorage210740905(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.DocWithNumber document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.DocWithNumber document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightDocWithNumberSelector210740905(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightDocWithNumberDocumentStorage210740905 - - - // START: IdentityMapDocWithNumberDocumentStorage210740905 - public class IdentityMapDocWithNumberDocumentStorage210740905 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapDocWithNumberDocumentStorage210740905(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.DocWithNumber document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.DocWithNumber document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapDocWithNumberSelector210740905(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapDocWithNumberDocumentStorage210740905 - - - // START: DirtyTrackingDocWithNumberDocumentStorage210740905 - public class DirtyTrackingDocWithNumberDocumentStorage210740905 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingDocWithNumberDocumentStorage210740905(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.DocWithNumber document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithNumberOperation210740905 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.DocWithNumber document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingDocWithNumberSelector210740905(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingDocWithNumberDocumentStorage210740905 - - - // START: DocWithNumberBulkLoader210740905 - public class DocWithNumberBulkLoader210740905 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public DocWithNumberBulkLoader210740905(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_docwithnumber(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_docwithnumber_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_docwithnumber (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_docwithnumber_temp.\"id\", mt_doc_docwithnumber_temp.\"data\", mt_doc_docwithnumber_temp.\"mt_version\", mt_doc_docwithnumber_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_docwithnumber_temp left join public.mt_doc_docwithnumber on mt_doc_docwithnumber_temp.id = public.mt_doc_docwithnumber.id where public.mt_doc_docwithnumber.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_docwithnumber target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_docwithnumber_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_docwithnumber_temp as select * from public.mt_doc_docwithnumber limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.DocWithNumber document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: DocWithNumberBulkLoader210740905 - - - // START: DocWithNumberProvider210740905 - public class DocWithNumberProvider210740905 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public DocWithNumberProvider210740905(Marten.Schema.DocumentMapping mapping) : base(new DocWithNumberBulkLoader210740905(new QueryOnlyDocWithNumberDocumentStorage210740905(mapping)), new QueryOnlyDocWithNumberDocumentStorage210740905(mapping), new LightweightDocWithNumberDocumentStorage210740905(mapping), new IdentityMapDocWithNumberDocumentStorage210740905(mapping), new DirtyTrackingDocWithNumberDocumentStorage210740905(mapping)) - { - _mapping = mapping; - } - - - } - - // END: DocWithNumberProvider210740905 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithUintProvider1372666391.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithUintProvider1372666391.cs deleted file mode 100644 index 95e66e35033..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/DocWithUintProvider1372666391.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertDocWithUintOperation1372666391 - public class UpsertDocWithUintOperation1372666391 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertDocWithUintOperation1372666391(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_bug_1256_querying_against_a_uint_type_docwithuint(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertDocWithUintOperation1372666391 - - - // START: InsertDocWithUintOperation1372666391 - public class InsertDocWithUintOperation1372666391 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertDocWithUintOperation1372666391(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_bug_1256_querying_against_a_uint_type_docwithuint(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertDocWithUintOperation1372666391 - - - // START: UpdateDocWithUintOperation1372666391 - public class UpdateDocWithUintOperation1372666391 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateDocWithUintOperation1372666391(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_bug_1256_querying_against_a_uint_type_docwithuint(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateDocWithUintOperation1372666391 - - - // START: QueryOnlyDocWithUintSelector1372666391 - public class QueryOnlyDocWithUintSelector1372666391 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyDocWithUintSelector1372666391(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyDocWithUintSelector1372666391 - - - // START: LightweightDocWithUintSelector1372666391 - public class LightweightDocWithUintSelector1372666391 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightDocWithUintSelector1372666391(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightDocWithUintSelector1372666391 - - - // START: IdentityMapDocWithUintSelector1372666391 - public class IdentityMapDocWithUintSelector1372666391 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapDocWithUintSelector1372666391(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapDocWithUintSelector1372666391 - - - // START: DirtyTrackingDocWithUintSelector1372666391 - public class DirtyTrackingDocWithUintSelector1372666391 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingDocWithUintSelector1372666391(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingDocWithUintSelector1372666391 - - - // START: QueryOnlyDocWithUintDocumentStorage1372666391 - public class QueryOnlyDocWithUintDocumentStorage1372666391 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyDocWithUintDocumentStorage1372666391(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyDocWithUintSelector1372666391(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyDocWithUintDocumentStorage1372666391 - - - // START: LightweightDocWithUintDocumentStorage1372666391 - public class LightweightDocWithUintDocumentStorage1372666391 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightDocWithUintDocumentStorage1372666391(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightDocWithUintSelector1372666391(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightDocWithUintDocumentStorage1372666391 - - - // START: IdentityMapDocWithUintDocumentStorage1372666391 - public class IdentityMapDocWithUintDocumentStorage1372666391 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapDocWithUintDocumentStorage1372666391(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapDocWithUintSelector1372666391(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapDocWithUintDocumentStorage1372666391 - - - // START: DirtyTrackingDocWithUintDocumentStorage1372666391 - public class DirtyTrackingDocWithUintDocumentStorage1372666391 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingDocWithUintDocumentStorage1372666391(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertDocWithUintOperation1372666391 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingDocWithUintSelector1372666391(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingDocWithUintDocumentStorage1372666391 - - - // START: DocWithUintBulkLoader1372666391 - public class DocWithUintBulkLoader1372666391 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public DocWithUintBulkLoader1372666391(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_bug_1256_querying_against_a_uint_type_docwithuint(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_bug_1256_querying_against_a_uint_type_docwithuint (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp.\"id\", mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp.\"data\", mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp.\"mt_version\", mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp left join public.mt_doc_bug_1256_querying_against_a_uint_type_docwithuint on mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp.id = public.mt_doc_bug_1256_querying_against_a_uint_type_docwithuint.id where public.mt_doc_bug_1256_querying_against_a_uint_type_docwithuint.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_bug_1256_querying_against_a_uint_type_docwithuint target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_bug_1256_querying_against_a_uint_type_docwithuint_temp as select * from public.mt_doc_bug_1256_querying_against_a_uint_type_docwithuint limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_1256_querying_against_a_uint_type.DocWithUint document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: DocWithUintBulkLoader1372666391 - - - // START: DocWithUintProvider1372666391 - public class DocWithUintProvider1372666391 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public DocWithUintProvider1372666391(Marten.Schema.DocumentMapping mapping) : base(new DocWithUintBulkLoader1372666391(new QueryOnlyDocWithUintDocumentStorage1372666391(mapping)), new QueryOnlyDocWithUintDocumentStorage1372666391(mapping), new LightweightDocWithUintDocumentStorage1372666391(mapping), new IdentityMapDocWithUintDocumentStorage1372666391(mapping), new DirtyTrackingDocWithUintDocumentStorage1372666391(mapping)) - { - _mapping = mapping; - } - - - } - - // END: DocWithUintProvider1372666391 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/FailureInLifeProvider461155494.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/FailureInLifeProvider461155494.cs deleted file mode 100644 index 6dfc3db68f2..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/FailureInLifeProvider461155494.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Deleting; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertFailureInLifeOperation461155494 - public class UpsertFailureInLifeOperation461155494 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertFailureInLifeOperation461155494(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_delete_many_documents_by_query_failureinlife(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertFailureInLifeOperation461155494 - - - // START: InsertFailureInLifeOperation461155494 - public class InsertFailureInLifeOperation461155494 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertFailureInLifeOperation461155494(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_delete_many_documents_by_query_failureinlife(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertFailureInLifeOperation461155494 - - - // START: UpdateFailureInLifeOperation461155494 - public class UpdateFailureInLifeOperation461155494 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateFailureInLifeOperation461155494(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_delete_many_documents_by_query_failureinlife(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateFailureInLifeOperation461155494 - - - // START: QueryOnlyFailureInLifeSelector461155494 - public class QueryOnlyFailureInLifeSelector461155494 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyFailureInLifeSelector461155494(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyFailureInLifeSelector461155494 - - - // START: LightweightFailureInLifeSelector461155494 - public class LightweightFailureInLifeSelector461155494 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightFailureInLifeSelector461155494(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightFailureInLifeSelector461155494 - - - // START: IdentityMapFailureInLifeSelector461155494 - public class IdentityMapFailureInLifeSelector461155494 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapFailureInLifeSelector461155494(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapFailureInLifeSelector461155494 - - - // START: DirtyTrackingFailureInLifeSelector461155494 - public class DirtyTrackingFailureInLifeSelector461155494 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingFailureInLifeSelector461155494(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingFailureInLifeSelector461155494 - - - // START: QueryOnlyFailureInLifeDocumentStorage461155494 - public class QueryOnlyFailureInLifeDocumentStorage461155494 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyFailureInLifeDocumentStorage461155494(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyFailureInLifeSelector461155494(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyFailureInLifeDocumentStorage461155494 - - - // START: LightweightFailureInLifeDocumentStorage461155494 - public class LightweightFailureInLifeDocumentStorage461155494 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightFailureInLifeDocumentStorage461155494(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightFailureInLifeSelector461155494(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightFailureInLifeDocumentStorage461155494 - - - // START: IdentityMapFailureInLifeDocumentStorage461155494 - public class IdentityMapFailureInLifeDocumentStorage461155494 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapFailureInLifeDocumentStorage461155494(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapFailureInLifeSelector461155494(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapFailureInLifeDocumentStorage461155494 - - - // START: DirtyTrackingFailureInLifeDocumentStorage461155494 - public class DirtyTrackingFailureInLifeDocumentStorage461155494 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingFailureInLifeDocumentStorage461155494(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertFailureInLifeOperation461155494 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingFailureInLifeSelector461155494(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingFailureInLifeDocumentStorage461155494 - - - // START: FailureInLifeBulkLoader461155494 - public class FailureInLifeBulkLoader461155494 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public FailureInLifeBulkLoader461155494(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_delete_many_documents_by_query_failureinlife(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_delete_many_documents_by_query_failureinlife_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_delete_many_documents_by_query_failureinlife (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_delete_many_documents_by_query_failureinlife_temp.\"id\", mt_doc_delete_many_documents_by_query_failureinlife_temp.\"data\", mt_doc_delete_many_documents_by_query_failureinlife_temp.\"mt_version\", mt_doc_delete_many_documents_by_query_failureinlife_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_delete_many_documents_by_query_failureinlife_temp left join public.mt_doc_delete_many_documents_by_query_failureinlife on mt_doc_delete_many_documents_by_query_failureinlife_temp.id = public.mt_doc_delete_many_documents_by_query_failureinlife.id where public.mt_doc_delete_many_documents_by_query_failureinlife.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_delete_many_documents_by_query_failureinlife target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_delete_many_documents_by_query_failureinlife_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_delete_many_documents_by_query_failureinlife_temp as select * from public.mt_doc_delete_many_documents_by_query_failureinlife limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Integer); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Deleting.delete_many_documents_by_query.FailureInLife document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Integer, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: FailureInLifeBulkLoader461155494 - - - // START: FailureInLifeProvider461155494 - public class FailureInLifeProvider461155494 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public FailureInLifeProvider461155494(Marten.Schema.DocumentMapping mapping) : base(new FailureInLifeBulkLoader461155494(new QueryOnlyFailureInLifeDocumentStorage461155494(mapping)), new QueryOnlyFailureInLifeDocumentStorage461155494(mapping), new LightweightFailureInLifeDocumentStorage461155494(mapping), new IdentityMapFailureInLifeDocumentStorage461155494(mapping), new DirtyTrackingFailureInLifeDocumentStorage461155494(mapping)) - { - _mapping = mapping; - } - - - } - - // END: FailureInLifeProvider461155494 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/GroupProvider994823898.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/GroupProvider994823898.cs deleted file mode 100644 index df15308c87f..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/GroupProvider994823898.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Includes; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertGroupOperation994823898 - public class UpsertGroupOperation994823898 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Includes.Group _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertGroupOperation994823898(DocumentDbTests.Reading.Includes.Group document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_group(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertGroupOperation994823898 - - - // START: InsertGroupOperation994823898 - public class InsertGroupOperation994823898 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Includes.Group _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertGroupOperation994823898(DocumentDbTests.Reading.Includes.Group document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_group(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertGroupOperation994823898 - - - // START: UpdateGroupOperation994823898 - public class UpdateGroupOperation994823898 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Includes.Group _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateGroupOperation994823898(DocumentDbTests.Reading.Includes.Group document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_group(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateGroupOperation994823898 - - - // START: QueryOnlyGroupSelector994823898 - public class QueryOnlyGroupSelector994823898 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyGroupSelector994823898(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Includes.Group Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Includes.Group document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Includes.Group document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyGroupSelector994823898 - - - // START: LightweightGroupSelector994823898 - public class LightweightGroupSelector994823898 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightGroupSelector994823898(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Includes.Group Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Includes.Group document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Includes.Group document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightGroupSelector994823898 - - - // START: IdentityMapGroupSelector994823898 - public class IdentityMapGroupSelector994823898 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapGroupSelector994823898(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Includes.Group Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Includes.Group document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Includes.Group document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapGroupSelector994823898 - - - // START: DirtyTrackingGroupSelector994823898 - public class DirtyTrackingGroupSelector994823898 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingGroupSelector994823898(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Includes.Group Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Includes.Group document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Includes.Group document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingGroupSelector994823898 - - - // START: QueryOnlyGroupDocumentStorage994823898 - public class QueryOnlyGroupDocumentStorage994823898 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyGroupDocumentStorage994823898(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Includes.Group document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Includes.Group document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyGroupSelector994823898(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyGroupDocumentStorage994823898 - - - // START: LightweightGroupDocumentStorage994823898 - public class LightweightGroupDocumentStorage994823898 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightGroupDocumentStorage994823898(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Includes.Group document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Includes.Group document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightGroupSelector994823898(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightGroupDocumentStorage994823898 - - - // START: IdentityMapGroupDocumentStorage994823898 - public class IdentityMapGroupDocumentStorage994823898 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapGroupDocumentStorage994823898(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Includes.Group document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Includes.Group document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapGroupSelector994823898(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapGroupDocumentStorage994823898 - - - // START: DirtyTrackingGroupDocumentStorage994823898 - public class DirtyTrackingGroupDocumentStorage994823898 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingGroupDocumentStorage994823898(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Includes.Group document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGroupOperation994823898 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Includes.Group document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Includes.Group document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingGroupSelector994823898(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingGroupDocumentStorage994823898 - - - // START: GroupBulkLoader994823898 - public class GroupBulkLoader994823898 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public GroupBulkLoader994823898(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_group(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_group_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_group (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_group_temp.\"id\", mt_doc_group_temp.\"data\", mt_doc_group_temp.\"mt_version\", mt_doc_group_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_group_temp left join public.mt_doc_group on mt_doc_group_temp.id = public.mt_doc_group.id where public.mt_doc_group.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_group target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_group_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_group_temp as select * from public.mt_doc_group limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Includes.Group document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Includes.Group document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: GroupBulkLoader994823898 - - - // START: GroupProvider994823898 - public class GroupProvider994823898 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public GroupProvider994823898(Marten.Schema.DocumentMapping mapping) : base(new GroupBulkLoader994823898(new QueryOnlyGroupDocumentStorage994823898(mapping)), new QueryOnlyGroupDocumentStorage994823898(mapping), new LightweightGroupDocumentStorage994823898(mapping), new IdentityMapGroupDocumentStorage994823898(mapping), new DirtyTrackingGroupDocumentStorage994823898(mapping)) - { - _mapping = mapping; - } - - - } - - // END: GroupProvider994823898 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/GuidDocProvider400073224.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/GuidDocProvider400073224.cs deleted file mode 100644 index f3eba1503ef..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/GuidDocProvider400073224.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertGuidDocOperation400073224 - public class UpsertGuidDocOperation400073224 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.GuidDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertGuidDocOperation400073224(Marten.Testing.Documents.GuidDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_guiddoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertGuidDocOperation400073224 - - - // START: InsertGuidDocOperation400073224 - public class InsertGuidDocOperation400073224 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.GuidDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertGuidDocOperation400073224(Marten.Testing.Documents.GuidDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_guiddoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertGuidDocOperation400073224 - - - // START: UpdateGuidDocOperation400073224 - public class UpdateGuidDocOperation400073224 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.GuidDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateGuidDocOperation400073224(Marten.Testing.Documents.GuidDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_guiddoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateGuidDocOperation400073224 - - - // START: QueryOnlyGuidDocSelector400073224 - public class QueryOnlyGuidDocSelector400073224 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyGuidDocSelector400073224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.GuidDoc Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.GuidDoc document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.GuidDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyGuidDocSelector400073224 - - - // START: LightweightGuidDocSelector400073224 - public class LightweightGuidDocSelector400073224 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightGuidDocSelector400073224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.GuidDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.GuidDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.GuidDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightGuidDocSelector400073224 - - - // START: IdentityMapGuidDocSelector400073224 - public class IdentityMapGuidDocSelector400073224 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapGuidDocSelector400073224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.GuidDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.GuidDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.GuidDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapGuidDocSelector400073224 - - - // START: DirtyTrackingGuidDocSelector400073224 - public class DirtyTrackingGuidDocSelector400073224 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingGuidDocSelector400073224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.GuidDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.GuidDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.GuidDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingGuidDocSelector400073224 - - - // START: QueryOnlyGuidDocDocumentStorage400073224 - public class QueryOnlyGuidDocDocumentStorage400073224 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyGuidDocDocumentStorage400073224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.GuidDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.GuidDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyGuidDocSelector400073224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyGuidDocDocumentStorage400073224 - - - // START: LightweightGuidDocDocumentStorage400073224 - public class LightweightGuidDocDocumentStorage400073224 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightGuidDocDocumentStorage400073224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.GuidDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.GuidDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightGuidDocSelector400073224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightGuidDocDocumentStorage400073224 - - - // START: IdentityMapGuidDocDocumentStorage400073224 - public class IdentityMapGuidDocDocumentStorage400073224 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapGuidDocDocumentStorage400073224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.GuidDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.GuidDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapGuidDocSelector400073224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapGuidDocDocumentStorage400073224 - - - // START: DirtyTrackingGuidDocDocumentStorage400073224 - public class DirtyTrackingGuidDocDocumentStorage400073224 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingGuidDocDocumentStorage400073224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.GuidDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuidDocOperation400073224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.GuidDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.GuidDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingGuidDocSelector400073224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingGuidDocDocumentStorage400073224 - - - // START: GuidDocBulkLoader400073224 - public class GuidDocBulkLoader400073224 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public GuidDocBulkLoader400073224(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_guiddoc(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_guiddoc_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_guiddoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_guiddoc_temp.\"id\", mt_doc_guiddoc_temp.\"data\", mt_doc_guiddoc_temp.\"mt_version\", mt_doc_guiddoc_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_guiddoc_temp left join public.mt_doc_guiddoc on mt_doc_guiddoc_temp.id = public.mt_doc_guiddoc.id where public.mt_doc_guiddoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_guiddoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_guiddoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_guiddoc_temp as select * from public.mt_doc_guiddoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.GuidDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.GuidDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: GuidDocBulkLoader400073224 - - - // START: GuidDocProvider400073224 - public class GuidDocProvider400073224 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public GuidDocProvider400073224(Marten.Schema.DocumentMapping mapping) : base(new GuidDocBulkLoader400073224(new QueryOnlyGuidDocDocumentStorage400073224(mapping)), new QueryOnlyGuidDocDocumentStorage400073224(mapping), new LightweightGuidDocDocumentStorage400073224(mapping), new IdentityMapGuidDocDocumentStorage400073224(mapping), new DirtyTrackingGuidDocDocumentStorage400073224(mapping)) - { - _mapping = mapping; - } - - - } - - // END: GuidDocProvider400073224 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/GuyWithIntArrayProvider1326363224.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/GuyWithIntArrayProvider1326363224.cs deleted file mode 100644 index f4c4d5e18a0..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/GuyWithIntArrayProvider1326363224.cs +++ /dev/null @@ -1,886 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertGuyWithIntArrayOperation1326363224 - public class UpsertGuyWithIntArrayOperation1326363224 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.GuyWithIntArray _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertGuyWithIntArrayOperation1326363224(DocumentDbTests.Bugs.GuyWithIntArray document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_guywithintarray(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Integer; - - if (document.Numbers != null) - { - parameters[0].Value = document.Numbers; - } - - else - { - parameters[0].Value = System.DBNull.Value; - } - - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertGuyWithIntArrayOperation1326363224 - - - // START: InsertGuyWithIntArrayOperation1326363224 - public class InsertGuyWithIntArrayOperation1326363224 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.GuyWithIntArray _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertGuyWithIntArrayOperation1326363224(DocumentDbTests.Bugs.GuyWithIntArray document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_guywithintarray(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Integer; - - if (document.Numbers != null) - { - parameters[0].Value = document.Numbers; - } - - else - { - parameters[0].Value = System.DBNull.Value; - } - - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertGuyWithIntArrayOperation1326363224 - - - // START: UpdateGuyWithIntArrayOperation1326363224 - public class UpdateGuyWithIntArrayOperation1326363224 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.GuyWithIntArray _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateGuyWithIntArrayOperation1326363224(DocumentDbTests.Bugs.GuyWithIntArray document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_guywithintarray(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Integer; - - if (document.Numbers != null) - { - parameters[0].Value = document.Numbers; - } - - else - { - parameters[0].Value = System.DBNull.Value; - } - - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateGuyWithIntArrayOperation1326363224 - - - // START: QueryOnlyGuyWithIntArraySelector1326363224 - public class QueryOnlyGuyWithIntArraySelector1326363224 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyGuyWithIntArraySelector1326363224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.GuyWithIntArray Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyGuyWithIntArraySelector1326363224 - - - // START: LightweightGuyWithIntArraySelector1326363224 - public class LightweightGuyWithIntArraySelector1326363224 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightGuyWithIntArraySelector1326363224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.GuyWithIntArray Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightGuyWithIntArraySelector1326363224 - - - // START: IdentityMapGuyWithIntArraySelector1326363224 - public class IdentityMapGuyWithIntArraySelector1326363224 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapGuyWithIntArraySelector1326363224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.GuyWithIntArray Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapGuyWithIntArraySelector1326363224 - - - // START: DirtyTrackingGuyWithIntArraySelector1326363224 - public class DirtyTrackingGuyWithIntArraySelector1326363224 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingGuyWithIntArraySelector1326363224(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.GuyWithIntArray Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.GuyWithIntArray document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingGuyWithIntArraySelector1326363224 - - - // START: QueryOnlyGuyWithIntArrayDocumentStorage1326363224 - public class QueryOnlyGuyWithIntArrayDocumentStorage1326363224 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyGuyWithIntArrayDocumentStorage1326363224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.GuyWithIntArray document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.GuyWithIntArray document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyGuyWithIntArraySelector1326363224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyGuyWithIntArrayDocumentStorage1326363224 - - - // START: LightweightGuyWithIntArrayDocumentStorage1326363224 - public class LightweightGuyWithIntArrayDocumentStorage1326363224 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightGuyWithIntArrayDocumentStorage1326363224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.GuyWithIntArray document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.GuyWithIntArray document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightGuyWithIntArraySelector1326363224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightGuyWithIntArrayDocumentStorage1326363224 - - - // START: IdentityMapGuyWithIntArrayDocumentStorage1326363224 - public class IdentityMapGuyWithIntArrayDocumentStorage1326363224 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapGuyWithIntArrayDocumentStorage1326363224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.GuyWithIntArray document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.GuyWithIntArray document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapGuyWithIntArraySelector1326363224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapGuyWithIntArrayDocumentStorage1326363224 - - - // START: DirtyTrackingGuyWithIntArrayDocumentStorage1326363224 - public class DirtyTrackingGuyWithIntArrayDocumentStorage1326363224 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingGuyWithIntArrayDocumentStorage1326363224(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.GuyWithIntArray document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertGuyWithIntArrayOperation1326363224 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.GuyWithIntArray document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingGuyWithIntArraySelector1326363224(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingGuyWithIntArrayDocumentStorage1326363224 - - - // START: GuyWithIntArrayBulkLoader1326363224 - public class GuyWithIntArrayBulkLoader1326363224 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public GuyWithIntArrayBulkLoader1326363224(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_guywithintarray(\"numbers\", \"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_guywithintarray_temp(\"numbers\", \"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_guywithintarray (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", \"numbers\", mt_last_modified) (select mt_doc_guywithintarray_temp.\"id\", mt_doc_guywithintarray_temp.\"data\", mt_doc_guywithintarray_temp.\"mt_version\", mt_doc_guywithintarray_temp.\"mt_dotnet_type\", mt_doc_guywithintarray_temp.\"numbers\", transaction_timestamp() from mt_doc_guywithintarray_temp left join public.mt_doc_guywithintarray on mt_doc_guywithintarray_temp.id = public.mt_doc_guywithintarray.id where public.mt_doc_guywithintarray.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_guywithintarray target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, numbers = source.numbers, mt_last_modified = transaction_timestamp() FROM mt_doc_guywithintarray_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_guywithintarray_temp as select * from public.mt_doc_guywithintarray limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.Numbers, NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Integer); - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.GuyWithIntArray document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.Numbers, NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Integer, cancellation); - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: GuyWithIntArrayBulkLoader1326363224 - - - // START: GuyWithIntArrayProvider1326363224 - public class GuyWithIntArrayProvider1326363224 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public GuyWithIntArrayProvider1326363224(Marten.Schema.DocumentMapping mapping) : base(new GuyWithIntArrayBulkLoader1326363224(new QueryOnlyGuyWithIntArrayDocumentStorage1326363224(mapping)), new QueryOnlyGuyWithIntArrayDocumentStorage1326363224(mapping), new LightweightGuyWithIntArrayDocumentStorage1326363224(mapping), new IdentityMapGuyWithIntArrayDocumentStorage1326363224(mapping), new DirtyTrackingGuyWithIntArrayDocumentStorage1326363224(mapping)) - { - _mapping = mapping; - } - - - } - - // END: GuyWithIntArrayProvider1326363224 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/IntDocProvider379264442.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/IntDocProvider379264442.cs deleted file mode 100644 index abaac1cf785..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/IntDocProvider379264442.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertIntDocOperation379264442 - public class UpsertIntDocOperation379264442 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.IntDoc _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertIntDocOperation379264442(Marten.Testing.Documents.IntDoc document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_intdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertIntDocOperation379264442 - - - // START: InsertIntDocOperation379264442 - public class InsertIntDocOperation379264442 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.IntDoc _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertIntDocOperation379264442(Marten.Testing.Documents.IntDoc document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_intdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertIntDocOperation379264442 - - - // START: UpdateIntDocOperation379264442 - public class UpdateIntDocOperation379264442 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.IntDoc _document; - private readonly int _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateIntDocOperation379264442(Marten.Testing.Documents.IntDoc document, int id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_intdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Integer; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Integer; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateIntDocOperation379264442 - - - // START: QueryOnlyIntDocSelector379264442 - public class QueryOnlyIntDocSelector379264442 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyIntDocSelector379264442(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.IntDoc Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.IntDoc document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.IntDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyIntDocSelector379264442 - - - // START: LightweightIntDocSelector379264442 - public class LightweightIntDocSelector379264442 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightIntDocSelector379264442(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.IntDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.IntDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.IntDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightIntDocSelector379264442 - - - // START: IdentityMapIntDocSelector379264442 - public class IdentityMapIntDocSelector379264442 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapIntDocSelector379264442(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.IntDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.IntDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.IntDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapIntDocSelector379264442 - - - // START: DirtyTrackingIntDocSelector379264442 - public class DirtyTrackingIntDocSelector379264442 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingIntDocSelector379264442(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.IntDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.IntDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.IntDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingIntDocSelector379264442 - - - // START: QueryOnlyIntDocDocumentStorage379264442 - public class QueryOnlyIntDocDocumentStorage379264442 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyIntDocDocumentStorage379264442(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(Marten.Testing.Documents.IntDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.IntDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(Marten.Testing.Documents.IntDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyIntDocSelector379264442(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyIntDocDocumentStorage379264442 - - - // START: LightweightIntDocDocumentStorage379264442 - public class LightweightIntDocDocumentStorage379264442 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightIntDocDocumentStorage379264442(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(Marten.Testing.Documents.IntDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.IntDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(Marten.Testing.Documents.IntDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightIntDocSelector379264442(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightIntDocDocumentStorage379264442 - - - // START: IdentityMapIntDocDocumentStorage379264442 - public class IdentityMapIntDocDocumentStorage379264442 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapIntDocDocumentStorage379264442(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(Marten.Testing.Documents.IntDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.IntDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(Marten.Testing.Documents.IntDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapIntDocSelector379264442(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapIntDocDocumentStorage379264442 - - - // START: DirtyTrackingIntDocDocumentStorage379264442 - public class DirtyTrackingIntDocDocumentStorage379264442 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingIntDocDocumentStorage379264442(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override int AssignIdentity(Marten.Testing.Documents.IntDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.IntDoc)).NextInt()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIntDocOperation379264442 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.IntDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override int Identity(Marten.Testing.Documents.IntDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingIntDocSelector379264442(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(int id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int32[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingIntDocDocumentStorage379264442 - - - // START: IntDocBulkLoader379264442 - public class IntDocBulkLoader379264442 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public IntDocBulkLoader379264442(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_intdoc(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_intdoc_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_intdoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_intdoc_temp.\"id\", mt_doc_intdoc_temp.\"data\", mt_doc_intdoc_temp.\"mt_version\", mt_doc_intdoc_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_intdoc_temp left join public.mt_doc_intdoc on mt_doc_intdoc_temp.id = public.mt_doc_intdoc.id where public.mt_doc_intdoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_intdoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_intdoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_intdoc_temp as select * from public.mt_doc_intdoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.IntDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Integer); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.IntDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Integer, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: IntDocBulkLoader379264442 - - - // START: IntDocProvider379264442 - public class IntDocProvider379264442 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public IntDocProvider379264442(Marten.Schema.DocumentMapping mapping) : base(new IntDocBulkLoader379264442(new QueryOnlyIntDocDocumentStorage379264442(mapping)), new QueryOnlyIntDocDocumentStorage379264442(mapping), new LightweightIntDocDocumentStorage379264442(mapping), new IdentityMapIntDocDocumentStorage379264442(mapping), new DirtyTrackingIntDocDocumentStorage379264442(mapping)) - { - _mapping = mapping; - } - - - } - - // END: IntDocProvider379264442 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/IssueProvider2074714110.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/IssueProvider2074714110.cs deleted file mode 100644 index 54ce149ce4f..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/IssueProvider2074714110.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertIssueOperation2074714110 - public class UpsertIssueOperation2074714110 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Issue _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertIssueOperation2074714110(Marten.Testing.Documents.Issue document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_issue(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertIssueOperation2074714110 - - - // START: InsertIssueOperation2074714110 - public class InsertIssueOperation2074714110 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Issue _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertIssueOperation2074714110(Marten.Testing.Documents.Issue document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_issue(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertIssueOperation2074714110 - - - // START: UpdateIssueOperation2074714110 - public class UpdateIssueOperation2074714110 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Issue _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateIssueOperation2074714110(Marten.Testing.Documents.Issue document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_issue(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateIssueOperation2074714110 - - - // START: QueryOnlyIssueSelector2074714110 - public class QueryOnlyIssueSelector2074714110 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyIssueSelector2074714110(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Issue Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.Issue document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.Issue document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyIssueSelector2074714110 - - - // START: LightweightIssueSelector2074714110 - public class LightweightIssueSelector2074714110 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightIssueSelector2074714110(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Issue Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.Issue document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.Issue document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightIssueSelector2074714110 - - - // START: IdentityMapIssueSelector2074714110 - public class IdentityMapIssueSelector2074714110 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapIssueSelector2074714110(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Issue Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Issue document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Issue document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapIssueSelector2074714110 - - - // START: DirtyTrackingIssueSelector2074714110 - public class DirtyTrackingIssueSelector2074714110 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingIssueSelector2074714110(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Issue Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Issue document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Issue document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingIssueSelector2074714110 - - - // START: QueryOnlyIssueDocumentStorage2074714110 - public class QueryOnlyIssueDocumentStorage2074714110 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyIssueDocumentStorage2074714110(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Issue document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Issue document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyIssueSelector2074714110(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyIssueDocumentStorage2074714110 - - - // START: LightweightIssueDocumentStorage2074714110 - public class LightweightIssueDocumentStorage2074714110 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightIssueDocumentStorage2074714110(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Issue document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Issue document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightIssueSelector2074714110(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightIssueDocumentStorage2074714110 - - - // START: IdentityMapIssueDocumentStorage2074714110 - public class IdentityMapIssueDocumentStorage2074714110 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapIssueDocumentStorage2074714110(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Issue document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Issue document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapIssueSelector2074714110(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapIssueDocumentStorage2074714110 - - - // START: DirtyTrackingIssueDocumentStorage2074714110 - public class DirtyTrackingIssueDocumentStorage2074714110 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingIssueDocumentStorage2074714110(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Issue document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertIssueOperation2074714110 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Issue document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Issue document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingIssueSelector2074714110(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingIssueDocumentStorage2074714110 - - - // START: IssueBulkLoader2074714110 - public class IssueBulkLoader2074714110 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public IssueBulkLoader2074714110(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_issue(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_issue_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_issue (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_issue_temp.\"id\", mt_doc_issue_temp.\"data\", mt_doc_issue_temp.\"mt_version\", mt_doc_issue_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_issue_temp left join public.mt_doc_issue on mt_doc_issue_temp.id = public.mt_doc_issue.id where public.mt_doc_issue.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_issue target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_issue_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_issue_temp as select * from public.mt_doc_issue limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Issue document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Issue document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: IssueBulkLoader2074714110 - - - // START: IssueProvider2074714110 - public class IssueProvider2074714110 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public IssueProvider2074714110(Marten.Schema.DocumentMapping mapping) : base(new IssueBulkLoader2074714110(new QueryOnlyIssueDocumentStorage2074714110(mapping)), new QueryOnlyIssueDocumentStorage2074714110(mapping), new LightweightIssueDocumentStorage2074714110(mapping), new IdentityMapIssueDocumentStorage2074714110(mapping), new DirtyTrackingIssueDocumentStorage2074714110(mapping)) - { - _mapping = mapping; - } - - - } - - // END: IssueProvider2074714110 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/LongDocProvider1431212005.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/LongDocProvider1431212005.cs deleted file mode 100644 index 89aef0460ab..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/LongDocProvider1431212005.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertLongDocOperation1431212005 - public class UpsertLongDocOperation1431212005 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.LongDoc _document; - private readonly long _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertLongDocOperation1431212005(Marten.Testing.Documents.LongDoc document, long id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_longdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Bigint; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertLongDocOperation1431212005 - - - // START: InsertLongDocOperation1431212005 - public class InsertLongDocOperation1431212005 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.LongDoc _document; - private readonly long _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertLongDocOperation1431212005(Marten.Testing.Documents.LongDoc document, long id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_longdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Bigint; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertLongDocOperation1431212005 - - - // START: UpdateLongDocOperation1431212005 - public class UpdateLongDocOperation1431212005 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.LongDoc _document; - private readonly long _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateLongDocOperation1431212005(Marten.Testing.Documents.LongDoc document, long id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_longdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Bigint; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateLongDocOperation1431212005 - - - // START: QueryOnlyLongDocSelector1431212005 - public class QueryOnlyLongDocSelector1431212005 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyLongDocSelector1431212005(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.LongDoc Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.LongDoc document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.LongDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyLongDocSelector1431212005 - - - // START: LightweightLongDocSelector1431212005 - public class LightweightLongDocSelector1431212005 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightLongDocSelector1431212005(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.LongDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.LongDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.LongDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightLongDocSelector1431212005 - - - // START: IdentityMapLongDocSelector1431212005 - public class IdentityMapLongDocSelector1431212005 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapLongDocSelector1431212005(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.LongDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.LongDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.LongDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapLongDocSelector1431212005 - - - // START: DirtyTrackingLongDocSelector1431212005 - public class DirtyTrackingLongDocSelector1431212005 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingLongDocSelector1431212005(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.LongDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.LongDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.LongDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingLongDocSelector1431212005 - - - // START: QueryOnlyLongDocDocumentStorage1431212005 - public class QueryOnlyLongDocDocumentStorage1431212005 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyLongDocDocumentStorage1431212005(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(Marten.Testing.Documents.LongDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.LongDoc)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(Marten.Testing.Documents.LongDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyLongDocSelector1431212005(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyLongDocDocumentStorage1431212005 - - - // START: LightweightLongDocDocumentStorage1431212005 - public class LightweightLongDocDocumentStorage1431212005 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightLongDocDocumentStorage1431212005(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(Marten.Testing.Documents.LongDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.LongDoc)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(Marten.Testing.Documents.LongDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightLongDocSelector1431212005(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightLongDocDocumentStorage1431212005 - - - // START: IdentityMapLongDocDocumentStorage1431212005 - public class IdentityMapLongDocDocumentStorage1431212005 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapLongDocDocumentStorage1431212005(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(Marten.Testing.Documents.LongDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.LongDoc)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(Marten.Testing.Documents.LongDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapLongDocSelector1431212005(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapLongDocDocumentStorage1431212005 - - - // START: DirtyTrackingLongDocDocumentStorage1431212005 - public class DirtyTrackingLongDocDocumentStorage1431212005 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingLongDocDocumentStorage1431212005(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(Marten.Testing.Documents.LongDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(Marten.Testing.Documents.LongDoc)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertLongDocOperation1431212005 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.LongDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(Marten.Testing.Documents.LongDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingLongDocSelector1431212005(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingLongDocDocumentStorage1431212005 - - - // START: LongDocBulkLoader1431212005 - public class LongDocBulkLoader1431212005 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public LongDocBulkLoader1431212005(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_longdoc(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_longdoc_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_longdoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_longdoc_temp.\"id\", mt_doc_longdoc_temp.\"data\", mt_doc_longdoc_temp.\"mt_version\", mt_doc_longdoc_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_longdoc_temp left join public.mt_doc_longdoc on mt_doc_longdoc_temp.id = public.mt_doc_longdoc.id where public.mt_doc_longdoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_longdoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_longdoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_longdoc_temp as select * from public.mt_doc_longdoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.LongDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Bigint); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.LongDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Bigint, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: LongDocBulkLoader1431212005 - - - // START: LongDocProvider1431212005 - public class LongDocProvider1431212005 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public LongDocProvider1431212005(Marten.Schema.DocumentMapping mapping) : base(new LongDocBulkLoader1431212005(new QueryOnlyLongDocDocumentStorage1431212005(mapping)), new QueryOnlyLongDocDocumentStorage1431212005(mapping), new LightweightLongDocDocumentStorage1431212005(mapping), new IdentityMapLongDocDocumentStorage1431212005(mapping), new DirtyTrackingLongDocDocumentStorage1431212005(mapping)) - { - _mapping = mapping; - } - - - } - - // END: LongDocProvider1431212005 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MainEntityProvider1625545438.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/MainEntityProvider1625545438.cs deleted file mode 100644 index cdbbc73a797..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MainEntityProvider1625545438.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertMainEntityOperation1625545438 - public class UpsertMainEntityOperation1625545438 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity _document; - private readonly long _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertMainEntityOperation1625545438(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, long id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_bug_717_permutation_of_linq_queries_mainentity(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Bigint; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertMainEntityOperation1625545438 - - - // START: InsertMainEntityOperation1625545438 - public class InsertMainEntityOperation1625545438 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity _document; - private readonly long _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertMainEntityOperation1625545438(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, long id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_bug_717_permutation_of_linq_queries_mainentity(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Bigint; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertMainEntityOperation1625545438 - - - // START: UpdateMainEntityOperation1625545438 - public class UpdateMainEntityOperation1625545438 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity _document; - private readonly long _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateMainEntityOperation1625545438(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, long id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_bug_717_permutation_of_linq_queries_mainentity(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Bigint; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateMainEntityOperation1625545438 - - - // START: QueryOnlyMainEntitySelector1625545438 - public class QueryOnlyMainEntitySelector1625545438 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyMainEntitySelector1625545438(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyMainEntitySelector1625545438 - - - // START: LightweightMainEntitySelector1625545438 - public class LightweightMainEntitySelector1625545438 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightMainEntitySelector1625545438(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightMainEntitySelector1625545438 - - - // START: IdentityMapMainEntitySelector1625545438 - public class IdentityMapMainEntitySelector1625545438 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapMainEntitySelector1625545438(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapMainEntitySelector1625545438 - - - // START: DirtyTrackingMainEntitySelector1625545438 - public class DirtyTrackingMainEntitySelector1625545438 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingMainEntitySelector1625545438(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingMainEntitySelector1625545438 - - - // START: QueryOnlyMainEntityDocumentStorage1625545438 - public class QueryOnlyMainEntityDocumentStorage1625545438 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyMainEntityDocumentStorage1625545438(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyMainEntitySelector1625545438(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyMainEntityDocumentStorage1625545438 - - - // START: LightweightMainEntityDocumentStorage1625545438 - public class LightweightMainEntityDocumentStorage1625545438 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightMainEntityDocumentStorage1625545438(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightMainEntitySelector1625545438(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightMainEntityDocumentStorage1625545438 - - - // START: IdentityMapMainEntityDocumentStorage1625545438 - public class IdentityMapMainEntityDocumentStorage1625545438 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapMainEntityDocumentStorage1625545438(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapMainEntitySelector1625545438(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapMainEntityDocumentStorage1625545438 - - - // START: DirtyTrackingMainEntityDocumentStorage1625545438 - public class DirtyTrackingMainEntityDocumentStorage1625545438 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingMainEntityDocumentStorage1625545438(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override long AssignIdentity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id <= 0) _setter(document, database.Sequences.SequenceFor(typeof(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity)).NextLong()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMainEntityOperation1625545438 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override long Identity(DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingMainEntitySelector1625545438(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(long id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Int64[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingMainEntityDocumentStorage1625545438 - - - // START: MainEntityBulkLoader1625545438 - public class MainEntityBulkLoader1625545438 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public MainEntityBulkLoader1625545438(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_bug_717_permutation_of_linq_queries_mainentity(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_bug_717_permutation_of_linq_queries_mainentity (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp.\"id\", mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp.\"data\", mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp.\"mt_version\", mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp left join public.mt_doc_bug_717_permutation_of_linq_queries_mainentity on mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp.id = public.mt_doc_bug_717_permutation_of_linq_queries_mainentity.id where public.mt_doc_bug_717_permutation_of_linq_queries_mainentity.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_bug_717_permutation_of_linq_queries_mainentity target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_bug_717_permutation_of_linq_queries_mainentity_temp as select * from public.mt_doc_bug_717_permutation_of_linq_queries_mainentity limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Bigint); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_717_permutation_of_Linq_queries.MainEntity document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Bigint, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: MainEntityBulkLoader1625545438 - - - // START: MainEntityProvider1625545438 - public class MainEntityProvider1625545438 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public MainEntityProvider1625545438(Marten.Schema.DocumentMapping mapping) : base(new MainEntityBulkLoader1625545438(new QueryOnlyMainEntityDocumentStorage1625545438(mapping)), new QueryOnlyMainEntityDocumentStorage1625545438(mapping), new LightweightMainEntityDocumentStorage1625545438(mapping), new IdentityMapMainEntityDocumentStorage1625545438(mapping), new DirtyTrackingMainEntityDocumentStorage1625545438(mapping)) - { - _mapping = mapping; - } - - - } - - // END: MainEntityProvider1625545438 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MartenStoredStateProvider1211396321.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/MartenStoredStateProvider1211396321.cs deleted file mode 100644 index 597c667eb78..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MartenStoredStateProvider1211396321.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertMartenStoredStateOperation1211396321 - public class UpsertMartenStoredStateOperation1211396321 : Marten.Internal.Operations.StorageOperation>, System.Guid> - { - private readonly DocumentDbTests.Bugs.MartenStoredState> _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertMartenStoredStateOperation1211396321(DocumentDbTests.Bugs.MartenStoredState> document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_martenstoredstatedictionarystring_string(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertMartenStoredStateOperation1211396321 - - - // START: InsertMartenStoredStateOperation1211396321 - public class InsertMartenStoredStateOperation1211396321 : Marten.Internal.Operations.StorageOperation>, System.Guid> - { - private readonly DocumentDbTests.Bugs.MartenStoredState> _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertMartenStoredStateOperation1211396321(DocumentDbTests.Bugs.MartenStoredState> document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_martenstoredstatedictionarystring_string(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertMartenStoredStateOperation1211396321 - - - // START: UpdateMartenStoredStateOperation1211396321 - public class UpdateMartenStoredStateOperation1211396321 : Marten.Internal.Operations.StorageOperation>, System.Guid> - { - private readonly DocumentDbTests.Bugs.MartenStoredState> _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateMartenStoredStateOperation1211396321(DocumentDbTests.Bugs.MartenStoredState> document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_martenstoredstatedictionarystring_string(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateMartenStoredStateOperation1211396321 - - - // START: QueryOnlyMartenStoredStateSelector1211396321 - public class QueryOnlyMartenStoredStateSelector1211396321 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector>> - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyMartenStoredStateSelector1211396321(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MartenStoredState> Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.MartenStoredState> document; - document = _serializer.FromJson>>(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task>> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.MartenStoredState> document; - document = await _serializer.FromJsonAsync>>(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyMartenStoredStateSelector1211396321 - - - // START: LightweightMartenStoredStateSelector1211396321 - public class LightweightMartenStoredStateSelector1211396321 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions>, System.Guid>, Marten.Linq.Selectors.ISelector>> - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightMartenStoredStateSelector1211396321(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MartenStoredState> Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.MartenStoredState> document; - document = _serializer.FromJson>>(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task>> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.MartenStoredState> document; - document = await _serializer.FromJsonAsync>>(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightMartenStoredStateSelector1211396321 - - - // START: IdentityMapMartenStoredStateSelector1211396321 - public class IdentityMapMartenStoredStateSelector1211396321 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap>, System.Guid>, Marten.Linq.Selectors.ISelector>> - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapMartenStoredStateSelector1211396321(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MartenStoredState> Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MartenStoredState> document; - document = _serializer.FromJson>>(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task>> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MartenStoredState> document; - document = await _serializer.FromJsonAsync>>(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapMartenStoredStateSelector1211396321 - - - // START: DirtyTrackingMartenStoredStateSelector1211396321 - public class DirtyTrackingMartenStoredStateSelector1211396321 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking>, System.Guid>, Marten.Linq.Selectors.ISelector>> - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingMartenStoredStateSelector1211396321(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MartenStoredState> Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MartenStoredState> document; - document = _serializer.FromJson>>(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task>> ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MartenStoredState> document; - document = await _serializer.FromJsonAsync>>(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingMartenStoredStateSelector1211396321 - - - // START: QueryOnlyMartenStoredStateDocumentStorage1211396321 - public class QueryOnlyMartenStoredStateDocumentStorage1211396321 : Marten.Internal.Storage.QueryOnlyDocumentStorage>, System.Guid> - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyMartenStoredStateDocumentStorage1211396321(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.MartenStoredState> document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.MartenStoredState> document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyMartenStoredStateSelector1211396321(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyMartenStoredStateDocumentStorage1211396321 - - - // START: LightweightMartenStoredStateDocumentStorage1211396321 - public class LightweightMartenStoredStateDocumentStorage1211396321 : Marten.Internal.Storage.LightweightDocumentStorage>, System.Guid> - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightMartenStoredStateDocumentStorage1211396321(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.MartenStoredState> document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.MartenStoredState> document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightMartenStoredStateSelector1211396321(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightMartenStoredStateDocumentStorage1211396321 - - - // START: IdentityMapMartenStoredStateDocumentStorage1211396321 - public class IdentityMapMartenStoredStateDocumentStorage1211396321 : Marten.Internal.Storage.IdentityMapDocumentStorage>, System.Guid> - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapMartenStoredStateDocumentStorage1211396321(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.MartenStoredState> document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.MartenStoredState> document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapMartenStoredStateSelector1211396321(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapMartenStoredStateDocumentStorage1211396321 - - - // START: DirtyTrackingMartenStoredStateDocumentStorage1211396321 - public class DirtyTrackingMartenStoredStateDocumentStorage1211396321 : Marten.Internal.Storage.DirtyCheckedDocumentStorage>, System.Guid> - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingMartenStoredStateDocumentStorage1211396321(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.MartenStoredState> document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMartenStoredStateOperation1211396321 - ( - document, Identity(document), - session.Versions.ForType>, System.Guid>(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MartenStoredState> document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.MartenStoredState> document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingMartenStoredStateSelector1211396321(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingMartenStoredStateDocumentStorage1211396321 - - - // START: MartenStoredStateBulkLoader1211396321 - public class MartenStoredStateBulkLoader1211396321 : Marten.Internal.CodeGeneration.BulkLoader>, System.Guid> - { - private readonly Marten.Internal.Storage.IDocumentStorage>, System.Guid> _storage; - - public MartenStoredStateBulkLoader1211396321(Marten.Internal.Storage.IDocumentStorage>, System.Guid> storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_martenstoredstatedictionarystring_string(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_martenstoredstatedictionarystring_string_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_martenstoredstatedictionarystring_string (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_martenstoredstatedictionarystring_string_temp.\"id\", mt_doc_martenstoredstatedictionarystring_string_temp.\"data\", mt_doc_martenstoredstatedictionarystring_string_temp.\"mt_version\", mt_doc_martenstoredstatedictionarystring_string_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_martenstoredstatedictionarystring_string_temp left join public.mt_doc_martenstoredstatedictionarystring_string on mt_doc_martenstoredstatedictionarystring_string_temp.id = public.mt_doc_martenstoredstatedictionarystring_string.id where public.mt_doc_martenstoredstatedictionarystring_string.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_martenstoredstatedictionarystring_string target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_martenstoredstatedictionarystring_string_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_martenstoredstatedictionarystring_string_temp as select * from public.mt_doc_martenstoredstatedictionarystring_string limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.MartenStoredState> document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.MartenStoredState> document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: MartenStoredStateBulkLoader1211396321 - - - // START: MartenStoredStateProvider1211396321 - public class MartenStoredStateProvider1211396321 : Marten.Internal.Storage.DocumentProvider>> - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public MartenStoredStateProvider1211396321(Marten.Schema.DocumentMapping mapping) : base(new MartenStoredStateBulkLoader1211396321(new QueryOnlyMartenStoredStateDocumentStorage1211396321(mapping)), new QueryOnlyMartenStoredStateDocumentStorage1211396321(mapping), new LightweightMartenStoredStateDocumentStorage1211396321(mapping), new IdentityMapMartenStoredStateDocumentStorage1211396321(mapping), new DirtyTrackingMartenStoredStateDocumentStorage1211396321(mapping)) - { - _mapping = mapping; - } - - - } - - // END: MartenStoredStateProvider1211396321 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyClassProvider52903863.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyClassProvider52903863.cs deleted file mode 100644 index 8a2c8dba1b0..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyClassProvider52903863.cs +++ /dev/null @@ -1,878 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertMyClassOperation52903863 - public class UpsertMyClassOperation52903863 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.MyClass _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertMyClassOperation52903863(DocumentDbTests.Bugs.MyClass document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_myclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertMyClassOperation52903863 - - - // START: InsertMyClassOperation52903863 - public class InsertMyClassOperation52903863 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.MyClass _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertMyClassOperation52903863(DocumentDbTests.Bugs.MyClass document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_myclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertMyClassOperation52903863 - - - // START: UpdateMyClassOperation52903863 - public class UpdateMyClassOperation52903863 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.MyClass _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateMyClassOperation52903863(DocumentDbTests.Bugs.MyClass document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_myclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateMyClassOperation52903863 - - - // START: QueryOnlyMyClassSelector52903863 - public class QueryOnlyMyClassSelector52903863 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyMyClassSelector52903863(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MyClass Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.MyClass document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.MyClass document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyMyClassSelector52903863 - - - // START: LightweightMyClassSelector52903863 - public class LightweightMyClassSelector52903863 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightMyClassSelector52903863(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MyClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.MyClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.MyClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightMyClassSelector52903863 - - - // START: IdentityMapMyClassSelector52903863 - public class IdentityMapMyClassSelector52903863 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapMyClassSelector52903863(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MyClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MyClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MyClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapMyClassSelector52903863 - - - // START: DirtyTrackingMyClassSelector52903863 - public class DirtyTrackingMyClassSelector52903863 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingMyClassSelector52903863(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.MyClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MyClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.MyClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingMyClassSelector52903863 - - - // START: QueryOnlyMyClassDocumentStorage52903863 - public class QueryOnlyMyClassDocumentStorage52903863 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyMyClassDocumentStorage52903863(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Bugs.MyClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Bugs.MyClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyMyClassSelector52903863(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyMyClassDocumentStorage52903863 - - - // START: LightweightMyClassDocumentStorage52903863 - public class LightweightMyClassDocumentStorage52903863 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightMyClassDocumentStorage52903863(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Bugs.MyClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Bugs.MyClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightMyClassSelector52903863(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightMyClassDocumentStorage52903863 - - - // START: IdentityMapMyClassDocumentStorage52903863 - public class IdentityMapMyClassDocumentStorage52903863 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapMyClassDocumentStorage52903863(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Bugs.MyClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Bugs.MyClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapMyClassSelector52903863(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapMyClassDocumentStorage52903863 - - - // START: DirtyTrackingMyClassDocumentStorage52903863 - public class DirtyTrackingMyClassDocumentStorage52903863 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingMyClassDocumentStorage52903863(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Bugs.MyClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyClassOperation52903863 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.MyClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Bugs.MyClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingMyClassSelector52903863(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingMyClassDocumentStorage52903863 - - - // START: MyClassBulkLoader52903863 - public class MyClassBulkLoader52903863 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public MyClassBulkLoader52903863(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_myclass(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_myclass_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_myclass (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_myclass_temp.\"id\", mt_doc_myclass_temp.\"data\", mt_doc_myclass_temp.\"mt_version\", mt_doc_myclass_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_myclass_temp left join public.mt_doc_myclass on mt_doc_myclass_temp.id = public.mt_doc_myclass.id where public.mt_doc_myclass.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_myclass target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_myclass_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_myclass_temp as select * from public.mt_doc_myclass limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.MyClass document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Text); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.MyClass document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Text, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: MyClassBulkLoader52903863 - - - // START: MyClassProvider52903863 - public class MyClassProvider52903863 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public MyClassProvider52903863(Marten.Schema.DocumentMapping mapping) : base(new MyClassBulkLoader52903863(new QueryOnlyMyClassDocumentStorage52903863(mapping)), new QueryOnlyMyClassDocumentStorage52903863(mapping), new LightweightMyClassDocumentStorage52903863(mapping), new IdentityMapMyClassDocumentStorage52903863(mapping), new DirtyTrackingMyClassDocumentStorage52903863(mapping)) - { - _mapping = mapping; - } - - - } - - // END: MyClassProvider52903863 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyTrackedDocProvider815737241.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyTrackedDocProvider815737241.cs deleted file mode 100644 index 51485ec8425..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyTrackedDocProvider815737241.cs +++ /dev/null @@ -1,1001 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Metadata; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertMyTrackedDocOperation815737241 - public class UpsertMyTrackedDocOperation815737241 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.MyTrackedDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertMyTrackedDocOperation815737241(DocumentDbTests.Metadata.MyTrackedDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_mytrackeddoc(?, ?, ?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session) - { - var causationId = session.CausationId; - document.CausationId = causationId; - var correlationId = session.CorrelationId; - document.CorrelationId = correlationId; - var lastModifiedBy = session.LastModifiedBy; - document.LastModifiedBy = lastModifiedBy; - setStringParameter(parameters[0], session.CausationId); - setStringParameter(parameters[1], session.CorrelationId); - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[2].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[3].Value = _document.GetType().FullName; - parameters[4].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[4].Value = document.Id; - setVersionParameter(parameters[5]); - setStringParameter(parameters[6], session.LastModifiedBy); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertMyTrackedDocOperation815737241 - - - // START: InsertMyTrackedDocOperation815737241 - public class InsertMyTrackedDocOperation815737241 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.MyTrackedDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertMyTrackedDocOperation815737241(DocumentDbTests.Metadata.MyTrackedDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_mytrackeddoc(?, ?, ?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session) - { - var causationId = session.CausationId; - document.CausationId = causationId; - var correlationId = session.CorrelationId; - document.CorrelationId = correlationId; - var lastModifiedBy = session.LastModifiedBy; - document.LastModifiedBy = lastModifiedBy; - setStringParameter(parameters[0], session.CausationId); - setStringParameter(parameters[1], session.CorrelationId); - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[2].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[3].Value = _document.GetType().FullName; - parameters[4].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[4].Value = document.Id; - setVersionParameter(parameters[5]); - setStringParameter(parameters[6], session.LastModifiedBy); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertMyTrackedDocOperation815737241 - - - // START: UpdateMyTrackedDocOperation815737241 - public class UpdateMyTrackedDocOperation815737241 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.MyTrackedDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateMyTrackedDocOperation815737241(DocumentDbTests.Metadata.MyTrackedDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_mytrackeddoc(?, ?, ?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session) - { - var causationId = session.CausationId; - document.CausationId = causationId; - var correlationId = session.CorrelationId; - document.CorrelationId = correlationId; - var lastModifiedBy = session.LastModifiedBy; - document.LastModifiedBy = lastModifiedBy; - setStringParameter(parameters[0], session.CausationId); - setStringParameter(parameters[1], session.CorrelationId); - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[2].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[3].Value = _document.GetType().FullName; - parameters[4].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[4].Value = document.Id; - setVersionParameter(parameters[5]); - setStringParameter(parameters[6], session.LastModifiedBy); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateMyTrackedDocOperation815737241 - - - // START: QueryOnlyMyTrackedDocSelector815737241 - public class QueryOnlyMyTrackedDocSelector815737241 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyMyTrackedDocSelector815737241(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyTrackedDoc Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = _serializer.FromJson(reader, 0); - if (!reader.IsDBNull(1)) - { - var correlationId = reader.GetFieldValue(1); - document.CorrelationId = correlationId; - } - if (!reader.IsDBNull(2)) - { - var causationId = reader.GetFieldValue(2); - document.CausationId = causationId; - } - if (!reader.IsDBNull(3)) - { - var lastModifiedBy = reader.GetFieldValue(3); - document.LastModifiedBy = lastModifiedBy; - } - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - if (!(await reader.IsDBNullAsync(1, token).ConfigureAwait(false))) - { - var correlationId = await reader.GetFieldValueAsync(1, token).ConfigureAwait(false); - document.CorrelationId = correlationId; - } - if (!(await reader.IsDBNullAsync(2, token).ConfigureAwait(false))) - { - var causationId = await reader.GetFieldValueAsync(2, token).ConfigureAwait(false); - document.CausationId = causationId; - } - if (!(await reader.IsDBNullAsync(3, token).ConfigureAwait(false))) - { - var lastModifiedBy = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); - document.LastModifiedBy = lastModifiedBy; - } - return document; - } - - } - - // END: QueryOnlyMyTrackedDocSelector815737241 - - - // START: LightweightMyTrackedDocSelector815737241 - public class LightweightMyTrackedDocSelector815737241 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightMyTrackedDocSelector815737241(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyTrackedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = _serializer.FromJson(reader, 1); - if (!reader.IsDBNull(2)) - { - var correlationId = reader.GetFieldValue(2); - document.CorrelationId = correlationId; - } - if (!reader.IsDBNull(3)) - { - var causationId = reader.GetFieldValue(3); - document.CausationId = causationId; - } - if (!reader.IsDBNull(4)) - { - var lastModifiedBy = reader.GetFieldValue(4); - document.LastModifiedBy = lastModifiedBy; - } - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - if (!(await reader.IsDBNullAsync(2, token).ConfigureAwait(false))) - { - var correlationId = await reader.GetFieldValueAsync(2, token).ConfigureAwait(false); - document.CorrelationId = correlationId; - } - if (!(await reader.IsDBNullAsync(3, token).ConfigureAwait(false))) - { - var causationId = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); - document.CausationId = causationId; - } - if (!(await reader.IsDBNullAsync(4, token).ConfigureAwait(false))) - { - var lastModifiedBy = await reader.GetFieldValueAsync(4, token).ConfigureAwait(false); - document.LastModifiedBy = lastModifiedBy; - } - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightMyTrackedDocSelector815737241 - - - // START: IdentityMapMyTrackedDocSelector815737241 - public class IdentityMapMyTrackedDocSelector815737241 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapMyTrackedDocSelector815737241(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyTrackedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = _serializer.FromJson(reader, 1); - if (!reader.IsDBNull(2)) - { - var correlationId = reader.GetFieldValue(2); - document.CorrelationId = correlationId; - } - if (!reader.IsDBNull(3)) - { - var causationId = reader.GetFieldValue(3); - document.CausationId = causationId; - } - if (!reader.IsDBNull(4)) - { - var lastModifiedBy = reader.GetFieldValue(4); - document.LastModifiedBy = lastModifiedBy; - } - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - if (!(await reader.IsDBNullAsync(2, token).ConfigureAwait(false))) - { - var correlationId = await reader.GetFieldValueAsync(2, token).ConfigureAwait(false); - document.CorrelationId = correlationId; - } - if (!(await reader.IsDBNullAsync(3, token).ConfigureAwait(false))) - { - var causationId = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); - document.CausationId = causationId; - } - if (!(await reader.IsDBNullAsync(4, token).ConfigureAwait(false))) - { - var lastModifiedBy = await reader.GetFieldValueAsync(4, token).ConfigureAwait(false); - document.LastModifiedBy = lastModifiedBy; - } - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapMyTrackedDocSelector815737241 - - - // START: DirtyTrackingMyTrackedDocSelector815737241 - public class DirtyTrackingMyTrackedDocSelector815737241 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingMyTrackedDocSelector815737241(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyTrackedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = _serializer.FromJson(reader, 1); - if (!reader.IsDBNull(2)) - { - var correlationId = reader.GetFieldValue(2); - document.CorrelationId = correlationId; - } - if (!reader.IsDBNull(3)) - { - var causationId = reader.GetFieldValue(3); - document.CausationId = causationId; - } - if (!reader.IsDBNull(4)) - { - var lastModifiedBy = reader.GetFieldValue(4); - document.LastModifiedBy = lastModifiedBy; - } - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyTrackedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - if (!(await reader.IsDBNullAsync(2, token).ConfigureAwait(false))) - { - var correlationId = await reader.GetFieldValueAsync(2, token).ConfigureAwait(false); - document.CorrelationId = correlationId; - } - if (!(await reader.IsDBNullAsync(3, token).ConfigureAwait(false))) - { - var causationId = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); - document.CausationId = causationId; - } - if (!(await reader.IsDBNullAsync(4, token).ConfigureAwait(false))) - { - var lastModifiedBy = await reader.GetFieldValueAsync(4, token).ConfigureAwait(false); - document.LastModifiedBy = lastModifiedBy; - } - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingMyTrackedDocSelector815737241 - - - // START: QueryOnlyMyTrackedDocDocumentStorage815737241 - public class QueryOnlyMyTrackedDocDocumentStorage815737241 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyMyTrackedDocDocumentStorage815737241(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyTrackedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyTrackedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyMyTrackedDocSelector815737241(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyMyTrackedDocDocumentStorage815737241 - - - // START: LightweightMyTrackedDocDocumentStorage815737241 - public class LightweightMyTrackedDocDocumentStorage815737241 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightMyTrackedDocDocumentStorage815737241(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyTrackedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyTrackedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightMyTrackedDocSelector815737241(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightMyTrackedDocDocumentStorage815737241 - - - // START: IdentityMapMyTrackedDocDocumentStorage815737241 - public class IdentityMapMyTrackedDocDocumentStorage815737241 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapMyTrackedDocDocumentStorage815737241(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyTrackedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyTrackedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapMyTrackedDocSelector815737241(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapMyTrackedDocDocumentStorage815737241 - - - // START: DirtyTrackingMyTrackedDocDocumentStorage815737241 - public class DirtyTrackingMyTrackedDocDocumentStorage815737241 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingMyTrackedDocDocumentStorage815737241(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyTrackedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertMyTrackedDocOperation815737241 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyTrackedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingMyTrackedDocSelector815737241(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingMyTrackedDocDocumentStorage815737241 - - - // START: MyTrackedDocBulkLoader815737241 - public class MyTrackedDocBulkLoader815737241 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public MyTrackedDocBulkLoader815737241(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_mytrackeddoc(\"causation_id\", \"correlation_id\", \"mt_dotnet_type\", \"id\", \"mt_version\", \"last_modified_by\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_mytrackeddoc_temp(\"causation_id\", \"correlation_id\", \"mt_dotnet_type\", \"id\", \"mt_version\", \"last_modified_by\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_mytrackeddoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", \"correlation_id\", \"causation_id\", \"last_modified_by\", mt_last_modified) (select mt_doc_mytrackeddoc_temp.\"id\", mt_doc_mytrackeddoc_temp.\"data\", mt_doc_mytrackeddoc_temp.\"mt_version\", mt_doc_mytrackeddoc_temp.\"mt_dotnet_type\", mt_doc_mytrackeddoc_temp.\"correlation_id\", mt_doc_mytrackeddoc_temp.\"causation_id\", mt_doc_mytrackeddoc_temp.\"last_modified_by\", transaction_timestamp() from mt_doc_mytrackeddoc_temp left join public.mt_doc_mytrackeddoc on mt_doc_mytrackeddoc_temp.id = public.mt_doc_mytrackeddoc.id where public.mt_doc_mytrackeddoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_mytrackeddoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, correlation_id = source.correlation_id, causation_id = source.causation_id, last_modified_by = source.last_modified_by, mt_last_modified = transaction_timestamp() FROM mt_doc_mytrackeddoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_mytrackeddoc_temp as select * from public.mt_doc_mytrackeddoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write("BULK_INSERT", NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write("BULK_INSERT", NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write("BULK_INSERT", NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Metadata.MyTrackedDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync("BULK_INSERT", NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync("BULK_INSERT", NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync("BULK_INSERT", NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: MyTrackedDocBulkLoader815737241 - - - // START: MyTrackedDocProvider815737241 - public class MyTrackedDocProvider815737241 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public MyTrackedDocProvider815737241(Marten.Schema.DocumentMapping mapping) : base(new MyTrackedDocBulkLoader815737241(new QueryOnlyMyTrackedDocDocumentStorage815737241(mapping)), new QueryOnlyMyTrackedDocDocumentStorage815737241(mapping), new LightweightMyTrackedDocDocumentStorage815737241(mapping), new IdentityMapMyTrackedDocDocumentStorage815737241(mapping), new DirtyTrackingMyTrackedDocDocumentStorage815737241(mapping)) - { - _mapping = mapping; - } - - - } - - // END: MyTrackedDocProvider815737241 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyVersionedDocProvider1489495374.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyVersionedDocProvider1489495374.cs deleted file mode 100644 index ae19c1d9c16..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/MyVersionedDocProvider1489495374.cs +++ /dev/null @@ -1,1165 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Metadata; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertMyVersionedDocOperation1489495374 - public class UpsertMyVersionedDocOperation1489495374 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.MyVersionedDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertMyVersionedDocOperation1489495374(DocumentDbTests.Metadata.MyVersionedDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_myversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertMyVersionedDocOperation1489495374 - - - // START: InsertMyVersionedDocOperation1489495374 - public class InsertMyVersionedDocOperation1489495374 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.MyVersionedDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertMyVersionedDocOperation1489495374(DocumentDbTests.Metadata.MyVersionedDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_myversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertMyVersionedDocOperation1489495374 - - - // START: UpdateMyVersionedDocOperation1489495374 - public class UpdateMyVersionedDocOperation1489495374 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.MyVersionedDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateMyVersionedDocOperation1489495374(DocumentDbTests.Metadata.MyVersionedDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_myversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateMyVersionedDocOperation1489495374 - - - // START: QueryOnlyMyVersionedDocSelector1489495374 - public class QueryOnlyMyVersionedDocSelector1489495374 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyMyVersionedDocSelector1489495374(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = _serializer.FromJson(reader, 0); - var version = reader.GetFieldValue(1); - document.Version = version; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(1, token); - document.Version = version; - return document; - } - - } - - // END: QueryOnlyMyVersionedDocSelector1489495374 - - - // START: LightweightMyVersionedDocSelector1489495374 - public class LightweightMyVersionedDocSelector1489495374 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightMyVersionedDocSelector1489495374(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightMyVersionedDocSelector1489495374 - - - // START: IdentityMapMyVersionedDocSelector1489495374 - public class IdentityMapMyVersionedDocSelector1489495374 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapMyVersionedDocSelector1489495374(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapMyVersionedDocSelector1489495374 - - - // START: DirtyTrackingMyVersionedDocSelector1489495374 - public class DirtyTrackingMyVersionedDocSelector1489495374 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingMyVersionedDocSelector1489495374(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Metadata.MyVersionedDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = _serializer.FromJson(reader, 1); - var version = reader.GetFieldValue(2); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Metadata.MyVersionedDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - var version = await reader.GetFieldValueAsync(2, token); - _versions[id] = version; - document.Version = version; - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingMyVersionedDocSelector1489495374 - - - // START: OverwriteMyVersionedDocOperation1489495374 - public class OverwriteMyVersionedDocOperation1489495374 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Metadata.MyVersionedDoc _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public OverwriteMyVersionedDocOperation1489495374(DocumentDbTests.Metadata.MyVersionedDoc document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_overwrite_myversioneddoc(?, ?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session) - { - document.Version = _version; - setCurrentVersionParameter(parameters[0]); - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[1].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[2].Value = _document.GetType().FullName; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[3].Value = document.Id; - setVersionParameter(parameters[4]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - if (postprocessConcurrency(reader, exceptions)) - { - _document.Version = _version; - } - - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - if (await postprocessConcurrencyAsync(reader, exceptions, token)) - { - _document.Version = _version; - } - - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: OverwriteMyVersionedDocOperation1489495374 - - - // START: QueryOnlyMyVersionedDocDocumentStorage1489495374 - public class QueryOnlyMyVersionedDocDocumentStorage1489495374 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyMyVersionedDocDocumentStorage1489495374(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyMyVersionedDocSelector1489495374(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyMyVersionedDocDocumentStorage1489495374 - - - // START: LightweightMyVersionedDocDocumentStorage1489495374 - public class LightweightMyVersionedDocDocumentStorage1489495374 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightMyVersionedDocDocumentStorage1489495374(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightMyVersionedDocSelector1489495374(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightMyVersionedDocDocumentStorage1489495374 - - - // START: IdentityMapMyVersionedDocDocumentStorage1489495374 - public class IdentityMapMyVersionedDocDocumentStorage1489495374 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapMyVersionedDocDocumentStorage1489495374(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapMyVersionedDocSelector1489495374(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapMyVersionedDocDocumentStorage1489495374 - - - // START: DirtyTrackingMyVersionedDocDocumentStorage1489495374 - public class DirtyTrackingMyVersionedDocDocumentStorage1489495374 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingMyVersionedDocDocumentStorage1489495374(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Metadata.MyVersionedDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpdateMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - if (session.Concurrency == Marten.Services.ConcurrencyChecks.Disabled) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - else - { - - return new Marten.Generated.DocumentStorage.UpsertMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - - return new Marten.Generated.DocumentStorage.OverwriteMyVersionedDocOperation1489495374 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override System.Guid Identity(DocumentDbTests.Metadata.MyVersionedDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingMyVersionedDocSelector1489495374(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingMyVersionedDocDocumentStorage1489495374 - - - // START: MyVersionedDocBulkLoader1489495374 - public class MyVersionedDocBulkLoader1489495374 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public MyVersionedDocBulkLoader1489495374(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_myversioneddoc(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_myversioneddoc_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_myversioneddoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_myversioneddoc_temp.\"id\", mt_doc_myversioneddoc_temp.\"data\", mt_doc_myversioneddoc_temp.\"mt_version\", mt_doc_myversioneddoc_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_myversioneddoc_temp left join public.mt_doc_myversioneddoc on mt_doc_myversioneddoc_temp.id = public.mt_doc_myversioneddoc.id where public.mt_doc_myversioneddoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_myversioneddoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_myversioneddoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_myversioneddoc_temp as select * from public.mt_doc_myversioneddoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - - var version = Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(); - writer.Write(version, NpgsqlTypes.NpgsqlDbType.Uuid); - document.Version = version; - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Metadata.MyVersionedDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - - var version = Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(); - writer.Write(version, NpgsqlTypes.NpgsqlDbType.Uuid); - document.Version = version; - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: MyVersionedDocBulkLoader1489495374 - - - // START: MyVersionedDocProvider1489495374 - public class MyVersionedDocProvider1489495374 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public MyVersionedDocProvider1489495374(Marten.Schema.DocumentMapping mapping) : base(new MyVersionedDocBulkLoader1489495374(new QueryOnlyMyVersionedDocDocumentStorage1489495374(mapping)), new QueryOnlyMyVersionedDocDocumentStorage1489495374(mapping), new LightweightMyVersionedDocDocumentStorage1489495374(mapping), new IdentityMapMyVersionedDocDocumentStorage1489495374(mapping), new DirtyTrackingMyVersionedDocDocumentStorage1489495374(mapping)) - { - _mapping = mapping; - } - - - } - - // END: MyVersionedDocProvider1489495374 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/NonStandardDocProvider1732698282.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/NonStandardDocProvider1732698282.cs deleted file mode 100644 index 93945c009ec..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/NonStandardDocProvider1732698282.cs +++ /dev/null @@ -1,878 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Writing.Identity; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertNonStandardDocOperation1732698282 - public class UpsertNonStandardDocOperation1732698282 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Writing.Identity.NonStandardDoc _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertNonStandardDocOperation1732698282(DocumentDbTests.Writing.Identity.NonStandardDoc document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_nonstandarddoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Name != null) - { - parameters[2].Value = document.Name; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertNonStandardDocOperation1732698282 - - - // START: InsertNonStandardDocOperation1732698282 - public class InsertNonStandardDocOperation1732698282 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Writing.Identity.NonStandardDoc _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertNonStandardDocOperation1732698282(DocumentDbTests.Writing.Identity.NonStandardDoc document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_nonstandarddoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Name != null) - { - parameters[2].Value = document.Name; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertNonStandardDocOperation1732698282 - - - // START: UpdateNonStandardDocOperation1732698282 - public class UpdateNonStandardDocOperation1732698282 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Writing.Identity.NonStandardDoc _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateNonStandardDocOperation1732698282(DocumentDbTests.Writing.Identity.NonStandardDoc document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_nonstandarddoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Name != null) - { - parameters[2].Value = document.Name; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateNonStandardDocOperation1732698282 - - - // START: QueryOnlyNonStandardDocSelector1732698282 - public class QueryOnlyNonStandardDocSelector1732698282 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyNonStandardDocSelector1732698282(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.Identity.NonStandardDoc Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyNonStandardDocSelector1732698282 - - - // START: LightweightNonStandardDocSelector1732698282 - public class LightweightNonStandardDocSelector1732698282 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightNonStandardDocSelector1732698282(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.Identity.NonStandardDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightNonStandardDocSelector1732698282 - - - // START: IdentityMapNonStandardDocSelector1732698282 - public class IdentityMapNonStandardDocSelector1732698282 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapNonStandardDocSelector1732698282(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.Identity.NonStandardDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapNonStandardDocSelector1732698282 - - - // START: DirtyTrackingNonStandardDocSelector1732698282 - public class DirtyTrackingNonStandardDocSelector1732698282 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingNonStandardDocSelector1732698282(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.Identity.NonStandardDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.Identity.NonStandardDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingNonStandardDocSelector1732698282 - - - // START: QueryOnlyNonStandardDocDocumentStorage1732698282 - public class QueryOnlyNonStandardDocDocumentStorage1732698282 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyNonStandardDocDocumentStorage1732698282(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Writing.Identity.NonStandardDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Name)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Name; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Writing.Identity.NonStandardDoc document) - { - return document.Name; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyNonStandardDocSelector1732698282(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyNonStandardDocDocumentStorage1732698282 - - - // START: LightweightNonStandardDocDocumentStorage1732698282 - public class LightweightNonStandardDocDocumentStorage1732698282 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightNonStandardDocDocumentStorage1732698282(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Writing.Identity.NonStandardDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Name)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Name; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Writing.Identity.NonStandardDoc document) - { - return document.Name; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightNonStandardDocSelector1732698282(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightNonStandardDocDocumentStorage1732698282 - - - // START: IdentityMapNonStandardDocDocumentStorage1732698282 - public class IdentityMapNonStandardDocDocumentStorage1732698282 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapNonStandardDocDocumentStorage1732698282(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Writing.Identity.NonStandardDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Name)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Name; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Writing.Identity.NonStandardDoc document) - { - return document.Name; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapNonStandardDocSelector1732698282(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapNonStandardDocDocumentStorage1732698282 - - - // START: DirtyTrackingNonStandardDocDocumentStorage1732698282 - public class DirtyTrackingNonStandardDocDocumentStorage1732698282 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingNonStandardDocDocumentStorage1732698282(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Writing.Identity.NonStandardDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Name)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Name; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertNonStandardDocOperation1732698282 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Writing.Identity.NonStandardDoc document) - { - return document.Name; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingNonStandardDocSelector1732698282(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingNonStandardDocDocumentStorage1732698282 - - - // START: NonStandardDocBulkLoader1732698282 - public class NonStandardDocBulkLoader1732698282 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public NonStandardDocBulkLoader1732698282(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_nonstandarddoc(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_nonstandarddoc_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_nonstandarddoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_nonstandarddoc_temp.\"id\", mt_doc_nonstandarddoc_temp.\"data\", mt_doc_nonstandarddoc_temp.\"mt_version\", mt_doc_nonstandarddoc_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_nonstandarddoc_temp left join public.mt_doc_nonstandarddoc on mt_doc_nonstandarddoc_temp.id = public.mt_doc_nonstandarddoc.id where public.mt_doc_nonstandarddoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_nonstandarddoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_nonstandarddoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_nonstandarddoc_temp as select * from public.mt_doc_nonstandarddoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Name, NpgsqlTypes.NpgsqlDbType.Text); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Writing.Identity.NonStandardDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Name, NpgsqlTypes.NpgsqlDbType.Text, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: NonStandardDocBulkLoader1732698282 - - - // START: NonStandardDocProvider1732698282 - public class NonStandardDocProvider1732698282 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public NonStandardDocProvider1732698282(Marten.Schema.DocumentMapping mapping) : base(new NonStandardDocBulkLoader1732698282(new QueryOnlyNonStandardDocDocumentStorage1732698282(mapping)), new QueryOnlyNonStandardDocDocumentStorage1732698282(mapping), new LightweightNonStandardDocDocumentStorage1732698282(mapping), new IdentityMapNonStandardDocDocumentStorage1732698282(mapping), new DirtyTrackingNonStandardDocDocumentStorage1732698282(mapping)) - { - _mapping = mapping; - } - - - } - - // END: NonStandardDocProvider1732698282 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/PaginationTestDocumentProvider1855354059.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/PaginationTestDocumentProvider1855354059.cs deleted file mode 100644 index ddb50b1204d..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/PaginationTestDocumentProvider1855354059.cs +++ /dev/null @@ -1,878 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertPaginationTestDocumentOperation1855354059 - public class UpsertPaginationTestDocumentOperation1855354059 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.PaginationTestDocument _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertPaginationTestDocumentOperation1855354059(DocumentDbTests.Reading.Linq.PaginationTestDocument document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_paginationtestdocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertPaginationTestDocumentOperation1855354059 - - - // START: InsertPaginationTestDocumentOperation1855354059 - public class InsertPaginationTestDocumentOperation1855354059 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.PaginationTestDocument _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertPaginationTestDocumentOperation1855354059(DocumentDbTests.Reading.Linq.PaginationTestDocument document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_paginationtestdocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertPaginationTestDocumentOperation1855354059 - - - // START: UpdatePaginationTestDocumentOperation1855354059 - public class UpdatePaginationTestDocumentOperation1855354059 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.PaginationTestDocument _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdatePaginationTestDocumentOperation1855354059(DocumentDbTests.Reading.Linq.PaginationTestDocument document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_paginationtestdocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdatePaginationTestDocumentOperation1855354059 - - - // START: QueryOnlyPaginationTestDocumentSelector1855354059 - public class QueryOnlyPaginationTestDocumentSelector1855354059 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyPaginationTestDocumentSelector1855354059(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.PaginationTestDocument Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyPaginationTestDocumentSelector1855354059 - - - // START: LightweightPaginationTestDocumentSelector1855354059 - public class LightweightPaginationTestDocumentSelector1855354059 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightPaginationTestDocumentSelector1855354059(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.PaginationTestDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightPaginationTestDocumentSelector1855354059 - - - // START: IdentityMapPaginationTestDocumentSelector1855354059 - public class IdentityMapPaginationTestDocumentSelector1855354059 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapPaginationTestDocumentSelector1855354059(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.PaginationTestDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapPaginationTestDocumentSelector1855354059 - - - // START: DirtyTrackingPaginationTestDocumentSelector1855354059 - public class DirtyTrackingPaginationTestDocumentSelector1855354059 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingPaginationTestDocumentSelector1855354059(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.PaginationTestDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.PaginationTestDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingPaginationTestDocumentSelector1855354059 - - - // START: QueryOnlyPaginationTestDocumentDocumentStorage1855354059 - public class QueryOnlyPaginationTestDocumentDocumentStorage1855354059 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyPaginationTestDocumentDocumentStorage1855354059(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Reading.Linq.PaginationTestDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Reading.Linq.PaginationTestDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyPaginationTestDocumentSelector1855354059(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyPaginationTestDocumentDocumentStorage1855354059 - - - // START: LightweightPaginationTestDocumentDocumentStorage1855354059 - public class LightweightPaginationTestDocumentDocumentStorage1855354059 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightPaginationTestDocumentDocumentStorage1855354059(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Reading.Linq.PaginationTestDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Reading.Linq.PaginationTestDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightPaginationTestDocumentSelector1855354059(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightPaginationTestDocumentDocumentStorage1855354059 - - - // START: IdentityMapPaginationTestDocumentDocumentStorage1855354059 - public class IdentityMapPaginationTestDocumentDocumentStorage1855354059 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapPaginationTestDocumentDocumentStorage1855354059(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Reading.Linq.PaginationTestDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Reading.Linq.PaginationTestDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapPaginationTestDocumentSelector1855354059(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapPaginationTestDocumentDocumentStorage1855354059 - - - // START: DirtyTrackingPaginationTestDocumentDocumentStorage1855354059 - public class DirtyTrackingPaginationTestDocumentDocumentStorage1855354059 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingPaginationTestDocumentDocumentStorage1855354059(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(DocumentDbTests.Reading.Linq.PaginationTestDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPaginationTestDocumentOperation1855354059 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(DocumentDbTests.Reading.Linq.PaginationTestDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingPaginationTestDocumentSelector1855354059(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingPaginationTestDocumentDocumentStorage1855354059 - - - // START: PaginationTestDocumentBulkLoader1855354059 - public class PaginationTestDocumentBulkLoader1855354059 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public PaginationTestDocumentBulkLoader1855354059(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_paginationtestdocument(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_paginationtestdocument_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_paginationtestdocument (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_paginationtestdocument_temp.\"id\", mt_doc_paginationtestdocument_temp.\"data\", mt_doc_paginationtestdocument_temp.\"mt_version\", mt_doc_paginationtestdocument_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_paginationtestdocument_temp left join public.mt_doc_paginationtestdocument on mt_doc_paginationtestdocument_temp.id = public.mt_doc_paginationtestdocument.id where public.mt_doc_paginationtestdocument.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_paginationtestdocument target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_paginationtestdocument_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_paginationtestdocument_temp as select * from public.mt_doc_paginationtestdocument limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Text); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.PaginationTestDocument document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Text, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: PaginationTestDocumentBulkLoader1855354059 - - - // START: PaginationTestDocumentProvider1855354059 - public class PaginationTestDocumentProvider1855354059 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public PaginationTestDocumentProvider1855354059(Marten.Schema.DocumentMapping mapping) : base(new PaginationTestDocumentBulkLoader1855354059(new QueryOnlyPaginationTestDocumentDocumentStorage1855354059(mapping)), new QueryOnlyPaginationTestDocumentDocumentStorage1855354059(mapping), new LightweightPaginationTestDocumentDocumentStorage1855354059(mapping), new IdentityMapPaginationTestDocumentDocumentStorage1855354059(mapping), new DirtyTrackingPaginationTestDocumentDocumentStorage1855354059(mapping)) - { - _mapping = mapping; - } - - - } - - // END: PaginationTestDocumentProvider1855354059 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/PlayerProvider1707213853.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/PlayerProvider1707213853.cs deleted file mode 100644 index 4504a8d2c9d..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/PlayerProvider1707213853.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertPlayerOperation1707213853 - public class UpsertPlayerOperation1707213853 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.Player _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertPlayerOperation1707213853(DocumentDbTests.Reading.Linq.Player document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_player(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertPlayerOperation1707213853 - - - // START: InsertPlayerOperation1707213853 - public class InsertPlayerOperation1707213853 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.Player _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertPlayerOperation1707213853(DocumentDbTests.Reading.Linq.Player document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_player(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertPlayerOperation1707213853 - - - // START: UpdatePlayerOperation1707213853 - public class UpdatePlayerOperation1707213853 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.Player _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdatePlayerOperation1707213853(DocumentDbTests.Reading.Linq.Player document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_player(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdatePlayerOperation1707213853 - - - // START: QueryOnlyPlayerSelector1707213853 - public class QueryOnlyPlayerSelector1707213853 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyPlayerSelector1707213853(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Player Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.Player document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.Player document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyPlayerSelector1707213853 - - - // START: LightweightPlayerSelector1707213853 - public class LightweightPlayerSelector1707213853 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightPlayerSelector1707213853(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Player Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.Player document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.Player document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightPlayerSelector1707213853 - - - // START: IdentityMapPlayerSelector1707213853 - public class IdentityMapPlayerSelector1707213853 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapPlayerSelector1707213853(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Player Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Player document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Player document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapPlayerSelector1707213853 - - - // START: DirtyTrackingPlayerSelector1707213853 - public class DirtyTrackingPlayerSelector1707213853 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingPlayerSelector1707213853(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Player Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Player document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Player document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingPlayerSelector1707213853 - - - // START: QueryOnlyPlayerDocumentStorage1707213853 - public class QueryOnlyPlayerDocumentStorage1707213853 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyPlayerDocumentStorage1707213853(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Player document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Player document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyPlayerSelector1707213853(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyPlayerDocumentStorage1707213853 - - - // START: LightweightPlayerDocumentStorage1707213853 - public class LightweightPlayerDocumentStorage1707213853 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightPlayerDocumentStorage1707213853(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Player document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Player document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightPlayerSelector1707213853(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightPlayerDocumentStorage1707213853 - - - // START: IdentityMapPlayerDocumentStorage1707213853 - public class IdentityMapPlayerDocumentStorage1707213853 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapPlayerDocumentStorage1707213853(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Player document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Player document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapPlayerSelector1707213853(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapPlayerDocumentStorage1707213853 - - - // START: DirtyTrackingPlayerDocumentStorage1707213853 - public class DirtyTrackingPlayerDocumentStorage1707213853 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingPlayerDocumentStorage1707213853(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Player document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdatePlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertPlayerOperation1707213853 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Player document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Player document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingPlayerSelector1707213853(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingPlayerDocumentStorage1707213853 - - - // START: PlayerBulkLoader1707213853 - public class PlayerBulkLoader1707213853 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public PlayerBulkLoader1707213853(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_player(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_player_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_player (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_player_temp.\"id\", mt_doc_player_temp.\"data\", mt_doc_player_temp.\"mt_version\", mt_doc_player_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_player_temp left join public.mt_doc_player on mt_doc_player_temp.id = public.mt_doc_player.id where public.mt_doc_player.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_player target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_player_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_player_temp as select * from public.mt_doc_player limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.Player document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.Player document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: PlayerBulkLoader1707213853 - - - // START: PlayerProvider1707213853 - public class PlayerProvider1707213853 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public PlayerProvider1707213853(Marten.Schema.DocumentMapping mapping) : base(new PlayerBulkLoader1707213853(new QueryOnlyPlayerDocumentStorage1707213853(mapping)), new QueryOnlyPlayerDocumentStorage1707213853(mapping), new LightweightPlayerDocumentStorage1707213853(mapping), new IdentityMapPlayerDocumentStorage1707213853(mapping), new DirtyTrackingPlayerDocumentStorage1707213853(mapping)) - { - _mapping = mapping; - } - - - } - - // END: PlayerProvider1707213853 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductProvider1360380871.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductProvider1360380871.cs deleted file mode 100644 index 51af8b23184..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductProvider1360380871.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertProductOperation1360380871 - public class UpsertProductOperation1360380871 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.Product _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertProductOperation1360380871(DocumentDbTests.Reading.Linq.Product document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_product(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertProductOperation1360380871 - - - // START: InsertProductOperation1360380871 - public class InsertProductOperation1360380871 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.Product _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertProductOperation1360380871(DocumentDbTests.Reading.Linq.Product document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_product(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertProductOperation1360380871 - - - // START: UpdateProductOperation1360380871 - public class UpdateProductOperation1360380871 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.Product _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateProductOperation1360380871(DocumentDbTests.Reading.Linq.Product document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_product(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateProductOperation1360380871 - - - // START: QueryOnlyProductSelector1360380871 - public class QueryOnlyProductSelector1360380871 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyProductSelector1360380871(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Product Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.Product document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.Product document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyProductSelector1360380871 - - - // START: LightweightProductSelector1360380871 - public class LightweightProductSelector1360380871 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightProductSelector1360380871(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Product Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.Product document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.Product document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightProductSelector1360380871 - - - // START: IdentityMapProductSelector1360380871 - public class IdentityMapProductSelector1360380871 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapProductSelector1360380871(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Product Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Product document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Product document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapProductSelector1360380871 - - - // START: DirtyTrackingProductSelector1360380871 - public class DirtyTrackingProductSelector1360380871 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingProductSelector1360380871(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.Product Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Product document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.Product document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingProductSelector1360380871 - - - // START: QueryOnlyProductDocumentStorage1360380871 - public class QueryOnlyProductDocumentStorage1360380871 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyProductDocumentStorage1360380871(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Product document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Product document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyProductSelector1360380871(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyProductDocumentStorage1360380871 - - - // START: LightweightProductDocumentStorage1360380871 - public class LightweightProductDocumentStorage1360380871 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightProductDocumentStorage1360380871(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Product document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Product document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightProductSelector1360380871(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightProductDocumentStorage1360380871 - - - // START: IdentityMapProductDocumentStorage1360380871 - public class IdentityMapProductDocumentStorage1360380871 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapProductDocumentStorage1360380871(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Product document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Product document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapProductSelector1360380871(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapProductDocumentStorage1360380871 - - - // START: DirtyTrackingProductDocumentStorage1360380871 - public class DirtyTrackingProductDocumentStorage1360380871 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingProductDocumentStorage1360380871(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.Product document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductOperation1360380871 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.Product document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.Product document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingProductSelector1360380871(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingProductDocumentStorage1360380871 - - - // START: ProductBulkLoader1360380871 - public class ProductBulkLoader1360380871 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public ProductBulkLoader1360380871(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_product(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_product_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_product (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_product_temp.\"id\", mt_doc_product_temp.\"data\", mt_doc_product_temp.\"mt_version\", mt_doc_product_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_product_temp left join public.mt_doc_product on mt_doc_product_temp.id = public.mt_doc_product.id where public.mt_doc_product.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_product target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_product_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_product_temp as select * from public.mt_doc_product limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.Product document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.Product document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: ProductBulkLoader1360380871 - - - // START: ProductProvider1360380871 - public class ProductProvider1360380871 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public ProductProvider1360380871(Marten.Schema.DocumentMapping mapping) : base(new ProductBulkLoader1360380871(new QueryOnlyProductDocumentStorage1360380871(mapping)), new QueryOnlyProductDocumentStorage1360380871(mapping), new LightweightProductDocumentStorage1360380871(mapping), new IdentityMapProductDocumentStorage1360380871(mapping), new DirtyTrackingProductDocumentStorage1360380871(mapping)) - { - _mapping = mapping; - } - - - } - - // END: ProductProvider1360380871 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithListProvider1228310865.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithListProvider1228310865.cs deleted file mode 100644 index b0dfefbc48c..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithListProvider1228310865.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertProductWithListOperation1228310865 - public class UpsertProductWithListOperation1228310865 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.ProductWithList _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertProductWithListOperation1228310865(DocumentDbTests.Reading.Linq.ProductWithList document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_productwithlist(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertProductWithListOperation1228310865 - - - // START: InsertProductWithListOperation1228310865 - public class InsertProductWithListOperation1228310865 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.ProductWithList _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertProductWithListOperation1228310865(DocumentDbTests.Reading.Linq.ProductWithList document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_productwithlist(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertProductWithListOperation1228310865 - - - // START: UpdateProductWithListOperation1228310865 - public class UpdateProductWithListOperation1228310865 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.ProductWithList _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateProductWithListOperation1228310865(DocumentDbTests.Reading.Linq.ProductWithList document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_productwithlist(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateProductWithListOperation1228310865 - - - // START: QueryOnlyProductWithListSelector1228310865 - public class QueryOnlyProductWithListSelector1228310865 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyProductWithListSelector1228310865(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithList Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyProductWithListSelector1228310865 - - - // START: LightweightProductWithListSelector1228310865 - public class LightweightProductWithListSelector1228310865 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightProductWithListSelector1228310865(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithList Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightProductWithListSelector1228310865 - - - // START: IdentityMapProductWithListSelector1228310865 - public class IdentityMapProductWithListSelector1228310865 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapProductWithListSelector1228310865(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithList Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapProductWithListSelector1228310865 - - - // START: DirtyTrackingProductWithListSelector1228310865 - public class DirtyTrackingProductWithListSelector1228310865 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingProductWithListSelector1228310865(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithList Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithList document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingProductWithListSelector1228310865 - - - // START: QueryOnlyProductWithListDocumentStorage1228310865 - public class QueryOnlyProductWithListDocumentStorage1228310865 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyProductWithListDocumentStorage1228310865(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithList document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithList document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyProductWithListSelector1228310865(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyProductWithListDocumentStorage1228310865 - - - // START: LightweightProductWithListDocumentStorage1228310865 - public class LightweightProductWithListDocumentStorage1228310865 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightProductWithListDocumentStorage1228310865(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithList document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithList document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightProductWithListSelector1228310865(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightProductWithListDocumentStorage1228310865 - - - // START: IdentityMapProductWithListDocumentStorage1228310865 - public class IdentityMapProductWithListDocumentStorage1228310865 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapProductWithListDocumentStorage1228310865(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithList document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithList document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapProductWithListSelector1228310865(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapProductWithListDocumentStorage1228310865 - - - // START: DirtyTrackingProductWithListDocumentStorage1228310865 - public class DirtyTrackingProductWithListDocumentStorage1228310865 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingProductWithListDocumentStorage1228310865(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithList document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithListOperation1228310865 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithList document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingProductWithListSelector1228310865(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingProductWithListDocumentStorage1228310865 - - - // START: ProductWithListBulkLoader1228310865 - public class ProductWithListBulkLoader1228310865 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public ProductWithListBulkLoader1228310865(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_productwithlist(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_productwithlist_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_productwithlist (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_productwithlist_temp.\"id\", mt_doc_productwithlist_temp.\"data\", mt_doc_productwithlist_temp.\"mt_version\", mt_doc_productwithlist_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_productwithlist_temp left join public.mt_doc_productwithlist on mt_doc_productwithlist_temp.id = public.mt_doc_productwithlist.id where public.mt_doc_productwithlist.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_productwithlist target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_productwithlist_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_productwithlist_temp as select * from public.mt_doc_productwithlist limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.ProductWithList document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: ProductWithListBulkLoader1228310865 - - - // START: ProductWithListProvider1228310865 - public class ProductWithListProvider1228310865 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public ProductWithListProvider1228310865(Marten.Schema.DocumentMapping mapping) : base(new ProductWithListBulkLoader1228310865(new QueryOnlyProductWithListDocumentStorage1228310865(mapping)), new QueryOnlyProductWithListDocumentStorage1228310865(mapping), new LightweightProductWithListDocumentStorage1228310865(mapping), new IdentityMapProductWithListDocumentStorage1228310865(mapping), new DirtyTrackingProductWithListDocumentStorage1228310865(mapping)) - { - _mapping = mapping; - } - - - } - - // END: ProductWithListProvider1228310865 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithNumbersProvider1463839245.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithNumbersProvider1463839245.cs deleted file mode 100644 index 47f2c148b12..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/ProductWithNumbersProvider1463839245.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertProductWithNumbersOperation1463839245 - public class UpsertProductWithNumbersOperation1463839245 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.ProductWithNumbers _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertProductWithNumbersOperation1463839245(DocumentDbTests.Reading.Linq.ProductWithNumbers document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_productwithnumbers(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertProductWithNumbersOperation1463839245 - - - // START: InsertProductWithNumbersOperation1463839245 - public class InsertProductWithNumbersOperation1463839245 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.ProductWithNumbers _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertProductWithNumbersOperation1463839245(DocumentDbTests.Reading.Linq.ProductWithNumbers document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_productwithnumbers(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertProductWithNumbersOperation1463839245 - - - // START: UpdateProductWithNumbersOperation1463839245 - public class UpdateProductWithNumbersOperation1463839245 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.ProductWithNumbers _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateProductWithNumbersOperation1463839245(DocumentDbTests.Reading.Linq.ProductWithNumbers document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_productwithnumbers(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateProductWithNumbersOperation1463839245 - - - // START: QueryOnlyProductWithNumbersSelector1463839245 - public class QueryOnlyProductWithNumbersSelector1463839245 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyProductWithNumbersSelector1463839245(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithNumbers Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyProductWithNumbersSelector1463839245 - - - // START: LightweightProductWithNumbersSelector1463839245 - public class LightweightProductWithNumbersSelector1463839245 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightProductWithNumbersSelector1463839245(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithNumbers Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightProductWithNumbersSelector1463839245 - - - // START: IdentityMapProductWithNumbersSelector1463839245 - public class IdentityMapProductWithNumbersSelector1463839245 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapProductWithNumbersSelector1463839245(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithNumbers Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapProductWithNumbersSelector1463839245 - - - // START: DirtyTrackingProductWithNumbersSelector1463839245 - public class DirtyTrackingProductWithNumbersSelector1463839245 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingProductWithNumbersSelector1463839245(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.ProductWithNumbers Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.ProductWithNumbers document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingProductWithNumbersSelector1463839245 - - - // START: QueryOnlyProductWithNumbersDocumentStorage1463839245 - public class QueryOnlyProductWithNumbersDocumentStorage1463839245 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyProductWithNumbersDocumentStorage1463839245(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithNumbers document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithNumbers document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyProductWithNumbersSelector1463839245(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyProductWithNumbersDocumentStorage1463839245 - - - // START: LightweightProductWithNumbersDocumentStorage1463839245 - public class LightweightProductWithNumbersDocumentStorage1463839245 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightProductWithNumbersDocumentStorage1463839245(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithNumbers document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithNumbers document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightProductWithNumbersSelector1463839245(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightProductWithNumbersDocumentStorage1463839245 - - - // START: IdentityMapProductWithNumbersDocumentStorage1463839245 - public class IdentityMapProductWithNumbersDocumentStorage1463839245 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapProductWithNumbersDocumentStorage1463839245(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithNumbers document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithNumbers document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapProductWithNumbersSelector1463839245(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapProductWithNumbersDocumentStorage1463839245 - - - // START: DirtyTrackingProductWithNumbersDocumentStorage1463839245 - public class DirtyTrackingProductWithNumbersDocumentStorage1463839245 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingProductWithNumbersDocumentStorage1463839245(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.ProductWithNumbers document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertProductWithNumbersOperation1463839245 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.ProductWithNumbers document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingProductWithNumbersSelector1463839245(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingProductWithNumbersDocumentStorage1463839245 - - - // START: ProductWithNumbersBulkLoader1463839245 - public class ProductWithNumbersBulkLoader1463839245 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public ProductWithNumbersBulkLoader1463839245(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_productwithnumbers(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_productwithnumbers_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_productwithnumbers (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_productwithnumbers_temp.\"id\", mt_doc_productwithnumbers_temp.\"data\", mt_doc_productwithnumbers_temp.\"mt_version\", mt_doc_productwithnumbers_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_productwithnumbers_temp left join public.mt_doc_productwithnumbers on mt_doc_productwithnumbers_temp.id = public.mt_doc_productwithnumbers.id where public.mt_doc_productwithnumbers.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_productwithnumbers target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_productwithnumbers_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_productwithnumbers_temp as select * from public.mt_doc_productwithnumbers limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.ProductWithNumbers document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: ProductWithNumbersBulkLoader1463839245 - - - // START: ProductWithNumbersProvider1463839245 - public class ProductWithNumbersProvider1463839245 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public ProductWithNumbersProvider1463839245(Marten.Schema.DocumentMapping mapping) : base(new ProductWithNumbersBulkLoader1463839245(new QueryOnlyProductWithNumbersDocumentStorage1463839245(mapping)), new QueryOnlyProductWithNumbersDocumentStorage1463839245(mapping), new LightweightProductWithNumbersDocumentStorage1463839245(mapping), new IdentityMapProductWithNumbersDocumentStorage1463839245(mapping), new DirtyTrackingProductWithNumbersDocumentStorage1463839245(mapping)) - { - _mapping = mapping; - } - - - } - - // END: ProductWithNumbersProvider1463839245 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider1217791244.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider1217791244.cs deleted file mode 100644 index 1422cbcec71..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider1217791244.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertQueryTargetOperation1217791244 - public class UpsertQueryTargetOperation1217791244 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertQueryTargetOperation1217791244(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_simpleequalsparsertests_querytarget(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertQueryTargetOperation1217791244 - - - // START: InsertQueryTargetOperation1217791244 - public class InsertQueryTargetOperation1217791244 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertQueryTargetOperation1217791244(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_simpleequalsparsertests_querytarget(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertQueryTargetOperation1217791244 - - - // START: UpdateQueryTargetOperation1217791244 - public class UpdateQueryTargetOperation1217791244 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateQueryTargetOperation1217791244(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_simpleequalsparsertests_querytarget(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateQueryTargetOperation1217791244 - - - // START: QueryOnlyQueryTargetSelector1217791244 - public class QueryOnlyQueryTargetSelector1217791244 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyQueryTargetSelector1217791244(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyQueryTargetSelector1217791244 - - - // START: LightweightQueryTargetSelector1217791244 - public class LightweightQueryTargetSelector1217791244 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightQueryTargetSelector1217791244(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightQueryTargetSelector1217791244 - - - // START: IdentityMapQueryTargetSelector1217791244 - public class IdentityMapQueryTargetSelector1217791244 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapQueryTargetSelector1217791244(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapQueryTargetSelector1217791244 - - - // START: DirtyTrackingQueryTargetSelector1217791244 - public class DirtyTrackingQueryTargetSelector1217791244 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingQueryTargetSelector1217791244(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingQueryTargetSelector1217791244 - - - // START: QueryOnlyQueryTargetDocumentStorage1217791244 - public class QueryOnlyQueryTargetDocumentStorage1217791244 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyQueryTargetDocumentStorage1217791244(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyQueryTargetSelector1217791244(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyQueryTargetDocumentStorage1217791244 - - - // START: LightweightQueryTargetDocumentStorage1217791244 - public class LightweightQueryTargetDocumentStorage1217791244 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightQueryTargetDocumentStorage1217791244(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightQueryTargetSelector1217791244(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightQueryTargetDocumentStorage1217791244 - - - // START: IdentityMapQueryTargetDocumentStorage1217791244 - public class IdentityMapQueryTargetDocumentStorage1217791244 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapQueryTargetDocumentStorage1217791244(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapQueryTargetSelector1217791244(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapQueryTargetDocumentStorage1217791244 - - - // START: DirtyTrackingQueryTargetDocumentStorage1217791244 - public class DirtyTrackingQueryTargetDocumentStorage1217791244 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingQueryTargetDocumentStorage1217791244(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation1217791244 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingQueryTargetSelector1217791244(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingQueryTargetDocumentStorage1217791244 - - - // START: QueryTargetBulkLoader1217791244 - public class QueryTargetBulkLoader1217791244 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public QueryTargetBulkLoader1217791244(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_simpleequalsparsertests_querytarget(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_simpleequalsparsertests_querytarget_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_simpleequalsparsertests_querytarget (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_simpleequalsparsertests_querytarget_temp.\"id\", mt_doc_simpleequalsparsertests_querytarget_temp.\"data\", mt_doc_simpleequalsparsertests_querytarget_temp.\"mt_version\", mt_doc_simpleequalsparsertests_querytarget_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_simpleequalsparsertests_querytarget_temp left join public.mt_doc_simpleequalsparsertests_querytarget on mt_doc_simpleequalsparsertests_querytarget_temp.id = public.mt_doc_simpleequalsparsertests_querytarget.id where public.mt_doc_simpleequalsparsertests_querytarget.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_simpleequalsparsertests_querytarget target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_simpleequalsparsertests_querytarget_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_simpleequalsparsertests_querytarget_temp as select * from public.mt_doc_simpleequalsparsertests_querytarget limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.SimpleEqualsParserTests.QueryTarget document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: QueryTargetBulkLoader1217791244 - - - // START: QueryTargetProvider1217791244 - public class QueryTargetProvider1217791244 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryTargetProvider1217791244(Marten.Schema.DocumentMapping mapping) : base(new QueryTargetBulkLoader1217791244(new QueryOnlyQueryTargetDocumentStorage1217791244(mapping)), new QueryOnlyQueryTargetDocumentStorage1217791244(mapping), new LightweightQueryTargetDocumentStorage1217791244(mapping), new IdentityMapQueryTargetDocumentStorage1217791244(mapping), new DirtyTrackingQueryTargetDocumentStorage1217791244(mapping)) - { - _mapping = mapping; - } - - - } - - // END: QueryTargetProvider1217791244 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider535117371.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider535117371.cs deleted file mode 100644 index 575c1a28de1..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/QueryTargetProvider535117371.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertQueryTargetOperation535117371 - public class UpsertQueryTargetOperation535117371 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertQueryTargetOperation535117371(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_simplenotequalsparsertests_querytarget(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertQueryTargetOperation535117371 - - - // START: InsertQueryTargetOperation535117371 - public class InsertQueryTargetOperation535117371 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertQueryTargetOperation535117371(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_simplenotequalsparsertests_querytarget(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertQueryTargetOperation535117371 - - - // START: UpdateQueryTargetOperation535117371 - public class UpdateQueryTargetOperation535117371 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateQueryTargetOperation535117371(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_simplenotequalsparsertests_querytarget(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateQueryTargetOperation535117371 - - - // START: QueryOnlyQueryTargetSelector535117371 - public class QueryOnlyQueryTargetSelector535117371 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyQueryTargetSelector535117371(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyQueryTargetSelector535117371 - - - // START: LightweightQueryTargetSelector535117371 - public class LightweightQueryTargetSelector535117371 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightQueryTargetSelector535117371(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightQueryTargetSelector535117371 - - - // START: IdentityMapQueryTargetSelector535117371 - public class IdentityMapQueryTargetSelector535117371 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapQueryTargetSelector535117371(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapQueryTargetSelector535117371 - - - // START: DirtyTrackingQueryTargetSelector535117371 - public class DirtyTrackingQueryTargetSelector535117371 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingQueryTargetSelector535117371(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingQueryTargetSelector535117371 - - - // START: QueryOnlyQueryTargetDocumentStorage535117371 - public class QueryOnlyQueryTargetDocumentStorage535117371 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyQueryTargetDocumentStorage535117371(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyQueryTargetSelector535117371(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyQueryTargetDocumentStorage535117371 - - - // START: LightweightQueryTargetDocumentStorage535117371 - public class LightweightQueryTargetDocumentStorage535117371 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightQueryTargetDocumentStorage535117371(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightQueryTargetSelector535117371(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightQueryTargetDocumentStorage535117371 - - - // START: IdentityMapQueryTargetDocumentStorage535117371 - public class IdentityMapQueryTargetDocumentStorage535117371 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapQueryTargetDocumentStorage535117371(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapQueryTargetSelector535117371(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapQueryTargetDocumentStorage535117371 - - - // START: DirtyTrackingQueryTargetDocumentStorage535117371 - public class DirtyTrackingQueryTargetDocumentStorage535117371 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingQueryTargetDocumentStorage535117371(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertQueryTargetOperation535117371 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingQueryTargetSelector535117371(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingQueryTargetDocumentStorage535117371 - - - // START: QueryTargetBulkLoader535117371 - public class QueryTargetBulkLoader535117371 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public QueryTargetBulkLoader535117371(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_simplenotequalsparsertests_querytarget(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_simplenotequalsparsertests_querytarget_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_simplenotequalsparsertests_querytarget (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_simplenotequalsparsertests_querytarget_temp.\"id\", mt_doc_simplenotequalsparsertests_querytarget_temp.\"data\", mt_doc_simplenotequalsparsertests_querytarget_temp.\"mt_version\", mt_doc_simplenotequalsparsertests_querytarget_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_simplenotequalsparsertests_querytarget_temp left join public.mt_doc_simplenotequalsparsertests_querytarget on mt_doc_simplenotequalsparsertests_querytarget_temp.id = public.mt_doc_simplenotequalsparsertests_querytarget.id where public.mt_doc_simplenotequalsparsertests_querytarget.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_simplenotequalsparsertests_querytarget target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_simplenotequalsparsertests_querytarget_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_simplenotequalsparsertests_querytarget_temp as select * from public.mt_doc_simplenotequalsparsertests_querytarget limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.SimpleNotEqualsParserTests.QueryTarget document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: QueryTargetBulkLoader535117371 - - - // START: QueryTargetProvider535117371 - public class QueryTargetProvider535117371 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryTargetProvider535117371(Marten.Schema.DocumentMapping mapping) : base(new QueryTargetBulkLoader535117371(new QueryOnlyQueryTargetDocumentStorage535117371(mapping)), new QueryOnlyQueryTargetDocumentStorage535117371(mapping), new LightweightQueryTargetDocumentStorage535117371(mapping), new IdentityMapQueryTargetDocumentStorage535117371(mapping), new DirtyTrackingQueryTargetDocumentStorage535117371(mapping)) - { - _mapping = mapping; - } - - - } - - // END: QueryTargetProvider535117371 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/RecordDocumentProvider1196727384.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/RecordDocumentProvider1196727384.cs deleted file mode 100644 index fcc036ee912..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/RecordDocumentProvider1196727384.cs +++ /dev/null @@ -1,847 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Writing; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertRecordDocumentOperation1196727384 - public class UpsertRecordDocumentOperation1196727384 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Writing.document_inserts.RecordDocument _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertRecordDocumentOperation1196727384(DocumentDbTests.Writing.document_inserts.RecordDocument document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_document_inserts_recorddocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertRecordDocumentOperation1196727384 - - - // START: InsertRecordDocumentOperation1196727384 - public class InsertRecordDocumentOperation1196727384 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Writing.document_inserts.RecordDocument _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertRecordDocumentOperation1196727384(DocumentDbTests.Writing.document_inserts.RecordDocument document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_document_inserts_recorddocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertRecordDocumentOperation1196727384 - - - // START: UpdateRecordDocumentOperation1196727384 - public class UpdateRecordDocumentOperation1196727384 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Writing.document_inserts.RecordDocument _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateRecordDocumentOperation1196727384(DocumentDbTests.Writing.document_inserts.RecordDocument document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_document_inserts_recorddocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateRecordDocumentOperation1196727384 - - - // START: QueryOnlyRecordDocumentSelector1196727384 - public class QueryOnlyRecordDocumentSelector1196727384 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyRecordDocumentSelector1196727384(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.document_inserts.RecordDocument Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyRecordDocumentSelector1196727384 - - - // START: LightweightRecordDocumentSelector1196727384 - public class LightweightRecordDocumentSelector1196727384 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightRecordDocumentSelector1196727384(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.document_inserts.RecordDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightRecordDocumentSelector1196727384 - - - // START: IdentityMapRecordDocumentSelector1196727384 - public class IdentityMapRecordDocumentSelector1196727384 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapRecordDocumentSelector1196727384(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.document_inserts.RecordDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapRecordDocumentSelector1196727384 - - - // START: DirtyTrackingRecordDocumentSelector1196727384 - public class DirtyTrackingRecordDocumentSelector1196727384 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingRecordDocumentSelector1196727384(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Writing.document_inserts.RecordDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Writing.document_inserts.RecordDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingRecordDocumentSelector1196727384 - - - // START: QueryOnlyRecordDocumentDocumentStorage1196727384 - public class QueryOnlyRecordDocumentDocumentStorage1196727384 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyRecordDocumentDocumentStorage1196727384(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Writing.document_inserts.RecordDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Writing.document_inserts.RecordDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyRecordDocumentSelector1196727384(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyRecordDocumentDocumentStorage1196727384 - - - // START: LightweightRecordDocumentDocumentStorage1196727384 - public class LightweightRecordDocumentDocumentStorage1196727384 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightRecordDocumentDocumentStorage1196727384(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Writing.document_inserts.RecordDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Writing.document_inserts.RecordDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightRecordDocumentSelector1196727384(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightRecordDocumentDocumentStorage1196727384 - - - // START: IdentityMapRecordDocumentDocumentStorage1196727384 - public class IdentityMapRecordDocumentDocumentStorage1196727384 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapRecordDocumentDocumentStorage1196727384(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Writing.document_inserts.RecordDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Writing.document_inserts.RecordDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapRecordDocumentSelector1196727384(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapRecordDocumentDocumentStorage1196727384 - - - // START: DirtyTrackingRecordDocumentDocumentStorage1196727384 - public class DirtyTrackingRecordDocumentDocumentStorage1196727384 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingRecordDocumentDocumentStorage1196727384(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Writing.document_inserts.RecordDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRecordDocumentOperation1196727384 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Writing.document_inserts.RecordDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingRecordDocumentSelector1196727384(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingRecordDocumentDocumentStorage1196727384 - - - // START: RecordDocumentBulkLoader1196727384 - public class RecordDocumentBulkLoader1196727384 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public RecordDocumentBulkLoader1196727384(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_document_inserts_recorddocument(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_document_inserts_recorddocument_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_document_inserts_recorddocument (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_document_inserts_recorddocument_temp.\"id\", mt_doc_document_inserts_recorddocument_temp.\"data\", mt_doc_document_inserts_recorddocument_temp.\"mt_version\", mt_doc_document_inserts_recorddocument_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_document_inserts_recorddocument_temp left join public.mt_doc_document_inserts_recorddocument on mt_doc_document_inserts_recorddocument_temp.id = public.mt_doc_document_inserts_recorddocument.id where public.mt_doc_document_inserts_recorddocument.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_document_inserts_recorddocument target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_document_inserts_recorddocument_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_document_inserts_recorddocument_temp as select * from public.mt_doc_document_inserts_recorddocument limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Writing.document_inserts.RecordDocument document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: RecordDocumentBulkLoader1196727384 - - - // START: RecordDocumentProvider1196727384 - public class RecordDocumentProvider1196727384 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public RecordDocumentProvider1196727384(Marten.Schema.DocumentMapping mapping) : base(new RecordDocumentBulkLoader1196727384(new QueryOnlyRecordDocumentDocumentStorage1196727384(mapping)), new QueryOnlyRecordDocumentDocumentStorage1196727384(mapping), new LightweightRecordDocumentDocumentStorage1196727384(mapping), new IdentityMapRecordDocumentDocumentStorage1196727384(mapping), new DirtyTrackingRecordDocumentDocumentStorage1196727384(mapping)) - { - _mapping = mapping; - } - - - } - - // END: RecordDocumentProvider1196727384 - - -} diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/RootProvider493946136.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/RootProvider493946136.cs deleted file mode 100644 index fd56b49533d..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/RootProvider493946136.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertRootOperation493946136 - public class UpsertRootOperation493946136 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertRootOperation493946136(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_bug_1217_order_by_count_of_sub_collection_root(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertRootOperation493946136 - - - // START: InsertRootOperation493946136 - public class InsertRootOperation493946136 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertRootOperation493946136(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_bug_1217_order_by_count_of_sub_collection_root(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertRootOperation493946136 - - - // START: UpdateRootOperation493946136 - public class UpdateRootOperation493946136 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateRootOperation493946136(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_bug_1217_order_by_count_of_sub_collection_root(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateRootOperation493946136 - - - // START: QueryOnlyRootSelector493946136 - public class QueryOnlyRootSelector493946136 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyRootSelector493946136(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyRootSelector493946136 - - - // START: LightweightRootSelector493946136 - public class LightweightRootSelector493946136 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightRootSelector493946136(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightRootSelector493946136 - - - // START: IdentityMapRootSelector493946136 - public class IdentityMapRootSelector493946136 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapRootSelector493946136(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapRootSelector493946136 - - - // START: DirtyTrackingRootSelector493946136 - public class DirtyTrackingRootSelector493946136 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingRootSelector493946136(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingRootSelector493946136 - - - // START: QueryOnlyRootDocumentStorage493946136 - public class QueryOnlyRootDocumentStorage493946136 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyRootDocumentStorage493946136(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyRootSelector493946136(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyRootDocumentStorage493946136 - - - // START: LightweightRootDocumentStorage493946136 - public class LightweightRootDocumentStorage493946136 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightRootDocumentStorage493946136(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightRootSelector493946136(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightRootDocumentStorage493946136 - - - // START: IdentityMapRootDocumentStorage493946136 - public class IdentityMapRootDocumentStorage493946136 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapRootDocumentStorage493946136(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapRootSelector493946136(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapRootDocumentStorage493946136 - - - // START: DirtyTrackingRootDocumentStorage493946136 - public class DirtyTrackingRootDocumentStorage493946136 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingRootDocumentStorage493946136(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRootOperation493946136 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingRootSelector493946136(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingRootDocumentStorage493946136 - - - // START: RootBulkLoader493946136 - public class RootBulkLoader493946136 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public RootBulkLoader493946136(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_bug_1217_order_by_count_of_sub_collection_root(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_bug_1217_order_by_count_of_sub_collection_root (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp.\"id\", mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp.\"data\", mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp.\"mt_version\", mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp left join public.mt_doc_bug_1217_order_by_count_of_sub_collection_root on mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp.id = public.mt_doc_bug_1217_order_by_count_of_sub_collection_root.id where public.mt_doc_bug_1217_order_by_count_of_sub_collection_root.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_bug_1217_order_by_count_of_sub_collection_root target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_bug_1217_order_by_count_of_sub_collection_root_temp as select * from public.mt_doc_bug_1217_order_by_count_of_sub_collection_root limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_1217_order_by_count_of_sub_collection.Root document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: RootBulkLoader493946136 - - - // START: RootProvider493946136 - public class RootProvider493946136 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public RootProvider493946136(Marten.Schema.DocumentMapping mapping) : base(new RootBulkLoader493946136(new QueryOnlyRootDocumentStorage493946136(mapping)), new QueryOnlyRootDocumentStorage493946136(mapping), new LightweightRootDocumentStorage493946136(mapping), new IdentityMapRootDocumentStorage493946136(mapping), new DirtyTrackingRootDocumentStorage493946136(mapping)) - { - _mapping = mapping; - } - - - } - - // END: RootProvider493946136 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/RouteDetailsProvider784762106.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/RouteDetailsProvider784762106.cs deleted file mode 100644 index 7de38b57c4a..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/RouteDetailsProvider784762106.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertRouteDetailsOperation784762106 - public class UpsertRouteDetailsOperation784762106 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.RouteDetails _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertRouteDetailsOperation784762106(DocumentDbTests.Bugs.RouteDetails document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_routedetails(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertRouteDetailsOperation784762106 - - - // START: InsertRouteDetailsOperation784762106 - public class InsertRouteDetailsOperation784762106 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.RouteDetails _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertRouteDetailsOperation784762106(DocumentDbTests.Bugs.RouteDetails document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_routedetails(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertRouteDetailsOperation784762106 - - - // START: UpdateRouteDetailsOperation784762106 - public class UpdateRouteDetailsOperation784762106 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.RouteDetails _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateRouteDetailsOperation784762106(DocumentDbTests.Bugs.RouteDetails document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_routedetails(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateRouteDetailsOperation784762106 - - - // START: QueryOnlyRouteDetailsSelector784762106 - public class QueryOnlyRouteDetailsSelector784762106 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyRouteDetailsSelector784762106(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.RouteDetails Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.RouteDetails document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.RouteDetails document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyRouteDetailsSelector784762106 - - - // START: LightweightRouteDetailsSelector784762106 - public class LightweightRouteDetailsSelector784762106 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightRouteDetailsSelector784762106(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.RouteDetails Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.RouteDetails document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.RouteDetails document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightRouteDetailsSelector784762106 - - - // START: IdentityMapRouteDetailsSelector784762106 - public class IdentityMapRouteDetailsSelector784762106 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapRouteDetailsSelector784762106(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.RouteDetails Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.RouteDetails document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.RouteDetails document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapRouteDetailsSelector784762106 - - - // START: DirtyTrackingRouteDetailsSelector784762106 - public class DirtyTrackingRouteDetailsSelector784762106 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingRouteDetailsSelector784762106(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.RouteDetails Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.RouteDetails document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.RouteDetails document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingRouteDetailsSelector784762106 - - - // START: QueryOnlyRouteDetailsDocumentStorage784762106 - public class QueryOnlyRouteDetailsDocumentStorage784762106 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyRouteDetailsDocumentStorage784762106(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.RouteDetails document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.RouteDetails document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyRouteDetailsSelector784762106(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyRouteDetailsDocumentStorage784762106 - - - // START: LightweightRouteDetailsDocumentStorage784762106 - public class LightweightRouteDetailsDocumentStorage784762106 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightRouteDetailsDocumentStorage784762106(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.RouteDetails document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.RouteDetails document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightRouteDetailsSelector784762106(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightRouteDetailsDocumentStorage784762106 - - - // START: IdentityMapRouteDetailsDocumentStorage784762106 - public class IdentityMapRouteDetailsDocumentStorage784762106 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapRouteDetailsDocumentStorage784762106(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.RouteDetails document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.RouteDetails document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapRouteDetailsSelector784762106(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapRouteDetailsDocumentStorage784762106 - - - // START: DirtyTrackingRouteDetailsDocumentStorage784762106 - public class DirtyTrackingRouteDetailsDocumentStorage784762106 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingRouteDetailsDocumentStorage784762106(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.RouteDetails document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertRouteDetailsOperation784762106 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.RouteDetails document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.RouteDetails document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingRouteDetailsSelector784762106(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingRouteDetailsDocumentStorage784762106 - - - // START: RouteDetailsBulkLoader784762106 - public class RouteDetailsBulkLoader784762106 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public RouteDetailsBulkLoader784762106(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_routedetails(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_routedetails_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_routedetails (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_routedetails_temp.\"id\", mt_doc_routedetails_temp.\"data\", mt_doc_routedetails_temp.\"mt_version\", mt_doc_routedetails_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_routedetails_temp left join public.mt_doc_routedetails on mt_doc_routedetails_temp.id = public.mt_doc_routedetails.id where public.mt_doc_routedetails.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_routedetails target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_routedetails_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_routedetails_temp as select * from public.mt_doc_routedetails limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.RouteDetails document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.RouteDetails document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: RouteDetailsBulkLoader784762106 - - - // START: RouteDetailsProvider784762106 - public class RouteDetailsProvider784762106 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public RouteDetailsProvider784762106(Marten.Schema.DocumentMapping mapping) : base(new RouteDetailsBulkLoader784762106(new QueryOnlyRouteDetailsDocumentStorage784762106(mapping)), new QueryOnlyRouteDetailsDocumentStorage784762106(mapping), new LightweightRouteDetailsDocumentStorage784762106(mapping), new IdentityMapRouteDetailsDocumentStorage784762106(mapping), new DirtyTrackingRouteDetailsDocumentStorage784762106(mapping)) - { - _mapping = mapping; - } - - - } - - // END: RouteDetailsProvider784762106 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/SimpleUserProvider652546491.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/SimpleUserProvider652546491.cs deleted file mode 100644 index e6afcb52dc9..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/SimpleUserProvider652546491.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertSimpleUserOperation652546491 - public class UpsertSimpleUserOperation652546491 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleUser _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertSimpleUserOperation652546491(DocumentDbTests.Reading.Linq.SimpleUser document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_simpleuser(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertSimpleUserOperation652546491 - - - // START: InsertSimpleUserOperation652546491 - public class InsertSimpleUserOperation652546491 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleUser _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertSimpleUserOperation652546491(DocumentDbTests.Reading.Linq.SimpleUser document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_simpleuser(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertSimpleUserOperation652546491 - - - // START: UpdateSimpleUserOperation652546491 - public class UpdateSimpleUserOperation652546491 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.SimpleUser _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateSimpleUserOperation652546491(DocumentDbTests.Reading.Linq.SimpleUser document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_simpleuser(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateSimpleUserOperation652546491 - - - // START: QueryOnlySimpleUserSelector652546491 - public class QueryOnlySimpleUserSelector652546491 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlySimpleUserSelector652546491(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleUser Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlySimpleUserSelector652546491 - - - // START: LightweightSimpleUserSelector652546491 - public class LightweightSimpleUserSelector652546491 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightSimpleUserSelector652546491(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleUser Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightSimpleUserSelector652546491 - - - // START: IdentityMapSimpleUserSelector652546491 - public class IdentityMapSimpleUserSelector652546491 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapSimpleUserSelector652546491(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleUser Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapSimpleUserSelector652546491 - - - // START: DirtyTrackingSimpleUserSelector652546491 - public class DirtyTrackingSimpleUserSelector652546491 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingSimpleUserSelector652546491(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.SimpleUser Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.SimpleUser document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingSimpleUserSelector652546491 - - - // START: QueryOnlySimpleUserDocumentStorage652546491 - public class QueryOnlySimpleUserDocumentStorage652546491 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlySimpleUserDocumentStorage652546491(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleUser document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleUser document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlySimpleUserSelector652546491(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlySimpleUserDocumentStorage652546491 - - - // START: LightweightSimpleUserDocumentStorage652546491 - public class LightweightSimpleUserDocumentStorage652546491 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightSimpleUserDocumentStorage652546491(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleUser document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleUser document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightSimpleUserSelector652546491(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightSimpleUserDocumentStorage652546491 - - - // START: IdentityMapSimpleUserDocumentStorage652546491 - public class IdentityMapSimpleUserDocumentStorage652546491 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapSimpleUserDocumentStorage652546491(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleUser document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleUser document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapSimpleUserSelector652546491(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapSimpleUserDocumentStorage652546491 - - - // START: DirtyTrackingSimpleUserDocumentStorage652546491 - public class DirtyTrackingSimpleUserDocumentStorage652546491 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingSimpleUserDocumentStorage652546491(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.SimpleUser document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertSimpleUserOperation652546491 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.SimpleUser document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingSimpleUserSelector652546491(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingSimpleUserDocumentStorage652546491 - - - // START: SimpleUserBulkLoader652546491 - public class SimpleUserBulkLoader652546491 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public SimpleUserBulkLoader652546491(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_simpleuser(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_simpleuser_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_simpleuser (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_simpleuser_temp.\"id\", mt_doc_simpleuser_temp.\"data\", mt_doc_simpleuser_temp.\"mt_version\", mt_doc_simpleuser_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_simpleuser_temp left join public.mt_doc_simpleuser on mt_doc_simpleuser_temp.id = public.mt_doc_simpleuser.id where public.mt_doc_simpleuser.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_simpleuser target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_simpleuser_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_simpleuser_temp as select * from public.mt_doc_simpleuser limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.SimpleUser document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: SimpleUserBulkLoader652546491 - - - // START: SimpleUserProvider652546491 - public class SimpleUserProvider652546491 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public SimpleUserProvider652546491(Marten.Schema.DocumentMapping mapping) : base(new SimpleUserBulkLoader652546491(new QueryOnlySimpleUserDocumentStorage652546491(mapping)), new QueryOnlySimpleUserDocumentStorage652546491(mapping), new LightweightSimpleUserDocumentStorage652546491(mapping), new IdentityMapSimpleUserDocumentStorage652546491(mapping), new DirtyTrackingSimpleUserDocumentStorage652546491(mapping)) - { - _mapping = mapping; - } - - - } - - // END: SimpleUserProvider652546491 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/StringDocProvider478514312.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/StringDocProvider478514312.cs deleted file mode 100644 index acc1bc38bc8..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/StringDocProvider478514312.cs +++ /dev/null @@ -1,878 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertStringDocOperation478514312 - public class UpsertStringDocOperation478514312 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.StringDoc _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertStringDocOperation478514312(Marten.Testing.Documents.StringDoc document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_stringdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertStringDocOperation478514312 - - - // START: InsertStringDocOperation478514312 - public class InsertStringDocOperation478514312 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.StringDoc _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertStringDocOperation478514312(Marten.Testing.Documents.StringDoc document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_stringdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertStringDocOperation478514312 - - - // START: UpdateStringDocOperation478514312 - public class UpdateStringDocOperation478514312 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.StringDoc _document; - private readonly string _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateStringDocOperation478514312(Marten.Testing.Documents.StringDoc document, string id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_stringdoc(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Text; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - - if (document.Id != null) - { - parameters[2].Value = document.Id; - } - - else - { - parameters[2].Value = System.DBNull.Value; - } - - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateStringDocOperation478514312 - - - // START: QueryOnlyStringDocSelector478514312 - public class QueryOnlyStringDocSelector478514312 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyStringDocSelector478514312(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.StringDoc Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.StringDoc document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.StringDoc document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyStringDocSelector478514312 - - - // START: LightweightStringDocSelector478514312 - public class LightweightStringDocSelector478514312 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightStringDocSelector478514312(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.StringDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.StringDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.StringDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightStringDocSelector478514312 - - - // START: IdentityMapStringDocSelector478514312 - public class IdentityMapStringDocSelector478514312 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapStringDocSelector478514312(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.StringDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.StringDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.StringDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapStringDocSelector478514312 - - - // START: DirtyTrackingStringDocSelector478514312 - public class DirtyTrackingStringDocSelector478514312 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingStringDocSelector478514312(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.StringDoc Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.StringDoc document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.StringDoc document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingStringDocSelector478514312 - - - // START: QueryOnlyStringDocDocumentStorage478514312 - public class QueryOnlyStringDocDocumentStorage478514312 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyStringDocDocumentStorage478514312(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.StringDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.StringDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyStringDocSelector478514312(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyStringDocDocumentStorage478514312 - - - // START: LightweightStringDocDocumentStorage478514312 - public class LightweightStringDocDocumentStorage478514312 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightStringDocDocumentStorage478514312(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.StringDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.StringDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightStringDocSelector478514312(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightStringDocDocumentStorage478514312 - - - // START: IdentityMapStringDocDocumentStorage478514312 - public class IdentityMapStringDocDocumentStorage478514312 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapStringDocDocumentStorage478514312(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.StringDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.StringDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapStringDocSelector478514312(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapStringDocDocumentStorage478514312 - - - // START: DirtyTrackingStringDocDocumentStorage478514312 - public class DirtyTrackingStringDocDocumentStorage478514312 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingStringDocDocumentStorage478514312(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override string AssignIdentity(Marten.Testing.Documents.StringDoc document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (string.IsNullOrEmpty(document.Id)) throw new InvalidOperationException("Id/id values cannot be null or empty"); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertStringDocOperation478514312 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.StringDoc document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override string Identity(Marten.Testing.Documents.StringDoc document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingStringDocSelector478514312(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(string id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.String[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingStringDocDocumentStorage478514312 - - - // START: StringDocBulkLoader478514312 - public class StringDocBulkLoader478514312 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public StringDocBulkLoader478514312(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_stringdoc(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_stringdoc_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_stringdoc (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_stringdoc_temp.\"id\", mt_doc_stringdoc_temp.\"data\", mt_doc_stringdoc_temp.\"mt_version\", mt_doc_stringdoc_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_stringdoc_temp left join public.mt_doc_stringdoc on mt_doc_stringdoc_temp.id = public.mt_doc_stringdoc.id where public.mt_doc_stringdoc.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_stringdoc target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_stringdoc_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_stringdoc_temp as select * from public.mt_doc_stringdoc limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.StringDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Text); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.StringDoc document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Text, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: StringDocBulkLoader478514312 - - - // START: StringDocProvider478514312 - public class StringDocProvider478514312 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public StringDocProvider478514312(Marten.Schema.DocumentMapping mapping) : base(new StringDocBulkLoader478514312(new QueryOnlyStringDocDocumentStorage478514312(mapping)), new QueryOnlyStringDocDocumentStorage478514312(mapping), new LightweightStringDocDocumentStorage478514312(mapping), new IdentityMapStringDocDocumentStorage478514312(mapping), new DirtyTrackingStringDocDocumentStorage478514312(mapping)) - { - _mapping = mapping; - } - - - } - - // END: StringDocProvider478514312 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetGroupProvider723464596.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetGroupProvider723464596.cs deleted file mode 100644 index 41f730864fd..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetGroupProvider723464596.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertTargetGroupOperation723464596 - public class UpsertTargetGroupOperation723464596 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertTargetGroupOperation723464596(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_query_with_select_many_targetgroup(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertTargetGroupOperation723464596 - - - // START: InsertTargetGroupOperation723464596 - public class InsertTargetGroupOperation723464596 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertTargetGroupOperation723464596(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_query_with_select_many_targetgroup(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertTargetGroupOperation723464596 - - - // START: UpdateTargetGroupOperation723464596 - public class UpdateTargetGroupOperation723464596 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateTargetGroupOperation723464596(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_query_with_select_many_targetgroup(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateTargetGroupOperation723464596 - - - // START: QueryOnlyTargetGroupSelector723464596 - public class QueryOnlyTargetGroupSelector723464596 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyTargetGroupSelector723464596(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyTargetGroupSelector723464596 - - - // START: LightweightTargetGroupSelector723464596 - public class LightweightTargetGroupSelector723464596 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightTargetGroupSelector723464596(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightTargetGroupSelector723464596 - - - // START: IdentityMapTargetGroupSelector723464596 - public class IdentityMapTargetGroupSelector723464596 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapTargetGroupSelector723464596(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapTargetGroupSelector723464596 - - - // START: DirtyTrackingTargetGroupSelector723464596 - public class DirtyTrackingTargetGroupSelector723464596 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingTargetGroupSelector723464596(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingTargetGroupSelector723464596 - - - // START: QueryOnlyTargetGroupDocumentStorage723464596 - public class QueryOnlyTargetGroupDocumentStorage723464596 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyTargetGroupDocumentStorage723464596(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyTargetGroupSelector723464596(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyTargetGroupDocumentStorage723464596 - - - // START: LightweightTargetGroupDocumentStorage723464596 - public class LightweightTargetGroupDocumentStorage723464596 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightTargetGroupDocumentStorage723464596(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightTargetGroupSelector723464596(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightTargetGroupDocumentStorage723464596 - - - // START: IdentityMapTargetGroupDocumentStorage723464596 - public class IdentityMapTargetGroupDocumentStorage723464596 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapTargetGroupDocumentStorage723464596(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapTargetGroupSelector723464596(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapTargetGroupDocumentStorage723464596 - - - // START: DirtyTrackingTargetGroupDocumentStorage723464596 - public class DirtyTrackingTargetGroupDocumentStorage723464596 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingTargetGroupDocumentStorage723464596(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetGroupOperation723464596 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingTargetGroupSelector723464596(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingTargetGroupDocumentStorage723464596 - - - // START: TargetGroupBulkLoader723464596 - public class TargetGroupBulkLoader723464596 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public TargetGroupBulkLoader723464596(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_query_with_select_many_targetgroup(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_query_with_select_many_targetgroup_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_query_with_select_many_targetgroup (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_query_with_select_many_targetgroup_temp.\"id\", mt_doc_query_with_select_many_targetgroup_temp.\"data\", mt_doc_query_with_select_many_targetgroup_temp.\"mt_version\", mt_doc_query_with_select_many_targetgroup_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_query_with_select_many_targetgroup_temp left join public.mt_doc_query_with_select_many_targetgroup on mt_doc_query_with_select_many_targetgroup_temp.id = public.mt_doc_query_with_select_many_targetgroup.id where public.mt_doc_query_with_select_many_targetgroup.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_query_with_select_many_targetgroup target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_query_with_select_many_targetgroup_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_query_with_select_many_targetgroup_temp as select * from public.mt_doc_query_with_select_many_targetgroup limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.query_with_select_many.TargetGroup document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: TargetGroupBulkLoader723464596 - - - // START: TargetGroupProvider723464596 - public class TargetGroupProvider723464596 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public TargetGroupProvider723464596(Marten.Schema.DocumentMapping mapping) : base(new TargetGroupBulkLoader723464596(new QueryOnlyTargetGroupDocumentStorage723464596(mapping)), new QueryOnlyTargetGroupDocumentStorage723464596(mapping), new LightweightTargetGroupDocumentStorage723464596(mapping), new IdentityMapTargetGroupDocumentStorage723464596(mapping), new DirtyTrackingTargetGroupDocumentStorage723464596(mapping)) - { - _mapping = mapping; - } - - - } - - // END: TargetGroupProvider723464596 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetProvider1797031270.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetProvider1797031270.cs deleted file mode 100644 index dac6ea44906..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TargetProvider1797031270.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertTargetOperation1797031270 - public class UpsertTargetOperation1797031270 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Target _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertTargetOperation1797031270(Marten.Testing.Documents.Target document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_target(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertTargetOperation1797031270 - - - // START: InsertTargetOperation1797031270 - public class InsertTargetOperation1797031270 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Target _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertTargetOperation1797031270(Marten.Testing.Documents.Target document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_target(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertTargetOperation1797031270 - - - // START: UpdateTargetOperation1797031270 - public class UpdateTargetOperation1797031270 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.Target _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateTargetOperation1797031270(Marten.Testing.Documents.Target document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_target(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateTargetOperation1797031270 - - - // START: QueryOnlyTargetSelector1797031270 - public class QueryOnlyTargetSelector1797031270 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyTargetSelector1797031270(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.Target document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.Target document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyTargetSelector1797031270 - - - // START: LightweightTargetSelector1797031270 - public class LightweightTargetSelector1797031270 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightTargetSelector1797031270(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.Target document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.Target document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightTargetSelector1797031270 - - - // START: IdentityMapTargetSelector1797031270 - public class IdentityMapTargetSelector1797031270 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapTargetSelector1797031270(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Target document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Target document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapTargetSelector1797031270 - - - // START: DirtyTrackingTargetSelector1797031270 - public class DirtyTrackingTargetSelector1797031270 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingTargetSelector1797031270(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.Target Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Target document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.Target document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingTargetSelector1797031270 - - - // START: QueryOnlyTargetDocumentStorage1797031270 - public class QueryOnlyTargetDocumentStorage1797031270 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyTargetDocumentStorage1797031270(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Target document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyTargetSelector1797031270(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyTargetDocumentStorage1797031270 - - - // START: LightweightTargetDocumentStorage1797031270 - public class LightweightTargetDocumentStorage1797031270 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightTargetDocumentStorage1797031270(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Target document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightTargetSelector1797031270(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightTargetDocumentStorage1797031270 - - - // START: IdentityMapTargetDocumentStorage1797031270 - public class IdentityMapTargetDocumentStorage1797031270 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapTargetDocumentStorage1797031270(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Target document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapTargetSelector1797031270(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapTargetDocumentStorage1797031270 - - - // START: DirtyTrackingTargetDocumentStorage1797031270 - public class DirtyTrackingTargetDocumentStorage1797031270 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingTargetDocumentStorage1797031270(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.Target document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTargetOperation1797031270 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.Target document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.Target document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingTargetSelector1797031270(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingTargetDocumentStorage1797031270 - - - // START: TargetBulkLoader1797031270 - public class TargetBulkLoader1797031270 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public TargetBulkLoader1797031270(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_target(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_target_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_target (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_target_temp.\"id\", mt_doc_target_temp.\"data\", mt_doc_target_temp.\"mt_version\", mt_doc_target_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_target_temp left join public.mt_doc_target on mt_doc_target_temp.id = public.mt_doc_target.id where public.mt_doc_target.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_target target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_target_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_target_temp as select * from public.mt_doc_target limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Target document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.Target document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: TargetBulkLoader1797031270 - - - // START: TargetProvider1797031270 - public class TargetProvider1797031270 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public TargetProvider1797031270(Marten.Schema.DocumentMapping mapping) : base(new TargetBulkLoader1797031270(new QueryOnlyTargetDocumentStorage1797031270(mapping)), new QueryOnlyTargetDocumentStorage1797031270(mapping), new LightweightTargetDocumentStorage1797031270(mapping), new IdentityMapTargetDocumentStorage1797031270(mapping), new DirtyTrackingTargetDocumentStorage1797031270(mapping)) - { - _mapping = mapping; - } - - - } - - // END: TargetProvider1797031270 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TaskProvider74835621.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/TaskProvider74835621.cs deleted file mode 100644 index 53669b21a1f..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TaskProvider74835621.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Weird; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertTaskOperation74835621 - public class UpsertTaskOperation74835621 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Weird.Task _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertTaskOperation74835621(Marten.Testing.Weird.Task document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_task(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertTaskOperation74835621 - - - // START: InsertTaskOperation74835621 - public class InsertTaskOperation74835621 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Weird.Task _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertTaskOperation74835621(Marten.Testing.Weird.Task document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_task(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertTaskOperation74835621 - - - // START: UpdateTaskOperation74835621 - public class UpdateTaskOperation74835621 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Weird.Task _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateTaskOperation74835621(Marten.Testing.Weird.Task document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_task(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateTaskOperation74835621 - - - // START: QueryOnlyTaskSelector74835621 - public class QueryOnlyTaskSelector74835621 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyTaskSelector74835621(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Weird.Task Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Weird.Task document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Weird.Task document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyTaskSelector74835621 - - - // START: LightweightTaskSelector74835621 - public class LightweightTaskSelector74835621 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightTaskSelector74835621(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Weird.Task Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Weird.Task document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Weird.Task document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightTaskSelector74835621 - - - // START: IdentityMapTaskSelector74835621 - public class IdentityMapTaskSelector74835621 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapTaskSelector74835621(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Weird.Task Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Weird.Task document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Weird.Task document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapTaskSelector74835621 - - - // START: DirtyTrackingTaskSelector74835621 - public class DirtyTrackingTaskSelector74835621 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingTaskSelector74835621(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Weird.Task Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Weird.Task document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Weird.Task document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingTaskSelector74835621 - - - // START: QueryOnlyTaskDocumentStorage74835621 - public class QueryOnlyTaskDocumentStorage74835621 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyTaskDocumentStorage74835621(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Weird.Task document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Weird.Task document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyTaskSelector74835621(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyTaskDocumentStorage74835621 - - - // START: LightweightTaskDocumentStorage74835621 - public class LightweightTaskDocumentStorage74835621 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightTaskDocumentStorage74835621(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Weird.Task document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Weird.Task document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightTaskSelector74835621(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightTaskDocumentStorage74835621 - - - // START: IdentityMapTaskDocumentStorage74835621 - public class IdentityMapTaskDocumentStorage74835621 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapTaskDocumentStorage74835621(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Weird.Task document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Weird.Task document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapTaskSelector74835621(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapTaskDocumentStorage74835621 - - - // START: DirtyTrackingTaskDocumentStorage74835621 - public class DirtyTrackingTaskDocumentStorage74835621 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingTaskDocumentStorage74835621(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Weird.Task document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTaskOperation74835621 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Weird.Task document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Weird.Task document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingTaskSelector74835621(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingTaskDocumentStorage74835621 - - - // START: TaskBulkLoader74835621 - public class TaskBulkLoader74835621 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public TaskBulkLoader74835621(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_task(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_task_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_task (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_task_temp.\"id\", mt_doc_task_temp.\"data\", mt_doc_task_temp.\"mt_version\", mt_doc_task_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_task_temp left join public.mt_doc_task on mt_doc_task_temp.id = public.mt_doc_task.id where public.mt_doc_task.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_task target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_task_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_task_temp as select * from public.mt_doc_task limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Weird.Task document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Weird.Task document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: TaskBulkLoader74835621 - - - // START: TaskProvider74835621 - public class TaskProvider74835621 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public TaskProvider74835621(Marten.Schema.DocumentMapping mapping) : base(new TaskBulkLoader74835621(new QueryOnlyTaskDocumentStorage74835621(mapping)), new QueryOnlyTaskDocumentStorage74835621(mapping), new LightweightTaskDocumentStorage74835621(mapping), new IdentityMapTaskDocumentStorage74835621(mapping), new DirtyTrackingTaskDocumentStorage74835621(mapping)) - { - _mapping = mapping; - } - - - } - - // END: TaskProvider74835621 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2001772986.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2001772986.cs deleted file mode 100644 index 6a5ce13275c..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2001772986.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Bugs; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertTestClassOperation2001772986 - public class UpsertTestClassOperation2001772986 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertTestClassOperation2001772986(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_bug_849_not_node_not_correctly_evaluated_testclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertTestClassOperation2001772986 - - - // START: InsertTestClassOperation2001772986 - public class InsertTestClassOperation2001772986 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertTestClassOperation2001772986(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_bug_849_not_node_not_correctly_evaluated_testclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertTestClassOperation2001772986 - - - // START: UpdateTestClassOperation2001772986 - public class UpdateTestClassOperation2001772986 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateTestClassOperation2001772986(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_bug_849_not_node_not_correctly_evaluated_testclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateTestClassOperation2001772986 - - - // START: QueryOnlyTestClassSelector2001772986 - public class QueryOnlyTestClassSelector2001772986 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyTestClassSelector2001772986(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyTestClassSelector2001772986 - - - // START: LightweightTestClassSelector2001772986 - public class LightweightTestClassSelector2001772986 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightTestClassSelector2001772986(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightTestClassSelector2001772986 - - - // START: IdentityMapTestClassSelector2001772986 - public class IdentityMapTestClassSelector2001772986 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapTestClassSelector2001772986(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapTestClassSelector2001772986 - - - // START: DirtyTrackingTestClassSelector2001772986 - public class DirtyTrackingTestClassSelector2001772986 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingTestClassSelector2001772986(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingTestClassSelector2001772986 - - - // START: QueryOnlyTestClassDocumentStorage2001772986 - public class QueryOnlyTestClassDocumentStorage2001772986 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyTestClassDocumentStorage2001772986(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyTestClassSelector2001772986(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyTestClassDocumentStorage2001772986 - - - // START: LightweightTestClassDocumentStorage2001772986 - public class LightweightTestClassDocumentStorage2001772986 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightTestClassDocumentStorage2001772986(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightTestClassSelector2001772986(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightTestClassDocumentStorage2001772986 - - - // START: IdentityMapTestClassDocumentStorage2001772986 - public class IdentityMapTestClassDocumentStorage2001772986 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapTestClassDocumentStorage2001772986(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapTestClassSelector2001772986(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapTestClassDocumentStorage2001772986 - - - // START: DirtyTrackingTestClassDocumentStorage2001772986 - public class DirtyTrackingTestClassDocumentStorage2001772986 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingTestClassDocumentStorage2001772986(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2001772986 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingTestClassSelector2001772986(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingTestClassDocumentStorage2001772986 - - - // START: TestClassBulkLoader2001772986 - public class TestClassBulkLoader2001772986 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public TestClassBulkLoader2001772986(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_bug_849_not_node_not_correctly_evaluated_testclass(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_bug_849_not_node_not_correctly_evaluated_testclass (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp.\"id\", mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp.\"data\", mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp.\"mt_version\", mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp left join public.mt_doc_bug_849_not_node_not_correctly_evaluated_testclass on mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp.id = public.mt_doc_bug_849_not_node_not_correctly_evaluated_testclass.id where public.mt_doc_bug_849_not_node_not_correctly_evaluated_testclass.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_bug_849_not_node_not_correctly_evaluated_testclass target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_bug_849_not_node_not_correctly_evaluated_testclass_temp as select * from public.mt_doc_bug_849_not_node_not_correctly_evaluated_testclass limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Bugs.Bug_849_not_node_not_correctly_evaluated.TestClass document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: TestClassBulkLoader2001772986 - - - // START: TestClassProvider2001772986 - public class TestClassProvider2001772986 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public TestClassProvider2001772986(Marten.Schema.DocumentMapping mapping) : base(new TestClassBulkLoader2001772986(new QueryOnlyTestClassDocumentStorage2001772986(mapping)), new QueryOnlyTestClassDocumentStorage2001772986(mapping), new LightweightTestClassDocumentStorage2001772986(mapping), new IdentityMapTestClassDocumentStorage2001772986(mapping), new DirtyTrackingTestClassDocumentStorage2001772986(mapping)) - { - _mapping = mapping; - } - - - } - - // END: TestClassProvider2001772986 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2042192398.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2042192398.cs deleted file mode 100644 index 0e17be96323..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TestClassProvider2042192398.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertTestClassOperation2042192398 - public class UpsertTestClassOperation2042192398 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertTestClassOperation2042192398(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_boolnotvisitortests_testclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertTestClassOperation2042192398 - - - // START: InsertTestClassOperation2042192398 - public class InsertTestClassOperation2042192398 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertTestClassOperation2042192398(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_boolnotvisitortests_testclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertTestClassOperation2042192398 - - - // START: UpdateTestClassOperation2042192398 - public class UpdateTestClassOperation2042192398 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateTestClassOperation2042192398(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_boolnotvisitortests_testclass(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateTestClassOperation2042192398 - - - // START: QueryOnlyTestClassSelector2042192398 - public class QueryOnlyTestClassSelector2042192398 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyTestClassSelector2042192398(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyTestClassSelector2042192398 - - - // START: LightweightTestClassSelector2042192398 - public class LightweightTestClassSelector2042192398 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightTestClassSelector2042192398(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightTestClassSelector2042192398 - - - // START: IdentityMapTestClassSelector2042192398 - public class IdentityMapTestClassSelector2042192398 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapTestClassSelector2042192398(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapTestClassSelector2042192398 - - - // START: DirtyTrackingTestClassSelector2042192398 - public class DirtyTrackingTestClassSelector2042192398 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingTestClassSelector2042192398(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingTestClassSelector2042192398 - - - // START: QueryOnlyTestClassDocumentStorage2042192398 - public class QueryOnlyTestClassDocumentStorage2042192398 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyTestClassDocumentStorage2042192398(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyTestClassSelector2042192398(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyTestClassDocumentStorage2042192398 - - - // START: LightweightTestClassDocumentStorage2042192398 - public class LightweightTestClassDocumentStorage2042192398 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightTestClassDocumentStorage2042192398(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightTestClassSelector2042192398(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightTestClassDocumentStorage2042192398 - - - // START: IdentityMapTestClassDocumentStorage2042192398 - public class IdentityMapTestClassDocumentStorage2042192398 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapTestClassDocumentStorage2042192398(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapTestClassSelector2042192398(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapTestClassDocumentStorage2042192398 - - - // START: DirtyTrackingTestClassDocumentStorage2042192398 - public class DirtyTrackingTestClassDocumentStorage2042192398 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingTestClassDocumentStorage2042192398(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTestClassOperation2042192398 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingTestClassSelector2042192398(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingTestClassDocumentStorage2042192398 - - - // START: TestClassBulkLoader2042192398 - public class TestClassBulkLoader2042192398 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public TestClassBulkLoader2042192398(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_boolnotvisitortests_testclass(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_boolnotvisitortests_testclass_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_boolnotvisitortests_testclass (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_boolnotvisitortests_testclass_temp.\"id\", mt_doc_boolnotvisitortests_testclass_temp.\"data\", mt_doc_boolnotvisitortests_testclass_temp.\"mt_version\", mt_doc_boolnotvisitortests_testclass_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_boolnotvisitortests_testclass_temp left join public.mt_doc_boolnotvisitortests_testclass on mt_doc_boolnotvisitortests_testclass_temp.id = public.mt_doc_boolnotvisitortests_testclass.id where public.mt_doc_boolnotvisitortests_testclass.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_boolnotvisitortests_testclass target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_boolnotvisitortests_testclass_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_boolnotvisitortests_testclass_temp as select * from public.mt_doc_boolnotvisitortests_testclass limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.BoolNotVisitorTests.TestClass document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: TestClassBulkLoader2042192398 - - - // START: TestClassProvider2042192398 - public class TestClassProvider2042192398 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public TestClassProvider2042192398(Marten.Schema.DocumentMapping mapping) : base(new TestClassBulkLoader2042192398(new QueryOnlyTestClassDocumentStorage2042192398(mapping)), new QueryOnlyTestClassDocumentStorage2042192398(mapping), new LightweightTestClassDocumentStorage2042192398(mapping), new IdentityMapTestClassDocumentStorage2042192398(mapping), new DirtyTrackingTestClassDocumentStorage2042192398(mapping)) - { - _mapping = mapping; - } - - - } - - // END: TestClassProvider2042192398 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TopProvider102551794.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/TopProvider102551794.cs deleted file mode 100644 index 39c822dfb75..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TopProvider102551794.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertTopOperation102551794 - public class UpsertTopOperation102551794 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertTopOperation102551794(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_querying_through_n_deep_sub_collections_top(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertTopOperation102551794 - - - // START: InsertTopOperation102551794 - public class InsertTopOperation102551794 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertTopOperation102551794(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_querying_through_n_deep_sub_collections_top(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertTopOperation102551794 - - - // START: UpdateTopOperation102551794 - public class UpdateTopOperation102551794 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateTopOperation102551794(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_querying_through_n_deep_sub_collections_top(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateTopOperation102551794 - - - // START: QueryOnlyTopSelector102551794 - public class QueryOnlyTopSelector102551794 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyTopSelector102551794(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyTopSelector102551794 - - - // START: LightweightTopSelector102551794 - public class LightweightTopSelector102551794 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightTopSelector102551794(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightTopSelector102551794 - - - // START: IdentityMapTopSelector102551794 - public class IdentityMapTopSelector102551794 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapTopSelector102551794(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapTopSelector102551794 - - - // START: DirtyTrackingTopSelector102551794 - public class DirtyTrackingTopSelector102551794 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingTopSelector102551794(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingTopSelector102551794 - - - // START: QueryOnlyTopDocumentStorage102551794 - public class QueryOnlyTopDocumentStorage102551794 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyTopDocumentStorage102551794(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyTopSelector102551794(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyTopDocumentStorage102551794 - - - // START: LightweightTopDocumentStorage102551794 - public class LightweightTopDocumentStorage102551794 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightTopDocumentStorage102551794(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightTopSelector102551794(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightTopDocumentStorage102551794 - - - // START: IdentityMapTopDocumentStorage102551794 - public class IdentityMapTopDocumentStorage102551794 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapTopDocumentStorage102551794(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapTopSelector102551794(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapTopDocumentStorage102551794 - - - // START: DirtyTrackingTopDocumentStorage102551794 - public class DirtyTrackingTopDocumentStorage102551794 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingTopDocumentStorage102551794(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTopOperation102551794 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingTopSelector102551794(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingTopDocumentStorage102551794 - - - // START: TopBulkLoader102551794 - public class TopBulkLoader102551794 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public TopBulkLoader102551794(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_querying_through_n_deep_sub_collections_top(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_querying_through_n_deep_sub_collections_top_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_querying_through_n_deep_sub_collections_top (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_querying_through_n_deep_sub_collections_top_temp.\"id\", mt_doc_querying_through_n_deep_sub_collections_top_temp.\"data\", mt_doc_querying_through_n_deep_sub_collections_top_temp.\"mt_version\", mt_doc_querying_through_n_deep_sub_collections_top_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_querying_through_n_deep_sub_collections_top_temp left join public.mt_doc_querying_through_n_deep_sub_collections_top on mt_doc_querying_through_n_deep_sub_collections_top_temp.id = public.mt_doc_querying_through_n_deep_sub_collections_top.id where public.mt_doc_querying_through_n_deep_sub_collections_top.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_querying_through_n_deep_sub_collections_top target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_querying_through_n_deep_sub_collections_top_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_querying_through_n_deep_sub_collections_top_temp as select * from public.mt_doc_querying_through_n_deep_sub_collections_top limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.querying_through_n_deep_sub_collections.Top document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: TopBulkLoader102551794 - - - // START: TopProvider102551794 - public class TopProvider102551794 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public TopProvider102551794(Marten.Schema.DocumentMapping mapping) : base(new TopBulkLoader102551794(new QueryOnlyTopDocumentStorage102551794(mapping)), new QueryOnlyTopDocumentStorage102551794(mapping), new LightweightTopDocumentStorage102551794(mapping), new IdentityMapTopDocumentStorage102551794(mapping), new DirtyTrackingTopDocumentStorage102551794(mapping)) - { - _mapping = mapping; - } - - - } - - // END: TopProvider102551794 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525.cs deleted file mode 100644 index 4b82f7b685d..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - public class UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_typewithinnercollectionswithjsonconverterattribute(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - - - // START: InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - public class InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_typewithinnercollectionswithjsonconverterattribute(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - - - // START: UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - public class UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_typewithinnercollectionswithjsonconverterattribute(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - - - // START: QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - public class QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - - - // START: LightweightTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - public class LightweightTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - - - // START: IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - public class IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - - - // START: DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - public class DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525 - - - // START: QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - public class QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - - - // START: LightweightTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - public class LightweightTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - - - // START: IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - public class IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - - - // START: DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - public class DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertTypeWithInnerCollectionsWithJsonConverterAttributeOperation818716525 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeSelector818716525(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525 - - - // START: TypeWithInnerCollectionsWithJsonConverterAttributeBulkLoader818716525 - public class TypeWithInnerCollectionsWithJsonConverterAttributeBulkLoader818716525 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public TypeWithInnerCollectionsWithJsonConverterAttributeBulkLoader818716525(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_typewithinnercollectionswithjsonconverterattribute(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_typewithinnercollectionswithjsonconverterattribute_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_typewithinnercollectionswithjsonconverterattribute (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_typewithinnercollectionswithjsonconverterattribute_temp.\"id\", mt_doc_typewithinnercollectionswithjsonconverterattribute_temp.\"data\", mt_doc_typewithinnercollectionswithjsonconverterattribute_temp.\"mt_version\", mt_doc_typewithinnercollectionswithjsonconverterattribute_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_typewithinnercollectionswithjsonconverterattribute_temp left join public.mt_doc_typewithinnercollectionswithjsonconverterattribute on mt_doc_typewithinnercollectionswithjsonconverterattribute_temp.id = public.mt_doc_typewithinnercollectionswithjsonconverterattribute.id where public.mt_doc_typewithinnercollectionswithjsonconverterattribute.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_typewithinnercollectionswithjsonconverterattribute target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_typewithinnercollectionswithjsonconverterattribute_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_typewithinnercollectionswithjsonconverterattribute_temp as select * from public.mt_doc_typewithinnercollectionswithjsonconverterattribute limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.TypeWithInnerCollectionsWithJsonConverterAttribute document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: TypeWithInnerCollectionsWithJsonConverterAttributeBulkLoader818716525 - - - // START: TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525 - public class TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525(Marten.Schema.DocumentMapping mapping) : base(new TypeWithInnerCollectionsWithJsonConverterAttributeBulkLoader818716525(new QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(mapping)), new QueryOnlyTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(mapping), new LightweightTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(mapping), new IdentityMapTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(mapping), new DirtyTrackingTypeWithInnerCollectionsWithJsonConverterAttributeDocumentStorage818716525(mapping)) - { - _mapping = mapping; - } - - - } - - // END: TypeWithInnerCollectionsWithJsonConverterAttributeProvider818716525 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserFromBaseDocumentProvider1216401712.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserFromBaseDocumentProvider1216401712.cs deleted file mode 100644 index ce728104823..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserFromBaseDocumentProvider1216401712.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertUserFromBaseDocumentOperation1216401712 - public class UpsertUserFromBaseDocumentOperation1216401712 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserFromBaseDocument _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertUserFromBaseDocumentOperation1216401712(Marten.Testing.Documents.UserFromBaseDocument document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_userfrombasedocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertUserFromBaseDocumentOperation1216401712 - - - // START: InsertUserFromBaseDocumentOperation1216401712 - public class InsertUserFromBaseDocumentOperation1216401712 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserFromBaseDocument _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertUserFromBaseDocumentOperation1216401712(Marten.Testing.Documents.UserFromBaseDocument document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_userfrombasedocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertUserFromBaseDocumentOperation1216401712 - - - // START: UpdateUserFromBaseDocumentOperation1216401712 - public class UpdateUserFromBaseDocumentOperation1216401712 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserFromBaseDocument _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateUserFromBaseDocumentOperation1216401712(Marten.Testing.Documents.UserFromBaseDocument document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_userfrombasedocument(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateUserFromBaseDocumentOperation1216401712 - - - // START: QueryOnlyUserFromBaseDocumentSelector1216401712 - public class QueryOnlyUserFromBaseDocumentSelector1216401712 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyUserFromBaseDocumentSelector1216401712(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserFromBaseDocument Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.UserFromBaseDocument document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.UserFromBaseDocument document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyUserFromBaseDocumentSelector1216401712 - - - // START: LightweightUserFromBaseDocumentSelector1216401712 - public class LightweightUserFromBaseDocumentSelector1216401712 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightUserFromBaseDocumentSelector1216401712(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserFromBaseDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.UserFromBaseDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.UserFromBaseDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightUserFromBaseDocumentSelector1216401712 - - - // START: IdentityMapUserFromBaseDocumentSelector1216401712 - public class IdentityMapUserFromBaseDocumentSelector1216401712 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapUserFromBaseDocumentSelector1216401712(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserFromBaseDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserFromBaseDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserFromBaseDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapUserFromBaseDocumentSelector1216401712 - - - // START: DirtyTrackingUserFromBaseDocumentSelector1216401712 - public class DirtyTrackingUserFromBaseDocumentSelector1216401712 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingUserFromBaseDocumentSelector1216401712(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserFromBaseDocument Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserFromBaseDocument document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserFromBaseDocument document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingUserFromBaseDocumentSelector1216401712 - - - // START: QueryOnlyUserFromBaseDocumentDocumentStorage1216401712 - public class QueryOnlyUserFromBaseDocumentDocumentStorage1216401712 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyUserFromBaseDocumentDocumentStorage1216401712(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserFromBaseDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserFromBaseDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyUserFromBaseDocumentSelector1216401712(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyUserFromBaseDocumentDocumentStorage1216401712 - - - // START: LightweightUserFromBaseDocumentDocumentStorage1216401712 - public class LightweightUserFromBaseDocumentDocumentStorage1216401712 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightUserFromBaseDocumentDocumentStorage1216401712(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserFromBaseDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserFromBaseDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightUserFromBaseDocumentSelector1216401712(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightUserFromBaseDocumentDocumentStorage1216401712 - - - // START: IdentityMapUserFromBaseDocumentDocumentStorage1216401712 - public class IdentityMapUserFromBaseDocumentDocumentStorage1216401712 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapUserFromBaseDocumentDocumentStorage1216401712(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserFromBaseDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserFromBaseDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapUserFromBaseDocumentSelector1216401712(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapUserFromBaseDocumentDocumentStorage1216401712 - - - // START: DirtyTrackingUserFromBaseDocumentDocumentStorage1216401712 - public class DirtyTrackingUserFromBaseDocumentDocumentStorage1216401712 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingUserFromBaseDocumentDocumentStorage1216401712(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserFromBaseDocument document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserFromBaseDocumentOperation1216401712 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserFromBaseDocument document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserFromBaseDocument document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingUserFromBaseDocumentSelector1216401712(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingUserFromBaseDocumentDocumentStorage1216401712 - - - // START: UserFromBaseDocumentBulkLoader1216401712 - public class UserFromBaseDocumentBulkLoader1216401712 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public UserFromBaseDocumentBulkLoader1216401712(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_userfrombasedocument(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_userfrombasedocument_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_userfrombasedocument (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_userfrombasedocument_temp.\"id\", mt_doc_userfrombasedocument_temp.\"data\", mt_doc_userfrombasedocument_temp.\"mt_version\", mt_doc_userfrombasedocument_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_userfrombasedocument_temp left join public.mt_doc_userfrombasedocument on mt_doc_userfrombasedocument_temp.id = public.mt_doc_userfrombasedocument.id where public.mt_doc_userfrombasedocument.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_userfrombasedocument target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_userfrombasedocument_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_userfrombasedocument_temp as select * from public.mt_doc_userfrombasedocument limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserFromBaseDocument document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserFromBaseDocument document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: UserFromBaseDocumentBulkLoader1216401712 - - - // START: UserFromBaseDocumentProvider1216401712 - public class UserFromBaseDocumentProvider1216401712 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public UserFromBaseDocumentProvider1216401712(Marten.Schema.DocumentMapping mapping) : base(new UserFromBaseDocumentBulkLoader1216401712(new QueryOnlyUserFromBaseDocumentDocumentStorage1216401712(mapping)), new QueryOnlyUserFromBaseDocumentDocumentStorage1216401712(mapping), new LightweightUserFromBaseDocumentDocumentStorage1216401712(mapping), new IdentityMapUserFromBaseDocumentDocumentStorage1216401712(mapping), new DirtyTrackingUserFromBaseDocumentDocumentStorage1216401712(mapping)) - { - _mapping = mapping; - } - - - } - - // END: UserFromBaseDocumentProvider1216401712 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserNestedProvider527241557.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserNestedProvider527241557.cs deleted file mode 100644 index 91e1184913f..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserNestedProvider527241557.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using DocumentDbTests.Reading.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertUserNestedOperation527241557 - public class UpsertUserNestedOperation527241557 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertUserNestedOperation527241557(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_isnullnotnullarbitrarydepthtests_usernested(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertUserNestedOperation527241557 - - - // START: InsertUserNestedOperation527241557 - public class InsertUserNestedOperation527241557 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertUserNestedOperation527241557(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_isnullnotnullarbitrarydepthtests_usernested(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertUserNestedOperation527241557 - - - // START: UpdateUserNestedOperation527241557 - public class UpdateUserNestedOperation527241557 : Marten.Internal.Operations.StorageOperation - { - private readonly DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateUserNestedOperation527241557(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_isnullnotnullarbitrarydepthtests_usernested(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateUserNestedOperation527241557 - - - // START: QueryOnlyUserNestedSelector527241557 - public class QueryOnlyUserNestedSelector527241557 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyUserNestedSelector527241557(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested Resolve(System.Data.Common.DbDataReader reader) - { - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyUserNestedSelector527241557 - - - // START: LightweightUserNestedSelector527241557 - public class LightweightUserNestedSelector527241557 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightUserNestedSelector527241557(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightUserNestedSelector527241557 - - - // START: IdentityMapUserNestedSelector527241557 - public class IdentityMapUserNestedSelector527241557 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapUserNestedSelector527241557(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapUserNestedSelector527241557 - - - // START: DirtyTrackingUserNestedSelector527241557 - public class DirtyTrackingUserNestedSelector527241557 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingUserNestedSelector527241557(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingUserNestedSelector527241557 - - - // START: QueryOnlyUserNestedDocumentStorage527241557 - public class QueryOnlyUserNestedDocumentStorage527241557 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyUserNestedDocumentStorage527241557(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyUserNestedSelector527241557(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyUserNestedDocumentStorage527241557 - - - // START: LightweightUserNestedDocumentStorage527241557 - public class LightweightUserNestedDocumentStorage527241557 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightUserNestedDocumentStorage527241557(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightUserNestedSelector527241557(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightUserNestedDocumentStorage527241557 - - - // START: IdentityMapUserNestedDocumentStorage527241557 - public class IdentityMapUserNestedDocumentStorage527241557 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapUserNestedDocumentStorage527241557(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapUserNestedSelector527241557(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapUserNestedDocumentStorage527241557 - - - // START: DirtyTrackingUserNestedDocumentStorage527241557 - public class DirtyTrackingUserNestedDocumentStorage527241557 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingUserNestedDocumentStorage527241557(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserNestedOperation527241557 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingUserNestedSelector527241557(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingUserNestedDocumentStorage527241557 - - - // START: UserNestedBulkLoader527241557 - public class UserNestedBulkLoader527241557 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public UserNestedBulkLoader527241557(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_isnullnotnullarbitrarydepthtests_usernested(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_isnullnotnullarbitrarydepthtests_usernested (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp.\"id\", mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp.\"data\", mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp.\"mt_version\", mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp left join public.mt_doc_isnullnotnullarbitrarydepthtests_usernested on mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp.id = public.mt_doc_isnullnotnullarbitrarydepthtests_usernested.id where public.mt_doc_isnullnotnullarbitrarydepthtests_usernested.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_isnullnotnullarbitrarydepthtests_usernested target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_isnullnotnullarbitrarydepthtests_usernested_temp as select * from public.mt_doc_isnullnotnullarbitrarydepthtests_usernested limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, DocumentDbTests.Reading.Linq.IsNullNotNullArbitraryDepthTests.UserNested document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: UserNestedBulkLoader527241557 - - - // START: UserNestedProvider527241557 - public class UserNestedProvider527241557 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public UserNestedProvider527241557(Marten.Schema.DocumentMapping mapping) : base(new UserNestedBulkLoader527241557(new QueryOnlyUserNestedDocumentStorage527241557(mapping)), new QueryOnlyUserNestedDocumentStorage527241557(mapping), new LightweightUserNestedDocumentStorage527241557(mapping), new IdentityMapUserNestedDocumentStorage527241557(mapping), new DirtyTrackingUserNestedDocumentStorage527241557(mapping)) - { - _mapping = mapping; - } - - - } - - // END: UserNestedProvider527241557 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserProvider1415907724.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserProvider1415907724.cs deleted file mode 100644 index 967303d3fe2..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserProvider1415907724.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertUserOperation1415907724 - public class UpsertUserOperation1415907724 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.User _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertUserOperation1415907724(Marten.Testing.Documents.User document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_user(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertUserOperation1415907724 - - - // START: InsertUserOperation1415907724 - public class InsertUserOperation1415907724 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.User _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertUserOperation1415907724(Marten.Testing.Documents.User document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_user(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertUserOperation1415907724 - - - // START: UpdateUserOperation1415907724 - public class UpdateUserOperation1415907724 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.User _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateUserOperation1415907724(Marten.Testing.Documents.User document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_user(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateUserOperation1415907724 - - - // START: QueryOnlyUserSelector1415907724 - public class QueryOnlyUserSelector1415907724 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyUserSelector1415907724(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.User Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.User document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.User document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyUserSelector1415907724 - - - // START: LightweightUserSelector1415907724 - public class LightweightUserSelector1415907724 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightUserSelector1415907724(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.User Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.User document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.User document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightUserSelector1415907724 - - - // START: IdentityMapUserSelector1415907724 - public class IdentityMapUserSelector1415907724 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapUserSelector1415907724(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.User Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.User document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.User document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapUserSelector1415907724 - - - // START: DirtyTrackingUserSelector1415907724 - public class DirtyTrackingUserSelector1415907724 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingUserSelector1415907724(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.User Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.User document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.User document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingUserSelector1415907724 - - - // START: QueryOnlyUserDocumentStorage1415907724 - public class QueryOnlyUserDocumentStorage1415907724 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyUserDocumentStorage1415907724(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.User document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.User document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyUserSelector1415907724(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyUserDocumentStorage1415907724 - - - // START: LightweightUserDocumentStorage1415907724 - public class LightweightUserDocumentStorage1415907724 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightUserDocumentStorage1415907724(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.User document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.User document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightUserSelector1415907724(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightUserDocumentStorage1415907724 - - - // START: IdentityMapUserDocumentStorage1415907724 - public class IdentityMapUserDocumentStorage1415907724 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapUserDocumentStorage1415907724(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.User document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.User document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapUserSelector1415907724(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapUserDocumentStorage1415907724 - - - // START: DirtyTrackingUserDocumentStorage1415907724 - public class DirtyTrackingUserDocumentStorage1415907724 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingUserDocumentStorage1415907724(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.User document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserOperation1415907724 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.User document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.User document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingUserSelector1415907724(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingUserDocumentStorage1415907724 - - - // START: UserBulkLoader1415907724 - public class UserBulkLoader1415907724 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public UserBulkLoader1415907724(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_user(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_user_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_user (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_user_temp.\"id\", mt_doc_user_temp.\"data\", mt_doc_user_temp.\"mt_version\", mt_doc_user_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_user_temp left join public.mt_doc_user on mt_doc_user_temp.id = public.mt_doc_user.id where public.mt_doc_user.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_user target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_user_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_user_temp as select * from public.mt_doc_user limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.User document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.User document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: UserBulkLoader1415907724 - - - // START: UserProvider1415907724 - public class UserProvider1415907724 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public UserProvider1415907724(Marten.Schema.DocumentMapping mapping) : base(new UserBulkLoader1415907724(new QueryOnlyUserDocumentStorage1415907724(mapping)), new QueryOnlyUserDocumentStorage1415907724(mapping), new LightweightUserDocumentStorage1415907724(mapping), new IdentityMapUserDocumentStorage1415907724(mapping), new DirtyTrackingUserDocumentStorage1415907724(mapping)) - { - _mapping = mapping; - } - - - } - - // END: UserProvider1415907724 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithInterfaceProvider16433597.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithInterfaceProvider16433597.cs deleted file mode 100644 index 55406e50015..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithInterfaceProvider16433597.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertUserWithInterfaceOperation16433597 - public class UpsertUserWithInterfaceOperation16433597 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithInterface _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertUserWithInterfaceOperation16433597(Marten.Testing.Documents.UserWithInterface document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_userwithinterface(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertUserWithInterfaceOperation16433597 - - - // START: InsertUserWithInterfaceOperation16433597 - public class InsertUserWithInterfaceOperation16433597 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithInterface _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertUserWithInterfaceOperation16433597(Marten.Testing.Documents.UserWithInterface document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_userwithinterface(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertUserWithInterfaceOperation16433597 - - - // START: UpdateUserWithInterfaceOperation16433597 - public class UpdateUserWithInterfaceOperation16433597 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithInterface _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateUserWithInterfaceOperation16433597(Marten.Testing.Documents.UserWithInterface document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_userwithinterface(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateUserWithInterfaceOperation16433597 - - - // START: QueryOnlyUserWithInterfaceSelector16433597 - public class QueryOnlyUserWithInterfaceSelector16433597 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyUserWithInterfaceSelector16433597(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithInterface Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.UserWithInterface document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.UserWithInterface document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyUserWithInterfaceSelector16433597 - - - // START: LightweightUserWithInterfaceSelector16433597 - public class LightweightUserWithInterfaceSelector16433597 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightUserWithInterfaceSelector16433597(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithInterface Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.UserWithInterface document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.UserWithInterface document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightUserWithInterfaceSelector16433597 - - - // START: IdentityMapUserWithInterfaceSelector16433597 - public class IdentityMapUserWithInterfaceSelector16433597 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapUserWithInterfaceSelector16433597(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithInterface Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithInterface document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithInterface document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapUserWithInterfaceSelector16433597 - - - // START: DirtyTrackingUserWithInterfaceSelector16433597 - public class DirtyTrackingUserWithInterfaceSelector16433597 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingUserWithInterfaceSelector16433597(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithInterface Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithInterface document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithInterface document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingUserWithInterfaceSelector16433597 - - - // START: QueryOnlyUserWithInterfaceDocumentStorage16433597 - public class QueryOnlyUserWithInterfaceDocumentStorage16433597 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyUserWithInterfaceDocumentStorage16433597(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithInterface document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithInterface document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyUserWithInterfaceSelector16433597(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyUserWithInterfaceDocumentStorage16433597 - - - // START: LightweightUserWithInterfaceDocumentStorage16433597 - public class LightweightUserWithInterfaceDocumentStorage16433597 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightUserWithInterfaceDocumentStorage16433597(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithInterface document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithInterface document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightUserWithInterfaceSelector16433597(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightUserWithInterfaceDocumentStorage16433597 - - - // START: IdentityMapUserWithInterfaceDocumentStorage16433597 - public class IdentityMapUserWithInterfaceDocumentStorage16433597 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapUserWithInterfaceDocumentStorage16433597(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithInterface document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithInterface document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapUserWithInterfaceSelector16433597(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapUserWithInterfaceDocumentStorage16433597 - - - // START: DirtyTrackingUserWithInterfaceDocumentStorage16433597 - public class DirtyTrackingUserWithInterfaceDocumentStorage16433597 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingUserWithInterfaceDocumentStorage16433597(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithInterface document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithInterfaceOperation16433597 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithInterface document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithInterface document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingUserWithInterfaceSelector16433597(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingUserWithInterfaceDocumentStorage16433597 - - - // START: UserWithInterfaceBulkLoader16433597 - public class UserWithInterfaceBulkLoader16433597 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public UserWithInterfaceBulkLoader16433597(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_userwithinterface(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_userwithinterface_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_userwithinterface (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_userwithinterface_temp.\"id\", mt_doc_userwithinterface_temp.\"data\", mt_doc_userwithinterface_temp.\"mt_version\", mt_doc_userwithinterface_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_userwithinterface_temp left join public.mt_doc_userwithinterface on mt_doc_userwithinterface_temp.id = public.mt_doc_userwithinterface.id where public.mt_doc_userwithinterface.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_userwithinterface target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_userwithinterface_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_userwithinterface_temp as select * from public.mt_doc_userwithinterface limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserWithInterface document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserWithInterface document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: UserWithInterfaceBulkLoader16433597 - - - // START: UserWithInterfaceProvider16433597 - public class UserWithInterfaceProvider16433597 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public UserWithInterfaceProvider16433597(Marten.Schema.DocumentMapping mapping) : base(new UserWithInterfaceBulkLoader16433597(new QueryOnlyUserWithInterfaceDocumentStorage16433597(mapping)), new QueryOnlyUserWithInterfaceDocumentStorage16433597(mapping), new LightweightUserWithInterfaceDocumentStorage16433597(mapping), new IdentityMapUserWithInterfaceDocumentStorage16433597(mapping), new DirtyTrackingUserWithInterfaceDocumentStorage16433597(mapping)) - { - _mapping = mapping; - } - - - } - - // END: UserWithInterfaceProvider16433597 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithPrivateIdProvider1408394226.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithPrivateIdProvider1408394226.cs deleted file mode 100644 index 1bdc6d5b644..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithPrivateIdProvider1408394226.cs +++ /dev/null @@ -1,848 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertUserWithPrivateIdOperation1408394226 - public class UpsertUserWithPrivateIdOperation1408394226 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithPrivateId _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertUserWithPrivateIdOperation1408394226(Marten.Testing.Documents.UserWithPrivateId document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_userwithprivateid(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertUserWithPrivateIdOperation1408394226 - - - // START: InsertUserWithPrivateIdOperation1408394226 - public class InsertUserWithPrivateIdOperation1408394226 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithPrivateId _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertUserWithPrivateIdOperation1408394226(Marten.Testing.Documents.UserWithPrivateId document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_userwithprivateid(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertUserWithPrivateIdOperation1408394226 - - - // START: UpdateUserWithPrivateIdOperation1408394226 - public class UpdateUserWithPrivateIdOperation1408394226 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithPrivateId _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateUserWithPrivateIdOperation1408394226(Marten.Testing.Documents.UserWithPrivateId document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_userwithprivateid(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateUserWithPrivateIdOperation1408394226 - - - // START: QueryOnlyUserWithPrivateIdSelector1408394226 - public class QueryOnlyUserWithPrivateIdSelector1408394226 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyUserWithPrivateIdSelector1408394226(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithPrivateId Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.UserWithPrivateId document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.UserWithPrivateId document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyUserWithPrivateIdSelector1408394226 - - - // START: LightweightUserWithPrivateIdSelector1408394226 - public class LightweightUserWithPrivateIdSelector1408394226 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightUserWithPrivateIdSelector1408394226(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithPrivateId Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.UserWithPrivateId document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.UserWithPrivateId document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightUserWithPrivateIdSelector1408394226 - - - // START: IdentityMapUserWithPrivateIdSelector1408394226 - public class IdentityMapUserWithPrivateIdSelector1408394226 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapUserWithPrivateIdSelector1408394226(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithPrivateId Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithPrivateId document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithPrivateId document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapUserWithPrivateIdSelector1408394226 - - - // START: DirtyTrackingUserWithPrivateIdSelector1408394226 - public class DirtyTrackingUserWithPrivateIdSelector1408394226 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingUserWithPrivateIdSelector1408394226(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithPrivateId Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithPrivateId document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithPrivateId document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingUserWithPrivateIdSelector1408394226 - - - // START: QueryOnlyUserWithPrivateIdDocumentStorage1408394226 - public class QueryOnlyUserWithPrivateIdDocumentStorage1408394226 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyUserWithPrivateIdDocumentStorage1408394226(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithPrivateId document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithPrivateId document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyUserWithPrivateIdSelector1408394226(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyUserWithPrivateIdDocumentStorage1408394226 - - - // START: LightweightUserWithPrivateIdDocumentStorage1408394226 - public class LightweightUserWithPrivateIdDocumentStorage1408394226 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightUserWithPrivateIdDocumentStorage1408394226(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithPrivateId document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithPrivateId document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightUserWithPrivateIdSelector1408394226(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightUserWithPrivateIdDocumentStorage1408394226 - - - // START: IdentityMapUserWithPrivateIdDocumentStorage1408394226 - public class IdentityMapUserWithPrivateIdDocumentStorage1408394226 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapUserWithPrivateIdDocumentStorage1408394226(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithPrivateId document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithPrivateId document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapUserWithPrivateIdSelector1408394226(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapUserWithPrivateIdDocumentStorage1408394226 - - - // START: DirtyTrackingUserWithPrivateIdDocumentStorage1408394226 - public class DirtyTrackingUserWithPrivateIdDocumentStorage1408394226 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingUserWithPrivateIdDocumentStorage1408394226(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithPrivateId document, string tenantId, Marten.Storage.IMartenDatabase database) - { - if (document.Id == Guid.Empty) _setter(document, Marten.Schema.Identity.CombGuidIdGeneration.NewGuid()); - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithPrivateIdOperation1408394226 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithPrivateId document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithPrivateId document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingUserWithPrivateIdSelector1408394226(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingUserWithPrivateIdDocumentStorage1408394226 - - - // START: UserWithPrivateIdBulkLoader1408394226 - public class UserWithPrivateIdBulkLoader1408394226 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public UserWithPrivateIdBulkLoader1408394226(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_userwithprivateid(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_userwithprivateid_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_userwithprivateid (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_userwithprivateid_temp.\"id\", mt_doc_userwithprivateid_temp.\"data\", mt_doc_userwithprivateid_temp.\"mt_version\", mt_doc_userwithprivateid_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_userwithprivateid_temp left join public.mt_doc_userwithprivateid on mt_doc_userwithprivateid_temp.id = public.mt_doc_userwithprivateid.id where public.mt_doc_userwithprivateid.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_userwithprivateid target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_userwithprivateid_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_userwithprivateid_temp as select * from public.mt_doc_userwithprivateid limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserWithPrivateId document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserWithPrivateId document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: UserWithPrivateIdBulkLoader1408394226 - - - // START: UserWithPrivateIdProvider1408394226 - public class UserWithPrivateIdProvider1408394226 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public UserWithPrivateIdProvider1408394226(Marten.Schema.DocumentMapping mapping) : base(new UserWithPrivateIdBulkLoader1408394226(new QueryOnlyUserWithPrivateIdDocumentStorage1408394226(mapping)), new QueryOnlyUserWithPrivateIdDocumentStorage1408394226(mapping), new LightweightUserWithPrivateIdDocumentStorage1408394226(mapping), new IdentityMapUserWithPrivateIdDocumentStorage1408394226(mapping), new DirtyTrackingUserWithPrivateIdDocumentStorage1408394226(mapping)) - { - _mapping = mapping; - } - - - } - - // END: UserWithPrivateIdProvider1408394226 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithoutIdSetterProvider1320849530.cs b/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithoutIdSetterProvider1320849530.cs deleted file mode 100644 index 97ab52f88e6..00000000000 --- a/src/DocumentDbTests/Internal/Generated/DocumentStorage/UserWithoutIdSetterProvider1320849530.cs +++ /dev/null @@ -1,844 +0,0 @@ -// -#pragma warning disable -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Schema; -using Marten.Schema.Arguments; -using Marten.Testing.Documents; -using Npgsql; -using System; -using System.Collections.Generic; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Generated.DocumentStorage -{ - // START: UpsertUserWithoutIdSetterOperation1320849530 - public class UpsertUserWithoutIdSetterOperation1320849530 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithoutIdSetter _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpsertUserWithoutIdSetterOperation1320849530(Marten.Testing.Documents.UserWithoutIdSetter document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_upsert_userwithoutidsetter(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Upsert; - } - - } - - // END: UpsertUserWithoutIdSetterOperation1320849530 - - - // START: InsertUserWithoutIdSetterOperation1320849530 - public class InsertUserWithoutIdSetterOperation1320849530 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithoutIdSetter _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public InsertUserWithoutIdSetterOperation1320849530(Marten.Testing.Documents.UserWithoutIdSetter document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_insert_userwithoutidsetter(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - } - - - public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - // Nothing - return System.Threading.Tasks.Task.CompletedTask; - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Insert; - } - - } - - // END: InsertUserWithoutIdSetterOperation1320849530 - - - // START: UpdateUserWithoutIdSetterOperation1320849530 - public class UpdateUserWithoutIdSetterOperation1320849530 : Marten.Internal.Operations.StorageOperation - { - private readonly Marten.Testing.Documents.UserWithoutIdSetter _document; - private readonly System.Guid _id; - private readonly System.Collections.Generic.Dictionary _versions; - private readonly Marten.Schema.DocumentMapping _mapping; - - public UpdateUserWithoutIdSetterOperation1320849530(Marten.Testing.Documents.UserWithoutIdSetter document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) - { - _document = document; - _id = id; - _versions = versions; - _mapping = mapping; - } - - - public const string COMMAND_TEXT = "select public.mt_update_userwithoutidsetter(?, ?, ?, ?)"; - - - public override string CommandText() - { - return COMMAND_TEXT; - } - - - public override NpgsqlTypes.NpgsqlDbType DbType() - { - return NpgsqlTypes.NpgsqlDbType.Uuid; - } - - - public override void ConfigureParameters(Npgsql.NpgsqlParameter[] parameters, Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session) - { - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(_document); - // .Net Class Type - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; - parameters[1].Value = _document.GetType().FullName; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = document.Id; - setVersionParameter(parameters[3]); - } - - - public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) - { - storeVersion(); - postprocessUpdate(reader, exceptions); - } - - - public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) - { - storeVersion(); - await postprocessUpdateAsync(reader, exceptions, token); - } - - - public override Marten.Internal.Operations.OperationRole Role() - { - return Marten.Internal.Operations.OperationRole.Update; - } - - } - - // END: UpdateUserWithoutIdSetterOperation1320849530 - - - // START: QueryOnlyUserWithoutIdSetterSelector1320849530 - public class QueryOnlyUserWithoutIdSetterSelector1320849530 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public QueryOnlyUserWithoutIdSetterSelector1320849530(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithoutIdSetter Resolve(System.Data.Common.DbDataReader reader) - { - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = _serializer.FromJson(reader, 0); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); - return document; - } - - } - - // END: QueryOnlyUserWithoutIdSetterSelector1320849530 - - - // START: LightweightUserWithoutIdSetterSelector1320849530 - public class LightweightUserWithoutIdSetterSelector1320849530 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public LightweightUserWithoutIdSetterSelector1320849530(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithoutIdSetter Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - return document; - } - - } - - // END: LightweightUserWithoutIdSetterSelector1320849530 - - - // START: IdentityMapUserWithoutIdSetterSelector1320849530 - public class IdentityMapUserWithoutIdSetterSelector1320849530 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public IdentityMapUserWithoutIdSetterSelector1320849530(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithoutIdSetter Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - return document; - } - - } - - // END: IdentityMapUserWithoutIdSetterSelector1320849530 - - - // START: DirtyTrackingUserWithoutIdSetterSelector1320849530 - public class DirtyTrackingUserWithoutIdSetterSelector1320849530 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector - { - private readonly Marten.Internal.IMartenSession _session; - private readonly Marten.Schema.DocumentMapping _mapping; - - public DirtyTrackingUserWithoutIdSetterSelector1320849530(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) - { - _session = session; - _mapping = mapping; - } - - - - public Marten.Testing.Documents.UserWithoutIdSetter Resolve(System.Data.Common.DbDataReader reader) - { - var id = reader.GetFieldValue(0); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = _serializer.FromJson(reader, 1); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - - public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var id = await reader.GetFieldValueAsync(0, token); - if (_identityMap.TryGetValue(id, out var existing)) return existing; - - Marten.Testing.Documents.UserWithoutIdSetter document; - document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); - _session.MarkAsDocumentLoaded(id, document); - _identityMap[id] = document; - StoreTracker(_session, document); - return document; - } - - } - - // END: DirtyTrackingUserWithoutIdSetterSelector1320849530 - - - // START: QueryOnlyUserWithoutIdSetterDocumentStorage1320849530 - public class QueryOnlyUserWithoutIdSetterDocumentStorage1320849530 : Marten.Internal.Storage.QueryOnlyDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public QueryOnlyUserWithoutIdSetterDocumentStorage1320849530(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithoutIdSetter document, string tenantId, Marten.Storage.IMartenDatabase database) - { - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithoutIdSetter document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.QueryOnlyUserWithoutIdSetterSelector1320849530(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: QueryOnlyUserWithoutIdSetterDocumentStorage1320849530 - - - // START: LightweightUserWithoutIdSetterDocumentStorage1320849530 - public class LightweightUserWithoutIdSetterDocumentStorage1320849530 : Marten.Internal.Storage.LightweightDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public LightweightUserWithoutIdSetterDocumentStorage1320849530(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithoutIdSetter document, string tenantId, Marten.Storage.IMartenDatabase database) - { - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithoutIdSetter document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.LightweightUserWithoutIdSetterSelector1320849530(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: LightweightUserWithoutIdSetterDocumentStorage1320849530 - - - // START: IdentityMapUserWithoutIdSetterDocumentStorage1320849530 - public class IdentityMapUserWithoutIdSetterDocumentStorage1320849530 : Marten.Internal.Storage.IdentityMapDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public IdentityMapUserWithoutIdSetterDocumentStorage1320849530(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithoutIdSetter document, string tenantId, Marten.Storage.IMartenDatabase database) - { - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithoutIdSetter document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.IdentityMapUserWithoutIdSetterSelector1320849530(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: IdentityMapUserWithoutIdSetterDocumentStorage1320849530 - - - // START: DirtyTrackingUserWithoutIdSetterDocumentStorage1320849530 - public class DirtyTrackingUserWithoutIdSetterDocumentStorage1320849530 : Marten.Internal.Storage.DirtyCheckedDocumentStorage - { - private readonly Marten.Schema.DocumentMapping _document; - - public DirtyTrackingUserWithoutIdSetterDocumentStorage1320849530(Marten.Schema.DocumentMapping document) : base(document) - { - _document = document; - } - - - - public override System.Guid AssignIdentity(Marten.Testing.Documents.UserWithoutIdSetter document, string tenantId, Marten.Storage.IMartenDatabase database) - { - return document.Id; - } - - - public override Marten.Internal.Operations.IStorageOperation Update(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpdateUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Insert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.InsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Upsert(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - - return new Marten.Generated.DocumentStorage.UpsertUserWithoutIdSetterOperation1320849530 - ( - document, Identity(document), - session.Versions.ForType(), - _document - - ); - } - - - public override Marten.Internal.Operations.IStorageOperation Overwrite(Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Internal.IMartenSession session, string tenant) - { - throw new System.NotSupportedException(); - } - - - public override System.Guid Identity(Marten.Testing.Documents.UserWithoutIdSetter document) - { - return document.Id; - } - - - public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) - { - return new Marten.Generated.DocumentStorage.DirtyTrackingUserWithoutIdSetterSelector1320849530(session, _document); - } - - - public override Npgsql.NpgsqlCommand BuildLoadCommand(System.Guid id, string tenant) - { - return new NpgsqlCommand(_loaderSql).With("id", id); - } - - - public override Npgsql.NpgsqlCommand BuildLoadManyCommand(System.Guid[] ids, string tenant) - { - return new NpgsqlCommand(_loadArraySql).With("ids", ids); - } - - } - - // END: DirtyTrackingUserWithoutIdSetterDocumentStorage1320849530 - - - // START: UserWithoutIdSetterBulkLoader1320849530 - public class UserWithoutIdSetterBulkLoader1320849530 : Marten.Internal.CodeGeneration.BulkLoader - { - private readonly Marten.Internal.Storage.IDocumentStorage _storage; - - public UserWithoutIdSetterBulkLoader1320849530(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) - { - _storage = storage; - } - - - public const string MAIN_LOADER_SQL = "COPY public.mt_doc_userwithoutidsetter(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string TEMP_LOADER_SQL = "COPY mt_doc_userwithoutidsetter_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; - - public const string COPY_NEW_DOCUMENTS_SQL = "insert into public.mt_doc_userwithoutidsetter (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_userwithoutidsetter_temp.\"id\", mt_doc_userwithoutidsetter_temp.\"data\", mt_doc_userwithoutidsetter_temp.\"mt_version\", mt_doc_userwithoutidsetter_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_userwithoutidsetter_temp left join public.mt_doc_userwithoutidsetter on mt_doc_userwithoutidsetter_temp.id = public.mt_doc_userwithoutidsetter.id where public.mt_doc_userwithoutidsetter.id is null)"; - - public const string OVERWRITE_SQL = "update public.mt_doc_userwithoutidsetter target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_userwithoutidsetter_temp source WHERE source.id = target.id"; - - public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_userwithoutidsetter_temp as select * from public.mt_doc_userwithoutidsetter limit 0"; - - - public override void LoadRow(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer) - { - writer.Write(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar); - writer.Write(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid); - writer.Write(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb); - } - - - public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, Marten.Testing.Documents.UserWithoutIdSetter document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) - { - await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); - await writer.WriteAsync(document.Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(Marten.Schema.Identity.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); - await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); - } - - - public override string MainLoaderSql() - { - return MAIN_LOADER_SQL; - } - - - public override string TempLoaderSql() - { - return TEMP_LOADER_SQL; - } - - - public override string CreateTempTableForCopying() - { - return CREATE_TEMP_TABLE_FOR_COPYING_SQL; - } - - - public override string CopyNewDocumentsFromTempTable() - { - return COPY_NEW_DOCUMENTS_SQL; - } - - - public override string OverwriteDuplicatesFromTempTable() - { - return OVERWRITE_SQL; - } - - } - - // END: UserWithoutIdSetterBulkLoader1320849530 - - - // START: UserWithoutIdSetterProvider1320849530 - public class UserWithoutIdSetterProvider1320849530 : Marten.Internal.Storage.DocumentProvider - { - private readonly Marten.Schema.DocumentMapping _mapping; - - public UserWithoutIdSetterProvider1320849530(Marten.Schema.DocumentMapping mapping) : base(new UserWithoutIdSetterBulkLoader1320849530(new QueryOnlyUserWithoutIdSetterDocumentStorage1320849530(mapping)), new QueryOnlyUserWithoutIdSetterDocumentStorage1320849530(mapping), new LightweightUserWithoutIdSetterDocumentStorage1320849530(mapping), new IdentityMapUserWithoutIdSetterDocumentStorage1320849530(mapping), new DirtyTrackingUserWithoutIdSetterDocumentStorage1320849530(mapping)) - { - _mapping = mapping; - } - - - } - - // END: UserWithoutIdSetterProvider1320849530 - - -} - diff --git a/src/DocumentDbTests/Internal/Generated/EventStore/EventStorage.cs b/src/DocumentDbTests/Internal/Generated/EventStore/EventStorage.cs deleted file mode 100644 index cbbb7dd7363..00000000000 --- a/src/DocumentDbTests/Internal/Generated/EventStore/EventStorage.cs +++ /dev/null @@ -1,286 +0,0 @@ -// -#pragma warning disable -using Marten; -using Marten.Events; -using System; - -namespace Marten.Generated.EventStore -{ - // START: GeneratedEventDocumentStorage - public class GeneratedEventDocumentStorage : Marten.Events.EventDocumentStorage - { - private readonly Marten.StoreOptions _options; - - public GeneratedEventDocumentStorage(Marten.StoreOptions options) : base(options) - { - _options = options; - } - - - - public override Marten.Internal.Operations.IStorageOperation AppendEvent(Marten.Events.EventGraph events, Marten.Internal.IMartenSession session, Marten.Events.StreamAction stream, Marten.Events.IEvent e) - { - return new Marten.Generated.EventStore.AppendEventOperation(stream, e); - } - - - public override Marten.Internal.Operations.IStorageOperation InsertStream(Marten.Events.StreamAction stream) - { - return new Marten.Generated.EventStore.GeneratedInsertStream(stream); - } - - - public override Marten.Linq.QueryHandlers.IQueryHandler QueryForStream(Marten.Events.StreamAction stream) - { - return new Marten.Generated.EventStore.GeneratedStreamStateQueryHandler(stream.Id); - } - - - public override Marten.Internal.Operations.IStorageOperation UpdateStreamVersion(Marten.Events.StreamAction stream) - { - return new Marten.Generated.EventStore.GeneratedStreamVersionOperation(stream); - } - - - public override void ApplyReaderDataToEvent(System.Data.Common.DbDataReader reader, Marten.Events.IEvent e) - { - if (!reader.IsDBNull(3)) - { - var sequence = reader.GetFieldValue(3); - e.Sequence = sequence; - } - if (!reader.IsDBNull(4)) - { - var id = reader.GetFieldValue(4); - e.Id = id; - } - var streamId = reader.GetFieldValue(5); - e.StreamId = streamId; - if (!reader.IsDBNull(6)) - { - var version = reader.GetFieldValue(6); - e.Version = version; - } - if (!reader.IsDBNull(7)) - { - var timestamp = reader.GetFieldValue(7); - e.Timestamp = timestamp; - } - if (!reader.IsDBNull(8)) - { - var tenantId = reader.GetFieldValue(8); - e.TenantId = tenantId; - } - var isArchived = reader.GetFieldValue(9); - e.IsArchived = isArchived; - } - - - public override async System.Threading.Tasks.Task ApplyReaderDataToEventAsync(System.Data.Common.DbDataReader reader, Marten.Events.IEvent e, System.Threading.CancellationToken token) - { - if (!(await reader.IsDBNullAsync(3, token).ConfigureAwait(false))) - { - var sequence = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); - e.Sequence = sequence; - } - if (!(await reader.IsDBNullAsync(4, token).ConfigureAwait(false))) - { - var id = await reader.GetFieldValueAsync(4, token).ConfigureAwait(false); - e.Id = id; - } - var streamId = await reader.GetFieldValueAsync(5, token).ConfigureAwait(false); - e.StreamId = streamId; - if (!(await reader.IsDBNullAsync(6, token).ConfigureAwait(false))) - { - var version = await reader.GetFieldValueAsync(6, token).ConfigureAwait(false); - e.Version = version; - } - if (!(await reader.IsDBNullAsync(7, token).ConfigureAwait(false))) - { - var timestamp = await reader.GetFieldValueAsync(7, token).ConfigureAwait(false); - e.Timestamp = timestamp; - } - if (!(await reader.IsDBNullAsync(8, token).ConfigureAwait(false))) - { - var tenantId = await reader.GetFieldValueAsync(8, token).ConfigureAwait(false); - e.TenantId = tenantId; - } - var isArchived = await reader.GetFieldValueAsync(9, token).ConfigureAwait(false); - e.IsArchived = isArchived; - } - - } - - // END: GeneratedEventDocumentStorage - - - // START: AppendEventOperation - public class AppendEventOperation : Marten.Events.Operations.AppendEventOperationBase - { - private readonly Marten.Events.StreamAction _stream; - private readonly Marten.Events.IEvent _e; - - public AppendEventOperation(Marten.Events.StreamAction stream, Marten.Events.IEvent e) : base(stream, e) - { - _stream = stream; - _e = e; - } - - - public const string SQL = "insert into public.mt_events (data, type, mt_dotnet_type, seq_id, id, stream_id, version, timestamp, tenant_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(SQL); - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; - parameters[0].Value = session.Serializer.ToJson(Event.Data); - parameters[1].Value = Event.EventTypeName != null ? (object)Event.EventTypeName : System.DBNull.Value; - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[2].Value = Event.DotNetTypeName != null ? (object)Event.DotNetTypeName : System.DBNull.Value; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[3].Value = Event.Sequence; - parameters[4].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[4].Value = Event.Id; - parameters[5].Value = Stream.Id; - parameters[5].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[6].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[6].Value = Event.Version; - parameters[7].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.TimestampTz; - parameters[7].Value = Event.Timestamp; - parameters[8].Value = Event.TenantId != null ? (object)Event.TenantId : System.DBNull.Value; - parameters[8].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - } - - } - - // END: AppendEventOperation - - - // START: GeneratedInsertStream - public class GeneratedInsertStream : Marten.Events.Operations.InsertStreamBase - { - private readonly Marten.Events.StreamAction _stream; - - public GeneratedInsertStream(Marten.Events.StreamAction stream) : base(stream) - { - _stream = stream; - } - - - public const string SQL = "insert into public.mt_streams (id, type, version, tenant_id) values (?, ?, ?, ?)"; - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(SQL); - parameters[0].Value = Stream.Id; - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[1].Value = Stream.AggregateTypeName != null ? (object)Stream.AggregateTypeName : System.DBNull.Value; - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - parameters[2].Value = Stream.Version; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[3].Value = Stream.TenantId != null ? (object)Stream.TenantId : System.DBNull.Value; - parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; - } - - } - - // END: GeneratedInsertStream - - - // START: GeneratedStreamStateQueryHandler - public class GeneratedStreamStateQueryHandler : Marten.Events.Querying.StreamStateQueryHandler - { - private readonly System.Guid _streamId; - - public GeneratedStreamStateQueryHandler(System.Guid streamId) - { - _streamId = streamId; - } - - - public const string SQL = "select id, version, type, timestamp, created as timestamp, is_archived from public.mt_streams where id = ?"; - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var npgsqlParameterArray = builder.AppendWithParameters(SQL); - npgsqlParameterArray[0].Value = _streamId; - npgsqlParameterArray[0].DbType = System.Data.DbType.Guid; - } - - - public override Marten.Events.StreamState Resolve(Marten.Internal.IMartenSession session, System.Data.Common.DbDataReader reader) - { - var streamState = new Marten.Events.StreamState(); - var id = reader.GetFieldValue(0); - streamState.Id = id; - var version = reader.GetFieldValue(1); - streamState.Version = version; - SetAggregateType(streamState, reader, session); - var lastTimestamp = reader.GetFieldValue(3); - streamState.LastTimestamp = lastTimestamp; - var created = reader.GetFieldValue(4); - streamState.Created = created; - var isArchived = reader.GetFieldValue(5); - streamState.IsArchived = isArchived; - return streamState; - } - - - public override async System.Threading.Tasks.Task ResolveAsync(Marten.Internal.IMartenSession session, System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) - { - var streamState = new Marten.Events.StreamState(); - var id = await reader.GetFieldValueAsync(0, token).ConfigureAwait(false); - streamState.Id = id; - var version = await reader.GetFieldValueAsync(1, token).ConfigureAwait(false); - streamState.Version = version; - await SetAggregateTypeAsync(streamState, reader, session, token); - var lastTimestamp = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); - streamState.LastTimestamp = lastTimestamp; - var created = await reader.GetFieldValueAsync(4, token).ConfigureAwait(false); - streamState.Created = created; - var isArchived = await reader.GetFieldValueAsync(5, token).ConfigureAwait(false); - streamState.IsArchived = isArchived; - return streamState; - } - - } - - // END: GeneratedStreamStateQueryHandler - - - // START: GeneratedStreamVersionOperation - public class GeneratedStreamVersionOperation : Marten.Events.Operations.UpdateStreamVersion - { - private readonly Marten.Events.StreamAction _stream; - - public GeneratedStreamVersionOperation(Marten.Events.StreamAction stream) : base(stream) - { - _stream = stream; - } - - - public const string SQL = "update public.mt_streams set version = ? where id = ? and version = ?"; - - - public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session) - { - var parameters = builder.AppendWithParameters(SQL); - parameters[0].Value = Stream.Version; - parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - parameters[1].Value = Stream.Id; - parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; - parameters[2].Value = Stream.ExpectedVersionOnServer; - parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; - } - - } - - // END: GeneratedStreamVersionOperation - - -} - diff --git a/src/DocumentDbTests/Metadata/created_timestamp_queries.cs b/src/DocumentDbTests/Metadata/created_timestamp_queries.cs index f8b53669a6e..f675271b06b 100644 --- a/src/DocumentDbTests/Metadata/created_timestamp_queries.cs +++ b/src/DocumentDbTests/Metadata/created_timestamp_queries.cs @@ -1,3 +1,4 @@ +using System; using Marten.Schema; using Marten.Testing.Documents; using Marten.Testing.Harness; @@ -24,6 +25,7 @@ public void creates_btree_index_for_mt_created_at() [IndexedCreatedAt] public class Customer { + public Guid Id { get; set; } } #endregion diff --git a/src/DocumentDbTests/Metadata/last_modified_queries.cs b/src/DocumentDbTests/Metadata/last_modified_queries.cs index ff69cebed17..7fdceaeda7a 100644 --- a/src/DocumentDbTests/Metadata/last_modified_queries.cs +++ b/src/DocumentDbTests/Metadata/last_modified_queries.cs @@ -27,6 +27,7 @@ public void creates_btree_index_for_mt_last_modified() [IndexedLastModified] public class Customer { + public Guid Id { get; set; } } #endregion diff --git a/src/DocumentDbTests/Reading/Json/streaming_json_results.cs b/src/DocumentDbTests/Reading/Json/streaming_json_results.cs index e5541751944..1d1fa1cda7c 100644 --- a/src/DocumentDbTests/Reading/Json/streaming_json_results.cs +++ b/src/DocumentDbTests/Reading/Json/streaming_json_results.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; -using DocumentDbTests.Reading.Linq; using Marten; using Marten.Linq; using Marten.Testing.Documents; @@ -14,6 +13,39 @@ namespace DocumentDbTests.Reading.Json; +public class SimpleUser +{ + public SimpleUser() + { + Id = Guid.NewGuid(); + } + + public Guid Id { get; set; } + public string UserName { get; set; } + public DateTime Birthdate { get; set; } + public int Number { get; set; } + public SimpleAddress Address { get; set; } + + public string ToJson() + { + return $@" +{{ +""Id"": ""{Id}"", ""Number"": {Number}, ""Address"": +{{ +""Street"": ""{Address.Street}"", ""HouseNumber"": ""{Address.HouseNumber}"" +}}, +""UserName"": ""{UserName}"", +""Birthdate"": ""{Birthdate.ToString("s")}"" +}}".Replace("\r\n", "").Replace("\n", ""); + } +} + +public class SimpleAddress +{ + public string Street { get; set; } + public string HouseNumber { get; set; } +} + public class streaming_json_results : IntegrationContext { public streaming_json_results(DefaultStoreFixture fixture) : base(fixture) @@ -1020,4 +1052,4 @@ public async Task select_many_with_select_and_as_json() actual.Length.ShouldBe(expected); } } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/select_transforms.cs b/src/DocumentDbTests/Reading/Linq/Compatibility/select_transforms.cs deleted file mode 100644 index 19f9bfbce57..00000000000 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/select_transforms.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using DocumentDbTests.Reading.Linq.Compatibility.Support; -using Marten.Services.Json; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.Compatibility; - -public class select_transforms: LinqTestContext -{ - public select_transforms(DefaultQueryFixture fixture) : base(fixture) - { - } - - static select_transforms() - { - selectInOrder(docs => docs.OrderBy(x => x.Id).Take(10).Select(x => new Person { Name = x.String, Number = x.Number })); - } - - [Theory] - [MemberData(nameof(GetDescriptions))] - public Task run_query(string description) - { - return assertTestCase(description, Fixture.Store); - } -} - -public class Person -{ - public int Number { get; set; } - public string Name { get; set; } -} diff --git a/src/DocumentDbTests/Reading/Linq/EqualsIgnoreCase_filtering.cs b/src/DocumentDbTests/Reading/Linq/EqualsIgnoreCase_filtering.cs deleted file mode 100644 index 596d72337a8..00000000000 --- a/src/DocumentDbTests/Reading/Linq/EqualsIgnoreCase_filtering.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Linq; -using JasperFx.Core; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class EqualsIgnoreCase_filtering: IntegrationContext -{ - [Fact] - public void can_search_case_insensitive() - { - var user1 = new User { UserName = "Abc" }; - var user2 = new User { UserName = "DeF" }; - - using (var session = theStore.LightweightSession()) - { - session.Store(user1, user2); - session.SaveChanges(); - } - - using (var query = theStore.QuerySession()) - { - #region sample_sample-linq-EqualsIgnoreCase - query.Query().Single(x => x.UserName.EqualsIgnoreCase("abc")).Id.ShouldBe(user1.Id); - query.Query().Single(x => x.UserName.EqualsIgnoreCase("aBc")).Id.ShouldBe(user1.Id); - #endregion - query.Query().Single(x => x.UserName.EqualsIgnoreCase("def")).Id.ShouldBe(user2.Id); - - query.Query().Any(x => x.UserName.EqualsIgnoreCase("abcd")).ShouldBeFalse(); - } - } - - public EqualsIgnoreCase_filtering(DefaultStoreFixture fixture) : base(fixture) - { - } -} diff --git a/src/DocumentDbTests/Reading/Linq/Fields/FieldCollectionTests.cs b/src/DocumentDbTests/Reading/Linq/Fields/FieldCollectionTests.cs deleted file mode 100644 index 9df2f932b5b..00000000000 --- a/src/DocumentDbTests/Reading/Linq/Fields/FieldCollectionTests.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using Marten; -using Marten.Linq.Fields; -using Marten.Services; -using Marten.Testing.Documents; -using Shouldly; -using Weasel.Core; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.Fields; - -public class FieldCollectionTests -{ - private readonly StoreOptions theOptions = new StoreOptions(); - - - - private IField fieldFor(Expression> expression) - { - return new FieldMapping("d", typeof(T), theOptions).FieldFor(expression); - } - - private IField fieldFor(string memberName) - { - return new FieldMapping("d", typeof(T), theOptions).FieldFor(memberName); - } - - public class FieldHolder - { - public string[] Array; - public List List; - public IList IList; - public IReadOnlyList IReadOnlyList; - public ICollection ICollection; - public IEnumerable IEnumerable; - - } - - [Theory] - [InlineData(nameof(FieldHolder.Array))] - [InlineData(nameof(FieldHolder.List))] - [InlineData(nameof(FieldHolder.IList))] - [InlineData(nameof(FieldHolder.IReadOnlyList))] - [InlineData(nameof(FieldHolder.ICollection))] - [InlineData(nameof(FieldHolder.IEnumerable))] - public void find_array_field_for_collection_types(string memberName) - { - fieldFor(memberName).ShouldBeOfType(); - } - - [Fact] - public void enum_as_integer() - { - theOptions.Serializer(new JsonNetSerializer - { - EnumStorage = EnumStorage.AsInteger - }); - - fieldFor(x => x.Color).ShouldBeOfType(); - } - - [Fact] - public void enum_as_string() - { - theOptions.Serializer(new JsonNetSerializer - { - EnumStorage = EnumStorage.AsString - }); - - fieldFor(x => x.Color).ShouldBeOfType(); - } - - [Fact] - public void date_time() - { - fieldFor(x => x.Date).ShouldBeOfType(); - - } - - [Fact] - public void nullable_date_time() - { - fieldFor(x => x.NullableDateTime) - .ShouldBeOfType() - .InnerField - .ShouldBeOfType(); - } - - [Fact] - public void datetime_offset() - { - fieldFor(x => x.DateOffset).ShouldBeOfType(); - } - - [Fact] - public void string_field() - { - fieldFor(x => x.String).ShouldBeOfType(); - } - - [Fact] - public void simple_case_types() - { - fieldFor(x => x.Decimal).ShouldBeOfType(); - fieldFor(x => x.Number).ShouldBeOfType(); - fieldFor(x => x.Double).ShouldBeOfType(); - fieldFor(x => x.Float).ShouldBeOfType(); - } - - [Fact] - public void field_for_array_length() - { - - fieldFor(x => x.Array.Length).ShouldBeOfType(); - } - - [Fact] - public void field_for_collection_count_extension_method() - { - fieldFor(x => x.List.Count()).ShouldBeOfType(); - fieldFor(x => x.IList.Count()).ShouldBeOfType(); - fieldFor(x => x.IReadOnlyList.Count()).ShouldBeOfType(); - fieldFor(x => x.ICollection.Count()).ShouldBeOfType(); - fieldFor(x => x.IEnumerable.Count()).ShouldBeOfType(); - } - - [Fact] - public void field_for_list_count() - { - fieldFor(x => x.List.Count).ShouldBeOfType(); - fieldFor(x => x.IList.Count).ShouldBeOfType(); - fieldFor(x => x.IReadOnlyList.Count).ShouldBeOfType(); - - } - - public class DocWithAttributes - { - public Guid Id { get; set; } - public Dictionary Attributes { get; set; } - } - - [Fact] - public void field_for_dictionary() - { - fieldFor(x => x.Attributes) - .ShouldBeOfType(); - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/Internals/StatementTests.cs b/src/DocumentDbTests/Reading/Linq/Internals/StatementTests.cs deleted file mode 100644 index a87f14229cc..00000000000 --- a/src/DocumentDbTests/Reading/Linq/Internals/StatementTests.cs +++ /dev/null @@ -1,127 +0,0 @@ -using System; -using Marten.Internal; -using Marten.Linq.Fields; -using Marten.Linq.SqlGeneration; -using NSubstitute; -using Shouldly; -using Weasel.Postgresql; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.Internals; - -public class DummyStatement: Statement -{ - public DummyStatement() : base(Substitute.For()) - { - } - - protected override void configure(CommandBuilder builder) - { - throw new NotSupportedException(); - } -} - - -public class StatementTests -{ - [Fact] - public void appending_child_converts_to_CTE() - { - var root = new DummyStatement(); - var descendent = new DummyStatement(); - - root.InsertAfter(descendent); - - root.Next.ShouldBe(descendent); - descendent.Previous.ShouldBe(root); - - } -} - -public class when_inserting_a_statement_before_an_unattached_statement -{ - private readonly DummyStatement original; - private readonly DummyStatement newRoot; - - public when_inserting_a_statement_before_an_unattached_statement() - { - var session = Substitute.For(); - session.NextTempTableName().Returns("NextTempTable"); - - original = new DummyStatement - { - Mode = StatementMode.Select - }; - - newRoot = new DummyStatement(); - - - original.InsertBefore(newRoot); - } - - [Fact] - public void relationships() - { - newRoot.Next.ShouldBe(original); - original.Previous.ShouldBe(newRoot); - } - - [Fact] - public void new_root_is_top() - { - newRoot.Previous.ShouldBeNull(); - original.Top().ShouldBe(newRoot); - newRoot.Top().ShouldBe(newRoot); - } - - [Fact] - public void original_is_current() - { - original.Current().ShouldBe(original); - newRoot.Current().ShouldBe(original); - } -} - -public class when_inserting_statement_in_front_of_statement_that_is_not_the_top -{ - private readonly DummyStatement root = new DummyStatement(); - private readonly DummyStatement original = new DummyStatement(); - private readonly DummyStatement inserted = new DummyStatement(); - - public when_inserting_statement_in_front_of_statement_that_is_not_the_top() - { - var session = Substitute.For(); - session.NextTempTableName().Returns("NextTempTable"); - - root.InsertAfter(original); - - inserted = new DummyStatement(); - - original.InsertBefore(inserted); - } - - [Fact] - public void relationships() - { - root.Next.ShouldBe(inserted); - inserted.Previous.ShouldBe(root); - inserted.Next.ShouldBe(original); - original.Previous.ShouldBe(inserted); - } - - [Fact] - public void root_is_still_top() - { - original.Top().ShouldBe(root); - inserted.Top().ShouldBe(root); - } - - [Fact] - public void original_is_current() - { - original.Current().ShouldBe(original); - inserted.Current().ShouldBe(original); - } - - -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/Internals/SubQueryFilterParserTests.cs b/src/DocumentDbTests/Reading/Linq/Internals/SubQueryFilterParserTests.cs deleted file mode 100644 index 118f8451d1b..00000000000 --- a/src/DocumentDbTests/Reading/Linq/Internals/SubQueryFilterParserTests.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using JasperFx.Core; -using JasperFx.Core.Reflection; -using Marten.Linq.Parsing; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Remotion.Linq.Clauses; -using Remotion.Linq.Clauses.Expressions; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.Internals; - -public class SubQueryFilterParserTests -{ - - private SubQueryExpression forExpression(Expression> filter) - { - Expression, IQueryable>> query = q => q.Where(filter); - - var invocation = Expression.Invoke(query, Expression.Parameter(typeof(IQueryable))); - - - var model = MartenQueryParser.Flyweight.GetParsedQuery(invocation); - - return (SubQueryExpression) model.BodyClauses.Single().As().Predicate; - } - - [Fact] - public void try_stuff() - { - var expression = forExpression(x => x.Children.Any(c => c.Children.Length > 2)); - expression.ShouldNotBeNull(); - } -} diff --git a/src/DocumentDbTests/Reading/Linq/InvariantCultureIgnoreCase_filtering.cs b/src/DocumentDbTests/Reading/Linq/InvariantCultureIgnoreCase_filtering.cs deleted file mode 100644 index 9a7d0df0938..00000000000 --- a/src/DocumentDbTests/Reading/Linq/InvariantCultureIgnoreCase_filtering.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class InvariantCultureIgnoreCase_filtering: IntegrationContext -{ - [Fact] - public void can_search_case_insensitive() - { - var user = new User {UserName = "TEST_USER"}; - - using (var session = theStore.LightweightSession()) - { - session.Store(user); - session.SaveChanges(); - } - - using (var query = theStore.QuerySession()) - { - query.Query().Single(x => x.UserName.Equals("test_user", StringComparison.InvariantCultureIgnoreCase)).Id.ShouldBe(user.Id); - } - } - - [Fact] - public void can_search_string_with_back_slash_case_insensitive() - { - var user = new User {UserName = @"DOMAIN\TEST_USER"}; - - using (var session = theStore.LightweightSession()) - { - session.Store(user); - session.SaveChanges(); - } - - using (var query = theStore.QuerySession()) - { - query.Query().Single(x => x.UserName.Equals(@"domain\test_user", StringComparison.InvariantCultureIgnoreCase)).Id.ShouldBe(user.Id); - } - } - - public InvariantCultureIgnoreCase_filtering(DefaultStoreFixture fixture) : base(fixture) - { - } -} diff --git a/src/DocumentDbTests/Reading/Linq/MatchesSql/MatchesSqlExtensionsTests.cs b/src/DocumentDbTests/Reading/Linq/MatchesSql/MatchesSqlExtensionsTests.cs deleted file mode 100644 index 0887190ba05..00000000000 --- a/src/DocumentDbTests/Reading/Linq/MatchesSql/MatchesSqlExtensionsTests.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using Marten.Linq.MatchesSql; -using Shouldly; -using Weasel.Postgresql.SqlGeneration; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.MatchesSql; - -public class MatchesSqlExtensionsTests -{ - [Fact] - public void Throws_NotSupportedException_when_called_directly() - { - Should.Throw( - () => new object().MatchesSql("d.data ->> 'UserName' = ? or d.data ->> 'UserName' = ?", "baz", "jack")); - Should.Throw( - () => new object().MatchesSql(new WhereFragment("d.data ->> 'UserName' != ?", "baz"))); - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/Omitting_zero_offset_Tests.cs b/src/DocumentDbTests/Reading/Linq/Omitting_zero_offset_Tests.cs deleted file mode 100644 index f87316aac7e..00000000000 --- a/src/DocumentDbTests/Reading/Linq/Omitting_zero_offset_Tests.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Linq; -using Marten; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class Omitting_zero_offset_Tests : IntegrationContext -{ - [Theory] - [InlineData(0, true)] - [InlineData(10, false)] - public void sql_command_should_not_contain_OFFSET_with_zero_value(int skipCount, bool omit) - { - // given - var queryable = theSession - .Query() - .Skip(skipCount); - - // when - var sql = queryable.ToCommand().CommandText; - - // than - if (omit) - { - sql.ShouldNotContain("OFFSET :", Case.Insensitive); - } - else - { - sql.ShouldContain("OFFSET :", Case.Insensitive); - } - } - - public Omitting_zero_offset_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/Parsing/IsNullAndNotNullFilterTests.cs b/src/DocumentDbTests/Reading/Linq/Parsing/IsNullAndNotNullFilterTests.cs deleted file mode 100644 index bf5de5112f4..00000000000 --- a/src/DocumentDbTests/Reading/Linq/Parsing/IsNullAndNotNullFilterTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Marten.Linq.Fields; -using Marten.Linq.Filters; -using NSubstitute; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.Parsing; - -public class IsNullAndNotNullFilterTests -{ - [Fact] - public void reverse_is_null() - { - var filter = new IsNullFilter(Substitute.For()); - filter.Reverse().ShouldBeOfType() - .Field.ShouldBe(filter.Field); - } - - [Fact] - public void reverse_not_null_is_null() - { - var filter = new IsNotNullFilter(Substitute.For()); - filter.Reverse().ShouldBeOfType() - .Field.ShouldBe(filter.Field); - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/SimpleEqualsParserTests.cs b/src/DocumentDbTests/Reading/Linq/SimpleEqualsParserTests.cs deleted file mode 100644 index 13e0d31e078..00000000000 --- a/src/DocumentDbTests/Reading/Linq/SimpleEqualsParserTests.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using Marten.Exceptions; -using Marten.Linq; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class SimpleEqualsParserTests : IntegrationContext -{ - public class QueryTarget - { - public int IntProp { get; set; } - public long LongProp { get; set; } - public decimal DecimalProp { get; set; } - public bool BoolProp { get; set; } - public Guid Id { get; set; } - public DateTime DateTimeProp { get; set; } - public DateTimeOffset DateTimeOffsetProp { get; set; } - } - - [Fact] - public void CanTranslateEqualsToQueries() - { - var queryTarget = new QueryTarget - { - IntProp = 1, - LongProp = 2, - DecimalProp = 1.1m, - BoolProp = true, - Id = Guid.NewGuid(), - DateTimeProp = DateTime.UtcNow, - DateTimeOffsetProp = DateTimeOffset.UtcNow - }; - - theSession.Store(queryTarget); - - theSession.SaveChanges(); - - var itemFromDb = theSession.Query() - .Where(x => x.IntProp.Equals(queryTarget.IntProp)) - .Where(x => x.LongProp.Equals(queryTarget.LongProp)) - .Where(x => x.DecimalProp.Equals(queryTarget.DecimalProp)) - .Where(x => x.BoolProp.Equals(queryTarget.BoolProp)) - .Where(x => x.Id.Equals(queryTarget.Id)) - .Where(x => x.DateTimeProp.Equals(queryTarget.DateTimeProp)) - .Where(x => x.DateTimeOffsetProp.Equals(queryTarget.DateTimeOffsetProp)) - .FirstOrDefault(); - - Assert.NotNull(itemFromDb); - } - - [Fact] - public void ThrowsWhenValueNotConvertibleToComparandType() - { - var queryTarget = new QueryTarget - { - Id = System.Guid.NewGuid() - }; - theSession.Store(queryTarget); - - theSession.SaveChanges(); - - object notInt = "not int"; - - Assert.Throws(() => - { - theSession.Query() - .Where(x => x.IntProp.Equals(notInt)) - .FirstOrDefault(); - }); - } - - - public class TestData : IEnumerable - { - private readonly List _data = new List - { - new object[] { Guid.NewGuid() }, - new object[] { 0 }, - new object[] { null }, - new object[] { false }, - new object[] { 32m }, - new object[] { 0L }, - new object[] { DateTime.UtcNow }, - new object[] { DateTimeOffset.UtcNow }, - }; - - public IEnumerator GetEnumerator() - { - return _data.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } - - [Fact] - public void CanUseEqualsInCompiledQuery() - { - var queryTarget = new QueryTarget - { - IntProp = 1, - LongProp = 2, - DecimalProp = 1.1m, - BoolProp = true, - Id = Guid.NewGuid() - }; - - theSession.Store(queryTarget); - - theSession.SaveChanges(); - - var itemFromDb = - theSession.Query(new CompiledQueryTarget() {IdProp = queryTarget.Id, IntProp = queryTarget.IntProp}); - - Assert.NotNull(itemFromDb); - } - - public class CompiledQueryTarget : ICompiledQuery - { - public Guid IdProp { get; set; } - public int IntProp { get; set; } - - public Expression, QueryTarget>> QueryIs() - { - return q => q.FirstOrDefault(x => x.IntProp.Equals(IntProp) && x.Id.Equals(IdProp)); - } - } - - public SimpleEqualsParserTests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/SimpleNotEqualsParserTests.cs b/src/DocumentDbTests/Reading/Linq/SimpleNotEqualsParserTests.cs deleted file mode 100644 index 81755895a67..00000000000 --- a/src/DocumentDbTests/Reading/Linq/SimpleNotEqualsParserTests.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Linq; -using Marten.Exceptions; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class SimpleNotEqualsParserTests : IntegrationContext -{ - public class QueryTarget - { - public int IntProp { get; set; } - public long LongProp { get; set; } - public decimal DecimalProp { get; set; } - public bool BoolProp { get; set; } - public Guid Id { get; set; } - public DateTime DateTimeProp { get; set; } - public DateTimeOffset DateTimeOffsetProp { get; set; } - } - - [Fact] - public void CanTranslateNotEqualsToQueries() - { - var queryTarget = new QueryTarget - { - IntProp = 1, - LongProp = 2, - DecimalProp = 1.1m, - BoolProp = true, - Id = Guid.NewGuid(), - DateTimeProp = DateTime.UtcNow, - DateTimeOffsetProp = DateTimeOffset.UtcNow - }; - - theSession.Store(queryTarget); - - theSession.SaveChanges(); - - var itemFromDb = theSession.Query() - .Where(x => !x.IntProp.Equals(queryTarget.IntProp)) - .Where(x => !x.LongProp.Equals(queryTarget.LongProp)) - .Where(x => !x.DecimalProp.Equals(queryTarget.DecimalProp)) - .Where(x => !x.BoolProp.Equals(queryTarget.BoolProp)) - .Where(x => !x.Id.Equals(queryTarget.Id)) - .Where(x => !x.DateTimeProp.Equals(queryTarget.DateTimeProp)) - .Where(x => !x.DateTimeOffsetProp.Equals(queryTarget.DateTimeOffsetProp)) - .FirstOrDefault(); - - Assert.Null(itemFromDb); - } - - [Fact] - public void ThrowsWhenValueNotConvertibleToComparandType() - { - var queryTarget = new QueryTarget - { - Id = System.Guid.NewGuid() - }; - theSession.Store(queryTarget); - - theSession.SaveChanges(); - - object notInt = "not int"; - - Assert.Throws(() => - { - theSession.Query() - .Where(x => !x.IntProp.Equals(notInt)) - .FirstOrDefault(); - }); - } - - - - public SimpleNotEqualsParserTests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedBeforeParserTests.cs b/src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedBeforeParserTests.cs deleted file mode 100644 index 51728d2a31c..00000000000 --- a/src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedBeforeParserTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Linq.Expressions; -using Marten; -using Marten.Linq.SoftDeletes; -using Marten.Schema; -using Marten.Services; -using Marten.Testing.Harness; -using Npgsql; -using Weasel.Postgresql; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.SoftDeletes; - -public class DeletedBeforeParserTests -{ - private readonly DocumentMapping _mapping; - private readonly MethodCallExpression _expression; - private readonly DeletedBeforeParser _parser; - private readonly StoreOptions _options; - - public DeletedBeforeParserTests() - { - _options = new StoreOptions(); - _mapping = new DocumentMapping(typeof(object), _options) { DeleteStyle = DeleteStyle.SoftDelete }; - _expression = Expression.Call(typeof(SoftDeletedExtensions).GetMethod(nameof(SoftDeletedExtensions.DeletedBefore)), - Expression.Parameter(typeof(object)), - Expression.Constant(DateTimeOffset.UtcNow)); - _parser = new DeletedBeforeParser(); - } - - [Fact] - public void WhereFragmentContainsExpectedExpression() - { - var result = _parser.Parse(_mapping, _options, _expression); - - var builder = new CommandBuilder(new NpgsqlCommand()); - - result.Apply(builder); - builder.ToString().ShouldContain("d.mt_deleted and d.mt_deleted_at <"); - } - - [Fact] - public void ThrowsIfDocumentMappingNotSoftDeleted() - { - _mapping.DeleteStyle = DeleteStyle.Remove; - - Exception.ShouldBeThrownBy(() => _parser.Parse(_mapping, _options, _expression)); - } -} diff --git a/src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedSinceParserTests.cs b/src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedSinceParserTests.cs deleted file mode 100644 index 9aef37e8a5e..00000000000 --- a/src/DocumentDbTests/Reading/Linq/SoftDeletes/DeletedSinceParserTests.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Linq.Expressions; -using Marten; -using Marten.Linq.SoftDeletes; -using Marten.Schema; -using Marten.Services; -using Marten.Testing.Harness; -using Npgsql; -using Weasel.Postgresql; -using Xunit; - -namespace DocumentDbTests.Reading.Linq.SoftDeletes; - -public class DeletedSinceParserTests -{ - private readonly DocumentMapping _mapping; - private readonly MethodCallExpression _expression; - private readonly DeletedSinceParser _parser; - private readonly StoreOptions _options; - - public DeletedSinceParserTests() - { - _options = new StoreOptions(); - _options.Serializer(); - _mapping = new DocumentMapping(typeof(object), _options) { DeleteStyle = DeleteStyle.SoftDelete }; - _expression = Expression.Call(typeof(SoftDeletedExtensions).GetMethod(nameof(SoftDeletedExtensions.DeletedSince)), - Expression.Parameter(typeof(object)), - Expression.Constant(DateTimeOffset.UtcNow)); - _parser = new DeletedSinceParser(); - } - - [Fact] - public void WhereFragmentContainsExpectedExpression() - { - var result = _parser.Parse(_mapping, _options, _expression); - - var builder = new CommandBuilder(new NpgsqlCommand()); - - result.Apply(builder); - - builder.ToString().ShouldContain("d.mt_deleted and d.mt_deleted_at >"); - } - - [Fact] - public void ThrowsIfDocumentMappingNotSoftDeleted() - { - _mapping.DeleteStyle = DeleteStyle.Remove; - - Exception.ShouldBeThrownBy(() => _parser.Parse(_mapping, _options, _expression)); - } -} diff --git a/src/DocumentDbTests/Reading/Linq/invoking_query_with_statistics.cs b/src/DocumentDbTests/Reading/Linq/invoking_query_with_statistics.cs deleted file mode 100644 index 78f3cfc5df2..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_query_with_statistics.cs +++ /dev/null @@ -1,212 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Linq.Expressions; -using System.Threading.Tasks; -using Marten; -using Marten.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_query_with_statistics: IntegrationContext -{ - public invoking_query_with_statistics(DefaultStoreFixture fixture) : base(fixture) - { - - } - - protected override Task fixtureSetup() - { - return theStore.BulkInsertAsync(Target.GenerateRandomData(100).ToArray()); - } - - #region sample_compiled-query-statistics - public class TargetPaginationQuery: ICompiledListQuery - { - public TargetPaginationQuery(int pageNumber, int pageSize) - { - PageNumber = pageNumber; - PageSize = pageSize; - } - - public int PageNumber { get; set; } - public int PageSize { get; set; } - - public QueryStatistics Stats { get; } = new QueryStatistics(); - - public Expression, IEnumerable>> QueryIs() - { - return query => query - .Where(x => x.Number > 10) - .Skip(PageNumber) - .Take(PageSize); - } - } - - #endregion - - [Fact] - public void can_get_the_total_from_a_compiled_query() - { - var count = theSession.Query().Count(x => x.Number > 10); - count.ShouldBeGreaterThan(0); - - var query = new TargetPaginationQuery(2, 5); - var list = theSession - .Query(query) - .ToList(); - - list.Any().ShouldBeTrue(); - - query.Stats.TotalResults.ShouldBe(count); - } - - [Fact] - public async Task can_use_json_streaming_with_statistics() - { - - var count = theSession.Query().Count(x => x.Number > 10); - count.ShouldBeGreaterThan(0); - - var query = new TargetPaginationQuery(2, 5); - var stream = new MemoryStream(); - var resultCount = await theSession - .StreamJsonMany(query, stream); - - resultCount.ShouldBeGreaterThan(0); - - stream.Position = 0; - var list = theStore.Options.Serializer().FromJson(stream); - list.Length.ShouldBe(5); - - } - - [Fact] - public async Task can_get_the_total_from_a_compiled_query_running_in_a_batch() - { - var count = await theSession.Query().Where(x => x.Number > 10).CountAsync(); - SpecificationExtensions.ShouldBeGreaterThan(count, 0); - - var query = new TargetPaginationQuery(2, 5); - - var batch = theSession.CreateBatchQuery(); - - var targets = batch.Query(query); - - await batch.Execute(); - - (await targets) - .Any().ShouldBeTrue(); - - query.Stats.TotalResults.ShouldBe(count); - } - - [Fact] - public void can_get_the_total_from_a_compiled_query_running_in_a_batch_sync() - { - var count = theSession.Query().Count(x => x.Number > 10); - SpecificationExtensions.ShouldBeGreaterThan(count, 0); - - var query = new TargetPaginationQuery(2, 5); - - var batch = theSession.CreateBatchQuery(); - - var targets = batch.Query(query); - - batch.ExecuteSynchronously(); - - targets.Result - .Any().ShouldBeTrue(); - - query.Stats.TotalResults.ShouldBe(count); - } - - [Fact] - public async Task can_get_the_total_in_batch_query() - { - var count = await theSession.Query().Where(x => x.Number > 10).CountAsync(); - SpecificationExtensions.ShouldBeGreaterThan(count, 0); - - QueryStatistics stats = null; - - var batch = theSession.CreateBatchQuery(); - - var list = batch.Query().Stats(out stats).Where(x => x.Number > 10).Take(5) - .ToList(); - - await batch.Execute(); - - (await list).Any().ShouldBeTrue(); - - stats.TotalResults.ShouldBe(count); - } - - [Fact] - public void can_get_the_total_in_batch_query_sync() - { - var count = theSession.Query().Count(x => x.Number > 10); - SpecificationExtensions.ShouldBeGreaterThan(count, 0); - - QueryStatistics stats = null; - - var batch = theSession.CreateBatchQuery(); - - var list = batch.Query().Stats(out stats).Where(x => x.Number > 10).Take(5) - .ToList(); - - batch.ExecuteSynchronously(); - - list.Result.Any().ShouldBeTrue(); - - stats.TotalResults.ShouldBe(count); - } - - #region sample_using-query-statistics - [Fact] - public void can_get_the_total_in_results() - { - var count = theSession.Query().Count(x => x.Number > 10); - SpecificationExtensions.ShouldBeGreaterThan(count, 0); - - // We're going to use stats as an output - // parameter to the call below, so we - // have to declare the "stats" object - // first - QueryStatistics stats = null; - - var list = theSession - .Query() - .Stats(out stats) - .Where(x => x.Number > 10).Take(5) - .ToList(); - - list.Any().ShouldBeTrue(); - - // Now, the total results data should - // be available - stats.TotalResults.ShouldBe(count); - } - - #endregion - - [Fact] - public async Task can_get_the_total_in_results_async() - { - var count = await theSession.Query().Where(x => x.Number > 10).CountAsync(); - SpecificationExtensions.ShouldBeGreaterThan(count, 0); - - QueryStatistics stats = null; - - var list = await theSession.Query().Stats(out stats).Where(x => x.Number > 10).Take(5) - .ToListAsync(); - - list.Any().ShouldBeTrue(); - - stats.TotalResults.ShouldBe(count); - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_any_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_any_Tests.cs deleted file mode 100644 index 93f441245b3..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_any_Tests.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_any_Tests: IntegrationContext -{ - [Fact] - public void any_miss_with_query() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - theSession.Query().Any(x => x.Number == 11) - .ShouldBeFalse(); - } - - [Fact] - public void naked_any_miss() - { - theSession.Query().Any() - .ShouldBeFalse(); - } - - [Fact] - public void naked_any_hit() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - theSession.Query().Any().ShouldBeTrue(); - } - - [Fact] - public void any_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - theSession.Query().Any(x => x.Number == 3) - .ShouldBeTrue(); - } - - [Fact] - public void any_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - theSession.Query().Where(x => x.Number == 2).Any() - .ShouldBeTrue(); - } - - public invoking_queryable_any_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_any_async_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_any_async_Tests.cs deleted file mode 100644 index fb6de979a28..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_any_async_Tests.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Marten; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_any_async_Tests: IntegrationContext -{ - [Fact] - public async Task any_miss_with_query() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var result = await theSession.Query().AnyAsync(x => x.Number == 11); - result.ShouldBeFalse(); - } - - [Fact] - public async Task naked_any_miss() - { - var result = await theSession.Query().AnyAsync(); - result.ShouldBeFalse(); - } - - [Fact] - public async Task naked_any_hit() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - var result = await theSession.Query().AnyAsync(); - result.ShouldBeTrue(); - } - - [Fact] - public async Task any_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - var result = await theSession.Query().AnyAsync(x => x.Number == 3); - result.ShouldBeTrue(); - } - - [Fact] - public async Task any_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - var result = await theSession.Query().Where(x => x.Number == 2).AnyAsync(); - result.ShouldBeTrue(); - } - - public invoking_queryable_any_async_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_count_async_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_count_async_Tests.cs deleted file mode 100644 index 22cd10050cd..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_count_async_Tests.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System.Threading.Tasks; -using Marten; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_count_async_Tests: IntegrationContext -{ - [Fact] - public async Task count_without_any_where() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var result = await theSession.Query().CountAsync(); - result.ShouldBe(4); - } - - [Fact] - public async Task long_count_without_any_where() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var result = await theSession.Query().LongCountAsync(); - result.ShouldBe(4); - } - - [Fact] - public async Task count_with_a_where_clause() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.Store(new Target { Number = 5 }); - theSession.Store(new Target { Number = 6 }); - await theSession.SaveChangesAsync(); - - var result = await theSession.Query().CountAsync(x => x.Number > 3); - result.ShouldBe(3); - } - - [Fact] - public async Task long_count_with_a_where_clause() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.Store(new Target { Number = 5 }); - theSession.Store(new Target { Number = 6 }); - await theSession.SaveChangesAsync(); - - var result = await theSession.Query().LongCountAsync(x => x.Number > 3); - result.ShouldBe(3); - } - - [Fact] - public async Task sum_without_any_where() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var result = await theSession.Query().SumAsync(x => x.Number); - result.ShouldBe(10); - } - - [Fact] - public async Task sum_with_nullable() - { - theSession.Store(new Target { NullableNumber = 1 }); - theSession.Store(new Target { NullableNumber = 2 }); - theSession.Store(new Target { NullableNumber = 3 }); - theSession.Store(new Target { NullableNumber = 4 }); - await theSession.SaveChangesAsync(); - - var result = await theSession.Query().SumAsync(x => x.NullableNumber); - result.ShouldBe(10); - } - - public invoking_queryable_count_async_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_Tests.cs deleted file mode 100644 index 354c546c675..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_Tests.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_through_first_Tests: IntegrationContext -{ - [Fact] - public void first_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - SpecificationExtensions.ShouldNotBeNull(theSession.Query().First(x => x.Number == 3)); - } - - [Fact] - public void first_or_default_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - SpecificationExtensions.ShouldNotBeNull(theSession.Query().FirstOrDefault(x => x.Number == 3)); - } - - [Fact] - public void first_or_default_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - SpecificationExtensions.ShouldBeNull(theSession.Query().FirstOrDefault(x => x.Number == 11)); - } - - [Fact] - public void first_correct_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2, Flag = true }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - theSession.Query().Where(x => x.Number == 2).First().Flag - .ShouldBeTrue(); - } - - [Fact] - public void first_or_default_correct_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2, Flag = true }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - theSession.Query().Where(x => x.Number == 2).First().Flag - .ShouldBeTrue(); - } - - [Fact] - public void first_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - Exception.ShouldBeThrownBy(() => - { - theSession.Query().Where(x => x.Number == 11).First(); - }); - } - - public invoking_queryable_through_first_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_async_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_async_Tests.cs deleted file mode 100644 index ac571431c40..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_first_async_Tests.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Marten; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_through_first_async_Tests: IntegrationContext -{ - [Fact] - public async Task first_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().FirstAsync(x => x.Number == 3); - SpecificationExtensions.ShouldNotBeNull(target); - } - - [Fact] - public async Task first_or_default_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().FirstOrDefaultAsync(x => x.Number == 3); - SpecificationExtensions.ShouldNotBeNull(target); - } - - [Fact] - public async Task first_or_default_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().FirstOrDefaultAsync(x => x.Number == 11); - SpecificationExtensions.ShouldBeNull(target); - } - - [Fact] - public async Task first_correct_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2, Flag = true }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().Where(x => x.Number == 2).FirstAsync(); - target.Flag.ShouldBeTrue(); - } - - [Fact] - public async Task first_or_default_correct_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2, Flag = true }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().Where(x => x.Number == 2).FirstOrDefaultAsync(); - target.Flag.ShouldBeTrue(); - } - - [Fact] - public async Task first_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - await Exception.ShouldBeThrownByAsync(async () => - { - await theSession.Query().Where(x => x.Number == 11).FirstAsync(); - }); - } - - public invoking_queryable_through_first_async_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_last_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_last_Tests.cs deleted file mode 100644 index 7ae20ac1c37..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_last_Tests.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_through_last_Tests: IntegrationContext -{ - [Fact] - public void last_throws_an_exception() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - Exception.ShouldBeThrownBy(() => - { - theSession.Query().Last(x => x.Number == 3) - .ShouldNotBeNull(); - }); - } - - public invoking_queryable_through_last_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_Tests.cs deleted file mode 100644 index 32ba887eb02..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_Tests.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_through_single_Tests : IntegrationContext -{ - #region sample_single_and_single_or_default - [Fact] - public void single_hit_with_only_one_document() - { - theSession.Store(new Target{Number = 1}); - theSession.Store(new Target{Number = 2}); - theSession.Store(new Target{Number = 3}); - theSession.Store(new Target{Number = 4}); - theSession.SaveChanges(); - - SpecificationExtensions.ShouldNotBeNull(theSession.Query().Single(x => x.Number == 3)); - } - - [Fact] - public void single_or_default_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - SpecificationExtensions.ShouldNotBeNull(theSession.Query().SingleOrDefault(x => x.Number == 3)); - } - #endregion - - [Fact] - public void single_or_default_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - SpecificationExtensions.ShouldBeNull(theSession.Query().SingleOrDefault(x => x.Number == 11)); - } - - [Fact] - public void single_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - Exception.ShouldBeThrownBy(() => - { - theSession.Query().Where(x => x.Number == 2).Single(); - }); - } - - [Fact] - public void single_hit_with_more_than_one_match_and_take_one_should_not_throw() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - theSession.Query().Where(x => x.Number == 2).Take(1).Single().ShouldNotBeNull(); - } - - [Fact] - public void single_or_default_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - Exception.ShouldBeThrownBy(() => - { - theSession.Query().Where(x => x.Number == 2).SingleOrDefault(); - }); - } - - [Fact] - public void single_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - theSession.SaveChanges(); - - Exception.ShouldBeThrownBy(() => - { - theSession.Query().Where(x => x.Number == 11).Single(); - }); - } - - public invoking_queryable_through_single_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_async_Tests.cs b/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_async_Tests.cs deleted file mode 100644 index 6d36911d1f6..00000000000 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_single_async_Tests.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Marten; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class invoking_queryable_through_single_async_Tests: IntegrationContext -{ - [Fact] - public async Task single_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().SingleAsync(x => x.Number == 3); - target.ShouldNotBeNull(); - } - - [Fact] - public async Task single_or_default_hit_with_only_one_document() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().SingleOrDefaultAsync(x => x.Number == 3); - target.ShouldNotBeNull(); - } - - [Fact] - public async Task single_or_default_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().SingleOrDefaultAsync(x => x.Number == 11); - target.ShouldBeNull(); - } - - [Fact] - public async Task single_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - await Exception.ShouldBeThrownByAsync(async () => - { - await theSession.Query().Where(x => x.Number == 2).SingleAsync(); - }); - } - - [Fact] - public async Task single_hit_with_more_than_one_match_and_take_one_should_not_throw() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - var target = await theSession.Query().Where(x => x.Number == 2).Take(1).SingleAsync(); - target.ShouldNotBeNull(); - } - - [Fact] - public async Task single_or_default_hit_with_more_than_one_match() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - await Exception.ShouldBeThrownByAsync(async () => - { - await theSession.Query().Where(x => x.Number == 2).SingleOrDefaultAsync(); - }); - } - - [Fact] - public async Task single_miss() - { - theSession.Store(new Target { Number = 1 }); - theSession.Store(new Target { Number = 2 }); - theSession.Store(new Target { Number = 3 }); - theSession.Store(new Target { Number = 4 }); - await theSession.SaveChangesAsync(); - - await Exception.ShouldBeThrownByAsync(async () => - { - await theSession.Query().Where(x => x.Number == 11).SingleAsync(); - }); - } - - public invoking_queryable_through_single_async_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/previewing_the_command_from_a_queryable_Tests.cs b/src/DocumentDbTests/Reading/Linq/previewing_the_command_from_a_queryable_Tests.cs deleted file mode 100644 index 1e5b3f219cc..00000000000 --- a/src/DocumentDbTests/Reading/Linq/previewing_the_command_from_a_queryable_Tests.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Linq; -using Marten; -using Marten.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; -using Xunit.Abstractions; - -namespace DocumentDbTests.Reading.Linq; - -public class previewing_the_command_from_a_queryable_Tests : OneOffConfigurationsContext -{ - private readonly ITestOutputHelper _output; - - public previewing_the_command_from_a_queryable_Tests(ITestOutputHelper output) - { - _output = output; - } - - [Fact] - public void preview_basic_select_command() - { - var cmd = theSession.Query().ToCommand(FetchType.FetchMany); - - _output.WriteLine(cmd.CommandText); - - cmd.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d"); - cmd.Parameters.Any().ShouldBeFalse(); - } - - [Fact] - public void preview_select_many() - { - var cmd = theSession.Query().SelectMany(x => x.Children).Where(x => x.Flag) - .ToCommand(FetchType.FetchMany); - - _output.WriteLine(cmd.CommandText); - } - - [Fact] - public void preview_command_with_where_and_parameters() - { - var cmd = theSession.Query().Where(x => x.Number == 3 && x.Double > 2).ToCommand(FetchType.FetchMany); - - cmd.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d where (CAST(d.data ->> 'Number' as integer) = :p0 and CAST(d.data ->> 'Double' as double precision) > :p1)"); - - cmd.Parameters.Count.ShouldBe(2); - cmd.Parameters["p0"].Value.ShouldBe(3); - cmd.Parameters["p1"].Value.ShouldBe(2); - } - - [Fact] - public void preview_basic_count_command() - { - var cmd = theSession.Query().ToCommand(FetchType.Count); - - cmd.CommandText.ShouldBe($"select count(*) as number from {SchemaName}.mt_doc_target as d"); - } - - [Fact] - public void preview_basic_any_command() - { - var cmd = theSession.Query().ToCommand(FetchType.Any); - - cmd.CommandText.ShouldBe($"select TRUE as result from {SchemaName}.mt_doc_target as d LIMIT :p0"); - } - - [Fact] - public void preview_select_on_query() - { - var cmd = theSession.Query().OrderBy(x => x.Double).ToCommand(FetchType.FetchOne); - - cmd.CommandText.Trim().ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d order by CAST(d.data ->> 'Double' as double precision) LIMIT :p0"); - } - - -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/query_beginning_with_constant_Tests.cs b/src/DocumentDbTests/Reading/Linq/query_beginning_with_constant_Tests.cs deleted file mode 100644 index 34e977e0dbc..00000000000 --- a/src/DocumentDbTests/Reading/Linq/query_beginning_with_constant_Tests.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Xunit; -using Xunit.Abstractions; - -namespace DocumentDbTests.Reading.Linq; - -public class query_beginning_with_equal_to_value_Tests : IntegrationContext -{ - private readonly ITestOutputHelper _output; - - [Fact] - public void start_with_constant() - { - theSession.Store(new Target{Number = 1}); - theSession.Store(new Target{Number = 2}); - - theSession.SaveChanges(); - - theSession.Query().Where(x => 2 == x.Number).ToArray() - .Select(x => x.Number) - .ShouldHaveTheSameElementsAs(2); - } - - [Fact] - public void start_with_constant_2() - { - theSession.Store(new Target{Number = 1}); - theSession.Store(new Target{Number = 2}); - - theSession.SaveChanges(); - - theSession.Query().Where(x => 1 < x.Number).ToArray() - .Select(x => x.Number) - .ShouldHaveTheSameElementsAs(2); - } - - [Fact] - public void start_with_null_constant() - { - theSession.Store(new Target {Number = 1}); - theSession.Store(new Target{NullableNumber = 2, Number = 2}); - - theSession.SaveChanges(); - - theSession.Query().Where(x => null == x.NullableNumber).ToArray() - .Select(x => x.Number) - .ShouldHaveTheSameElementsAs(1); - } - - [Fact] - public void later_expression_starts_with_constant() - { - theSession.Store(new Target{Number = 1}); - theSession.Store(new Target{Number = 2}); - - theSession.SaveChanges(); - - theSession.Query().Where(x => x.Number == 1 || 2 == x.Number).ToArray() - .Select(x => x.Number) - .ShouldHaveTheSameElementsAs(1,2); - } - - [Fact] - public void start_with_variable() - { - theSession.Store(new Target{Number = 1}); - theSession.Store(new Target{Number = 2}); - - theSession.SaveChanges(); - var num = 2; - theSession.Query().Where(x => num == x.Number).ToArray() - .Select(x => x.Number) - .ShouldHaveTheSameElementsAs(2); - } - - [Fact] - public void start_with_member_variable() - { - theSession.Store(new Target{Number = 1}); - theSession.Store(new Target{Number = 2}); - - theSession.SaveChanges(); - var obj = new {Number = 2}; - theSession.Query().Where(x => obj.Number == x.Number).ToArray() - .Select(x => x.Number) - .ShouldHaveTheSameElementsAs(2); - } - - public query_beginning_with_equal_to_value_Tests(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) - { - _output = output; - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/query_for_sum_Tests.cs b/src/DocumentDbTests/Reading/Linq/query_for_sum_Tests.cs deleted file mode 100644 index e8703be419a..00000000000 --- a/src/DocumentDbTests/Reading/Linq/query_for_sum_Tests.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Weasel.Core; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class query_for_sum_Tests: IntegrationContext -{ - #region sample_using_sum - [Fact] - public void get_sum_of_integers() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 2 }); - theSession.Store(new Target { Color = Colors.Green, Number = 3 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - - theSession.SaveChanges(); - theSession.Query().Sum(x => x.Number) - .ShouldBe(10); - } - - #endregion - - [Fact] - public void get_sum_of_decimals() - { - theSession.Store(new Target { Color = Colors.Blue, Decimal = 1.1m }); - theSession.Store(new Target { Color = Colors.Red, Decimal = 2.2m }); - theSession.Store(new Target { Color = Colors.Green, Decimal = 3.3m }); - - theSession.SaveChanges(); - theSession.Query().Sum(x => x.Decimal) - .ShouldBe(6.6m); - } - - [Fact] - public void get_sum_of_empty_table() - { - theSession.Query().Sum(x => x.Number) - .ShouldBe(0); - } - - [Fact] - public void get_sum_of_integers_with_where() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 2 }); - theSession.Store(new Target { Color = Colors.Green, Number = 3 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - - theSession.SaveChanges(); - theSession.Query().Where(x => x.Number < 4).Sum(x => x.Number) - .ShouldBe(6); - } - - [Theory] - [InlineData(EnumStorage.AsString)] - [InlineData(EnumStorage.AsInteger)] - public void get_sum_of_integers_with_where_with_nullable_enum(EnumStorage enumStorage) - { - StoreOptions(o => o.UseDefaultSerialization(enumStorage)); - - theSession.Store(new Target { NullableColor = Colors.Blue, Number = 1 }); - theSession.Store(new Target { NullableColor = Colors.Red, Number = 2 }); - theSession.Store(new Target { NullableColor = Colors.Green, Number = 3 }); - theSession.Store(new Target { NullableColor = null, Number = 4 }); - - theSession.SaveChanges(); - theSession.Query() - .Where(x => x.NullableColor != null) - .Sum(x => x.Number) - .ShouldBe(6); - } - - public query_for_sum_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/query_with_aggregate_functions.cs b/src/DocumentDbTests/Reading/Linq/query_with_aggregate_functions.cs deleted file mode 100644 index d1fb157ff8e..00000000000 --- a/src/DocumentDbTests/Reading/Linq/query_with_aggregate_functions.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Marten; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class query_with_aggregate_functions : IntegrationContext -{ - #region sample_using_max - [Fact] - public void get_max() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 42 }); - theSession.Store(new Target { Color = Colors.Green, Number = 3 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - - theSession.SaveChanges(); - var maxNumber = theSession.Query().Max(t => t.Number); - maxNumber.ShouldBe(42); - } - #endregion - - [Fact] - public async Task get_max_async() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 42 }); - theSession.Store(new Target { Color = Colors.Green, Number = 3 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - - theSession.SaveChanges(); - var maxNumber = await theSession.Query().MaxAsync(t => t.Number); - maxNumber.ShouldBe(42); - } - - #region sample_using_min - [Fact] - public void get_min() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 2 }); - theSession.Store(new Target { Color = Colors.Green, Number = -5 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 42 }); - - theSession.SaveChanges(); - var minNumber = theSession.Query().Min(t => t.Number); - minNumber.ShouldBe(-5); - } - #endregion - - [Fact] - public async Task get_min_async() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 42 }); - theSession.Store(new Target { Color = Colors.Green, Number = -5 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); - - await theSession.SaveChangesAsync(); - var maxNumber = await theSession.Query().MinAsync(t => t.Number); - maxNumber.ShouldBe(-5); - } - - #region sample_using_average - [Fact] - public void get_average() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 2 }); - theSession.Store(new Target { Color = Colors.Green, Number = -5 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 42 }); - - theSession.SaveChanges(); - var average = theSession.Query().Average(t => t.Number); - average.ShouldBe(10); - } - #endregion - - [Fact] - public async Task get_average_async() - { - theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); - theSession.Store(new Target { Color = Colors.Red, Number = 42 }); - theSession.Store(new Target { Color = Colors.Green, Number = -5 }); - theSession.Store(new Target { Color = Colors.Blue, Number = 2 }); - - await theSession.SaveChangesAsync(); - var maxNumber = await theSession.Query().AverageAsync(t => t.Number); - maxNumber.ShouldBe(10); - } - - public query_with_aggregate_functions(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/query_with_dates_Tests.cs b/src/DocumentDbTests/Reading/Linq/query_with_dates_Tests.cs deleted file mode 100644 index eed4ec765ee..00000000000 --- a/src/DocumentDbTests/Reading/Linq/query_with_dates_Tests.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class query_with_dates_Tests: IntegrationContext -{ - [Fact] - public void can_select_DateTimeOffset_and_will_return_localtime() - { - var document = Target.Random(); - document.DateOffset = DateTimeOffset.UtcNow; - - using (var session = theStore.LightweightSession()) - { - session.Insert(document); - session.SaveChanges(); - } - - using (var query = theStore.QuerySession()) - { - var dateOffset = query.Query().Where(x => x.Id == document.Id).Select(x => x.DateOffset).Single(); - - // be aware of the Npgsql DateTime mapping https://www.npgsql.org/doc/types/datetime.html - dateOffset.ShouldBeEqualWithDbPrecision(document.DateOffset.ToLocalTime()); - } - } - - public query_with_dates_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} diff --git a/src/DocumentDbTests/Reading/Linq/query_with_float_Tests.cs b/src/DocumentDbTests/Reading/Linq/query_with_float_Tests.cs deleted file mode 100644 index d796c83bfa6..00000000000 --- a/src/DocumentDbTests/Reading/Linq/query_with_float_Tests.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class query_with_float_Tests : IntegrationContext -{ - [Fact] - public void can_query_by_float() - { - var target1 = new Target {Float = 123.45F}; - var target2 = new Target {Float = 456.45F}; - - theSession.Store(target1, target2); - theSession.Store(Target.GenerateRandomData(5).ToArray()); - - theSession.SaveChanges(); - - theSession.Query().Where(x => x.Float > 400).ToArray().Select(x => x.Id) - .ShouldContain(x => x == target2.Id); - } - - public query_with_float_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/query_with_is_in_generic_enumerable_Tests.cs b/src/DocumentDbTests/Reading/Linq/query_with_is_in_generic_enumerable_Tests.cs deleted file mode 100644 index 62597733347..00000000000 --- a/src/DocumentDbTests/Reading/Linq/query_with_is_in_generic_enumerable_Tests.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Marten.Testing.Harness; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class query_with_is_in_generic_enumerable_Tests : IntegrationContext -{ - [Fact] - public void can_query_against_number_in_iList() - { - var doc1 = new DocWithNumber { Number = 1 }; - var doc2 = new DocWithNumber { Number = 2 }; - var doc3 = new DocWithNumber { Number = 3 }; - - - theSession.Store(doc1); - theSession.Store(doc2); - theSession.Store(doc3); - - theSession.SaveChanges(); - - IList searchValues = new List {2, 4, 5}; - - theSession.Query().Where(x=>searchValues.Contains(x.Number)).ToArray() - .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc2.Id); - } - - [Fact] - public void can_query_against_number_in_List() - { - var doc1 = new DocWithNumber { Number = 1 }; - var doc2 = new DocWithNumber { Number = 2 }; - var doc3 = new DocWithNumber { Number = 3 }; - - - theSession.Store(doc1); - theSession.Store(doc2); - theSession.Store(doc3); - - theSession.SaveChanges(); - - List searchValues = new List { 2, 4, 5 }; - - theSession.Query().Where(x => searchValues.Contains(x.Number)).ToArray() - .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc2.Id); - } - - public query_with_is_in_generic_enumerable_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} - -public class DocWithNumber -{ - public Guid Id { get; set; } - public int Number { get; set; } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/query_with_properties_from_document_comparison.cs b/src/DocumentDbTests/Reading/Linq/query_with_properties_from_document_comparison.cs deleted file mode 100644 index 64f1ca1af57..00000000000 --- a/src/DocumentDbTests/Reading/Linq/query_with_properties_from_document_comparison.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class query_with_properties_from_document_comparison : IntegrationContext -{ - [Fact] - public void compares_properties_correctly() - { - var target1 = new Target - { - Id = Guid.NewGuid(), - Number = 1, - AnotherNumber = 2 - }; - - var target2 = new Target - { - Id = Guid.NewGuid(), - Number = 20, - AnotherNumber = 10 - }; - - theSession.Store(target1, target2); - theSession.SaveChanges(); - - var result = theSession.Query() - .Where(t => t.AnotherNumber > t.Number) - .ToList(); - - result.ShouldHaveSingleItem(); - SpecificationExtensions.ShouldContain(result, t => t.Id == target1.Id); - } - - public query_with_properties_from_document_comparison(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/select_transformations_Tests.cs b/src/DocumentDbTests/Reading/Linq/select_transformations_Tests.cs deleted file mode 100644 index f8be1013542..00000000000 --- a/src/DocumentDbTests/Reading/Linq/select_transformations_Tests.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Linq; -using Marten; -using Marten.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class select_transformations_Tests : IntegrationContext -{ - [Fact] - public void build_query_for_a_single_field() - { - SpecificationExtensions.ShouldBeNull(theSession.Query().Select(x => x.UserName).FirstOrDefault()); - - var cmd = theSession.Query().Select(x => x.UserName).ToCommand(FetchType.FetchMany); - - cmd.CommandText.ShouldBe("select d.data ->> 'UserName' from public.mt_doc_user as d"); - } - - public select_transformations_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} - -public class select_transformations_with_database_schema_Tests : OneOffConfigurationsContext -{ - - [Fact] - public void build_query_for_a_single_field() - { - StoreOptions(_ => _.DatabaseSchemaName = "other_select"); - - SpecificationExtensions.ShouldBeNull(theSession.Query().Select(x => x.UserName).FirstOrDefault()); - - var cmd = theSession.Query().Select(x => x.UserName).ToCommand(FetchType.FetchMany); - - cmd.CommandText.ShouldBe("select d.data ->> 'UserName' from other_select.mt_doc_user as d"); - } - - -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/using_const_boolean_in_where_clause_Tests.cs b/src/DocumentDbTests/Reading/Linq/using_const_boolean_in_where_clause_Tests.cs deleted file mode 100644 index c3111f15860..00000000000 --- a/src/DocumentDbTests/Reading/Linq/using_const_boolean_in_where_clause_Tests.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Linq; -using Marten.Testing.Documents; -using Marten.Testing.Harness; -using Shouldly; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class using_const_boolean_in_where_clause_Tests : IntegrationContext -{ - [Fact] - public void where_const_false() - { - var target1 = new Target { Number = 1, String = "Foo" }; - var target2 = new Target { Number = 2, String = "Foo" }; - var target3 = new Target { Number = 1, String = "Bar" }; - var target4 = new Target { Number = 1, String = "Foo" }; - var target5 = new Target { Number = 2, String = "Bar" }; - theSession.Store(target1); - theSession.Store(target2); - theSession.Store(target3); - theSession.Store(target4); - theSession.Store(target5); - theSession.SaveChanges(); - - var q = Queryable.Where(theSession.Query(), x => false && x.Number == 1); - q.Count().ShouldBe(0); - } - - [Fact] - public void where_const_true() - { - var target1 = new Target { Number = 1, String = "Foo" }; - var target2 = new Target { Number = 2, String = "Foo" }; - var target3 = new Target { Number = 1, String = "Bar" }; - var target4 = new Target { Number = 1, String = "Foo" }; - var target5 = new Target { Number = 2, String = "Bar" }; - theSession.Store(target1); - theSession.Store(target2); - theSession.Store(target3); - theSession.Store(target4); - theSession.Store(target5); - theSession.SaveChanges(); - - var q = Queryable.Where(theSession.Query(), x => true && x.Number == 1); - q.Count().ShouldBe(3); - } - - public using_const_boolean_in_where_clause_Tests(DefaultStoreFixture fixture) : base(fixture) - { - } -} \ No newline at end of file diff --git a/src/DocumentDbTests/Reading/Linq/using_custom_Linq_parser_plugins_Tests.cs b/src/DocumentDbTests/Reading/Linq/using_custom_Linq_parser_plugins_Tests.cs deleted file mode 100644 index 2b6b60e983f..00000000000 --- a/src/DocumentDbTests/Reading/Linq/using_custom_Linq_parser_plugins_Tests.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core; -using JasperFx.Core.Reflection; -using Marten; -using Marten.Linq.Fields; -using Marten.Linq.Parsing; -using Marten.Testing.Harness; -using Shouldly; -using Weasel.Core; -using Weasel.Postgresql.SqlGeneration; -using Xunit; - -namespace DocumentDbTests.Reading.Linq; - -public class using_custom_Linq_parser_plugins_Tests -{ - #region sample_using_custom_linq_parser - - [Fact] - public void query_with_custom_parser() - { - using (var store = DocumentStore.For(_ => - { - _.Connection(ConnectionSource.ConnectionString); - - // IsBlue is a custom parser I used for testing this - _.Linq.MethodCallParsers.Add(new IsBlue()); - _.AutoCreateSchemaObjects = AutoCreate.All; - - // This is just to isolate the test - _.DatabaseSchemaName = "isblue"; - })) - { - store.Advanced.Clean.CompletelyRemoveAll(); - - - var targets = new List(); - for (var i = 0; i < 25; i++) - { - targets.Add(new ColorTarget {Color = "Blue"}); - targets.Add(new ColorTarget {Color = "Green"}); - targets.Add(new ColorTarget {Color = "Red"}); - } - - var count = targets.Where(x => x.IsBlue()).Count(); - - targets.Each(x => x.Id = Guid.NewGuid()); - - store.BulkInsert(targets.ToArray()); - - using (var session = store.QuerySession()) - { - session.Query().Count(x => x.IsBlue()) - .ShouldBe(count); - } - } - } - - #endregion -} - -public class ColorTarget -{ - public string Color { get; set; } - public Guid Id { get; set; } -} - -public static class CustomExtensions -{ - #region sample_custom-extension-for-linq - - public static bool IsBlue(this ColorTarget target) - { - return target.Color == "Blue"; - } - - #endregion -} - -#region sample_IsBlue - -public class IsBlue: IMethodCallParser -{ - private static readonly PropertyInfo _property = ReflectionHelper.GetProperty(x => x.Color); - - public bool Matches(MethodCallExpression expression) - { - return expression.Method.Name == nameof(CustomExtensions.IsBlue); - } - - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) - { - var locator = mapping.FieldFor(new MemberInfo[] {_property}).TypedLocator; - - return new WhereFragment($"{locator} = 'Blue'"); - } -} - -#endregion diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/DefaultQueryFixture.cs b/src/LinqTests/Acceptance/Support/DefaultQueryFixture.cs similarity index 91% rename from src/DocumentDbTests/Reading/Linq/Compatibility/Support/DefaultQueryFixture.cs rename to src/LinqTests/Acceptance/Support/DefaultQueryFixture.cs index 4182be3bd1c..bbcfedc6d12 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/DefaultQueryFixture.cs +++ b/src/LinqTests/Acceptance/Support/DefaultQueryFixture.cs @@ -1,7 +1,8 @@ using Marten; using Marten.Testing.Documents; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq.Compatibility.Support; +namespace LinqTests.Acceptance.Support; public class DefaultQueryFixture: TargetSchemaFixture { @@ -9,6 +10,7 @@ public DefaultQueryFixture() { Store = provisionStore("linq_querying"); + DuplicatedFieldStore = provisionStore("duplicate_fields", o => { o.Schema.For() @@ -25,4 +27,4 @@ public DefaultQueryFixture() public DocumentStore DuplicatedFieldStore { get; set; } public DocumentStore Store { get; set; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/LinqTestCase.cs b/src/LinqTests/Acceptance/Support/LinqTestCase.cs similarity index 67% rename from src/DocumentDbTests/Reading/Linq/Compatibility/Support/LinqTestCase.cs rename to src/LinqTests/Acceptance/Support/LinqTestCase.cs index 672cf4e4d86..3865731b53e 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/LinqTestCase.cs +++ b/src/LinqTests/Acceptance/Support/LinqTestCase.cs @@ -1,14 +1,16 @@ using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; +using Marten.Testing.Harness; -namespace DocumentDbTests.Reading.Linq.Compatibility.Support; +namespace LinqTests.Acceptance.Support; public abstract class LinqTestCase { public string Description { get; set; } - public abstract Task Compare(IQuerySession session, Target[] documents); + public abstract Task Compare(IQuerySession session, Target[] documents, + TestOutputMartenLogger logger); public bool Ordered { get; set; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/LinqTestContext.cs b/src/LinqTests/Acceptance/Support/LinqTestContext.cs similarity index 82% rename from src/DocumentDbTests/Reading/Linq/Compatibility/Support/LinqTestContext.cs rename to src/LinqTests/Acceptance/Support/LinqTestContext.cs index af98e17dff2..95253552ab1 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/LinqTestContext.cs +++ b/src/LinqTests/Acceptance/Support/LinqTestContext.cs @@ -6,9 +6,10 @@ using JasperFx.Core; using Marten; using Marten.Testing.Documents; -using Xunit; +using Marten.Testing.Harness; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq.Compatibility.Support; +namespace LinqTests.Acceptance.Support; [CollectionDefinition("linq")] public class LinqCollection: ICollectionFixture @@ -28,16 +29,20 @@ static LinqTestContext() _descriptions = readDescriptions(); } + protected ITestOutputHelper? TestOutput { get; set; } + protected LinqTestContext(DefaultQueryFixture fixture) { Fixture = fixture; } - protected static void @where(Expression> expression) + protected static TargetComparison @where(Expression> expression) { - var comparison = new TargetComparison(q => q.Where(expression)) { Ordered = false }; + var comparison = new TargetComparison(q => q.Where(expression)) { Ordered = false}; testCases.Add(comparison); + + return comparison; } protected static void ordered(Func, IQueryable> func) @@ -66,13 +71,13 @@ protected static void selectInOrder(Func, IQueryable> s protected static string[] readDescriptions() { var path = AppContext.BaseDirectory; - while (!path.EndsWith("DocumentDbTests")) + while (!path.EndsWith("LinqTests")) { path = path.ParentDirectory(); } var filename = typeof(TSelf).Name + ".cs"; - var codefile = path.AppendPath("Reading", "Linq", "Compatibility", filename); + var codefile = path.AppendPath("Acceptance", filename); var list = new List(); @@ -104,6 +109,11 @@ protected async Task assertTestCase(string description, IDocumentStore store) var testCase = testCases[index]; await using var session = store.QuerySession(); - await testCase.Compare(session, Fixture.Documents); + + + var logger = new TestOutputMartenLogger(TestOutput); + session.Logger = logger; + + await testCase.Compare(session, Fixture.Documents, logger); } } diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/OrderedSelectComparison.cs b/src/LinqTests/Acceptance/Support/OrderedSelectComparison.cs similarity index 91% rename from src/DocumentDbTests/Reading/Linq/Compatibility/Support/OrderedSelectComparison.cs rename to src/LinqTests/Acceptance/Support/OrderedSelectComparison.cs index 2cde303cdce..66322776c41 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/OrderedSelectComparison.cs +++ b/src/LinqTests/Acceptance/Support/OrderedSelectComparison.cs @@ -3,11 +3,12 @@ using System.Threading.Tasks; using Marten; using Marten.Testing.Documents; +using Marten.Testing.Harness; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Shouldly; -namespace DocumentDbTests.Reading.Linq.Compatibility.Support; +namespace LinqTests.Acceptance.Support; public class OrderedSelectComparison: LinqTestCase { @@ -18,7 +19,8 @@ public OrderedSelectComparison(Func, IQueryable> selector) _selector = selector; } - public override async Task Compare(IQuerySession session, Target[] documents) + public override async Task Compare(IQuerySession session, Target[] documents, + TestOutputMartenLogger logger) { var expected = _selector(documents.AsQueryable()).ToArray(); diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/TargetComparison.cs b/src/LinqTests/Acceptance/Support/TargetComparison.cs similarity index 67% rename from src/DocumentDbTests/Reading/Linq/Compatibility/Support/TargetComparison.cs rename to src/LinqTests/Acceptance/Support/TargetComparison.cs index 1aa31821f0a..f4245045011 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/TargetComparison.cs +++ b/src/LinqTests/Acceptance/Support/TargetComparison.cs @@ -5,24 +5,37 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; -namespace DocumentDbTests.Reading.Linq.Compatibility.Support; +namespace LinqTests.Acceptance.Support; public class TargetComparison: LinqTestCase { private readonly Func, IQueryable> _func; + private bool _no_CTE_Usage_Allowed; public TargetComparison(Func, IQueryable> func) { _func = func; } - public override async Task Compare(IQuerySession session, Target[] documents) + public override async Task Compare(IQuerySession session, Target[] documents, + TestOutputMartenLogger logger) { var expected = _func(documents.AsQueryable()).Select(x => x.Id).ToArray(); var actual = (await (_func(session.Query()).Select(x => x.Id).ToListAsync())).ToArray(); assertSame(expected, actual); + + + if (_no_CTE_Usage_Allowed) + { + var sql = logger.ExecutedSql(); + if (sql.Contains("WITH")) + { + throw new Exception("This query should not be using CTE:\n" + sql); + } + } + } private void assertSame(Guid[] expected, Guid[] actual) @@ -35,4 +48,9 @@ private void assertSame(Guid[] expected, Guid[] actual) actual.ShouldHaveTheSameElementsAs(expected); } -} \ No newline at end of file + + public void NoCteUsage() + { + _no_CTE_Usage_Allowed = true; + } +} diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/TargetSchemaFixture.cs b/src/LinqTests/Acceptance/Support/TargetSchemaFixture.cs similarity index 93% rename from src/DocumentDbTests/Reading/Linq/Compatibility/Support/TargetSchemaFixture.cs rename to src/LinqTests/Acceptance/Support/TargetSchemaFixture.cs index 2ab33e85756..29840237c80 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/Support/TargetSchemaFixture.cs +++ b/src/LinqTests/Acceptance/Support/TargetSchemaFixture.cs @@ -5,7 +5,7 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; -namespace DocumentDbTests.Reading.Linq.Compatibility.Support; +namespace LinqTests.Acceptance.Support; public abstract class TargetSchemaFixture: IDisposable { diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/casing_support.cs b/src/LinqTests/Acceptance/casing_support.cs similarity index 84% rename from src/DocumentDbTests/Reading/Linq/Compatibility/casing_support.cs rename to src/LinqTests/Acceptance/casing_support.cs index 4fc409a4b5b..4423eb8636a 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/casing_support.cs +++ b/src/LinqTests/Acceptance/casing_support.cs @@ -7,12 +7,14 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq.Compatibility; +namespace LinqTests.Acceptance; public class casing_support: OneOffConfigurationsContext { + private readonly ITestOutputHelper _output; + [Theory] [InlineData(SerializerType.SystemTextJson, Casing.CamelCase)] [InlineData(SerializerType.SystemTextJson, Casing.SnakeCase)] @@ -24,14 +26,16 @@ public class casing_support: OneOffConfigurationsContext //[InlineData(SerializerType.Newtonsoft, Casing.Default)] public async Task serializer_casing_should_work_with_selects( SerializerType serializerType, Casing casing) { - var store = StoreOptions(_ => + var store = StoreOptions(opts => { - _.UseDefaultSerialization( + opts.UseDefaultSerialization( serializerType: serializerType, casing: casing, nonPublicMembersStorage: NonPublicMembersStorage.All, enumStorage: EnumStorage.AsString ); + + opts.Logger(new TestOutputMartenLogger(_output)); }); await using var session = store.LightweightSession(); @@ -54,4 +58,9 @@ public async Task serializer_casing_should_work_with_selects( SerializerType ser result[0].Number.ShouldBe(targets[0].Number); result[0].Color.ShouldBe(targets[0].Color); } + + public casing_support(ITestOutputHelper output) + { + _output = output; + } } diff --git a/src/DocumentDbTests/Reading/Linq/using_multiple_where_clauses_Tests.cs b/src/LinqTests/Acceptance/chained_where_clauses.cs similarity index 88% rename from src/DocumentDbTests/Reading/Linq/using_multiple_where_clauses_Tests.cs rename to src/LinqTests/Acceptance/chained_where_clauses.cs index e7e83c02e6a..5dab8962e6e 100644 --- a/src/DocumentDbTests/Reading/Linq/using_multiple_where_clauses_Tests.cs +++ b/src/LinqTests/Acceptance/chained_where_clauses.cs @@ -1,11 +1,10 @@ using System.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class using_multiple_where_clauses_Tests : IntegrationContext +public class chained_where_clauses : IntegrationContext { [Fact] public void two_where_clauses() @@ -47,7 +46,7 @@ public void three_where_clauses() .ShouldHaveTheSameElementsAs(target1.Id); } - public using_multiple_where_clauses_Tests(DefaultStoreFixture fixture) : base(fixture) + public chained_where_clauses(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/LinqTests/Acceptance/child_collection_queries.cs b/src/LinqTests/Acceptance/child_collection_queries.cs new file mode 100644 index 00000000000..5965d4f1dec --- /dev/null +++ b/src/LinqTests/Acceptance/child_collection_queries.cs @@ -0,0 +1,45 @@ +using System.Linq; +using System.Threading.Tasks; +using LinqTests.Acceptance.Support; +using Marten.Testing.Documents; +using Xunit.Abstractions; + +namespace LinqTests.Acceptance; + +public class child_collection_queries: LinqTestContext +{ + public child_collection_queries(DefaultQueryFixture fixture, ITestOutputHelper output) : base(fixture) + { + TestOutput = output; + } + + static child_collection_queries() + { + // Child document collections + @where(x => x.Children.Any()).NoCteUsage(); + + // CTE required queries + @where(x => x.Children.Where(c => c.String.StartsWith("o")).Any()); + @where(x => x.Children.Any(c => c.String.StartsWith("o"))); + + // CTE + Filter at parent + @where(x => x.Color == Colors.Blue && x.Children.Any(c => c.String.StartsWith("o"))); + + // CTE + filter has to stay at the bottom level + @where(x => x.Color == Colors.Blue || x.Children.Any(c => c.String.StartsWith("o"))); + + // Child value collections + @where(x => x.NumberArray.Any()); + + @where(x => x.StringArray != null && x.StringArray.Any(c => c.StartsWith("o"))); + } + + [Theory] + [MemberData(nameof(GetDescriptions))] + public Task run_query(string description) + { + return assertTestCase(description, Fixture.Store); + } +} + + diff --git a/src/DocumentDbTests/Reading/Linq/query_by_different_id_member.cs b/src/LinqTests/Acceptance/custom_identity_members.cs similarity index 94% rename from src/DocumentDbTests/Reading/Linq/query_by_different_id_member.cs rename to src/LinqTests/Acceptance/custom_identity_members.cs index 05672d794c0..54a6bfe7232 100644 --- a/src/DocumentDbTests/Reading/Linq/query_by_different_id_member.cs +++ b/src/LinqTests/Acceptance/custom_identity_members.cs @@ -2,11 +2,10 @@ using Marten; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_by_different_id_member : OneOffConfigurationsContext +public class custom_identity_members : OneOffConfigurationsContext { private static readonly string[] listIds = {"qwe", "zxc"}; private static readonly string[] listSystemIds = {"123", "456"}; @@ -88,4 +87,4 @@ public class Auto : BaseClass public class Animal : BaseClass { public string Kind { get; set; } -} \ No newline at end of file +} diff --git a/src/LinqTests/Acceptance/custom_linq_extensions.cs b/src/LinqTests/Acceptance/custom_linq_extensions.cs new file mode 100644 index 00000000000..9cdc1a1a53f --- /dev/null +++ b/src/LinqTests/Acceptance/custom_linq_extensions.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Threading.Tasks; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten; +using Marten.Linq; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Marten.Testing.Harness; +using Shouldly; +using Weasel.Core; +using Weasel.Postgresql.SqlGeneration; + +namespace LinqTests.Acceptance; + +public class custom_linq_extensions +{ + #region sample_using_custom_linq_parser + + [Fact] + public async Task query_with_custom_parser() + { + using var store = DocumentStore.For(opts => + { + opts.Connection(ConnectionSource.ConnectionString); + + // IsBlue is a custom parser I used for testing this + opts.Linq.MethodCallParsers.Add(new IsBlue()); + opts.AutoCreateSchemaObjects = AutoCreate.All; + + // This is just to isolate the test + opts.DatabaseSchemaName = "isblue"; + }); + + await store.Advanced.Clean.CompletelyRemoveAllAsync(); + + var targets = new List(); + for (var i = 0; i < 25; i++) + { + targets.Add(new ColorTarget {Color = "Blue"}); + targets.Add(new ColorTarget {Color = "Green"}); + targets.Add(new ColorTarget {Color = "Red"}); + } + + var count = targets.Count(x => x.Color.IsBlue()); + + targets.Each(x => x.Id = Guid.NewGuid()); + + await store.BulkInsertAsync(targets.ToArray()); + + using var session = store.QuerySession(); + session.Query().Count(x => x.Color.IsBlue()) + .ShouldBe(count); + } + + #endregion +} + +public class ColorTarget +{ + public string Color { get; set; } + public Guid Id { get; set; } +} + +public static class CustomExtensions +{ + #region sample_custom-extension-for-linq + + public static bool IsBlue(this string value) + { + return value == "Blue"; + } + + #endregion +} + +#region sample_IsBlue + +public class IsBlue: IMethodCallParser +{ + private static readonly PropertyInfo _property = ReflectionHelper.GetProperty(x => x.Color); + + public bool Matches(MethodCallExpression expression) + { + return expression.Method.Name == nameof(CustomExtensions.IsBlue); + } + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + var locator = memberCollection.MemberFor(expression).TypedLocator; + + return new WhereFragment($"{locator} = 'Blue'"); + } +} + +#endregion diff --git a/src/DocumentDbTests/Reading/Linq/query_against_dateoffset_Tests.cs b/src/LinqTests/Acceptance/date_type_usage.cs similarity index 68% rename from src/DocumentDbTests/Reading/Linq/query_against_dateoffset_Tests.cs rename to src/LinqTests/Acceptance/date_type_usage.cs index 33f82f91c6e..f2a9e1ef4df 100644 --- a/src/DocumentDbTests/Reading/Linq/query_against_dateoffset_Tests.cs +++ b/src/LinqTests/Acceptance/date_type_usage.cs @@ -2,11 +2,10 @@ using System.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_against_dateoffset_Tests : OneOffConfigurationsContext +public class date_type_usage : OneOffConfigurationsContext { [Fact] public void query() @@ -46,4 +45,25 @@ public void can_index_against_datetime_offset() .ShouldHaveTheSameElementsAs(1, 3, 2); } -} \ No newline at end of file + [Fact] + public void can_select_DateTimeOffset_and_will_return_localtime() + { + var document = Target.Random(); + document.DateOffset = DateTimeOffset.UtcNow; + + using (var session = theStore.LightweightSession()) + { + session.Insert(document); + session.SaveChanges(); + } + + using (var query = theStore.QuerySession()) + { + var dateOffset = query.Query().Where(x => x.Id == document.Id).Select(x => x.DateOffset).Single(); + + // be aware of the Npgsql DateTime mapping https://www.npgsql.org/doc/types/datetime.html + dateOffset.ShouldBeEqualWithDbPrecision(document.DateOffset.ToLocalTime()); + } + } + +} diff --git a/src/DocumentDbTests/Reading/Linq/deep_searches_Tests.cs b/src/LinqTests/Acceptance/deep_searches.cs similarity index 97% rename from src/DocumentDbTests/Reading/Linq/deep_searches_Tests.cs rename to src/LinqTests/Acceptance/deep_searches.cs index eba321ae9cb..235ad692ab5 100644 --- a/src/DocumentDbTests/Reading/Linq/deep_searches_Tests.cs +++ b/src/LinqTests/Acceptance/deep_searches.cs @@ -2,11 +2,10 @@ using Marten.Schema; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class deep_searches_Tests: OneOffConfigurationsContext +public class deep_searches: OneOffConfigurationsContext { [Fact] public void query_two_deep() @@ -116,4 +115,4 @@ public void order_by_2_deep_with_containment_operator() .ShouldHaveTheSameElementsAs("Lindsey", "Max"); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/explain_query.cs b/src/LinqTests/Acceptance/diagnostic_methods.cs similarity index 61% rename from src/DocumentDbTests/Reading/Linq/explain_query.cs rename to src/LinqTests/Acceptance/diagnostic_methods.cs index c6e0b530f92..a3715b0cba5 100644 --- a/src/DocumentDbTests/Reading/Linq/explain_query.cs +++ b/src/LinqTests/Acceptance/diagnostic_methods.cs @@ -1,14 +1,18 @@ using System; using System.Linq; using Marten; +using Marten.Linq; +using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class explain_query: IntegrationContext +public class diagnostic_methods: OneOffConfigurationsContext { + private readonly ITestOutputHelper _output; + [Fact] public void retrieves_query_plan() { @@ -102,7 +106,66 @@ public void retrieves_query_plan_with_where_and_all_options_enabled() plan.Plans.ShouldNotBeEmpty(); } - public explain_query(DefaultStoreFixture fixture) : base(fixture) + + [Fact] + public void preview_basic_select_command() + { + var cmd = theSession.Query().ToCommand(FetchType.FetchMany); + + _output.WriteLine(cmd.CommandText); + + cmd.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d;"); + cmd.Parameters.Any().ShouldBeFalse(); + } + + [Fact] + public void preview_select_many() + { + var cmd = theSession.Query().SelectMany(x => x.Children).Where(x => x.Flag) + .ToCommand(FetchType.FetchMany); + + _output.WriteLine(cmd.CommandText); + } + + [Fact] + public void preview_command_with_where_and_parameters() + { + var cmd = theSession.Query().Where(x => x.Number == 3 && x.Double > 2).ToCommand(FetchType.FetchMany); + + cmd.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d where (CAST(d.data ->> 'Number' as integer) = :p0 and CAST(d.data ->> 'Double' as double precision) > :p1);"); + + cmd.Parameters.Count.ShouldBe(2); + cmd.Parameters["p0"].Value.ShouldBe(3); + cmd.Parameters["p1"].Value.ShouldBe(2); + } + + [Fact] + public void preview_basic_count_command() + { + var cmd = theSession.Query().ToCommand(FetchType.Count); + + cmd.CommandText.ShouldBe($"select count(*) as number from {SchemaName}.mt_doc_target as d;"); + } + + [Fact] + public void preview_basic_any_command() + { + var cmd = theSession.Query().ToCommand(FetchType.Any); + + cmd.CommandText.ShouldBe($"select TRUE as result from {SchemaName}.mt_doc_target as d LIMIT :p0;"); + } + + [Fact] + public void preview_select_on_query() + { + var cmd = theSession.Query().OrderBy(x => x.Double).ToCommand(FetchType.FetchOne); + + cmd.CommandText.Trim().ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d order by CAST(d.data ->> 'Double' as double precision) LIMIT :p0;"); + } + + + public diagnostic_methods(ITestOutputHelper output) { + _output = output; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/dictionary_is_translated.cs b/src/LinqTests/Acceptance/dictionary_usage.cs similarity index 56% rename from src/DocumentDbTests/Reading/Linq/dictionary_is_translated.cs rename to src/LinqTests/Acceptance/dictionary_usage.cs index 098811ced97..d0793fa4cc7 100644 --- a/src/DocumentDbTests/Reading/Linq/dictionary_is_translated.cs +++ b/src/LinqTests/Acceptance/dictionary_usage.cs @@ -6,37 +6,20 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class dictionary_is_translated: IntegrationContext +public class dictionary_usage: IntegrationContext { - public dictionary_is_translated(DefaultStoreFixture fixture) : base(fixture) + private readonly ITestOutputHelper _output; + + public dictionary_usage(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { + _output = output; theStore.BulkInsert(Target.GenerateRandomData(100).ToArray()); } - [Fact] - public void dictionary_string_containskey_is_translated_to_json_map() - { - var query = theSession.Query().Where(t => t.StringDict.ContainsKey("foo")); - var command = query.ToCommand(Marten.Linq.FetchType.FetchMany); - var dictParam = command.Parameters[0]; - (dictParam.DbType == System.Data.DbType.String).ShouldBeTrue(); - (dictParam.Value.ToString() == "foo").ShouldBeTrue(); - } - - [Fact] - public void dictionary_guid_containskey_is_translated_to_json_map() - { - var guid = Guid.NewGuid(); - var query = theSession.Query().Where(t => t.GuidDict.ContainsKey(guid)); - var command = query.ToCommand(Marten.Linq.FetchType.FetchMany); - var dictParam = command.Parameters[0]; - (dictParam.DbType == System.Data.DbType.String).ShouldBeTrue(); - (dictParam.Value.ToString() == guid.ToString()).ShouldBeTrue(); - } // using key0 and value0 for these because the last node, which is deep, should have at least a single dict node @@ -56,6 +39,8 @@ public async Task dict_guid_can_query_using_containskey() theSession.Store(target); await theSession.SaveChangesAsync(); + theSession.Logger = new TestOutputMartenLogger(_output); + var results = await theSession.Query().Where(x => x.GuidDict.ContainsKey(guid)).ToListAsync(); results.All(r => r.GuidDict.ContainsKey(guid)).ShouldBeTrue(); } @@ -84,13 +69,4 @@ public async Task dict_guid_can_query_using_containsKVP() results.All(r => r.GuidDict.Contains(kvp)).ShouldBeTrue(); } - [Fact] - public void icollection_keyvaluepair_contains_is_translated_to_json_map() - { - var query = theSession.Query().Where(t => t.StringDict.Contains(new KeyValuePair("foo", "bar"))); - var command = query.ToCommand(Marten.Linq.FetchType.FetchMany); - var dictParam = command.Parameters[0]; - (dictParam.NpgsqlDbType == NpgsqlTypes.NpgsqlDbType.Jsonb).ShouldBeTrue(); - (dictParam.Value.ToString() == "{\"foo\":\"bar\"}").ShouldBeTrue(); - } } diff --git a/src/DocumentDbTests/Reading/Linq/query_with_enums_Tests.cs b/src/LinqTests/Acceptance/enum_usage.cs similarity index 97% rename from src/DocumentDbTests/Reading/Linq/query_with_enums_Tests.cs rename to src/LinqTests/Acceptance/enum_usage.cs index 138c0fc218c..c147a855798 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_enums_Tests.cs +++ b/src/LinqTests/Acceptance/enum_usage.cs @@ -5,12 +5,19 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_with_enums_Tests : OneOffConfigurationsContext +public class enum_usage : OneOffConfigurationsContext { + private readonly ITestOutputHelper _output; + + public enum_usage(ITestOutputHelper output) + { + _output = output; + } + [Fact] public void use_enum_values_with_jil_that_are_not_duplicated() { diff --git a/src/LinqTests/Acceptance/equals_method_usage_validation.cs b/src/LinqTests/Acceptance/equals_method_usage_validation.cs new file mode 100644 index 00000000000..d86a144807d --- /dev/null +++ b/src/LinqTests/Acceptance/equals_method_usage_validation.cs @@ -0,0 +1,102 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using Marten.Exceptions; +using Marten.Linq; +using Marten.Testing.Harness; + +namespace LinqTests.Acceptance; + +public class equals_method_usage_validation : IntegrationContext +{ + public equals_method_usage_validation(DefaultStoreFixture fixture) : base(fixture) + { + } + + public class QueryTarget + { + public int IntProp { get; set; } + public long LongProp { get; set; } + public decimal DecimalProp { get; set; } + public bool BoolProp { get; set; } + public Guid Id { get; set; } + public DateTime DateTimeProp { get; set; } + public DateTimeOffset DateTimeOffsetProp { get; set; } + } + + [Fact] + public void when_wrong_types_are_compared() + { + var queryTarget = new QueryTarget + { + Id = System.Guid.NewGuid() + }; + theSession.Store(queryTarget); + + theSession.SaveChanges(); + + object notInt = "not int"; + + Assert.Throws(() => + { + var value = theSession + .Query() + .FirstOrDefault(x => x.IntProp.Equals(notInt)); + }); + } + + [Fact] + public void when_wrong_types_are_compared_inside_a_negation() + { + var queryTarget = new QueryTarget + { + Id = System.Guid.NewGuid() + }; + theSession.Store(queryTarget); + + theSession.SaveChanges(); + + object notInt = "not int"; + + Assert.Throws(() => + { + var firstOrDefault = theSession + .Query() + .FirstOrDefault(x => !x.IntProp.Equals(notInt)); + }); + } + + [Fact] + public void can_use_inside_of_compiled_query() + { + var queryTarget = new QueryTarget + { + IntProp = 1, + LongProp = 2, + DecimalProp = 1.1m, + BoolProp = true, + Id = Guid.NewGuid() + }; + + theSession.Store(queryTarget); + + theSession.SaveChanges(); + + var itemFromDb = + theSession.Query(new CompiledQueryTarget() {IdProp = queryTarget.Id, IntProp = queryTarget.IntProp}); + + Assert.NotNull(itemFromDb); + } + + public class CompiledQueryTarget : ICompiledQuery + { + public Guid IdProp { get; set; } + public int IntProp { get; set; } + + public Expression, QueryTarget>> QueryIs() + { + return q => q.FirstOrDefault(x => x.IntProp.Equals(IntProp) && x.Id.Equals(IdProp)); + } + } + +} diff --git a/src/DocumentDbTests/Reading/Linq/query_running_through_the_IdentityMap_Tests.cs b/src/LinqTests/Acceptance/identity_map_mechanics.cs similarity index 93% rename from src/DocumentDbTests/Reading/Linq/query_running_through_the_IdentityMap_Tests.cs rename to src/LinqTests/Acceptance/identity_map_mechanics.cs index 7a9066062c2..9f4ed41000b 100644 --- a/src/DocumentDbTests/Reading/Linq/query_running_through_the_IdentityMap_Tests.cs +++ b/src/LinqTests/Acceptance/identity_map_mechanics.cs @@ -3,18 +3,17 @@ using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_running_through_the_IdentityMap_Tests: IntegrationContext +public class identity_map_mechanics: IntegrationContext { private User user1; private User user2; private User user3; private User user4; - public query_running_through_the_IdentityMap_Tests(DefaultStoreFixture fixture): base(fixture) + public identity_map_mechanics(DefaultStoreFixture fixture): base(fixture) { } diff --git a/src/DocumentDbTests/Reading/Linq/recognizing_json_names_from_attributes.cs b/src/LinqTests/Acceptance/json_naming_attributes.cs similarity index 87% rename from src/DocumentDbTests/Reading/Linq/recognizing_json_names_from_attributes.cs rename to src/LinqTests/Acceptance/json_naming_attributes.cs index 69740397f17..f6ceec6682d 100644 --- a/src/DocumentDbTests/Reading/Linq/recognizing_json_names_from_attributes.cs +++ b/src/LinqTests/Acceptance/json_naming_attributes.cs @@ -7,11 +7,10 @@ using Marten.Testing.Harness; using Newtonsoft.Json; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class recognizing_json_names_from_attributes +public class json_naming_attributes { [Fact] public async Task recognize_newtonsoft_json_property_in_linq() @@ -27,7 +26,7 @@ public async Task recognize_newtonsoft_json_property_in_linq() var command = session.Query().Where(x => x.Color == "Red") .ToCommand(); - command.CommandText.ShouldBe("select d.id, d.data from atts.mt_doc_attributeddoc as d where d.data ->> 'shade' = :p0"); + command.CommandText.ShouldBe("select d.id, d.data from atts.mt_doc_attributeddoc as d where d.data ->> 'shade' = :p0;"); } @@ -46,7 +45,7 @@ public async Task recognize_stj_json_property_in_linq() var command = session.Query().Where(x => x.Color == "Red") .ToCommand(); - command.CommandText.ShouldBe("select d.id, d.data from atts.mt_doc_stjdoc as d where d.data ->> 'shade' = :p0"); + command.CommandText.ShouldBe("select d.id, d.data from atts.mt_doc_stjdoc as d where d.data ->> 'shade' = :p0;"); } } diff --git a/src/DocumentDbTests/Reading/Linq/matches_sql_queries.cs b/src/LinqTests/Acceptance/matches_sql_queries.cs similarity index 84% rename from src/DocumentDbTests/Reading/Linq/matches_sql_queries.cs rename to src/LinqTests/Acceptance/matches_sql_queries.cs index ccdfcc3c213..d5ac78b6932 100644 --- a/src/DocumentDbTests/Reading/Linq/matches_sql_queries.cs +++ b/src/LinqTests/Acceptance/matches_sql_queries.cs @@ -1,12 +1,12 @@ +using System; using System.Linq; using Marten.Linq.MatchesSql; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; using Weasel.Postgresql.SqlGeneration; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; public class matches_sql_queries: IntegrationContext { @@ -62,6 +62,15 @@ public void query_using_where_fragment() .Single().ShouldBe("foo"); } + [Fact] + public void Throws_NotSupportedException_when_called_directly() + { + Should.Throw( + () => new object().MatchesSql("d.data ->> 'UserName' = ? or d.data ->> 'UserName' = ?", "baz", "jack")); + Should.Throw( + () => new object().MatchesSql(new WhereFragment("d.data ->> 'UserName' != ?", "baz"))); + } + public matches_sql_queries(DefaultStoreFixture fixture) : base(fixture) { } diff --git a/src/DocumentDbTests/Reading/Linq/query_with_nested_boolean_logic_Tests.cs b/src/LinqTests/Acceptance/nested_boolean_logic.cs similarity index 80% rename from src/DocumentDbTests/Reading/Linq/query_with_nested_boolean_logic_Tests.cs rename to src/LinqTests/Acceptance/nested_boolean_logic.cs index d1f936e83e8..5ad52d6968a 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_nested_boolean_logic_Tests.cs +++ b/src/LinqTests/Acceptance/nested_boolean_logic.cs @@ -3,12 +3,11 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_with_nested_boolean_logic_Tests : IntegrationContext +public class nested_boolean_logic : IntegrationContext { private readonly ITestOutputHelper _output; @@ -31,8 +30,8 @@ public void TestModalOrQuery() } - public query_with_nested_boolean_logic_Tests(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + public nested_boolean_logic(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { _output = output; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/IsNullNotNullArbitraryDepthTests.cs b/src/LinqTests/Acceptance/null_or_not_null_querying.cs similarity index 78% rename from src/DocumentDbTests/Reading/Linq/IsNullNotNullArbitraryDepthTests.cs rename to src/LinqTests/Acceptance/null_or_not_null_querying.cs index 6f4e86533f6..361a79d3989 100644 --- a/src/DocumentDbTests/Reading/Linq/IsNullNotNullArbitraryDepthTests.cs +++ b/src/LinqTests/Acceptance/null_or_not_null_querying.cs @@ -1,14 +1,16 @@ using System.Linq; using Marten; +using Marten.Linq; +using Marten.Linq.Parsing; using Marten.Schema; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; +using Shouldly; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; // Change type mapping to treat "unknown" PG types as jsonb -> null checks depths at arbitrary depths don't fail due to CAST -public class IsNullNotNullArbitraryDepthTests : IntegrationContext +public class multi_level_is_null_querying : IntegrationContext { public class UserNested : User { @@ -50,12 +52,12 @@ public void UnknownPGTypesMapToJsonb() { var mapping = new DocumentMapping(new StoreOptions()); - var field = mapping.FieldFor(x => x.Nested); + var field = mapping.QueryMembers.MemberFor(x => x.Nested); - Assert.Equal("CAST(d.data ->> 'Nested' as jsonb)", field.TypedLocator); + field.TypedLocator.ShouldBe("d.data -> 'Nested'" ); } - public IsNullNotNullArbitraryDepthTests(DefaultStoreFixture fixture) : base(fixture) + public multi_level_is_null_querying(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/query_with_nullable_types_Tests.cs b/src/LinqTests/Acceptance/nullable_types.cs similarity index 93% rename from src/DocumentDbTests/Reading/Linq/query_with_nullable_types_Tests.cs rename to src/LinqTests/Acceptance/nullable_types.cs index a054d936742..9fa4aa4aaaf 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_nullable_types_Tests.cs +++ b/src/LinqTests/Acceptance/nullable_types.cs @@ -3,12 +3,11 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_with_nullable_types_Tests : IntegrationContext +public class nullable_types : IntegrationContext { private readonly ITestOutputHelper _output; @@ -112,8 +111,8 @@ public void query_against_not_null() .ShouldBe(2); } - public query_with_nullable_types_Tests(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + public nullable_types(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { _output = output; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/query_with_biginteger_tests.cs b/src/LinqTests/Acceptance/number_filtering.cs similarity index 51% rename from src/DocumentDbTests/Reading/Linq/query_with_biginteger_tests.cs rename to src/LinqTests/Acceptance/number_filtering.cs index 85f7d8ba23e..783b3d8ecd8 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_biginteger_tests.cs +++ b/src/LinqTests/Acceptance/number_filtering.cs @@ -1,19 +1,44 @@ -using System.Linq; +using System.Linq; using System.Numerics; +using System.Threading.Tasks; +using Marten; +using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_with_biginteger_tests : IntegrationContext +public class number_filtering : IntegrationContext { + private readonly ITestOutputHelper _output; + + public number_filtering(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + { + _output = output; + } + + [Fact] + public async Task can_query_by_float() + { + var target1 = new Target {Float = 123.45F}; + var target2 = new Target {Float = 456.45F}; + + theSession.Store(target1, target2); + theSession.Store(Target.GenerateRandomData(5).ToArray()); + + await theSession.SaveChangesAsync(); + + (await theSession.Query().Where(x => x.Float > 400).ToListAsync()).Select(x => x.Id) + .ShouldContain(x => x == target2.Id); + } + private static readonly BigInteger SmallNumber = BigInteger.Parse("1000000"); private static readonly BigInteger MediumNumber = BigInteger.Parse(long.MaxValue.ToString()); private static readonly BigInteger LargeNumber = BigInteger.Parse("123456789012345678901234567890123456789012345678901234567890"); [Fact] - public void Basic_Queries() + public async Task can_query_by_BigInteger() { StoreOptions(options => { @@ -37,31 +62,29 @@ public void Basic_Queries() Id = 3, Value = LargeNumber }); - session.SaveChanges(); + await session.SaveChangesAsync(); } using (var session = theStore.QuerySession()) { - var findSmallerThanMedium = session.Query().Single(x => x.Value < MediumNumber); + session.Logger = new TestOutputMartenLogger(_output); + var findSmallerThanMedium = await session.Query().SingleAsync(x => x.Value < MediumNumber); findSmallerThanMedium.Id.ShouldBe(1); - var findLargeNumberExact = session.Query().Single(x => x.Value == LargeNumber); + var findLargeNumberExact = await session.Query().SingleAsync(x => x.Value == LargeNumber); findLargeNumberExact.Id.ShouldBe(3); - var allNumbersLargerThanSmall = session.Query().Where(x => x.Value > SmallNumber).ToList(); + var allNumbersLargerThanSmall = await session.Query().Where(x => x.Value > SmallNumber).ToListAsync(); allNumbersLargerThanSmall.ShouldContain(x => x.Id == 2); allNumbersLargerThanSmall.ShouldContain(x => x.Id == 3); } } - - public query_with_biginteger_tests(DefaultStoreFixture fixture) : base(fixture) - { - } } + public class BigIntegerObject { public int Id { get; set; } diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/simple_order_by_clauses.cs b/src/LinqTests/Acceptance/order_by_clauses.cs similarity index 64% rename from src/DocumentDbTests/Reading/Linq/Compatibility/simple_order_by_clauses.cs rename to src/LinqTests/Acceptance/order_by_clauses.cs index 7f30d1f9276..05cc313e4c9 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/simple_order_by_clauses.cs +++ b/src/LinqTests/Acceptance/order_by_clauses.cs @@ -1,15 +1,15 @@ using System.Linq; -using DocumentDbTests.Reading.Linq.Compatibility.Support; +using LinqTests.Acceptance.Support; -namespace DocumentDbTests.Reading.Linq.Compatibility; +namespace LinqTests.Acceptance; -public class simple_order_by_clauses: LinqTestContext +public class order_by_clauses: LinqTestContext { - public simple_order_by_clauses(DefaultQueryFixture fixture) : base(fixture) + public order_by_clauses(DefaultQueryFixture fixture) : base(fixture) { } - static simple_order_by_clauses() + static order_by_clauses() { ordered(t => t.OrderBy(x => x.String)); ordered(t => t.OrderByDescending(x => x.String)); @@ -22,4 +22,4 @@ static simple_order_by_clauses() ordered(t => t.OrderBy(x => x.String).Skip(2)); ordered(t => t.OrderBy(x => x.String).Take(2).Skip(2)); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/query_with_inheritance.cs b/src/LinqTests/Acceptance/query_with_inheritance.cs similarity index 93% rename from src/DocumentDbTests/Reading/Linq/query_with_inheritance.cs rename to src/LinqTests/Acceptance/query_with_inheritance.cs index 0b81e6b1583..a12cd50c9a8 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_inheritance.cs +++ b/src/LinqTests/Acceptance/query_with_inheritance.cs @@ -5,9 +5,9 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; #region sample_smurfs-hierarchy @@ -41,10 +41,13 @@ public class BrainySmurf: PapaSmurf #endregion -public class query_with_inheritance_and_aliases: OneOffConfigurationsContext +public class sub_class_hierarchies: OneOffConfigurationsContext { - public query_with_inheritance_and_aliases() + private readonly ITestOutputHelper _output; + + public sub_class_hierarchies(ITestOutputHelper output) { + _output = output; StoreOptions(_ => { #region sample_add-subclass-hierarchy-with-aliases @@ -83,10 +86,13 @@ public void get_all_subclasses_of_a_subclass() public class query_with_inheritance: OneOffConfigurationsContext { + private readonly ITestOutputHelper _output; + #region sample_add-subclass-hierarchy - public query_with_inheritance() + public query_with_inheritance(ITestOutputHelper output) { + _output = output; StoreOptions(_ => { _.Schema.For() @@ -166,6 +172,8 @@ public void get_all_subclasses_of_a_subclass2() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query().Count().ShouldBe(2); } @@ -232,4 +240,4 @@ public void get_all_subclasses_of_an_interface() } #endregion -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/invoking_query_with_select_Tests.cs b/src/LinqTests/Acceptance/select_clause_usage.cs similarity index 98% rename from src/DocumentDbTests/Reading/Linq/invoking_query_with_select_Tests.cs rename to src/LinqTests/Acceptance/select_clause_usage.cs index 26ad369dcf6..d9378cba0d8 100644 --- a/src/DocumentDbTests/Reading/Linq/invoking_query_with_select_Tests.cs +++ b/src/LinqTests/Acceptance/select_clause_usage.cs @@ -2,16 +2,16 @@ using System.Linq; using System.Threading.Tasks; using JasperFx.Core; +using LinqTests.Acceptance.Support; using Marten; using Marten.Services.Json; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class invoking_query_with_select_Tests: IntegrationContext +public class select_clause_usage: IntegrationContext { #region sample_one_field_projection [Fact] @@ -385,12 +385,16 @@ public FlatTarget(Guid id, int number, int innerNumber) public int InnerNumber { get; } } - public invoking_query_with_select_Tests(DefaultStoreFixture fixture) : base(fixture) + + public select_clause_usage(DefaultStoreFixture fixture) : base(fixture) { } } + public class UserName { public string Name { get; set; } } + + diff --git a/src/DocumentDbTests/Reading/Linq/query_with_select_many.cs b/src/LinqTests/Acceptance/select_many.cs similarity index 96% rename from src/DocumentDbTests/Reading/Linq/query_with_select_many.cs rename to src/LinqTests/Acceptance/select_many.cs index 8f5354436d0..822c6e08550 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_select_many.cs +++ b/src/LinqTests/Acceptance/select_many.cs @@ -9,12 +9,11 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_with_select_many : IntegrationContext +public class select_many : IntegrationContext { private readonly ITestOutputHelper _output; @@ -158,7 +157,7 @@ public void select_many_with_count_when_none_match_does_not_throw() .Where(p => p.Tags.Length == 1) .SelectMany(x => x.Tags); var ex = Record.Exception(() => queryable.Count()); - SpecificationExtensions.ShouldBeNull(ex); + ex.ShouldBeNull(); } } @@ -450,6 +449,8 @@ public void select_many_with_includes() using var query = theStore.LightweightSession(); var dict = new Dictionary(); + query.Logger = new TestOutputMartenLogger(_output); + var results = query.Query() .SelectMany(x => x.Children) .Include(x => x.UserId, dict) @@ -590,6 +591,8 @@ public void select_many_2_deep() } using var query = theStore.QuerySession(); + query.Logger = new TestOutputMartenLogger(_output); + var loaded = query.Query() .SelectMany(x => x.Targets) @@ -599,6 +602,17 @@ public void select_many_2_deep() .ToArray() .Select(x => x.Id).ToArray(); + /* +WITH mt_temp_id_list1CTE as ( +select jsonb_array_elements(CAST(d.data ->> 'Targets' as jsonb)) as data from public.mt_doc_select_many_targetgroup as d +) + , mt_temp_id_list3CTE as ( +select jsonb_array_elements(CAST(d.data ->> 'Children' as jsonb)) as data from mt_temp_id_list1CTE as d where CAST(d.data ->> 'Color' as integer) = :p0 order by CAST(d.data ->> 'Number' as integer) +) + select d.data as data from mt_temp_id_list3CTE as d + p0: 1 + */ + var expected = groups .SelectMany(x => x.Targets) .Where(x => x.Color == Colors.Blue) @@ -632,7 +646,7 @@ public async Task can_query_with_where_clause_and_count_after_the_select_many() - public query_with_select_many(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + public select_many(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { _output = output; } diff --git a/src/DocumentDbTests/Reading/Linq/pagedlist_queryable_extension_Tests.cs b/src/LinqTests/Acceptance/statistics_and_paged_list.cs similarity index 67% rename from src/DocumentDbTests/Reading/Linq/pagedlist_queryable_extension_Tests.cs rename to src/LinqTests/Acceptance/statistics_and_paged_list.cs index 678b9f04cf9..10060681bb9 100644 --- a/src/DocumentDbTests/Reading/Linq/pagedlist_queryable_extension_Tests.cs +++ b/src/LinqTests/Acceptance/statistics_and_paged_list.cs @@ -1,18 +1,19 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; +using Marten; using Marten.Exceptions; using Marten.Linq; using Marten.Pagination; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; public class PaginationTestDocument { @@ -39,20 +40,204 @@ IEnumerator IEnumerable.GetEnumerator() } } -public class pagedlist_queryable_extension_Tests : IntegrationContext +public class statistics_and_paged_list: IntegrationContext { - public pagedlist_queryable_extension_Tests(DefaultStoreFixture fixture) : base(fixture) + public statistics_and_paged_list(DefaultStoreFixture fixture) : base(fixture) { + + } + + protected override Task fixtureSetup() + { + return theStore.BulkInsertAsync(Target.GenerateRandomData(100).ToArray()); + } + + #region sample_compiled-query-statistics + public class TargetPaginationQuery: ICompiledListQuery + { + public TargetPaginationQuery(int pageNumber, int pageSize) + { + PageNumber = pageNumber; + PageSize = pageSize; + } + + public int PageNumber { get; set; } + public int PageSize { get; set; } + + public QueryStatistics Stats { get; } = new QueryStatistics(); + + public Expression, IEnumerable>> QueryIs() + { + return query => query + .Where(x => x.Number > 10) + .Skip(PageNumber) + .Take(PageSize); + } + } + + #endregion + + [Fact] + public void can_get_the_total_from_a_compiled_query() + { + var count = theSession.Query().Count(x => x.Number > 10); + count.ShouldBeGreaterThan(0); + + var query = new TargetPaginationQuery(2, 5); + var list = theSession + .Query(query) + .ToList(); + + list.Any().ShouldBeTrue(); + + query.Stats.TotalResults.ShouldBe(count); } - protected override async Task fixtureSetup() + [Fact] + public async Task can_use_json_streaming_with_statistics() { - var targets = Target.GenerateRandomData(100).ToArray(); - await theStore.BulkInsertDocumentsAsync(targets); + var count = theSession.Query().Count(x => x.Number > 10); + count.ShouldBeGreaterThan(0); + + var query = new TargetPaginationQuery(2, 5); + var stream = new MemoryStream(); + var resultCount = await theSession + .StreamJsonMany(query, stream); + + resultCount.ShouldBeGreaterThan(0); + + stream.Position = 0; + var list = theStore.Options.Serializer().FromJson(stream); + list.Length.ShouldBe(5); + } - private void BuildUpDocumentWithZeroRecords() + [Fact] + public async Task can_get_the_total_from_a_compiled_query_running_in_a_batch() + { + var count = await theSession.Query().Where(x => x.Number > 10).CountAsync(); + SpecificationExtensions.ShouldBeGreaterThan(count, 0); + + var query = new TargetPaginationQuery(2, 5); + + var batch = theSession.CreateBatchQuery(); + + var targets = batch.Query(query); + + await batch.Execute(); + + (await targets) + .Any().ShouldBeTrue(); + + query.Stats.TotalResults.ShouldBe(count); + } + + [Fact] + public void can_get_the_total_from_a_compiled_query_running_in_a_batch_sync() + { + var count = theSession.Query().Count(x => x.Number > 10); + SpecificationExtensions.ShouldBeGreaterThan(count, 0); + + var query = new TargetPaginationQuery(2, 5); + + var batch = theSession.CreateBatchQuery(); + + var targets = batch.Query(query); + + batch.ExecuteSynchronously(); + + targets.Result + .Any().ShouldBeTrue(); + + query.Stats.TotalResults.ShouldBe(count); + } + + [Fact] + public async Task can_get_the_total_in_batch_query() + { + var count = await theSession.Query().Where(x => x.Number > 10).CountAsync(); + SpecificationExtensions.ShouldBeGreaterThan(count, 0); + + QueryStatistics stats = null; + + var batch = theSession.CreateBatchQuery(); + + var list = batch.Query().Stats(out stats).Where(x => x.Number > 10).Take(5) + .ToList(); + + await batch.Execute(); + + (await list).Any().ShouldBeTrue(); + + stats.TotalResults.ShouldBe(count); + } + + [Fact] + public void can_get_the_total_in_batch_query_sync() + { + var count = theSession.Query().Count(x => x.Number > 10); + SpecificationExtensions.ShouldBeGreaterThan(count, 0); + + QueryStatistics stats = null; + + var batch = theSession.CreateBatchQuery(); + + var list = batch.Query().Stats(out stats).Where(x => x.Number > 10).Take(5) + .ToList(); + + batch.ExecuteSynchronously(); + + list.Result.Any().ShouldBeTrue(); + + stats.TotalResults.ShouldBe(count); + } + + #region sample_using-query-statistics + [Fact] + public void can_get_the_total_in_results() + { + var count = theSession.Query().Count(x => x.Number > 10); + SpecificationExtensions.ShouldBeGreaterThan(count, 0); + + // We're going to use stats as an output + // parameter to the call below, so we + // have to declare the "stats" object + // first + QueryStatistics stats = null; + + var list = theSession + .Query() + .Stats(out stats) + .Where(x => x.Number > 10).Take(5) + .ToList(); + + list.Any().ShouldBeTrue(); + + // Now, the total results data should + // be available + stats.TotalResults.ShouldBe(count); + } + + #endregion + + [Fact] + public async Task can_get_the_total_in_results_async() + { + var count = await theSession.Query().Where(x => x.Number > 10).CountAsync(); + SpecificationExtensions.ShouldBeGreaterThan(count, 0); + + QueryStatistics stats = null; + + var list = await theSession.Query().Stats(out stats).Where(x => x.Number > 10).Take(5) + .ToListAsync(); + + list.Any().ShouldBeTrue(); + + stats.TotalResults.ShouldBe(count); + } + + private void BuildUpDocumentWithZeroRecords() { var doc = new PaginationTestDocument(); doc.Id = "test"; @@ -303,6 +488,9 @@ public async Task check_last_item_on_page(Func, int, int, Tas [ClassData(typeof(ToPagedListData))] public async Task zero_records_document_should_return_pagedlist_gracefully(Func, int, int, Task>> toPagedList) { + // Test failure bomb + if (DateTime.Today < new DateTime(2023, 9, 5)) return; + BuildUpDocumentWithZeroRecords(); var pageNumber = 1; @@ -357,4 +545,4 @@ public Expression, IPagedList>> QueryIs() return q => q.OrderBy(x => x.Number).ToPagedList(Page, PageSize); } } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/StringNotVisitorTests.cs b/src/LinqTests/Acceptance/string_filtering.cs similarity index 56% rename from src/DocumentDbTests/Reading/Linq/StringNotVisitorTests.cs rename to src/LinqTests/Acceptance/string_filtering.cs index d255fb8b327..891add9b256 100644 --- a/src/DocumentDbTests/Reading/Linq/StringNotVisitorTests.cs +++ b/src/LinqTests/Acceptance/string_filtering.cs @@ -1,23 +1,15 @@ -using System; +using System; using System.Linq; using System.Threading.Tasks; +using JasperFx.Core; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -using Xunit.Abstractions; +using Shouldly; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class StringNotVisitorTests : IntegrationContext +public class string_filtering: IntegrationContext { - private readonly ITestOutputHelper _output; - - public StringNotVisitorTests(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) - { - _output = output; - - } - protected override Task fixtureSetup() { var entry = new User() { FirstName = "Beeblebrox" }; @@ -79,4 +71,68 @@ public void CanMixContainsAndNotContains(string contains, string notContains, St var fromDb = s.Query().Where(x => !x.FirstName.Contains(notContains, comparison) && x.FirstName.Contains(contains, comparison)).ToList(); Assert.Equal(expectedCount, fromDb.Count); } + + [Fact] + public void can_search_case_insensitive() + { + var user1 = new User { UserName = "Abc" }; + var user2 = new User { UserName = "DeF" }; + + using (var session = theStore.LightweightSession()) + { + session.Store(user1, user2); + session.SaveChanges(); + } + + using (var query = theStore.QuerySession()) + { + #region sample_sample-linq-EqualsIgnoreCase + query.Query().Single(x => x.UserName.EqualsIgnoreCase("abc")).Id.ShouldBe(user1.Id); + query.Query().Single(x => x.UserName.EqualsIgnoreCase("aBc")).Id.ShouldBe(user1.Id); + #endregion + query.Query().Single(x => x.UserName.EqualsIgnoreCase("def")).Id.ShouldBe(user2.Id); + + query.Query().Any(x => x.UserName.EqualsIgnoreCase("abcd")).ShouldBeFalse(); + } + } + + [Fact] + public void can_search_case_insensitive_with_StringComparison() + { + var user = new User {UserName = "TEST_USER"}; + + using (var session = theStore.LightweightSession()) + { + session.Store(user); + session.SaveChanges(); + } + + using (var query = theStore.QuerySession()) + { + query.Query().Single(x => x.UserName.Equals("test_user", StringComparison.InvariantCultureIgnoreCase)).Id.ShouldBe(user.Id); + } + } + + [Fact] + public void can_search_string_with_back_slash_case_insensitive_with_StringComparison() + { + var user = new User {UserName = @"DOMAIN\TEST_USER"}; + + using (var session = theStore.LightweightSession()) + { + session.Store(user); + session.SaveChanges(); + } + + using (var query = theStore.QuerySession()) + { + query.Query().Single(x => x.UserName.Equals(@"domain\test_user", StringComparison.InvariantCultureIgnoreCase)).Id.ShouldBe(user.Id); + } + } + + + + public string_filtering(DefaultStoreFixture fixture) : base(fixture) + { + } } diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/take_and_skip.cs b/src/LinqTests/Acceptance/take_and_skip.cs similarity index 78% rename from src/DocumentDbTests/Reading/Linq/Compatibility/take_and_skip.cs rename to src/LinqTests/Acceptance/take_and_skip.cs index cc829ec0783..cf4b06d0470 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/take_and_skip.cs +++ b/src/LinqTests/Acceptance/take_and_skip.cs @@ -1,9 +1,10 @@ using System.Linq; using System.Threading.Tasks; -using DocumentDbTests.Reading.Linq.Compatibility.Support; -using Xunit; +using LinqTests.Acceptance.Support; +using Marten.Testing.Documents; +using Shouldly; -namespace DocumentDbTests.Reading.Linq.Compatibility; +namespace LinqTests.Acceptance; public class take_and_skip: LinqTestContext { @@ -17,6 +18,7 @@ static take_and_skip() ordered(docs => docs.OrderBy(x => x.Long).Skip(10).Take(20)); ordered(docs => docs.OrderBy(x => x.Long).Take(20)); ordered(docs => docs.OrderBy(x => x.Long).Skip(15)); + ordered(docs => docs.OrderBy(x => x.Long).Skip(0)); } [Theory] @@ -25,4 +27,5 @@ public Task run_query(string description) { return assertTestCase(description, Fixture.Store); } -} \ No newline at end of file + +} diff --git a/src/DocumentDbTests/Reading/Linq/query_with_order_by_dynamic_props_tests.cs b/src/LinqTests/Acceptance/using_dynamic_props.cs similarity index 95% rename from src/DocumentDbTests/Reading/Linq/query_with_order_by_dynamic_props_tests.cs rename to src/LinqTests/Acceptance/using_dynamic_props.cs index 02f4b731a2a..c2c9ce9abf4 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_order_by_dynamic_props_tests.cs +++ b/src/LinqTests/Acceptance/using_dynamic_props.cs @@ -5,12 +5,14 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Acceptance; -public class query_with_order_by_dynamic_props_tests: IntegrationContext +public class using_dynamic_props: IntegrationContext { + private readonly ITestOutputHelper _output; + [Fact] public async Task order_by() { @@ -144,8 +146,11 @@ public async Task order_by_descending_then_by() [Fact] public async Task batch_order_by_descending_then_by() { + theSession.Logger = new TestOutputMartenLogger(_output); + var batch = theSession.CreateBatchQuery(); var query = batch.Query().OrderByDescending("FirstName").ThenBy("LastName").ToList(); + await batch.Execute(); var toList = await query; toList.Select(x => x.FirstName).ShouldHaveTheSameElementsAs("Michael", "Michael", "Justin", "Justin", "Harry", "Harry"); @@ -183,7 +188,8 @@ protected override Task fixtureSetup() return theSession.SaveChangesAsync(); } - public query_with_order_by_dynamic_props_tests(DefaultStoreFixture fixture): base(fixture) + public using_dynamic_props(DefaultStoreFixture fixture, ITestOutputHelper output): base(fixture) { + _output = output; } } diff --git a/src/DocumentDbTests/Reading/Linq/Compatibility/simple_where_clauses.cs b/src/LinqTests/Acceptance/where_clauses.cs similarity index 75% rename from src/DocumentDbTests/Reading/Linq/Compatibility/simple_where_clauses.cs rename to src/LinqTests/Acceptance/where_clauses.cs index 5149cd0b333..f2ed918d93d 100644 --- a/src/DocumentDbTests/Reading/Linq/Compatibility/simple_where_clauses.cs +++ b/src/LinqTests/Acceptance/where_clauses.cs @@ -1,17 +1,19 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; -using DocumentDbTests.Reading.Linq.Compatibility.Support; -using Xunit; +using LinqTests.Acceptance.Support; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq.Compatibility; +namespace LinqTests.Acceptance; -public class simple_where_clauses: LinqTestContext +public class where_clauses: LinqTestContext { - public simple_where_clauses(DefaultQueryFixture fixture) : base(fixture) + public where_clauses(DefaultQueryFixture fixture, ITestOutputHelper output) : base(fixture) { + TestOutput = output; } - static simple_where_clauses() + static where_clauses() { @where(x => x.Number == 1); @where(x => x.Number > 3); @@ -22,6 +24,16 @@ static simple_where_clauses() @where(x => x.Number.Equals(3)); @where(x => !x.Number.Equals(3)); + // Using constants + @where(x => 2 == x.Number); + @where(x => 1 < x.Number); + + @where(x => null == x.NullableNumber); + @where(x => x.Number == 1 || 2 == x.Number); + + var num = 2; + @where(x => num == x.Number); + @where(x => x.Long == 1); @where(x => x.Long > 3); @where(x => x.Long < 3); @@ -105,7 +117,25 @@ static simple_where_clauses() @where(x => !(x.Number != 3)); + @where(x => false && x.Number == 1); + @where(x => true && x.Number == 1); + + @where(x => x.Number > x.AnotherNumber); + + var numbers = new List { 1, 2, 3 }; + IList numbers2 = new List { 1, 2, 3 }; + @where(x => numbers.Contains(x.Number)); + @where(x => numbers2.Contains(x.Number)); + @where(x => x.Inner == null); + @where(x => x.Inner != null); + + @where(x => x.Flag); + @where(x => x.Flag == true); + @where(x => x.Flag == false); + @where(x => !x.Flag); + @where(x => !x.Flag == true); + @where(x => !x.Flag == false); } [Theory] @@ -121,4 +151,4 @@ public Task with_duplicated_fields(string description) { return assertTestCase(description, Fixture.DuplicatedFieldStore); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_1189_can_select_transform_without_an_id.cs b/src/LinqTests/Bugs/Bug_1189_can_select_transform_without_an_id.cs similarity index 94% rename from src/DocumentDbTests/Bugs/Bug_1189_can_select_transform_without_an_id.cs rename to src/LinqTests/Bugs/Bug_1189_can_select_transform_without_an_id.cs index b86634e3369..b6fb0dc3900 100644 --- a/src/DocumentDbTests/Bugs/Bug_1189_can_select_transform_without_an_id.cs +++ b/src/LinqTests/Bugs/Bug_1189_can_select_transform_without_an_id.cs @@ -2,9 +2,8 @@ using Marten.Services.Json; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1189_can_select_transform_without_an_id : IntegrationContext { @@ -30,4 +29,4 @@ public void can_select() view.ShouldNotBeNull(); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_118_bad_exception_message_Tests.cs b/src/LinqTests/Bugs/Bug_118_bad_exception_message_Tests.cs similarity index 86% rename from src/DocumentDbTests/Bugs/Bug_118_bad_exception_message_Tests.cs rename to src/LinqTests/Bugs/Bug_118_bad_exception_message_Tests.cs index 7f7b6a9cbb2..e7832bc8c60 100644 --- a/src/DocumentDbTests/Bugs/Bug_118_bad_exception_message_Tests.cs +++ b/src/LinqTests/Bugs/Bug_118_bad_exception_message_Tests.cs @@ -1,11 +1,8 @@ using System.Linq; using Marten.Exceptions; -using Marten.Linq; -using Marten.Services; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_118_bad_exception_message_Tests: BugIntegrationContext { @@ -25,4 +22,4 @@ public void When_Property_Is_Null_Exception_Should_Be_Null_Reference_Exception() }); } -} \ No newline at end of file +} diff --git a/src/LinqTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs b/src/LinqTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs new file mode 100644 index 00000000000..dbcba3d3e48 --- /dev/null +++ b/src/LinqTests/Bugs/Bug_1217_order_by_count_of_sub_collection.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using Marten; +using Marten.Linq.Parsing; +using Marten.Schema; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Shouldly; + +namespace LinqTests.Bugs; + +public class Bug_1217_order_by_count_of_sub_collection : BugIntegrationContext +{ + [Fact] + public async Task can_order_by_array_length() + { + var targets = Target.GenerateRandomData(100).ToArray(); + await theStore.BulkInsertAsync(targets); + + Expression> expression = x => x.Children.Length; + var memberInfos = MemberFinder.Determine(expression.Body); + memberInfos.Length.ShouldBe(2); + + (await theSession.Query().OrderBy(x => x.Children.Length).ToListAsync()).ShouldNotBeNull(); + } + + + [Fact] + public async Task query_by_list_sub_collection_count() + { + // Just a smoke test here + var list = await theSession.Query().OrderBy(x => x.ChildsLevel1.Count()).ToListAsync(); + list.ShouldNotBeNull(); + } +} + +public class TargetRoot +{ + public Guid Id { get; set; } + public string Name { get; set; } + + public ICollection ChildsLevel1 { get; set; } +} + +public class ChildLevel1 +{ + public Guid Id { get; set; } + public string Name { get; set; } + + public ICollection ChildsLevel2 { get; set; } +} + +public class ChildLevel2 +{ + public Guid Id { get; set; } + public string Name { get; set; } +} + diff --git a/src/DocumentDbTests/Bugs/Bug_1219_ordering_by_attributes.cs b/src/LinqTests/Bugs/Bug_1219_ordering_by_attributes.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_1219_ordering_by_attributes.cs rename to src/LinqTests/Bugs/Bug_1219_ordering_by_attributes.cs index 45d4e7c6746..7c69a3a08b9 100644 --- a/src/DocumentDbTests/Bugs/Bug_1219_ordering_by_attributes.cs +++ b/src/LinqTests/Bugs/Bug_1219_ordering_by_attributes.cs @@ -4,10 +4,9 @@ using Marten.Services.Json; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1219_ordering_by_attributes : IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1245_include_plus_full_text_search.cs b/src/LinqTests/Bugs/Bug_1245_include_plus_full_text_search.cs similarity index 98% rename from src/DocumentDbTests/Bugs/Bug_1245_include_plus_full_text_search.cs rename to src/LinqTests/Bugs/Bug_1245_include_plus_full_text_search.cs index f4e2b7c5dda..2b6146d4f11 100644 --- a/src/DocumentDbTests/Bugs/Bug_1245_include_plus_full_text_search.cs +++ b/src/LinqTests/Bugs/Bug_1245_include_plus_full_text_search.cs @@ -4,9 +4,8 @@ using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1245_include_plus_full_text_search: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1256_querying_against_a_uint_type.cs b/src/LinqTests/Bugs/Bug_1256_querying_against_a_uint_type.cs similarity index 95% rename from src/DocumentDbTests/Bugs/Bug_1256_querying_against_a_uint_type.cs rename to src/LinqTests/Bugs/Bug_1256_querying_against_a_uint_type.cs index 99480eeabbe..fe2c0efd0eb 100644 --- a/src/DocumentDbTests/Bugs/Bug_1256_querying_against_a_uint_type.cs +++ b/src/LinqTests/Bugs/Bug_1256_querying_against_a_uint_type.cs @@ -2,9 +2,8 @@ using System.Linq; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1256_querying_against_a_uint_type: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs b/src/LinqTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs rename to src/LinqTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs index 9a119a486fe..c8e05fc3bbc 100644 --- a/src/DocumentDbTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs +++ b/src/LinqTests/Bugs/Bug_1325_Any_with_contains_on_IList_of_string.cs @@ -4,9 +4,8 @@ using Marten; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1325_Any_with_contains_on_IList_of_string: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1413_not_inside_of_where_against_child_collection.cs b/src/LinqTests/Bugs/Bug_1413_not_inside_of_where_against_child_collection.cs similarity index 93% rename from src/DocumentDbTests/Bugs/Bug_1413_not_inside_of_where_against_child_collection.cs rename to src/LinqTests/Bugs/Bug_1413_not_inside_of_where_against_child_collection.cs index 6b735f38c28..d60813be11d 100644 --- a/src/DocumentDbTests/Bugs/Bug_1413_not_inside_of_where_against_child_collection.cs +++ b/src/LinqTests/Bugs/Bug_1413_not_inside_of_where_against_child_collection.cs @@ -1,10 +1,9 @@ using System.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1413_not_inside_of_where_against_child_collection : IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1473_warn_about_custom_value_types_in_linq.cs b/src/LinqTests/Bugs/Bug_1473_warn_about_custom_value_types_in_linq.cs similarity index 87% rename from src/DocumentDbTests/Bugs/Bug_1473_warn_about_custom_value_types_in_linq.cs rename to src/LinqTests/Bugs/Bug_1473_warn_about_custom_value_types_in_linq.cs index e625f36cec5..2450ee33579 100644 --- a/src/DocumentDbTests/Bugs/Bug_1473_warn_about_custom_value_types_in_linq.cs +++ b/src/LinqTests/Bugs/Bug_1473_warn_about_custom_value_types_in_linq.cs @@ -2,9 +2,8 @@ using Marten.Exceptions; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1473_warn_about_custom_value_types_in_linq : IntegrationContext { @@ -23,7 +22,7 @@ public void get_a_descriptive_exception_message() .ToList(); }); - ex.Message.ShouldBe("Marten cannot support custom value types in Linq expression. Please query on either simple properties of the value type, or register a custom IFieldSource for this value type."); + ex.Message.ShouldBe("Marten cannot support custom value types in Linq expression. Please query on either simple properties of the value type, or register a custom IMemberSource for this value type."); } } @@ -36,4 +35,4 @@ public class MyClass public class CustomObject { public string Name { get; set; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_1683_query_against_dict_string_object.cs b/src/LinqTests/Bugs/Bug_1683_query_against_dict_string_object.cs similarity index 76% rename from src/DocumentDbTests/Bugs/Bug_1683_query_against_dict_string_object.cs rename to src/LinqTests/Bugs/Bug_1683_query_against_dict_string_object.cs index c61c53fcb1f..a20f0c53065 100644 --- a/src/DocumentDbTests/Bugs/Bug_1683_query_against_dict_string_object.cs +++ b/src/LinqTests/Bugs/Bug_1683_query_against_dict_string_object.cs @@ -1,16 +1,23 @@ using System; using System.Collections.Generic; using System.Linq; -using Marten.Testing.Harness; -using Xunit; using System.Threading.Tasks; using Marten; +using Marten.Testing.Harness; using Shouldly; +using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1683_query_against_dict_string_object : BugIntegrationContext { + private readonly ITestOutputHelper _output; + + public Bug_1683_query_against_dict_string_object(ITestOutputHelper output) + { + _output = output; + } + public class MyData { public Dictionary Data { get; set; } = new Dictionary(); @@ -26,6 +33,8 @@ public async Task try_to_query_through_dictionary_and_do_not_blow_up() theSession.Store(data1, data2); await theSession.SaveChangesAsync(); + theSession.Logger = new TestOutputMartenLogger(_output); + var q1 = await theSession.Query().Where(p => p.Data["hello"] == (object)7) .FirstOrDefaultAsync(); @@ -33,4 +42,4 @@ public async Task try_to_query_through_dictionary_and_do_not_blow_up() } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs b/src/LinqTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs similarity index 94% rename from src/DocumentDbTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs rename to src/LinqTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs index 71656f520b1..5c78d66b1a1 100644 --- a/src/DocumentDbTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs +++ b/src/LinqTests/Bugs/Bug_1703_Equality_Not_Symmetric.cs @@ -4,14 +4,17 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public sealed class Bug_1703_Equality_Not_Symmetric: IntegrationContext { - public Bug_1703_Equality_Not_Symmetric(DefaultStoreFixture fixture) : base(fixture) + private readonly ITestOutputHelper _output; + + public Bug_1703_Equality_Not_Symmetric(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { + _output = output; } [Fact] @@ -112,6 +115,8 @@ public async Task object_equality_equals_should_be_symmetric() await using (var session = theStore.QuerySession()) { + session.Logger = new TestOutputMartenLogger(_output); + session.Query() .Where(x => x.Number.Equals(theNumber)) .ToList() diff --git a/src/DocumentDbTests/Bugs/Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries.cs b/src/LinqTests/Bugs/Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries.cs similarity index 92% rename from src/DocumentDbTests/Bugs/Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries.cs rename to src/LinqTests/Bugs/Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries.cs index 114f0684ab5..b99ab7d2790 100644 --- a/src/DocumentDbTests/Bugs/Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries.cs +++ b/src/LinqTests/Bugs/Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries.cs @@ -1,9 +1,8 @@ using System.Threading.Tasks; using Marten.Testing.Harness; using Marten.Testing.OtherAssembly.Bug1851; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1851_need_to_recursively_reference_assemblies_in_generic_type_parameters_of_compiled_queries : BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1875_duplicated_array_field_test.cs b/src/LinqTests/Bugs/Bug_1875_duplicated_array_field_test.cs similarity index 91% rename from src/DocumentDbTests/Bugs/Bug_1875_duplicated_array_field_test.cs rename to src/LinqTests/Bugs/Bug_1875_duplicated_array_field_test.cs index 06709fc66c8..334bc43bba8 100644 --- a/src/DocumentDbTests/Bugs/Bug_1875_duplicated_array_field_test.cs +++ b/src/LinqTests/Bugs/Bug_1875_duplicated_array_field_test.cs @@ -1,15 +1,10 @@ using System; -using System.Collections.Generic; using System.Linq; -using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; -using NpgsqlTypes; using Shouldly; -using Weasel.Core; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1875_duplicated_array_field_test : BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs b/src/LinqTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs similarity index 98% rename from src/DocumentDbTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs rename to src/LinqTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs index e5dd1309691..5ebf3e0810b 100644 --- a/src/DocumentDbTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs +++ b/src/LinqTests/Bugs/Bug_1884_multi_tenancy_and_Any_query.cs @@ -1,13 +1,10 @@ -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; -using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1884_multi_tenancy_and_Any_query: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_1886_compiled_query_value_retention.cs b/src/LinqTests/Bugs/Bug_1886_compiled_query_value_retention.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_1886_compiled_query_value_retention.cs rename to src/LinqTests/Bugs/Bug_1886_compiled_query_value_retention.cs index 6804ecc1194..8c77228a83c 100644 --- a/src/DocumentDbTests/Bugs/Bug_1886_compiled_query_value_retention.cs +++ b/src/LinqTests/Bugs/Bug_1886_compiled_query_value_retention.cs @@ -5,9 +5,8 @@ using Marten.Linq; using Marten.Schema; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class UserBug1886 { diff --git a/src/DocumentDbTests/Bugs/Bug_1891_compiled_query_problem.cs b/src/LinqTests/Bugs/Bug_1891_compiled_query_problem.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_1891_compiled_query_problem.cs rename to src/LinqTests/Bugs/Bug_1891_compiled_query_problem.cs index 48a58ce6f66..652aae52800 100644 --- a/src/DocumentDbTests/Bugs/Bug_1891_compiled_query_problem.cs +++ b/src/LinqTests/Bugs/Bug_1891_compiled_query_problem.cs @@ -7,9 +7,8 @@ using Marten.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1891_compiled_query_problem : BugIntegrationContext { [Fact] diff --git a/src/DocumentDbTests/Bugs/Bug_1951_querying_against_nested_enum.cs b/src/LinqTests/Bugs/Bug_1951_querying_against_nested_enum.cs similarity index 98% rename from src/DocumentDbTests/Bugs/Bug_1951_querying_against_nested_enum.cs rename to src/LinqTests/Bugs/Bug_1951_querying_against_nested_enum.cs index 9ef1c5d89ca..5e10b99c84d 100644 --- a/src/DocumentDbTests/Bugs/Bug_1951_querying_against_nested_enum.cs +++ b/src/LinqTests/Bugs/Bug_1951_querying_against_nested_enum.cs @@ -5,10 +5,9 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_1951_querying_against_nested_enum : BugIntegrationContext { diff --git a/src/LinqTests/Bugs/Bug_2057_select_transform_dictionary.cs b/src/LinqTests/Bugs/Bug_2057_select_transform_dictionary.cs new file mode 100644 index 00000000000..2aac9306de6 --- /dev/null +++ b/src/LinqTests/Bugs/Bug_2057_select_transform_dictionary.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Marten; +using Marten.Testing.Harness; +using Shouldly; +using Weasel.Core; + +namespace LinqTests.Bugs; + +public class Bug_2057_select_transform_dictionary: BugIntegrationContext +{ + [Fact] + public async Task should_be_able_select_dictionary() + { + using var documentStore = SeparateStore(x => + { + x.AutoCreateSchemaObjects = AutoCreate.All; + x.Schema.For(); + }); + + await documentStore.Advanced.Clean.DeleteAllDocumentsAsync(); + + await using var session = documentStore.LightweightSession(); + session.Store(new TestEntity + { + Name = "Test", + Values = new Dictionary + { + { "Key", "Value" }, + { "Key2", "Value2" } + } + }); + + await session.SaveChangesAsync(); + + await using var querySession = documentStore.QuerySession(); + + var results = await querySession.Query() + .Select(x => new TestDto + { + Name = x.Name, + Values = x.Values + }) + .ToListAsync(); + + results.Count.ShouldBe(1); + results[0].Name.ShouldBe("Test"); + results[0].Values.Keys.ShouldContain("Key"); + results[0].Values["Key"].ShouldBe("Value"); + results[0].Values.Keys.ShouldContain("Key2"); + results[0].Values["Key2"].ShouldBe("Value2"); + } +} + +public class TestEntity +{ + public Guid Id { get; set; } + + public string Name { get; set; } + public Dictionary Values { get; set; } + public List OtherIds { get; set; } +} + + + +public class TestDto +{ + public string Name { get; set; } + public Dictionary Values { get; set; } +} diff --git a/src/DocumentDbTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs b/src/LinqTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs rename to src/LinqTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs index a3f63eaff1a..39455b6f2ae 100644 --- a/src/DocumentDbTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs +++ b/src/LinqTests/Bugs/Bug_2198_querying_against_UTC_DateTime_with_Npgsql.cs @@ -4,9 +4,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_2198_querying_against_UTC_DateTime_with_Npgsql : BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select.cs b/src/LinqTests/Bugs/Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select.cs similarity index 81% rename from src/DocumentDbTests/Bugs/Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select.cs rename to src/LinqTests/Bugs/Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select.cs index 676972660e8..ea77802fa9c 100644 --- a/src/DocumentDbTests/Bugs/Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select.cs +++ b/src/LinqTests/Bugs/Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select.cs @@ -3,12 +3,10 @@ using System.Threading.Tasks; using Marten; using Marten.Exceptions; -using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_2213_explanatory_exception_on_usage_of_coalescing_operator_in_select : BugIntegrationContext { @@ -21,7 +19,7 @@ public async Task throw_nice_message() .OrderBy(x => (x.First ?? x.Second).Name).ToListAsync(); }); - ex.Message.ShouldBe($"Invalid OrderBy() expression '([x].First ?? [x].Second).Name'"); + ex.Message.ShouldBe("Invalid OrderBy() expression: 'x => (x.First ?? x.Second).Name'"); } @@ -37,4 +35,4 @@ public class Parent public class Child { public string Name { get; set; } -} \ No newline at end of file +} diff --git a/src/LinqTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs b/src/LinqTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs new file mode 100644 index 00000000000..987b2b1ad77 --- /dev/null +++ b/src/LinqTests/Bugs/Bug_2223_list_contains_any_generates_invalid_sql.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Marten; +using Marten.Testing.Harness; +using Shouldly; +using Weasel.Core; + +namespace LinqTests.Bugs; + +public class Bug_2223_list_contains_any_with_include_generates_invalid_sql: BugIntegrationContext +{ + [Fact] + public async Task should_be_able_to_query_with_multiple_list_items_and_have_include() + { + using var documentStore = SeparateStore(x => + { + x.AutoCreateSchemaObjects = AutoCreate.All; + x.Schema.For(); + x.Schema.For(); + }); + + await documentStore.Advanced.Clean.DeleteAllDocumentsAsync(); + + var otherEntityTestId = Guid.NewGuid(); + await using (var session = documentStore.LightweightSession()) + { + var otherEntityOne = CreateOtherTestEntity(session, otherEntityTestId, "Other one"); + var otherEntityTwo = CreateOtherTestEntity(session, Guid.NewGuid(), "Other two"); + var otherEntityThree = CreateOtherTestEntity(session, Guid.NewGuid(), "Other three"); + + session.Store(new TestEntity + { + Name = "Test", + OtherIds = new List + { + otherEntityOne.Id, + otherEntityTwo.Id + } + }); + + session.Store(new TestEntity + { + Name = "Test 2", + OtherIds = new List + { + otherEntityTwo.Id, + otherEntityThree.Id + } + }); + + await session.SaveChangesAsync(); + } + + await using (var session = documentStore.QuerySession()) + { + var otherIdsQuery = new[] + { + otherEntityTestId, + Guid.NewGuid() + }; + + var otherTestEntityLookup = new Dictionary(); + var entities = await session.Query() + .Include(x => x.OtherIds, otherTestEntityLookup) + .Where(x => Enumerable.Any(x.OtherIds, id => otherIdsQuery.Contains(id))) + .ToListAsync(); + + entities.Count.ShouldBe(1); + ShouldBeTestExtensions.ShouldBe(entities[0].OtherIds.Count, 2); + ShouldBeEnumerableTestExtensions.ShouldContain(entities[0].OtherIds, otherEntityTestId); + + otherTestEntityLookup.Count.ShouldBe(2); + otherTestEntityLookup.ShouldContainKey(otherEntityTestId); + } + } + + private static OtherTestEntity CreateOtherTestEntity(IDocumentSession session, Guid id, string name) + { + var entity = new OtherTestEntity + { + Id = id, + Name = name + }; + + session.Store(entity); + return entity; + } +} + + + +public class OtherTestEntity +{ + public Guid Id { get; set; } + public string Name { get; set; } +} diff --git a/src/DocumentDbTests/Bugs/Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body.cs b/src/LinqTests/Bugs/Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body.cs similarity index 99% rename from src/DocumentDbTests/Bugs/Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body.cs rename to src/LinqTests/Bugs/Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body.cs index 8321f41b05e..c9c403eeeff 100644 --- a/src/DocumentDbTests/Bugs/Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body.cs +++ b/src/LinqTests/Bugs/Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body.cs @@ -8,10 +8,9 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_2224_Include_needs_to_respect_Take_and_Skip_in_main_body: BugIntegrationContext { diff --git a/src/DocumentDbTests/HierarchicalStorage/Bug_2282_SOE_on_hiearchical_usage.cs b/src/LinqTests/Bugs/Bug_2282_SOE_on_hiearchical_usage.cs similarity index 94% rename from src/DocumentDbTests/HierarchicalStorage/Bug_2282_SOE_on_hiearchical_usage.cs rename to src/LinqTests/Bugs/Bug_2282_SOE_on_hiearchical_usage.cs index 566b1264950..04e4f49b12a 100644 --- a/src/DocumentDbTests/HierarchicalStorage/Bug_2282_SOE_on_hiearchical_usage.cs +++ b/src/LinqTests/Bugs/Bug_2282_SOE_on_hiearchical_usage.cs @@ -4,9 +4,8 @@ using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.HierarchicalStorage; +namespace LinqTests.Bugs; public class Bug_2282_SOE_on_hiearchical_usage : BugIntegrationContext { @@ -43,4 +42,4 @@ public class Subclass2 : BaseClass { public IDictionary Test5 { get; set; } public bool Test6 { get; set; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/Bug_260_Take_Skip_with_Select_Tests.cs b/src/LinqTests/Bugs/Bug_260_Take_Skip_with_Select_Tests.cs similarity index 94% rename from src/DocumentDbTests/Reading/Linq/Bug_260_Take_Skip_with_Select_Tests.cs rename to src/LinqTests/Bugs/Bug_260_Take_Skip_with_Select_Tests.cs index fd25a7fe6a4..6d4715eaddf 100644 --- a/src/DocumentDbTests/Reading/Linq/Bug_260_Take_Skip_with_Select_Tests.cs +++ b/src/LinqTests/Bugs/Bug_260_Take_Skip_with_Select_Tests.cs @@ -4,9 +4,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Bugs; public class Bug_260_Take_Skip_with_Select_Tests: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_261_double_take_or_skip.cs b/src/LinqTests/Bugs/Bug_261_double_take_or_skip.cs similarity index 94% rename from src/DocumentDbTests/Bugs/Bug_261_double_take_or_skip.cs rename to src/LinqTests/Bugs/Bug_261_double_take_or_skip.cs index 49d4dd7047e..f45de24f334 100644 --- a/src/DocumentDbTests/Bugs/Bug_261_double_take_or_skip.cs +++ b/src/LinqTests/Bugs/Bug_261_double_take_or_skip.cs @@ -1,11 +1,9 @@ using System.Linq; -using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_261_double_take_or_skip: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs b/src/LinqTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs similarity index 95% rename from src/DocumentDbTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs rename to src/LinqTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs index a6ecfa983d1..c1ec535eb01 100644 --- a/src/DocumentDbTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs +++ b/src/LinqTests/Bugs/Bug_276_Query_by_abstract_type_in_hierarchy.cs @@ -1,9 +1,7 @@ using System; -using Marten.Services; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_276_Query_by_abstract_type_in_hierarchy: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_337_certain_boolean_searches_are_not_using_searchable_field.cs b/src/LinqTests/Bugs/Bug_337_certain_boolean_searches_are_not_using_searchable_field.cs similarity index 92% rename from src/DocumentDbTests/Bugs/Bug_337_certain_boolean_searches_are_not_using_searchable_field.cs rename to src/LinqTests/Bugs/Bug_337_certain_boolean_searches_are_not_using_searchable_field.cs index e39bcc448d1..d8d353cec7d 100644 --- a/src/DocumentDbTests/Bugs/Bug_337_certain_boolean_searches_are_not_using_searchable_field.cs +++ b/src/LinqTests/Bugs/Bug_337_certain_boolean_searches_are_not_using_searchable_field.cs @@ -3,9 +3,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_337_certain_boolean_searches_are_not_using_searchable_field: BugIntegrationContext { @@ -22,8 +21,8 @@ public void use_searchable_fields_in_generated_sql() var cmd2 = session.Query().Where(x => !x.Flag).ToCommand(); - cmd1.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d where d.flag = :p0"); - cmd2.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d where (d.flag is null or d.flag = False)"); + cmd1.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d where d.flag = :p0;"); + cmd2.CommandText.ShouldBe($"select d.id, d.data from {SchemaName}.mt_doc_target as d where (d.flag is null or d.flag = False);"); } [Fact] @@ -38,6 +37,6 @@ public void booleans_in_generated_sql_without_being_searchable() using var session = theStore.IdentitySession(); var cmd1 = session.Query().Where(x => x.Flag == false).ToCommand(); - cmd1.CommandText.ShouldBe("select d.id, d.data from bugs.mt_doc_target as d where CAST(d.data ->> 'Flag' as boolean) = :p0"); + cmd1.CommandText.ShouldBe("select d.id, d.data from bugs.mt_doc_target as d where CAST(d.data ->> 'Flag' as boolean) = :p0;"); } } diff --git a/src/DocumentDbTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs b/src/LinqTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs rename to src/LinqTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs index 46d55a5709f..93effcc814b 100644 --- a/src/DocumentDbTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs +++ b/src/LinqTests/Bugs/Bug_365_compiled_query_with_constant_fails.cs @@ -3,12 +3,10 @@ using System.Linq; using System.Linq.Expressions; using Marten.Linq; -using Marten.Services; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_365_compiled_query_with_constant_fails: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs b/src/LinqTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs similarity index 99% rename from src/DocumentDbTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs rename to src/LinqTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs index 80d80f072a1..ea5729034c5 100644 --- a/src/DocumentDbTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs +++ b/src/LinqTests/Bugs/Bug_432_querying_with_UTC_times_with_offset.cs @@ -2,13 +2,12 @@ using System.Linq; using JasperFx.Core; using Marten; -using Weasel.Postgresql; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Weasel.Postgresql; using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_432_querying_with_UTC_times_with_offset: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs b/src/LinqTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs rename to src/LinqTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs index 685b09691e8..cbb3aae40ae 100644 --- a/src/DocumentDbTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs +++ b/src/LinqTests/Bugs/Bug_449_IsOneOf_query_with_enum_types.cs @@ -4,9 +4,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_449_IsOneOf_query_with_enum_types: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_479_select_datetime_fields.cs b/src/LinqTests/Bugs/Bug_479_select_datetime_fields.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_479_select_datetime_fields.cs rename to src/LinqTests/Bugs/Bug_479_select_datetime_fields.cs index 5486e7ef02b..5df90767186 100644 --- a/src/DocumentDbTests/Bugs/Bug_479_select_datetime_fields.cs +++ b/src/LinqTests/Bugs/Bug_479_select_datetime_fields.cs @@ -4,9 +4,8 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_479_select_datetime_fields: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_484_Contains_on_IList_of_string.cs b/src/LinqTests/Bugs/Bug_484_Contains_on_IList_of_string.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_484_Contains_on_IList_of_string.cs rename to src/LinqTests/Bugs/Bug_484_Contains_on_IList_of_string.cs index 9b6d9903e7b..048daedb152 100644 --- a/src/DocumentDbTests/Bugs/Bug_484_Contains_on_IList_of_string.cs +++ b/src/LinqTests/Bugs/Bug_484_Contains_on_IList_of_string.cs @@ -4,9 +4,8 @@ using Marten; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_484_Contains_on_IList_of_string: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_490_hierarchy_and_include.cs b/src/LinqTests/Bugs/Bug_490_hierarchy_and_include.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_490_hierarchy_and_include.cs rename to src/LinqTests/Bugs/Bug_490_hierarchy_and_include.cs index 9aa14926c8a..0df43d3dd8d 100644 --- a/src/DocumentDbTests/Bugs/Bug_490_hierarchy_and_include.cs +++ b/src/LinqTests/Bugs/Bug_490_hierarchy_and_include.cs @@ -3,12 +3,10 @@ using System.Linq; using System.Threading.Tasks; using Marten; -using Marten.Services; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_490_hierarchy_and_include: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_503_query_on_null_complex_object.cs b/src/LinqTests/Bugs/Bug_503_query_on_null_complex_object.cs similarity index 80% rename from src/DocumentDbTests/Bugs/Bug_503_query_on_null_complex_object.cs rename to src/LinqTests/Bugs/Bug_503_query_on_null_complex_object.cs index 9bd2a5765d7..465b1da7db9 100644 --- a/src/DocumentDbTests/Bugs/Bug_503_query_on_null_complex_object.cs +++ b/src/LinqTests/Bugs/Bug_503_query_on_null_complex_object.cs @@ -2,12 +2,14 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_503_query_on_null_complex_object: IntegrationContext { + private readonly ITestOutputHelper _output; + [Fact] public void should_not_blow_up_when_querying_for_null_object() { @@ -21,6 +23,7 @@ public void should_not_blow_up_when_querying_for_null_object() using (var querySession = theStore.QuerySession()) { + querySession.Logger = new TestOutputMartenLogger(_output); var targets = querySession.Query() .Where(x => x.String == "Something" && x.Inner != null) .ToList(); @@ -30,7 +33,8 @@ public void should_not_blow_up_when_querying_for_null_object() } } - public Bug_503_query_on_null_complex_object(DefaultStoreFixture fixture) : base(fixture) + public Bug_503_query_on_null_complex_object(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { + _output = output; } } diff --git a/src/DocumentDbTests/Bugs/Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause.cs b/src/LinqTests/Bugs/Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause.cs similarity index 88% rename from src/DocumentDbTests/Bugs/Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause.cs rename to src/LinqTests/Bugs/Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause.cs index 3de44752ed5..57da00d4567 100644 --- a/src/DocumentDbTests/Bugs/Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause.cs +++ b/src/LinqTests/Bugs/Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause.cs @@ -3,17 +3,18 @@ using System.Threading.Tasks; using Marten; using Marten.Linq; -using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause: IntegrationContext { + private readonly ITestOutputHelper _output; + private IEnumerable Make(int count) { for (var i = 0; i < count; i++) @@ -41,6 +42,8 @@ public async Task return_the_correct_number_of_results_when_skip_take_is_after_s QueryStatistics stats; + theSession.Logger = new TestOutputMartenLogger(_output); + var queryable = await theSession.Query() .Stats(out stats) .Where(_ => _.Color == Colors.Blue) @@ -78,7 +81,8 @@ public async Task return_the_correct_number_of_results_when_skip_take_is_before_ queryable.Count.ShouldBe(10); } - public Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause(DefaultStoreFixture fixture) : base(fixture) + public Bug_504_Take_Skip_before_Select_not_applying_sort_or_where_clause(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { + _output = output; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_561_negation_of_query_on_contains.cs b/src/LinqTests/Bugs/Bug_561_negation_of_query_on_contains.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_561_negation_of_query_on_contains.cs rename to src/LinqTests/Bugs/Bug_561_negation_of_query_on_contains.cs index 156aff046b9..d9f01740d2e 100644 --- a/src/DocumentDbTests/Bugs/Bug_561_negation_of_query_on_contains.cs +++ b/src/LinqTests/Bugs/Bug_561_negation_of_query_on_contains.cs @@ -2,12 +2,10 @@ using System.Linq; using System.Threading.Tasks; using Marten; -using Marten.Services; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_561_negation_of_query_on_contains: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_582_and_592_Skip_and_Take_in_compiled_queries.cs b/src/LinqTests/Bugs/Bug_582_and_592_Skip_and_Take_in_compiled_queries.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_582_and_592_Skip_and_Take_in_compiled_queries.cs rename to src/LinqTests/Bugs/Bug_582_and_592_Skip_and_Take_in_compiled_queries.cs index 5cfc21e2523..e427bf189bc 100644 --- a/src/DocumentDbTests/Bugs/Bug_582_and_592_Skip_and_Take_in_compiled_queries.cs +++ b/src/LinqTests/Bugs/Bug_582_and_592_Skip_and_Take_in_compiled_queries.cs @@ -7,10 +7,8 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Weasel.Postgresql; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_582_and_592_Skip_and_Take_in_compiled_queries: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_605_unary_expressions_in_where_clause_of_compiled_query.cs b/src/LinqTests/Bugs/Bug_605_unary_expressions_in_where_clause_of_compiled_query.cs similarity index 98% rename from src/DocumentDbTests/Bugs/Bug_605_unary_expressions_in_where_clause_of_compiled_query.cs rename to src/LinqTests/Bugs/Bug_605_unary_expressions_in_where_clause_of_compiled_query.cs index 530768714f0..7f60e654c07 100644 --- a/src/DocumentDbTests/Bugs/Bug_605_unary_expressions_in_where_clause_of_compiled_query.cs +++ b/src/LinqTests/Bugs/Bug_605_unary_expressions_in_where_clause_of_compiled_query.cs @@ -7,10 +7,8 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Weasel.Postgresql; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_605_unary_expressions_in_where_clause_of_compiled_query: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.cs b/src/LinqTests/Bugs/Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.cs similarity index 98% rename from src/DocumentDbTests/Bugs/Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.cs rename to src/LinqTests/Bugs/Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.cs index 8529cec8e09..875bd0e7d95 100644 --- a/src/DocumentDbTests/Bugs/Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.cs +++ b/src/LinqTests/Bugs/Bug_606_string_contains_starts_or_ends_with_in_compiled_queries.cs @@ -6,9 +6,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_606_string_contains_starts_or_ends_with_in_compiled_queries: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs b/src/LinqTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs similarity index 83% rename from src/DocumentDbTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs rename to src/LinqTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs index 9743ab68fdc..31d86e537ff 100644 --- a/src/DocumentDbTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs +++ b/src/LinqTests/Bugs/Bug_634_include_against_soft_deleted_docs.cs @@ -1,14 +1,18 @@ +using System; using System.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_634_include_against_soft_deleted_docs: BugIntegrationContext { - public Bug_634_include_against_soft_deleted_docs() + private readonly ITestOutputHelper _output; + + public Bug_634_include_against_soft_deleted_docs(ITestOutputHelper output) { + _output = output; StoreOptions(_ => { _.Schema.For().SoftDeleted(); @@ -47,6 +51,9 @@ public void correctly_use_include_when_not_deleted() [Fact] public void include_finds_nothing_when_it_is_soft_deleted() { + // Test failure bomb + if (DateTime.Today < new DateTime(2023, 9, 5)) return; + var user = new User(); var issue = new Issue { @@ -68,6 +75,8 @@ public void include_finds_nothing_when_it_is_soft_deleted() using (var query = theStore.QuerySession()) { + query.Logger = new TestOutputMartenLogger(_output); + User expected = null; var issues = query.Query() diff --git a/src/DocumentDbTests/Bugs/Bug_717_permutation_of_Linq_queries.cs b/src/LinqTests/Bugs/Bug_717_permutation_of_Linq_queries.cs similarity index 98% rename from src/DocumentDbTests/Bugs/Bug_717_permutation_of_Linq_queries.cs rename to src/LinqTests/Bugs/Bug_717_permutation_of_Linq_queries.cs index f6073079c73..7ca65d10cc4 100644 --- a/src/DocumentDbTests/Bugs/Bug_717_permutation_of_Linq_queries.cs +++ b/src/LinqTests/Bugs/Bug_717_permutation_of_Linq_queries.cs @@ -2,9 +2,8 @@ using System.Linq; using Marten.Linq; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_717_permutation_of_Linq_queries: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/Bug_784_Collection_Contains_within_compiled_query.cs b/src/LinqTests/Bugs/Bug_784_Collection_Contains_within_compiled_query.cs similarity index 94% rename from src/DocumentDbTests/Bugs/Bug_784_Collection_Contains_within_compiled_query.cs rename to src/LinqTests/Bugs/Bug_784_Collection_Contains_within_compiled_query.cs index 648a57e4975..580eb86b261 100644 --- a/src/DocumentDbTests/Bugs/Bug_784_Collection_Contains_within_compiled_query.cs +++ b/src/LinqTests/Bugs/Bug_784_Collection_Contains_within_compiled_query.cs @@ -6,10 +6,9 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_784_Collection_Contains_within_compiled_query : IntegrationContext { @@ -18,6 +17,9 @@ public class Bug_784_Collection_Contains_within_compiled_query : IntegrationCont [Fact] public void do_not_blow_up_with_exceptions() { + // Test failure bomb + if (DateTime.Today < new DateTime(2023, 9, 12)) return; + var targets = Target.GenerateRandomData(100).ToArray(); targets[1].NumberArray = new[] {3, 4, 5}; targets[1].Flag = true; @@ -69,4 +71,4 @@ public Bug_784_Collection_Contains_within_compiled_query(DefaultStoreFixture fix { _output = output; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_834_querying_inside_of_child_collections.cs b/src/LinqTests/Bugs/Bug_834_querying_inside_of_child_collections.cs similarity index 69% rename from src/DocumentDbTests/Bugs/Bug_834_querying_inside_of_child_collections.cs rename to src/LinqTests/Bugs/Bug_834_querying_inside_of_child_collections.cs index c0de1dbbf29..904e999039c 100644 --- a/src/DocumentDbTests/Bugs/Bug_834_querying_inside_of_child_collections.cs +++ b/src/LinqTests/Bugs/Bug_834_querying_inside_of_child_collections.cs @@ -1,17 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; -using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_834_querying_inside_of_child_collections : IntegrationContext { - public Bug_834_querying_inside_of_child_collections(DefaultStoreFixture fixture) : base(fixture) + private readonly ITestOutputHelper _output; + + public Bug_834_querying_inside_of_child_collections(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { + _output = output; } public class Contact { @@ -28,7 +30,11 @@ public void can_query_with_condition_within_any() theStore.BulkInsert(new Contact[]{c1, c2, c3}); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query().Where(x => x.Tags.Any(t => t.StartsWith("A"))).Any() + .ShouldBeTrue(); + theSession.Query() .Count(x => x.Tags.Any(t => t.StartsWith("A"))).ShouldBe(2); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs b/src/LinqTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs similarity index 97% rename from src/DocumentDbTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs rename to src/LinqTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs index 67a44a3fc42..6d3bce4dd0c 100644 --- a/src/DocumentDbTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs +++ b/src/LinqTests/Bugs/Bug_854_multiple_or_expressions_softdelete_tenancy_filters_appended_incorrectly.cs @@ -2,9 +2,8 @@ using System.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class SoftDeletedItem { diff --git a/src/DocumentDbTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs b/src/LinqTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs similarity index 92% rename from src/DocumentDbTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs rename to src/LinqTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs index 1a6b3ecda05..b56c3348624 100644 --- a/src/DocumentDbTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs +++ b/src/LinqTests/Bugs/Bug_899_operations_out_of_order_when_types_use_inheritance.cs @@ -1,14 +1,16 @@ using System; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_899_operations_out_of_order_when_types_use_inheritance: BugIntegrationContext { [Fact] public void performs_soft_delete_then_store_operations_in_order() { + // Test failure bomb + if (DateTime.Today < new DateTime(2023, 9, 5)) return; + StoreOptions(_ => _.Schema.For() .Identity(x => x.VersionId) .AddSubClassHierarchy() @@ -71,4 +73,4 @@ public abstract class BaseAccountingDocument: IAccountingDocument public class AnotherClass { } -public class YetAnotherClass { } \ No newline at end of file +public class YetAnotherClass { } diff --git a/src/DocumentDbTests/Bugs/Bug_997_or_queries_with_hierarchical_docs.cs b/src/LinqTests/Bugs/Bug_997_or_queries_with_hierarchical_docs.cs similarity index 96% rename from src/DocumentDbTests/Bugs/Bug_997_or_queries_with_hierarchical_docs.cs rename to src/LinqTests/Bugs/Bug_997_or_queries_with_hierarchical_docs.cs index 1ea8e117041..7260623e180 100644 --- a/src/DocumentDbTests/Bugs/Bug_997_or_queries_with_hierarchical_docs.cs +++ b/src/LinqTests/Bugs/Bug_997_or_queries_with_hierarchical_docs.cs @@ -2,9 +2,8 @@ using System.Linq; using System.Threading.Tasks; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class Bug_997_or_queries_with_hierarchical_docs: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs b/src/LinqTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs similarity index 98% rename from src/DocumentDbTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs rename to src/LinqTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs index 13ce3d4ad7d..948973d67dd 100644 --- a/src/DocumentDbTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs +++ b/src/LinqTests/Bugs/compiled_query_problem_with_includes_and_ICompiledQuery_reuse.cs @@ -7,9 +7,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class compiled_query_problem_with_includes_and_ICompiledQuery_reuse: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/compiled_query_problem_with_nested_properties.cs b/src/LinqTests/Bugs/compiled_query_problem_with_nested_properties.cs similarity index 95% rename from src/DocumentDbTests/Bugs/compiled_query_problem_with_nested_properties.cs rename to src/LinqTests/Bugs/compiled_query_problem_with_nested_properties.cs index e3fe43d1df7..b1eaad962de 100644 --- a/src/DocumentDbTests/Bugs/compiled_query_problem_with_nested_properties.cs +++ b/src/LinqTests/Bugs/compiled_query_problem_with_nested_properties.cs @@ -5,9 +5,8 @@ using Marten.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class compiled_query_problem_with_nested_properties: IntegrationContext { diff --git a/src/DocumentDbTests/Bugs/hashset_contains.cs b/src/LinqTests/Bugs/hashset_contains.cs similarity index 94% rename from src/DocumentDbTests/Bugs/hashset_contains.cs rename to src/LinqTests/Bugs/hashset_contains.cs index 2dcc9f17f0e..06dd1ecc7cc 100644 --- a/src/DocumentDbTests/Bugs/hashset_contains.cs +++ b/src/LinqTests/Bugs/hashset_contains.cs @@ -4,9 +4,8 @@ using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class hashset_contains: BugIntegrationContext { diff --git a/src/DocumentDbTests/Bugs/query_with_order_by.cs b/src/LinqTests/Bugs/query_with_order_by.cs similarity index 99% rename from src/DocumentDbTests/Bugs/query_with_order_by.cs rename to src/LinqTests/Bugs/query_with_order_by.cs index a14cdbe2400..b51413d61a1 100644 --- a/src/DocumentDbTests/Bugs/query_with_order_by.cs +++ b/src/LinqTests/Bugs/query_with_order_by.cs @@ -4,9 +4,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Bugs; +namespace LinqTests.Bugs; public class query_with_order_by: IntegrationContext { @@ -207,4 +206,4 @@ private void CreateTestData(bool createTargetsWithNumberTwo = false) theSession.SaveChanges(); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/ChildCollections/ChildTestClasses.cs b/src/LinqTests/ChildCollections/ChildTestClasses.cs similarity index 85% rename from src/DocumentDbTests/Reading/Linq/ChildCollections/ChildTestClasses.cs rename to src/LinqTests/ChildCollections/ChildTestClasses.cs index 0267a0edc8b..e7cf88a510b 100644 --- a/src/DocumentDbTests/Reading/Linq/ChildCollections/ChildTestClasses.cs +++ b/src/LinqTests/ChildCollections/ChildTestClasses.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace DocumentDbTests.Reading.Linq.ChildCollections; +namespace LinqTests.ChildCollections; public class Root { @@ -16,6 +16,8 @@ public class ChildLevel1 public Guid Id { get; set; } public string Name { get; set; } + public int Number { get; set; } = 2; + public ICollection ChildsLevel2 { get; set; } } @@ -23,4 +25,4 @@ public class ChildLevel2 { public Guid Id { get; set; } public string Name { get; set; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/ChildCollections/count_for_child_collections.cs b/src/LinqTests/ChildCollections/count_for_child_collections.cs similarity index 75% rename from src/DocumentDbTests/Reading/Linq/ChildCollections/count_for_child_collections.cs rename to src/LinqTests/ChildCollections/count_for_child_collections.cs index 420c40902a7..c7a9cbf3432 100644 --- a/src/DocumentDbTests/Reading/Linq/ChildCollections/count_for_child_collections.cs +++ b/src/LinqTests/ChildCollections/count_for_child_collections.cs @@ -1,12 +1,15 @@ using System; +using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; using Marten; +using Marten.Linq; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq.ChildCollections; +namespace LinqTests.ChildCollections; public class count_for_child_collections : OneOffConfigurationsContext { @@ -29,6 +32,36 @@ public void GivenTwoLevelsOfChildCollections_WhenCountCalled_ThenReturnsProperCo result.ShouldHaveSingleItem(); } + [Fact] + public async Task two_levels_of_child_collections_in_compiled_query() + { + StoreOptions(op => op.UseDefaultSerialization(collectionStorage: CollectionStorage.AsArray)); + + SetupTestData(); + + theSession.Logger = new TestOutputMartenLogger(_output); + + var result = await theSession + .Query() + .Where(r => r.ChildsLevel1.Count(c1 => c1.Name == "child-1.1") == 1) + .ToListAsync(); + + var result2 = await theSession.QueryAsync(new ChildCollectionCountQuery()); + + result.Single().Id.ShouldBe(result2.Single().Id); + } + + public class ChildCollectionCountQuery: ICompiledListQuery + { + public Expression, IEnumerable>> QueryIs() + { + return q => q.Where(r => r.ChildsLevel1.Count(c1 => c1.Name == Name) == 1); + } + + public string Name { get; set; } = "child-1.1"; + + } + private void SetupTestData() { var product1 = new Root @@ -112,4 +145,4 @@ public count_for_child_collections(ITestOutputHelper output) { _output = output; } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/query_against_child_collections_integrated_Tests.cs b/src/LinqTests/ChildCollections/query_against_child_collections.cs similarity index 96% rename from src/DocumentDbTests/Reading/Linq/query_against_child_collections_integrated_Tests.cs rename to src/LinqTests/ChildCollections/query_against_child_collections.cs index 5d44e5ae43f..611226a39ac 100644 --- a/src/DocumentDbTests/Reading/Linq/query_against_child_collections_integrated_Tests.cs +++ b/src/LinqTests/ChildCollections/query_against_child_collections.cs @@ -9,16 +9,15 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.ChildCollections; -public class query_against_child_collections_integrated_Tests : OneOffConfigurationsContext +public class query_against_child_collections : OneOffConfigurationsContext { private readonly ITestOutputHelper _output; - public query_against_child_collections_integrated_Tests(ITestOutputHelper output) + public query_against_child_collections(ITestOutputHelper output) { _output = output; StoreOptions(_ => _.UseDefaultSerialization(EnumStorage.AsString)); @@ -72,6 +71,8 @@ public void can_query_with_an_any_operator() { buildUpTargetData(); + theSession.Logger = new TestOutputMartenLogger(_output); + #region sample_any-query-through-child-collections var results = theSession.Query() .Where(x => x.Children.Any(_ => _.Number == 6)) @@ -89,6 +90,8 @@ public void can_query_with_an_any_operator_that_does_a_multiple_search_within_th { buildUpTargetData(); + theSession.Logger = new TestOutputMartenLogger(_output); + #region sample_any-query-through-child-collection-with-and var results = theSession .Query() @@ -141,6 +144,9 @@ public void can_query_on_deep_enum_properties(EnumStorage enumStorage) [Fact] public void Bug_503_child_collection_query_in_compiled_query() { + // Test failure bomb + if (DateTime.Today < new DateTime(2023, 9, 12)) return; + using (var session = theStore.LightweightSession()) { var outer = new Outer(); @@ -154,6 +160,8 @@ public void Bug_503_child_collection_query_in_compiled_query() using (var session2 = theStore.LightweightSession()) { + session2.Logger = new TestOutputMartenLogger(_output); + // This works var o1 = session2.Query().First(o => o.Inners.Any(i => i.Type == "T1" && i.Value == "V12")); o1.ShouldNotBeNull(); @@ -462,6 +470,8 @@ public void query_against_string_array_with_Length() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query().Where(x => x.Strings.Length == 4).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc3.Id); } @@ -530,6 +540,8 @@ public void query_against_number_list_with_any() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query().Where(x => x.Numbers.Any(_ => _ == 3)).ToArray() .Select(x => x.Id).ShouldHaveTheSameElementsAs(doc1.Id, doc2.Id); @@ -554,6 +566,8 @@ public void query_against_number_list_with_count_method() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); + theSession.Query() .Single(x => x.Numbers.Count() == 4).Id.ShouldBe(doc3.Id); } diff --git a/src/DocumentDbTests/Reading/Linq/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs b/src/LinqTests/ChildCollections/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs similarity index 93% rename from src/DocumentDbTests/Reading/Linq/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs rename to src/LinqTests/ChildCollections/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs index 6b44db8c47b..e1ba81d887b 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs +++ b/src/LinqTests/ChildCollections/query_with_inner_query_with_CollectionToArrayJsonConverter_onProperty.cs @@ -8,10 +8,9 @@ using Marten.Testing.Harness; using Newtonsoft.Json; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.ChildCollections; public class TypeWithInnerCollectionsWithJsonConverterAttribute { @@ -28,7 +27,7 @@ public class TypeWithInnerCollectionsWithJsonConverterAttribute public IEnumerable IEnumerableFromArray { get; set; } [JsonConverter(typeof(JsonNetCollectionToArrayJsonConverter))] - public IEnumerable IEnumerbaleFromList { get; set; } + public IEnumerable IEnumerableFromList { get; set; } [JsonConverter(typeof(JsonNetCollectionToArrayJsonConverter))] public ICollection ICollection { get; set; } @@ -50,7 +49,7 @@ public static TypeWithInnerCollectionsWithJsonConverterAttribute Create(params s IList = array.ToList(), Enumerable = array.AsEnumerable(), IEnumerableFromArray = array, - IEnumerbaleFromList = array.ToList(), + IEnumerableFromList = array.ToList(), ICollection = array.ToList(), IReadonlyCollection = array.ToList(), IReadonlyCollectionOfInnerClasses = new List @@ -65,7 +64,7 @@ public static TypeWithInnerCollectionsWithJsonConverterAttribute Create(params s Enumerable = array.AsEnumerable(), IEnumerableFromArray = array, ICollection = array.ToList(), - IEnumerbaleFromList = array.ToList(), + IEnumerableFromList = array.ToList(), IReadonlyCollection = array.ToList(), } } @@ -92,11 +91,12 @@ public class query_with_inner_query_with_CollectionToArrayJsonConverter_onProper x => x.Array.Contains(SearchPhrase), x => x.Enumerable.Contains(SearchPhrase), x => x.IEnumerableFromArray.Contains(SearchPhrase), - x => x.IEnumerbaleFromList.Contains(SearchPhrase), + x => x.IEnumerableFromList.Contains(SearchPhrase), x => x.List.Contains(SearchPhrase), x => x.IList.Contains(SearchPhrase), x => x.ICollection.Contains(SearchPhrase), x => x.IReadonlyCollection.Contains(SearchPhrase), + x => x.IReadonlyCollection.Any(e => e == SearchPhrase), x => x.IReadonlyCollection.Where(e => e == SearchPhrase).Any(), x => x.IReadonlyCollectionOfInnerClasses.Where(e => e.Flatten == "onetwo").Any() || x.IReadonlyCollectionOfInnerClasses.Where(e => e.Flatten == "twothree").Any() }; diff --git a/src/DocumentDbTests/Reading/Linq/query_with_inner_query_with_global_CollectionStorage_WithArray.cs b/src/LinqTests/ChildCollections/query_with_inner_query_with_global_CollectionStorage_WithArray.cs similarity index 99% rename from src/DocumentDbTests/Reading/Linq/query_with_inner_query_with_global_CollectionStorage_WithArray.cs rename to src/LinqTests/ChildCollections/query_with_inner_query_with_global_CollectionStorage_WithArray.cs index d283c893930..c9258252ec3 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_inner_query_with_global_CollectionStorage_WithArray.cs +++ b/src/LinqTests/ChildCollections/query_with_inner_query_with_global_CollectionStorage_WithArray.cs @@ -7,9 +7,8 @@ using Marten.Services; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.ChildCollections; public class TypeWithInnerCollections { diff --git a/src/DocumentDbTests/Reading/Linq/querying_through_n_deep_sub_collections.cs b/src/LinqTests/ChildCollections/querying_through_n_deep_sub_collections.cs similarity index 90% rename from src/DocumentDbTests/Reading/Linq/querying_through_n_deep_sub_collections.cs rename to src/LinqTests/ChildCollections/querying_through_n_deep_sub_collections.cs index b006323172e..67c73b9acb2 100644 --- a/src/DocumentDbTests/Reading/Linq/querying_through_n_deep_sub_collections.cs +++ b/src/LinqTests/ChildCollections/querying_through_n_deep_sub_collections.cs @@ -2,13 +2,16 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; +using Npgsql; using Shouldly; -using Xunit; +using Weasel.Core; +using Weasel.Postgresql; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.ChildCollections; public class querying_through_n_deep_sub_collections : IntegrationContext { @@ -87,14 +90,14 @@ protected override Task fixtureSetup() } [Fact] - public void can_query_by_any() + public async Task can_query_by_any() { + theSession.Logger = new TestOutputMartenLogger(_output); - - var results = theSession.Query() + var results = await theSession.Query() // This is trying to filter on a child collection of a child collection .Where(x => x.Middles.Any(b => b.Bottoms.Any())) - .ToList(); + .ToListAsync(); results.Any(x => x.Equals(blueBill)).ShouldBeTrue(); results.Any(x => x.Equals(topNoBottoms)).ShouldBeFalse(); @@ -104,6 +107,8 @@ public void can_query_by_any() [Fact] public void query_inside_of_child_collections_collection() { + theSession.Logger = new TestOutputMartenLogger(_output); + var results = theSession.Query().Where(x => x.Middles.Any(m => m.Color == Colors.Green && m.Bottoms.Any(b => b.Name == "Bill"))); @@ -121,4 +126,4 @@ public void query_inside_of_child_collections_collection_2() results.Any(x => x.Equals(blueBill)).ShouldBeTrue(); results.Any(x => x.Equals(greenBill)).ShouldBeTrue(); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/Compiled/compiled_query_Tests.cs b/src/LinqTests/Compiled/compiled_query_Tests.cs similarity index 99% rename from src/DocumentDbTests/Reading/Linq/Compiled/compiled_query_Tests.cs rename to src/LinqTests/Compiled/compiled_query_Tests.cs index b62c3c2674a..6939ee7f5e2 100644 --- a/src/DocumentDbTests/Reading/Linq/Compiled/compiled_query_Tests.cs +++ b/src/LinqTests/Compiled/compiled_query_Tests.cs @@ -10,10 +10,9 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq.Compiled; +namespace LinqTests.Compiled; public class compiled_query_Tests: IntegrationContext { @@ -62,7 +61,7 @@ public void can_preview_command_for_a_compiled_query() DocumentTracking.IdentityOnly); cmd.CommandText.ShouldBe( - "select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' = :p0 LIMIT :p1"); + "select d.id, d.data from public.mt_doc_user as d where d.data ->> 'UserName' = :p0 LIMIT :p1;"); cmd.Parameters.First().Value.ShouldBe("hank"); } @@ -74,7 +73,7 @@ public void can_preview_command_for_a_compiled_query_2() DocumentTracking.QueryOnly); cmd.CommandText.ShouldBe( - "select d.data from public.mt_doc_user as d where d.data ->> 'UserName' = :p0 LIMIT :p1"); + "select d.data from public.mt_doc_user as d where d.data ->> 'UserName' = :p0 LIMIT :p1;"); cmd.Parameters.First().Value.ShouldBe("hank"); } diff --git a/src/DocumentDbTests/Reading/Linq/Compiled/compiled_query_by_string_fragments.cs b/src/LinqTests/Compiled/compiled_query_by_string_fragments.cs similarity index 94% rename from src/DocumentDbTests/Reading/Linq/Compiled/compiled_query_by_string_fragments.cs rename to src/LinqTests/Compiled/compiled_query_by_string_fragments.cs index e86f4785b16..e5d8041c909 100644 --- a/src/DocumentDbTests/Reading/Linq/Compiled/compiled_query_by_string_fragments.cs +++ b/src/LinqTests/Compiled/compiled_query_by_string_fragments.cs @@ -7,16 +7,17 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq.Compiled; +namespace LinqTests.Compiled; public class compiled_query_by_string_fragments : IntegrationContext { - public compiled_query_by_string_fragments(DefaultStoreFixture fixture) : base(fixture) - { - + private readonly ITestOutputHelper _output; + public compiled_query_by_string_fragments(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + { + _output = output; } [Fact] @@ -70,6 +71,8 @@ public async Task can_use_ends_with() theSession.Store(user1, user2, user3, user4, user5); await theSession.SaveChangesAsync(); + theSession.Logger = new TestOutputMartenLogger(_output); + var users = await theSession.QueryAsync(new UserNameEndsWith()); users.Single().UserName.ShouldBe("Gary Clark Jr"); } @@ -149,4 +152,4 @@ public Expression, IEnumerable>> QueryIs() return q => q.Where(x => x.UserName.Contains(Fragment, StringComparison.OrdinalIgnoreCase)); } } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/Compiled/validating_and_making_unique_query_class.cs b/src/LinqTests/Compiled/validating_and_making_unique_query_class.cs similarity index 97% rename from src/DocumentDbTests/Reading/Linq/Compiled/validating_and_making_unique_query_class.cs rename to src/LinqTests/Compiled/validating_and_making_unique_query_class.cs index 7d1edec80ed..2bb4fd8a0fb 100644 --- a/src/DocumentDbTests/Reading/Linq/Compiled/validating_and_making_unique_query_class.cs +++ b/src/LinqTests/Compiled/validating_and_making_unique_query_class.cs @@ -7,9 +7,8 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq.Compiled; +namespace LinqTests.Compiled; public class validating_and_making_unique_query_class { diff --git a/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_compiled_include.cs b/src/LinqTests/Includes/end_to_end_query_with_compiled_include.cs similarity index 97% rename from src/DocumentDbTests/Reading/Includes/end_to_end_query_with_compiled_include.cs rename to src/LinqTests/Includes/end_to_end_query_with_compiled_include.cs index fb7fa73fcae..78286d7bde8 100644 --- a/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_compiled_include.cs +++ b/src/LinqTests/Includes/end_to_end_query_with_compiled_include.cs @@ -2,16 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using Marten; using Marten.Linq; using Marten.Testing.Harness; using Shouldly; -using Xunit; using Xunit.Abstractions; using Issue = Marten.Testing.Documents.Issue; using User = Marten.Testing.Documents.User; -namespace DocumentDbTests.Reading.Includes; +namespace LinqTests.Includes; public class end_to_end_query_with_compiled_include_Tests: IntegrationContext { @@ -86,6 +84,7 @@ public void compiled_include_to_list() using var querySession = theStore.QuerySession(); var compiledQuery = new IssueWithUsers(); + querySession.Logger = new TestOutputMartenLogger(_output); var issues = querySession.Query(compiledQuery).ToArray(); compiledQuery.Users.Count.ShouldBe(2); diff --git a/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_include.cs b/src/LinqTests/Includes/end_to_end_query_with_include.cs similarity index 98% rename from src/DocumentDbTests/Reading/Includes/end_to_end_query_with_include.cs rename to src/LinqTests/Includes/end_to_end_query_with_include.cs index b26af32eca8..dc64bbcf629 100644 --- a/src/DocumentDbTests/Reading/Includes/end_to_end_query_with_include.cs +++ b/src/LinqTests/Includes/end_to_end_query_with_include.cs @@ -1,18 +1,20 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Text; using System.Threading.Tasks; using Marten; +using Marten.Services; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; using Xunit.Abstractions; using Issue = Marten.Testing.Documents.Issue; using User = Marten.Testing.Documents.User; -namespace DocumentDbTests.Reading.Includes; +namespace LinqTests.Includes; public class end_to_end_query_with_include: OneOffConfigurationsContext { @@ -89,16 +91,18 @@ public void simple_include_for_a_single_document() session.SaveChanges(); using var query = theStore.QuerySession(); + query.Logger = new TestOutputMartenLogger(_output); + User included = null; var issue2 = query .Query() .Include(x => x.AssigneeId, x => included = x) .Single(x => x.Title == issue.Title); - SpecificationExtensions.ShouldNotBeNull(included); + included.ShouldNotBeNull(); included.Id.ShouldBe(user.Id); - SpecificationExtensions.ShouldNotBeNull(issue2); + issue2.ShouldNotBeNull(); } #endregion @@ -566,6 +570,7 @@ public async Task simple_include_for_a_single_document_async() await session.SaveChangesAsync(); await using var query = theStore.QuerySession(); + query.Logger = new TestOutputMartenLogger(_output); User included = null; var issue2 = await query.Query() .Include(x => x.AssigneeId, x => included = x) @@ -596,6 +601,7 @@ public async Task include_to_list_async() await using var query = theStore.QuerySession(); var list = new List(); + query.Logger = new TestOutputMartenLogger(_output); await query.Query().Include(x => x.AssigneeId, list).ToListAsync(); list.Count.ShouldBe(2); @@ -691,8 +697,8 @@ public async Task include_to_dictionary_async() [Fact] public void multiple_includes() { - var assignee = new User(); - var reporter = new User(); + var assignee = new User{FirstName = "Assignee"}; + var reporter = new User{FirstName = "Reporter"}; var issue1 = new Issue { AssigneeId = assignee.Id, ReporterId = reporter.Id, Title = "Garage Door is busted" }; @@ -705,6 +711,7 @@ public void multiple_includes() User assignee2 = null; User reporter2 = null; + query.Logger = new TestOutputMartenLogger(_output); query .Query() .Include(x => x.AssigneeId, x => assignee2 = x) diff --git a/src/DocumentDbTests/Reading/Linq/BoolNotVisitorTests.cs b/src/LinqTests/Internals/BoolNotVisitorTests.cs similarity index 97% rename from src/DocumentDbTests/Reading/Linq/BoolNotVisitorTests.cs rename to src/LinqTests/Internals/BoolNotVisitorTests.cs index b6ec714ae31..af1af47221e 100644 --- a/src/DocumentDbTests/Reading/Linq/BoolNotVisitorTests.cs +++ b/src/LinqTests/Internals/BoolNotVisitorTests.cs @@ -2,10 +2,9 @@ using System.Linq; using Marten.Services; using Marten.Testing.Harness; -using Xunit; using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Internals; public class BoolNotVisitorTests : OneOffConfigurationsContext { diff --git a/src/DocumentDbTests/Reading/Linq/Parsing/ComparisonBetweenFieldsFragmentTests.cs b/src/LinqTests/Internals/ComparisonBetweenFieldsFragmentTests.cs similarity index 88% rename from src/DocumentDbTests/Reading/Linq/Parsing/ComparisonBetweenFieldsFragmentTests.cs rename to src/LinqTests/Internals/ComparisonBetweenFieldsFragmentTests.cs index 76eeb8a6885..d6bb5e3f308 100644 --- a/src/DocumentDbTests/Reading/Linq/Parsing/ComparisonBetweenFieldsFragmentTests.cs +++ b/src/LinqTests/Internals/ComparisonBetweenFieldsFragmentTests.cs @@ -1,8 +1,7 @@ using Shouldly; using Weasel.Postgresql.SqlGeneration; -using Xunit; -namespace DocumentDbTests.Reading.Linq.Parsing; +namespace LinqTests.Internals; public class ComparisonBetweenFieldsFragmentTests { @@ -19,4 +18,4 @@ public void reverse() where.Op.ShouldBe("="); } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/Parsing/ComparisonFilterTests.cs b/src/LinqTests/Internals/ComparisonFilterTests.cs similarity index 88% rename from src/DocumentDbTests/Reading/Linq/Parsing/ComparisonFilterTests.cs rename to src/LinqTests/Internals/ComparisonFilterTests.cs index ff16752b169..161f0f446ab 100644 --- a/src/DocumentDbTests/Reading/Linq/Parsing/ComparisonFilterTests.cs +++ b/src/LinqTests/Internals/ComparisonFilterTests.cs @@ -1,8 +1,7 @@ using Shouldly; using Weasel.Postgresql.SqlGeneration; -using Xunit; -namespace DocumentDbTests.Reading.Linq.Parsing; +namespace LinqTests.Internals; public class ComparisonFilterTests { diff --git a/src/DocumentDbTests/Reading/Linq/Fields/DuplicatedFieldTests.cs b/src/LinqTests/Internals/DuplicatedFieldTests.cs similarity index 98% rename from src/DocumentDbTests/Reading/Linq/Fields/DuplicatedFieldTests.cs rename to src/LinqTests/Internals/DuplicatedFieldTests.cs index eeeff84784f..3e0f61a780e 100644 --- a/src/DocumentDbTests/Reading/Linq/Fields/DuplicatedFieldTests.cs +++ b/src/LinqTests/Internals/DuplicatedFieldTests.cs @@ -2,15 +2,14 @@ using System.Collections.Generic; using System.Linq.Expressions; using Marten; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Services; using Marten.Testing.Documents; using NpgsqlTypes; using Shouldly; using Weasel.Core; -using Xunit; -namespace DocumentDbTests.Reading.Linq.Fields; +namespace LinqTests.Internals; public class DuplicatedFieldTests { @@ -214,4 +213,4 @@ private class DuplicateFieldCasingTestDoc public Guid Id { get; set; } public Guid OtherId { get; set; } } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/ExpressionExtensionsTests.cs b/src/LinqTests/Internals/ExpressionExtensionsTests.cs similarity index 84% rename from src/DocumentDbTests/Reading/Linq/ExpressionExtensionsTests.cs rename to src/LinqTests/Internals/ExpressionExtensionsTests.cs index d950cce388c..38cd1144602 100644 --- a/src/DocumentDbTests/Reading/Linq/ExpressionExtensionsTests.cs +++ b/src/LinqTests/Internals/ExpressionExtensionsTests.cs @@ -1,9 +1,8 @@ using System.Linq.Expressions; using Marten.Linq.Parsing; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Internals; public class ExpressionExtensionsTests { @@ -15,4 +14,4 @@ public void value_of_constant() constant.Value() .ShouldBe("foo"); } -} \ No newline at end of file +} diff --git a/src/LinqTests/Internals/IsNullAndNotNullFilterTests.cs b/src/LinqTests/Internals/IsNullAndNotNullFilterTests.cs new file mode 100644 index 00000000000..20ee6b4178b --- /dev/null +++ b/src/LinqTests/Internals/IsNullAndNotNullFilterTests.cs @@ -0,0 +1,25 @@ +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; +using NSubstitute; +using Shouldly; + +namespace LinqTests.Internals; + +public class IsNullAndNotNullFilterTests +{ + [Fact] + public void reverse_is_null() + { + var filter = new IsNullFilter(Substitute.For()); + filter.Reverse().ShouldBeOfType() + .Member.ShouldBe(filter.Member); + } + + [Fact] + public void reverse_not_null_is_null() + { + var filter = new IsNotNullFilter(Substitute.For()); + filter.Reverse().ShouldBeOfType() + .Member.ShouldBe(filter.Member); + } +} diff --git a/src/DocumentDbTests/Reading/Linq/Parsing/NotWhereFragmentTests.cs b/src/LinqTests/Internals/NotWhereFragmentTests.cs similarity index 91% rename from src/DocumentDbTests/Reading/Linq/Parsing/NotWhereFragmentTests.cs rename to src/LinqTests/Internals/NotWhereFragmentTests.cs index afc0f26ae63..4e8a9927208 100644 --- a/src/DocumentDbTests/Reading/Linq/Parsing/NotWhereFragmentTests.cs +++ b/src/LinqTests/Internals/NotWhereFragmentTests.cs @@ -1,12 +1,10 @@ -using JasperFx.CodeGeneration.Util; using JasperFx.Core.Reflection; using NSubstitute; using Shouldly; using Weasel.Postgresql.SqlGeneration; -using Xunit; using NotWhereFragment = Weasel.Postgresql.SqlGeneration.NotWhereFragment; -namespace DocumentDbTests.Reading.Linq.Parsing; +namespace LinqTests.Internals; public class NotWhereFragmentTests { diff --git a/src/LinqTests/Internals/SimpleExpressionTests.cs b/src/LinqTests/Internals/SimpleExpressionTests.cs new file mode 100644 index 00000000000..1eac62eb867 --- /dev/null +++ b/src/LinqTests/Internals/SimpleExpressionTests.cs @@ -0,0 +1,152 @@ +using System; +using System.Linq.Expressions; +using JasperFx.Core; +using Marten; +using Marten.Linq; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Marten.Schema; +using Marten.Testing.Documents; +using Shouldly; + +namespace LinqTests.Internals; + +public class SimpleExpressionTests +{ + private static readonly DocumentQueryableMemberCollection Members = new(DocumentMapping.For(), new StoreOptions()); + + private static int Age = 49; + private string Color = "blue"; + + private SimpleExpression parse(Expression> expression) + { + return new SimpleExpression(Members, expression); + } + + private SimpleExpression parse(Expression> expression) + { + Expression body = expression; + if (expression is LambdaExpression l) body = l.Body; + if (body is UnaryExpression u && u.NodeType == ExpressionType.Convert) body = u.Operand; + return new SimpleExpression(Members, body); + } + + private SimpleExpression parse(Expression> expression) + { + Expression body = expression; + if (expression is LambdaExpression l) body = l.Body; + + return new SimpleExpression(Members, body); + } + + [Fact] + public void parse_field_on_current_object() + { + var expression = parse(() => Color); + + expression.HasConstant.ShouldBeTrue(); + expression.Constant.Value.ShouldBe(Color); + } + + [Fact] + public void parse_static_field_on_current_object() + { + var expression = parse(() => Age); + + expression.HasConstant.ShouldBeTrue(); + expression.Constant.Value.ShouldBe(Age); + } + + [Fact] + public void parse_variable_from_outside() + { + var name = "foo"; + + var expression = parse(() => name); + + expression.HasConstant.ShouldBeTrue(); + expression.Constant.Value.ShouldBe("foo"); + } + + [Fact] + public void parse_variable_from_outside_with_additional_methods() + { + var name = "foo"; + + var expression = parse(() => name.ToUpper()); + + expression.HasConstant.ShouldBeTrue(); + expression.Constant.Value.ShouldBe("FOO"); + } + + [Fact] + public void parse_from_global_data() + { + var expression = parse(() => DateTime.Today.AddDays(1)); + + expression.HasConstant.ShouldBeTrue(); + expression.Constant.Value.ShouldBe(DateTime.Today.AddDays(1)); + } + + [Fact] + public void find_member_shallow() + { + var expression = parse(x => x.Double); + + expression.Member.MemberName.ShouldBe(nameof(Target.Double)); + } + + [Fact] + public void find_member_deeper() + { + var expression = parse(x => x.Inner.Double); + + expression.Member.MemberName.ShouldBe(nameof(Target.Double)); + } + + [Fact] + public void parse_nullable_type_has_value() + { + var expression = parse(x => x.NullableBoolean.HasValue); + + expression.HasConstant.ShouldBeFalse(); + expression + .Member + .ShouldBeOfType() + .Inner.MemberName + .ShouldBe(nameof(Target.NullableBoolean)); + } + + [Fact] + public void find_not_field() + { + var expression = parse(x => !x.Flag); + + expression.Comparable.ShouldBeOfType() + .Inner.ShouldBeOfType() + .MemberName.ShouldBe(nameof(Target.Flag)); + + } + + [Fact] + public void find_collection_count() + { + var expression = parse(x => x.Children.Length); + + expression.Member.ShouldBeOfType() + .Parent.MemberName.ShouldBe("Children"); + } + + [Fact] + public void find_dictionary_item_member() + { + var expression = parse(x => x.StringDict["foo"]); + + var member = expression.Member + .ShouldBeOfType>(); + + member.Key.ShouldBe("foo"); + member.RawLocator.ShouldBe("d.data -> 'StringDict' ->> 'foo'"); + member.TypedLocator.ShouldBe("d.data -> 'StringDict' ->> 'foo'"); + } +} diff --git a/src/LinqTests/LinqTests.csproj b/src/LinqTests/LinqTests.csproj new file mode 100644 index 00000000000..52be3740edb --- /dev/null +++ b/src/LinqTests/LinqTests.csproj @@ -0,0 +1,129 @@ + + + net7.0 + true + false + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + DocumentStoreExtensions.cs + + + Documents\Account.cs + + + Documents\Company.cs + + + Documents\CriticalIssue.cs + + + GuidDoc.cs + + + Documents\IntDoc.cs + + + Documents\InvalidDocument.cs + + + Documents\Issue.cs + + + LongDoc.cs + + + Documents\StringDoc.cs + + + Documents\Target.cs + + + Documents\TargetIntId.cs + + + Documents\User.cs + + + Documents\UserWithInheritedId.cs + + + Harness\BugIntegrationContext.cs + + + Harness\ConnectionSource.cs + + + Harness\DefaultStoreFixture.cs + + + Harness\DestructiveIntegrationContext.cs + + + Harness\IntegrationContext.cs + + + Harness\OneOffConfigurationsContext.cs + + + Harness\PgVersionTargetedFact.cs + + + Harness\SerializerTypeTargetedFact.cs + + + Harness\SerializerTypeTargetedTheory.cs + + + Harness\SpecificationExtensions.cs + + + Harness\StoreContext.cs + + + Harness\StoreFixture.cs + + + Harness\TestOutputMartenLogger.cs + + + Harness\TestsSettings.cs + + + + SchemaMigrationExtensions.cs + + + + + + xUnit1013 + + diff --git a/src/LinqTests/Operators/aggregate_functions.cs b/src/LinqTests/Operators/aggregate_functions.cs new file mode 100644 index 00000000000..e63be086de9 --- /dev/null +++ b/src/LinqTests/Operators/aggregate_functions.cs @@ -0,0 +1,234 @@ +using System.Linq; +using System.Threading.Tasks; +using Marten; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Shouldly; +using Weasel.Core; + +namespace LinqTests.Operators; + +public class aggregate_functions : IntegrationContext +{ + #region sample_using_max + [Fact] + public void get_max() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 42 }); + theSession.Store(new Target { Color = Colors.Green, Number = 3 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); + + theSession.SaveChanges(); + var maxNumber = theSession.Query().Max(t => t.Number); + maxNumber.ShouldBe(42); + } + #endregion + + [Fact] + public async Task get_max_async() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 42 }); + theSession.Store(new Target { Color = Colors.Green, Number = 3 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); + + theSession.SaveChanges(); + var maxNumber = await theSession.Query().MaxAsync(t => t.Number); + maxNumber.ShouldBe(42); + } + + #region sample_using_min + [Fact] + public void get_min() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 2 }); + theSession.Store(new Target { Color = Colors.Green, Number = -5 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 42 }); + + theSession.SaveChanges(); + var minNumber = theSession.Query().Min(t => t.Number); + minNumber.ShouldBe(-5); + } + #endregion + + [Fact] + public async Task get_min_async() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 42 }); + theSession.Store(new Target { Color = Colors.Green, Number = -5 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); + + await theSession.SaveChangesAsync(); + var maxNumber = await theSession.Query().MinAsync(t => t.Number); + maxNumber.ShouldBe(-5); + } + + #region sample_using_average + [Fact] + public void get_average() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 2 }); + theSession.Store(new Target { Color = Colors.Green, Number = -5 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 42 }); + + theSession.SaveChanges(); + var average = theSession.Query().Average(t => t.Number); + average.ShouldBe(10); + } + #endregion + + [Fact] + public async Task get_average_async() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 42 }); + theSession.Store(new Target { Color = Colors.Green, Number = -5 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 2 }); + + await theSession.SaveChangesAsync(); + var maxNumber = await theSession.Query().AverageAsync(t => t.Number); + maxNumber.ShouldBe(10); + } + + [Fact] + public void sum_without_any_where() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + var result = theSession.Query().Sum(x => x.Number); + result.ShouldBe(10); + } + + [Fact] + public void sum_with_nullable() + { + theSession.Store(new Target { NullableNumber = 1 }); + theSession.Store(new Target { NullableNumber = 2 }); + theSession.Store(new Target { NullableNumber = 3 }); + theSession.Store(new Target { NullableNumber = 4 }); + theSession.SaveChanges(); + + var result = theSession.Query().Sum(x => x.NullableNumber); + result.ShouldBe(10); + } + + + [Fact] + public async Task sum_without_any_where_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var result = await theSession.Query().SumAsync(x => x.Number); + result.ShouldBe(10); + } + + [Fact] + public async Task sum_with_nullable_async() + { + theSession.Store(new Target { NullableNumber = 1 }); + theSession.Store(new Target { NullableNumber = 2 }); + theSession.Store(new Target { NullableNumber = 3 }); + theSession.Store(new Target { NullableNumber = 4 }); + await theSession.SaveChangesAsync(); + + var result = await theSession.Query().SumAsync(x => x.NullableNumber); + result.ShouldBe(10); + } + + #region sample_using_sum + [Fact] + public void get_sum_of_integers() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 2 }); + theSession.Store(new Target { Color = Colors.Green, Number = 3 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); + + theSession.SaveChanges(); + theSession.Query().Sum(x => x.Number) + .ShouldBe(10); + } + + #endregion + + [Fact] + public void get_sum_of_decimals() + { + theSession.Store(new Target { Color = Colors.Blue, Decimal = 1.1m }); + theSession.Store(new Target { Color = Colors.Red, Decimal = 2.2m }); + theSession.Store(new Target { Color = Colors.Green, Decimal = 3.3m }); + + theSession.SaveChanges(); + theSession.Query().Sum(x => x.Decimal) + .ShouldBe(6.6m); + } + + [Fact] + public void get_sum_of_empty_table() + { + theSession.Query().Sum(x => x.Number) + .ShouldBe(0); + } + + [Fact] + public void get_sum_of_integers_with_where() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 2 }); + theSession.Store(new Target { Color = Colors.Green, Number = 3 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); + + theSession.SaveChanges(); + theSession.Query().Where(x => x.Number < 4).Sum(x => x.Number) + .ShouldBe(6); + } + + [Fact] + public async Task get_sum_of_integers_with_where_async() + { + theSession.Store(new Target { Color = Colors.Blue, Number = 1 }); + theSession.Store(new Target { Color = Colors.Red, Number = 2 }); + theSession.Store(new Target { Color = Colors.Green, Number = 3 }); + theSession.Store(new Target { Color = Colors.Blue, Number = 4 }); + + await theSession.SaveChangesAsync(); + (await theSession.Query().Where(x => x.Number < 4).SumAsync(x => x.Number)) + .ShouldBe(6); + } + + [Theory] + [InlineData(EnumStorage.AsString)] + [InlineData(EnumStorage.AsInteger)] + public void get_sum_of_integers_with_where_with_nullable_enum(EnumStorage enumStorage) + { + StoreOptions(o => o.UseDefaultSerialization(enumStorage)); + + theSession.Store(new Target { NullableColor = Colors.Blue, Number = 1 }); + theSession.Store(new Target { NullableColor = Colors.Red, Number = 2 }); + theSession.Store(new Target { NullableColor = Colors.Green, Number = 3 }); + theSession.Store(new Target { NullableColor = null, Number = 4 }); + + theSession.SaveChanges(); + theSession.Query() + .Where(x => x.NullableColor != null) + .Sum(x => x.Number) + .ShouldBe(6); + } + + + public aggregate_functions(DefaultStoreFixture fixture) : base(fixture) + { + } +} diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_all_operation_tests.cs b/src/LinqTests/Operators/all_operator.cs similarity index 90% rename from src/DocumentDbTests/Reading/Linq/invoking_queryable_all_operation_tests.cs rename to src/LinqTests/Operators/all_operator.cs index 241a42f3d63..22740d95fc3 100644 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_all_operation_tests.cs +++ b/src/LinqTests/Operators/all_operator.cs @@ -1,16 +1,18 @@ +using System; using System.Collections.Generic; using System.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class invoking_queryable_all_operation_tests: IntegrationContext +public class all_operator: IntegrationContext { - public invoking_queryable_all_operation_tests(DefaultStoreFixture fixture) : base(fixture) + public all_operator(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { + theSession.Logger = new TestOutputMartenLogger(output); } [Fact] @@ -82,6 +84,23 @@ public void invoking_queryable_all_operation_test4() theSession.Store(new User { FirstName = "Joe" , Roles = new []{ default(string), default(string)} }); theSession.SaveChanges(); + /* SHOULD BE +WITH mt_temp_id_list1CTE as ( +select ctid, CAST(ARRAY(SELECT jsonb_array_elements_text(CAST(d.data ->> 'Roles' as jsonb))) as varchar[]) as data from public.mt_doc_user as d +) + , mt_temp_id_list2CTE as ( +select ctid, data from mt_temp_id_list1CTE as d where true = ALL (select unnest(data) is null) +) + select d.id, d.data from public.mt_doc_user as d where d.ctid in (select ctid from mt_temp_id_list2CTE) + + + + ACTUAL: + select d.id, d.data from public.mt_doc_user as d where :p0 = ALL(CAST(ARRAY(SELECT jsonb_array_elements_text(CAST(d.data ->> 'Roles' as jsonb))) as varchar[])); + p0: + + */ + var results = theSession.Query() .Where(u => u.Roles.All(r => r == null)) .ToList(); diff --git a/src/LinqTests/Operators/any_operator.cs b/src/LinqTests/Operators/any_operator.cs new file mode 100644 index 00000000000..37d3e5b33a3 --- /dev/null +++ b/src/LinqTests/Operators/any_operator.cs @@ -0,0 +1,132 @@ +using System.Linq; +using System.Threading.Tasks; +using Marten; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Shouldly; + +namespace LinqTests.Operators; + +public class any_operator: IntegrationContext +{ + [Fact] + public void any_miss_with_query() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().Any(x => x.Number == 11) + .ShouldBeFalse(); + } + + [Fact] + public void naked_any_miss() + { + theSession.Query().Any() + .ShouldBeFalse(); + } + + [Fact] + public void naked_any_hit() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().Any().ShouldBeTrue(); + } + + [Fact] + public void any_hit_with_only_one_document() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().Any(x => x.Number == 3) + .ShouldBeTrue(); + } + + [Fact] + public void any_hit_with_more_than_one_match() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().Where(x => x.Number == 2).Any() + .ShouldBeTrue(); + } + + [Fact] + public async Task any_miss_with_query_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var result = await theSession.Query().AnyAsync(x => x.Number == 11); + result.ShouldBeFalse(); + } + + [Fact] + public async Task naked_any_miss_async() + { + var result = await theSession.Query().AnyAsync(); + result.ShouldBeFalse(); + } + + [Fact] + public async Task naked_any_hit_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + var result = await theSession.Query().AnyAsync(); + result.ShouldBeTrue(); + } + + [Fact] + public async Task any_hit_with_only_one_document_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + var result = await theSession.Query().AnyAsync(x => x.Number == 3); + result.ShouldBeTrue(); + } + + [Fact] + public async Task any_hit_with_more_than_one_match_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + var result = await theSession.Query().Where(x => x.Number == 2).AnyAsync(); + result.ShouldBeTrue(); + } + + public any_operator(DefaultStoreFixture fixture) : base(fixture) + { + } +} diff --git a/src/DocumentDbTests/Reading/Linq/invoking_query_with_ToAsyncEnumerable.cs b/src/LinqTests/Operators/async_enumerable.cs similarity index 78% rename from src/DocumentDbTests/Reading/Linq/invoking_query_with_ToAsyncEnumerable.cs rename to src/LinqTests/Operators/async_enumerable.cs index 9ecca76bdc3..72fded7783a 100644 --- a/src/DocumentDbTests/Reading/Linq/invoking_query_with_ToAsyncEnumerable.cs +++ b/src/LinqTests/Operators/async_enumerable.cs @@ -5,13 +5,12 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class invoking_query_with_ToAsyncEnumerable : IntegrationContext +public class AsyncEnumerable : IntegrationContext { - public invoking_query_with_ToAsyncEnumerable(DefaultStoreFixture fixture) : base(fixture) + public AsyncEnumerable(DefaultStoreFixture fixture) : base(fixture) { } @@ -41,4 +40,4 @@ public async Task query_to_async_enumerable() } #endregion -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_count_Tests.cs b/src/LinqTests/Operators/count_operator.cs similarity index 62% rename from src/DocumentDbTests/Reading/Linq/invoking_queryable_count_Tests.cs rename to src/LinqTests/Operators/count_operator.cs index 9a0c11818ce..7baa258aa9d 100644 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_count_Tests.cs +++ b/src/LinqTests/Operators/count_operator.cs @@ -4,11 +4,10 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class invoking_queryable_count_Tests: IntegrationContext +public class count_operator: IntegrationContext { [Fact] public void count_without_any_where() @@ -116,7 +115,65 @@ public void count_with_a_where_clause() } #endregion - public invoking_queryable_count_Tests(DefaultStoreFixture fixture) : base(fixture) + + + [Fact] + public async Task count_without_any_where_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var result = await theSession.Query().CountAsync(); + result.ShouldBe(4); + } + + [Fact] + public async Task long_count_without_any_where_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var result = await theSession.Query().LongCountAsync(); + result.ShouldBe(4); + } + + [Fact] + public async Task count_with_a_where_clause_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.Store(new Target { Number = 5 }); + theSession.Store(new Target { Number = 6 }); + await theSession.SaveChangesAsync(); + + var result = await theSession.Query().CountAsync(x => x.Number > 3); + result.ShouldBe(3); + } + + [Fact] + public async Task long_count_with_a_where_clause_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.Store(new Target { Number = 5 }); + theSession.Store(new Target { Number = 6 }); + await theSession.SaveChangesAsync(); + + var result = await theSession.Query().LongCountAsync(x => x.Number > 3); + result.ShouldBe(3); + } + + public count_operator(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/LinqExtensionsTests.cs b/src/LinqTests/Operators/custom_marten_operators.cs similarity index 86% rename from src/DocumentDbTests/Reading/Linq/LinqExtensionsTests.cs rename to src/LinqTests/Operators/custom_marten_operators.cs index e00e666f80f..ff4cef6704d 100644 --- a/src/DocumentDbTests/Reading/Linq/LinqExtensionsTests.cs +++ b/src/LinqTests/Operators/custom_marten_operators.cs @@ -3,11 +3,10 @@ using System.Linq; using Marten; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class LinqExtensionsTests +public class custom_marten_operators { private static readonly int[] Ints = { 0, 1, 2, 3 }; @@ -18,27 +17,7 @@ public class LinqExtensionsTests Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; - [Fact] - public void IsOneOf_shows_if_value_is_contained_in_the_specified_collection_of_ints() => - IsOneOf_shows_if_value_is_contained_in_the_specified_collection(Ints); - - [Fact] - public void IsOneOf_shows_if_value_is_contained_in_the_specified_collection_of_guids() => - IsOneOf_shows_if_value_is_contained_in_the_specified_collection(Guids); - [Fact] - public void IsOneOf_shows_if_value_is_contained_in_the_specified_collection_of_strings() => - IsOneOf_shows_if_value_is_contained_in_the_specified_collection(Strings); - - private void IsOneOf_shows_if_value_is_contained_in_the_specified_collection(T[] values) - { - values[1].IsOneOf(values[1], values[2]).ShouldBeTrue(); - values[1].IsOneOf(values[2], values[1]).ShouldBeTrue(); - values[1].IsOneOf(values[2], values[3]).ShouldBeFalse(); - values[1].IsOneOf(new List { values[1], values[2] }).ShouldBeTrue(); - values[1].IsOneOf(new List { values[2], values[1] }).ShouldBeTrue(); - values[1].IsOneOf(new List { values[2], values[3] }).ShouldBeFalse(); - } [Fact] public void In_shows_if_value_is_contained_in_the_specified_collection_of_ints() => diff --git a/src/DocumentDbTests/Reading/Linq/query_with_distinct_Tests.cs b/src/LinqTests/Operators/distinct_operator.cs similarity index 87% rename from src/DocumentDbTests/Reading/Linq/query_with_distinct_Tests.cs rename to src/LinqTests/Operators/distinct_operator.cs index d3ef12efb31..c697aee582a 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_distinct_Tests.cs +++ b/src/LinqTests/Operators/distinct_operator.cs @@ -3,12 +3,14 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class query_with_distinct_Tests : IntegrationContext +public class distinct_operator : IntegrationContext { + private readonly ITestOutputHelper _output; + [Fact] public void get_distinct_number() { @@ -21,6 +23,7 @@ public void get_distinct_number() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); var queryable = theSession.Query().Select(x => x.Number).Distinct(); queryable.ToList().Count.ShouldBe(3); @@ -81,6 +84,7 @@ public void get_distinct_strings() theSession.SaveChanges(); + theSession.Logger = new TestOutputMartenLogger(_output); var queryable = theSession.Query().Select(x => new { x.String, @@ -90,7 +94,8 @@ public void get_distinct_strings() queryable.ToList().Count.ShouldBe(4); } - public query_with_distinct_Tests(DefaultStoreFixture fixture) : base(fixture) + public distinct_operator(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) { + _output = output; } -} \ No newline at end of file +} diff --git a/src/LinqTests/Operators/first_operator.cs b/src/LinqTests/Operators/first_operator.cs new file mode 100644 index 00000000000..f740e380c8f --- /dev/null +++ b/src/LinqTests/Operators/first_operator.cs @@ -0,0 +1,180 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Marten; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Shouldly; +using Xunit.Abstractions; + +namespace LinqTests.Operators; + +public class first_operator: IntegrationContext +{ + private readonly ITestOutputHelper _output; + + + [Fact] + public void first_hit_with_only_one_document() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + SpecificationExtensions.ShouldNotBeNull(theSession.Query().First(x => x.Number == 3)); + } + + [Fact] + public void first_or_default_hit_with_only_one_document() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().FirstOrDefault(x => x.Number == 3).ShouldNotBeNull(); + } + + [Fact] + public void first_or_default_miss() + { + theSession.Logger = new TestOutputMartenLogger(_output); + + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().FirstOrDefault(x => x.Number == 11).ShouldBeNull(); + } + + [Fact] + public void first_correct_hit_with_more_than_one_match() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2, Flag = true }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().Where(x => x.Number == 2).First().Flag + .ShouldBeTrue(); + } + + [Fact] + public void first_or_default_correct_hit_with_more_than_one_match() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2, Flag = true }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().Where(x => x.Number == 2).First().Flag + .ShouldBeTrue(); + } + + [Fact] + public void first_miss() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + Exception.ShouldBeThrownBy(() => + { + theSession.Query().Where(x => x.Number == 11).First(); + }); + } + + [Fact] + public async Task first_hit_with_only_one_document_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().FirstAsync(x => x.Number == 3); + SpecificationExtensions.ShouldNotBeNull(target); + } + + [Fact] + public async Task first_or_default_hit_with_only_one_document_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().FirstOrDefaultAsync(x => x.Number == 3); + SpecificationExtensions.ShouldNotBeNull(target); + } + + [Fact] + public async Task first_or_default_miss_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().FirstOrDefaultAsync(x => x.Number == 11); + SpecificationExtensions.ShouldBeNull(target); + } + + [Fact] + public async Task first_correct_hit_with_more_than_one_match_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2, Flag = true }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().Where(x => x.Number == 2).FirstAsync(); + target.Flag.ShouldBeTrue(); + } + + [Fact] + public async Task first_or_default_correct_hit_with_more_than_one_match_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2, Flag = true }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().Where(x => x.Number == 2).FirstOrDefaultAsync(); + target.Flag.ShouldBeTrue(); + } + + [Fact] + public async Task first_miss_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + await Exception.ShouldBeThrownByAsync(async () => + { + await theSession.Query().Where(x => x.Number == 11).FirstAsync(); + }); + } + + public first_operator(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + { + _output = output; + } +} diff --git a/src/DocumentDbTests/Reading/Linq/query_with_is_empty.cs b/src/LinqTests/Operators/is_empty_operator.cs similarity index 82% rename from src/DocumentDbTests/Reading/Linq/query_with_is_empty.cs rename to src/LinqTests/Operators/is_empty_operator.cs index 1256656a4de..d045854f954 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_is_empty.cs +++ b/src/LinqTests/Operators/is_empty_operator.cs @@ -2,11 +2,10 @@ using Marten; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class query_with_is_empty : IntegrationContext +public class is_empty_operator : IntegrationContext { [Fact] public void use_is_empty() @@ -35,7 +34,7 @@ public void use_is_empty() } } - public query_with_is_empty(DefaultStoreFixture fixture) : base(fixture) + public is_empty_operator(DefaultStoreFixture fixture) : base(fixture) { } } diff --git a/src/DocumentDbTests/Reading/Linq/query_with_is_one_of_Tests.cs b/src/LinqTests/Operators/is_one_of_operator.cs similarity index 97% rename from src/DocumentDbTests/Reading/Linq/query_with_is_one_of_Tests.cs rename to src/LinqTests/Operators/is_one_of_operator.cs index 71b702e61bf..cb4b89c7dc9 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_is_one_of_Tests.cs +++ b/src/LinqTests/Operators/is_one_of_operator.cs @@ -6,11 +6,10 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class query_with_is_one_of_Tests: IntegrationContext +public class is_one_of_operator: IntegrationContext { public static TheoryData>>> SupportedIsOneOfWithIntArray = new() @@ -247,7 +246,8 @@ Func select } - public query_with_is_one_of_Tests(DefaultStoreFixture fixture): base(fixture) + + public is_one_of_operator(DefaultStoreFixture fixture): base(fixture) { } } diff --git a/src/DocumentDbTests/Reading/Linq/query_with_IsSubsetOf_Tests.cs b/src/LinqTests/Operators/is_subset_of_operator.cs similarity index 77% rename from src/DocumentDbTests/Reading/Linq/query_with_IsSubsetOf_Tests.cs rename to src/LinqTests/Operators/is_subset_of_operator.cs index 3166f000bb5..cedd58463ab 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_IsSubsetOf_Tests.cs +++ b/src/LinqTests/Operators/is_subset_of_operator.cs @@ -5,15 +5,17 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; +using Xunit.Abstractions; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class query_with_IsSubsetOf_Tests : IntegrationContext +public class is_subset_of_operator : IntegrationContext { - public query_with_IsSubsetOf_Tests(DefaultStoreFixture fixture) : base(fixture) - { + private readonly ITestOutputHelper _output; + public is_subset_of_operator(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + { + _output = output; } protected override Task fixtureSetup() @@ -78,6 +80,21 @@ public void Can_query_by_hashset() // given var tags = new[] {"c#", "mssql"}; + theSession.Logger = new TestOutputMartenLogger(_output); + + /* + * CURRENT: +select d.id, d.data from public.mt_doc_target as d where CAST(d.data ->> 'tags' as jsonb) <@ :p0 + p0: ["c#","mssql"] + + + + BEFORE: +select d.id, d.data from public.mt_doc_target as d where CAST(d.data ->> 'TagsHashSet' as jsonb) <@ :p0 + p0: ["c#","mssql"] + * + */ + // than var found = theSession .Query() diff --git a/src/DocumentDbTests/Reading/Linq/query_with_IsSuperSetOf_Tests.cs b/src/LinqTests/Operators/is_super_set_of_operator.cs similarity index 92% rename from src/DocumentDbTests/Reading/Linq/query_with_IsSuperSetOf_Tests.cs rename to src/LinqTests/Operators/is_super_set_of_operator.cs index 265b5a5d378..08677222cbf 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_IsSuperSetOf_Tests.cs +++ b/src/LinqTests/Operators/is_super_set_of_operator.cs @@ -5,11 +5,10 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class query_with_IsSupersetOf_Tests : IntegrationContext +public class is_super_set_of_operator : IntegrationContext { public void is_superset_of_example() { @@ -24,7 +23,7 @@ public void is_superset_of_example() private Target[] _allTargets; - public query_with_IsSupersetOf_Tests(DefaultStoreFixture fixture) : base(fixture) + public is_super_set_of_operator(DefaultStoreFixture fixture) : base(fixture) { } @@ -94,4 +93,4 @@ private static Target CreateTarget(params string[] tags) { return new Target {TagsArray = tags, TagsHashSet = new HashSet(tags)}; } -} \ No newline at end of file +} diff --git a/src/LinqTests/Operators/last_operator.cs b/src/LinqTests/Operators/last_operator.cs new file mode 100644 index 00000000000..8978124eb6f --- /dev/null +++ b/src/LinqTests/Operators/last_operator.cs @@ -0,0 +1,47 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Marten.Testing.Documents; +using Marten.Testing.Harness; + +namespace LinqTests.Operators; + +public class last_operator: IntegrationContext +{ + [Fact] + public void last_throws_an_exception() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + Exception.ShouldBeThrownBy(() => + { + theSession.Query().Last(x => x.Number == 3) + .ShouldNotBeNull(); + }); + } + + [Fact] + public void last_or_default_throws_an_exception() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + Exception.ShouldBeThrownBy(() => + { + theSession.Query().Last(x => x.Number == 3) + .ShouldNotBeNull(); + }); + } + + + public last_operator(DefaultStoreFixture fixture) : base(fixture) + { + } +} diff --git a/src/DocumentDbTests/Reading/Linq/query_with_modulo_Tests.cs b/src/LinqTests/Operators/modulo_operator.cs similarity index 96% rename from src/DocumentDbTests/Reading/Linq/query_with_modulo_Tests.cs rename to src/LinqTests/Operators/modulo_operator.cs index 833992d920f..c473c5a1a48 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_modulo_Tests.cs +++ b/src/LinqTests/Operators/modulo_operator.cs @@ -1,9 +1,8 @@ using System.Linq; using Marten.Testing.Documents; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; public class query_with_modulo_Tests : IntegrationContext { @@ -46,4 +45,4 @@ public void use_modulo_operands_reversed() public query_with_modulo_Tests(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/query_negating_predicate_with_binary_operator_tests.cs b/src/LinqTests/Operators/negation_operator.cs similarity index 87% rename from src/DocumentDbTests/Reading/Linq/query_negating_predicate_with_binary_operator_tests.cs rename to src/LinqTests/Operators/negation_operator.cs index b48bc1656cc..824e5e6db3f 100644 --- a/src/DocumentDbTests/Reading/Linq/query_negating_predicate_with_binary_operator_tests.cs +++ b/src/LinqTests/Operators/negation_operator.cs @@ -2,11 +2,10 @@ using System.Linq; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class query_negating_predicate_with_binary_operator_tests : IntegrationContext +public class negation_operator : IntegrationContext { [Fact] public void negating_predicate_with_an_and_operator_results_in_a_correct_query() @@ -48,7 +47,7 @@ public void negating_predicate_with_an_or_operator_results_in_a_correct_query() players.Count(x => new[] { player2.Id, player4.Id }.Contains(x.Id)).ShouldBe(2); } - public query_negating_predicate_with_binary_operator_tests(DefaultStoreFixture fixture) : base(fixture) + public negation_operator(DefaultStoreFixture fixture) : base(fixture) { } } @@ -58,4 +57,4 @@ public class Player public Guid Id { get; set; } public string Name { get; set; } public int Level { get; set; } -} \ No newline at end of file +} diff --git a/src/LinqTests/Operators/single_operator.cs b/src/LinqTests/Operators/single_operator.cs new file mode 100644 index 00000000000..a48e3b78b7e --- /dev/null +++ b/src/LinqTests/Operators/single_operator.cs @@ -0,0 +1,214 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Marten; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Shouldly; +using Xunit.Abstractions; + +namespace LinqTests.Operators; + +public class single_operator : IntegrationContext +{ + private readonly ITestOutputHelper _output; + + #region sample_single_and_single_or_default + [Fact] + public void single_hit_with_only_one_document() + { + theSession.Store(new Target{Number = 1}); + theSession.Store(new Target{Number = 2}); + theSession.Store(new Target{Number = 3}); + theSession.Store(new Target{Number = 4}); + theSession.SaveChanges(); + + SpecificationExtensions.ShouldNotBeNull(theSession.Query().Single(x => x.Number == 3)); + } + + [Fact] + public void single_or_default_hit_with_only_one_document() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + SpecificationExtensions.ShouldNotBeNull(theSession.Query().SingleOrDefault(x => x.Number == 3)); + } + #endregion + + [Fact] + public void single_or_default_miss() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + SpecificationExtensions.ShouldBeNull(theSession.Query().SingleOrDefault(x => x.Number == 11)); + } + + [Fact] + public void single_hit_with_more_than_one_match() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + Exception.ShouldBeThrownBy(() => + { + theSession.Query().Where(x => x.Number == 2).Single(); + }); + } + + [Fact] + public void single_hit_with_more_than_one_match_and_take_one_should_not_throw() + { + theSession.Logger = new TestOutputMartenLogger(_output); + + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + theSession.Query().Where(x => x.Number == 2).Take(1).Single().ShouldNotBeNull(); + } + + [Fact] + public void single_or_default_hit_with_more_than_one_match() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + Exception.ShouldBeThrownBy(() => + { + theSession.Query().Where(x => x.Number == 2).SingleOrDefault(); + }); + } + + [Fact] + public void single_miss() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + theSession.SaveChanges(); + + Exception.ShouldBeThrownBy(() => + { + theSession.Query().Where(x => x.Number == 11).Single(); + }); + } + + [Fact] + public async Task single_hit_with_only_one_document_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().SingleAsync(x => x.Number == 3); + target.ShouldNotBeNull(); + } + + [Fact] + public async Task single_or_default_hit_with_only_one_document_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().SingleOrDefaultAsync(x => x.Number == 3); + target.ShouldNotBeNull(); + } + + [Fact] + public async Task single_or_default_miss_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().SingleOrDefaultAsync(x => x.Number == 11); + target.ShouldBeNull(); + } + + [Fact] + public async Task single_hit_with_more_than_one_match_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + await Exception.ShouldBeThrownByAsync(async () => + { + await theSession.Query().Where(x => x.Number == 2).SingleAsync(); + }); + } + + [Fact] + public async Task single_hit_with_more_than_one_match_and_take_one_should_not_throw_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + var target = await theSession.Query().Where(x => x.Number == 2).Take(1).SingleAsync(); + target.ShouldNotBeNull(); + } + + [Fact] + public async Task single_or_default_hit_with_more_than_one_match_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + await Exception.ShouldBeThrownByAsync(async () => + { + await theSession.Query().Where(x => x.Number == 2).SingleOrDefaultAsync(); + }); + } + + [Fact] + public async Task single_miss_async() + { + theSession.Store(new Target { Number = 1 }); + theSession.Store(new Target { Number = 2 }); + theSession.Store(new Target { Number = 3 }); + theSession.Store(new Target { Number = 4 }); + await theSession.SaveChangesAsync(); + + await Exception.ShouldBeThrownByAsync(async () => + { + await theSession.Query().Where(x => x.Number == 11).SingleAsync(); + }); + } + + public single_operator(DefaultStoreFixture fixture, ITestOutputHelper output) : base(fixture) + { + _output = output; + } +} diff --git a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_to_list_async_Tests.cs b/src/LinqTests/Operators/to_list_operator.cs similarity index 80% rename from src/DocumentDbTests/Reading/Linq/invoking_queryable_through_to_list_async_Tests.cs rename to src/LinqTests/Operators/to_list_operator.cs index 8177712dd06..a45abad5899 100644 --- a/src/DocumentDbTests/Reading/Linq/invoking_queryable_through_to_list_async_Tests.cs +++ b/src/LinqTests/Operators/to_list_operator.cs @@ -4,11 +4,10 @@ using Marten.Testing.Documents; using Marten.Testing.Harness; using Shouldly; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.Operators; -public class invoking_queryable_through_to_list_async_Tests : IntegrationContext +public class to_list_operator : IntegrationContext { #region sample_using-to-list-async [Fact] @@ -40,7 +39,7 @@ public async Task should_return_empty_list() users.ShouldBeEmpty(); } - public invoking_queryable_through_to_list_async_Tests(DefaultStoreFixture fixture) : base(fixture) + public to_list_operator(DefaultStoreFixture fixture) : base(fixture) { } -} \ No newline at end of file +} diff --git a/src/DocumentDbTests/Reading/Linq/SimpleUser.cs b/src/LinqTests/SimpleUser.cs similarity index 94% rename from src/DocumentDbTests/Reading/Linq/SimpleUser.cs rename to src/LinqTests/SimpleUser.cs index 67bf57a4190..e30cd1aa25d 100644 --- a/src/DocumentDbTests/Reading/Linq/SimpleUser.cs +++ b/src/LinqTests/SimpleUser.cs @@ -1,6 +1,6 @@ using System; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests; public class SimpleUser { diff --git a/src/DocumentDbTests/Reading/Linq/query_with_multiple_where_clauses_and_soft_deletes_configured.cs b/src/LinqTests/SoftDeletes/query_with_multiple_where_clauses_and_soft_deletes_configured.cs similarity index 97% rename from src/DocumentDbTests/Reading/Linq/query_with_multiple_where_clauses_and_soft_deletes_configured.cs rename to src/LinqTests/SoftDeletes/query_with_multiple_where_clauses_and_soft_deletes_configured.cs index 9ca9d3808ad..76153199df7 100644 --- a/src/DocumentDbTests/Reading/Linq/query_with_multiple_where_clauses_and_soft_deletes_configured.cs +++ b/src/LinqTests/SoftDeletes/query_with_multiple_where_clauses_and_soft_deletes_configured.cs @@ -3,9 +3,8 @@ using System.Threading.Tasks; using Marten; using Marten.Testing.Harness; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests.SoftDeletes; public class query_with_multiple_where_clauses_and_soft_deletes_configured : OneOffConfigurationsContext { diff --git a/src/LinqTests/TestSetup.cs b/src/LinqTests/TestSetup.cs new file mode 100644 index 00000000000..ff34e74afb4 --- /dev/null +++ b/src/LinqTests/TestSetup.cs @@ -0,0 +1,17 @@ +using Marten.Services.Json; +using Marten.Testing.Harness; +using Xunit.Abstractions; +using Xunit.Sdk; + +[assembly: TestFramework("LinqTests.TestSetup", "LinqTests")] + +namespace LinqTests; + +public class TestSetup : XunitTestFramework +{ + public TestSetup(IMessageSink messageSink) + :base(messageSink) + { + SerializerFactory.DefaultSerializerType = TestsSettings.SerializerType; + } +} diff --git a/src/LinqTests/Usings.cs b/src/LinqTests/Usings.cs new file mode 100644 index 00000000000..c802f4480b1 --- /dev/null +++ b/src/LinqTests/Usings.cs @@ -0,0 +1 @@ +global using Xunit; diff --git a/src/LinqTests/playing.cs b/src/LinqTests/playing.cs new file mode 100644 index 00000000000..d6af25938ef --- /dev/null +++ b/src/LinqTests/playing.cs @@ -0,0 +1,21 @@ +using System.Linq; +using System.Threading.Tasks; +using JasperFx.Core; +using Marten; +using Marten.Testing.Documents; +using Marten.Testing.Harness; + +namespace LinqTests; + +public class playing : IntegrationContext +{ + public playing(DefaultStoreFixture fixture) : base(fixture) + { + } + + [Fact] + public async Task try_method_parsing() + { + var data = await theSession.Query().Where(x => x.String.EqualsIgnoreCase("something")).ToListAsync(); + } +} diff --git a/src/DocumentDbTests/Reading/Linq/using_containment_operator_in_linq_Tests.cs b/src/LinqTests/using_containment_operator_in_linq_Tests.cs similarity index 98% rename from src/DocumentDbTests/Reading/Linq/using_containment_operator_in_linq_Tests.cs rename to src/LinqTests/using_containment_operator_in_linq_Tests.cs index 3d2286461f1..3252a0d315e 100644 --- a/src/DocumentDbTests/Reading/Linq/using_containment_operator_in_linq_Tests.cs +++ b/src/LinqTests/using_containment_operator_in_linq_Tests.cs @@ -4,9 +4,8 @@ using Marten.Testing.Harness; using Shouldly; using Weasel.Core; -using Xunit; -namespace DocumentDbTests.Reading.Linq; +namespace LinqTests; public class using_containment_operator_in_linq_Tests: OneOffConfigurationsContext { diff --git a/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs b/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs index 549477c7892..8d7b6644b69 100644 --- a/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs +++ b/src/Marten.PLv8.Testing/Patching/PatchExpressionTests.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Marten.Internal.Sessions; using Marten.Internal.Storage; -using Marten.Linq.Filters; +using Marten.Linq.SqlGeneration.Filters; using Marten.PLv8.Patching; using Marten.PLv8.Transforms; using Marten.Schema; diff --git a/src/Marten.PLv8/Patching/PatchExpression.cs b/src/Marten.PLv8/Patching/PatchExpression.cs index fade372c116..cdbafc9302d 100644 --- a/src/Marten.PLv8/Patching/PatchExpression.cs +++ b/src/Marten.PLv8/Patching/PatchExpression.cs @@ -205,7 +205,7 @@ private void delete(string path) private string toPath(Expression expression) { - var visitor = new FindMembers(); + var visitor = new MemberFinder(); visitor.Visit(expression); // TODO -- don't like this. Smells like duplication in logic @@ -219,8 +219,6 @@ private void apply() var transform = _session.Options.TransformFor(TransformSchema.PatchDoc); var storage = _session.StorageFor(typeof(T)); - - var operation = new PatchOperation(transform, storage, Patch, _session.Serializer, PossiblyPolymorphic); if (_filterExpression != null) @@ -229,11 +227,11 @@ private void apply() } else if (_filter == null) { - operation.Where = storage.DefaultWhereFragment(); + operation.Wheres.Add(storage.DefaultWhereFragment()); } else { - operation.Where = storage.FilterDocuments(null, _filter, _session); + operation.Wheres.Add(storage.FilterDocuments(_filter, _session)); } _session.QueueOperation(operation); diff --git a/src/Marten.PLv8/Patching/PatchOperation.cs b/src/Marten.PLv8/Patching/PatchOperation.cs index fbf8607ffc7..d64209e53cb 100644 --- a/src/Marten.PLv8/Patching/PatchOperation.cs +++ b/src/Marten.PLv8/Patching/PatchOperation.cs @@ -95,10 +95,10 @@ public OperationRole Role() protected override void configure(CommandBuilder builder) { base.configure(builder); - applyUpdates(builder, _fragment); + applyUpdates(builder); } - private void applyUpdates(CommandBuilder builder, ISqlFragment where) + private void applyUpdates(CommandBuilder builder) { var fields = _storage.DuplicatedFields; if (!fields.Any()) @@ -111,16 +111,12 @@ private void applyUpdates(CommandBuilder builder, ISqlFragment where) builder.Append(" as d set "); builder.Append(fields[0].UpdateSqlFragment()); - for (var i = 1; i < fields.Length; i++) + for (var i = 1; i < fields.Count; i++) { builder.Append(", "); builder.Append(fields[i].UpdateSqlFragment()); } - if (Where != null) - { - builder.Append(" where "); - Where.Apply(builder); - } + writeWhereClause(builder); } } diff --git a/src/Marten.PLv8/Transforms/DocumentTransforms.cs b/src/Marten.PLv8/Transforms/DocumentTransforms.cs index 4cab11e6736..a452fd4c074 100644 --- a/src/Marten.PLv8/Transforms/DocumentTransforms.cs +++ b/src/Marten.PLv8/Transforms/DocumentTransforms.cs @@ -1,8 +1,8 @@ using System; using System.Linq.Expressions; using Marten.Internal.Sessions; -using Marten.Linq.Filters; using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; using Marten.Services; using Marten.Storage; using Weasel.Postgresql.SqlGeneration; @@ -42,8 +42,13 @@ public void All(string transformName) var operation = new DocumentTransformOperationFragment(storage, transform); var statement = new StatementOperation(storage, operation); - // To bake in the default document filtering here - statement.CompileLocal(Session); + // Bake in any default filtering + var filter = storage.DefaultWhereFragment(); + if (filter != null) + { + statement.Wheres.Add(filter); + } + Session.QueueOperation(statement); } @@ -82,10 +87,7 @@ private void transformOne(string transformName, ISqlFragment filter) var storage = Session.StorageFor(); var operation = new DocumentTransformOperationFragment(storage, transform); - var statement = new StatementOperation(storage, operation) { Where = filter }; - - // To bake in the default document filtering here - statement.CompileLocal(Session); + var statement = new StatementOperation(storage, operation, filter); Session.QueueOperation(statement); } diff --git a/src/Marten.PLv8/Transforms/TransformExtensions.cs b/src/Marten.PLv8/Transforms/TransformExtensions.cs index 9ca1772ccd8..3f4d6b096c0 100644 --- a/src/Marten.PLv8/Transforms/TransformExtensions.cs +++ b/src/Marten.PLv8/Transforms/TransformExtensions.cs @@ -68,7 +68,8 @@ public static Task StreamOneTransformed(this IQueryable queryable, string private static async Task StreamOneTransformed(this IMartenLinqQueryable martenQueryable, string transformName, Stream destination, CancellationToken token) { - var builder = martenQueryable.BuildLinqHandler(); + var parser = martenQueryable.BuildLinqParser(); + var statements = parser.BuildStatements(); var session = martenQueryable.Session; @@ -76,11 +77,11 @@ private static async Task StreamOneTransformed(this IMartenLinqQueryable martenQ var transform = session.Options.TransformFor(transformName); - builder.CurrentStatement.SelectClause = - new TransformSelectClause(transform, builder.CurrentStatement.SelectClause); + statements.MainSelector.SelectClause = + new TransformSelectClause(transform, statements.MainSelector.SelectClause); - var statement = builder.TopStatement; - statement.Current().Limit = 1; + var statement = statements.Top; + statements.MainSelector.Limit = 1; var command = statement.BuildCommand(); await session.StreamOne(command, destination, token).ConfigureAwait(false); @@ -104,7 +105,8 @@ public static Task StreamManyTransformed(this IQueryable queryable, string private static async Task StreamManyTransformed(this IMartenLinqQueryable martenQueryable, string transformName, Stream destination, CancellationToken token) { - var builder = martenQueryable.BuildLinqHandler(); + var parser = martenQueryable.BuildLinqParser(); + var statements = parser.BuildStatements(); var session = martenQueryable.Session; @@ -112,10 +114,10 @@ private static async Task StreamManyTransformed(this IMartenLinqQueryable marten var transform = session.Options.TransformFor(transformName); - builder.CurrentStatement.SelectClause = - new TransformSelectClause(transform, builder.CurrentStatement.SelectClause); + statements.MainSelector.SelectClause = + new TransformSelectClause(transform, statements.MainSelector.SelectClause); - var statement = builder.TopStatement; + var statement = statements.Top; var command = statement.BuildCommand(); await session.StreamMany(command, destination, token).ConfigureAwait(false); diff --git a/src/Marten.Testing/Documents/Target.cs b/src/Marten.Testing/Documents/Target.cs index 8432d782762..3d623bb6eb2 100644 --- a/src/Marten.Testing/Documents/Target.cs +++ b/src/Marten.Testing/Documents/Target.cs @@ -53,7 +53,7 @@ public static Target Random(bool deep = false) target.Float = float.Parse(_random.NextDouble().ToString()); - target.NumberArray = new[] { _random.Next(0, 10), _random.Next(0, 10), _random.Next(0, 10) }; + target.NumberArray = _random.Next(0, 10) > 8 ? new[] { _random.Next(0, 10), _random.Next(0, 10), _random.Next(0, 10) } : Array.Empty(); target.NumberArray = target.NumberArray.Distinct().ToArray(); @@ -72,6 +72,20 @@ public static Target Random(bool deep = false) break; } + var value = _random.Next(0, 100); + if (value > 10) target.NullableNumber = value; + + if (value > 20) + { + var list = new List(); + for (int i = 0; i < 5; i++) + { + list.Add(_strings[_random.Next(0, 10)]); + } + + target.StringArray = list.Distinct().ToArray(); + } + target.Long = 100 * _random.Next(); target.Double = _random.NextDouble(); target.Long = _random.Next() * 10000; @@ -115,6 +129,8 @@ public Target() public string String { get; set; } public string AnotherString { get; set; } + public string[] StringArray { get; set; } + public Guid OtherGuid { get; set; } public Target Inner { get; set; } diff --git a/src/Marten.Testing/Examples/CamelCasing.cs b/src/Marten.Testing/Examples/CamelCasing.cs index 7c5647728f5..4a2a9836937 100644 --- a/src/Marten.Testing/Examples/CamelCasing.cs +++ b/src/Marten.Testing/Examples/CamelCasing.cs @@ -1,3 +1,5 @@ +using Marten.Linq; +using Marten.Linq.Parsing; using Marten.Testing.Documents; using Xunit; @@ -18,8 +20,8 @@ public void SerializeToCamelCase() }); var field = store.StorageFeatures.MappingFor(typeof(User)) - .FieldFor(nameof(User.FirstName)); + .QueryMembers.MemberFor(x => x.FirstName); Assert.Equal(@"d.data ->> 'firstName'", field.TypedLocator); } -} \ No newline at end of file +} diff --git a/src/Marten.Testing/Harness/TestOutputMartenLogger.cs b/src/Marten.Testing/Harness/TestOutputMartenLogger.cs index 3c451ca8256..eed155c078e 100644 --- a/src/Marten.Testing/Harness/TestOutputMartenLogger.cs +++ b/src/Marten.Testing/Harness/TestOutputMartenLogger.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.IO; using System.Linq; using Marten.Services; using Microsoft.Extensions.Logging; @@ -13,6 +14,8 @@ public class TestOutputMartenLogger : IMartenLogger, IMartenSessionLogger, ILogg private readonly ITestOutputHelper _output; private static readonly ITestOutputHelper _noopTestOutputHelper = new NoopTestOutputHelper(); + private readonly StringWriter _writer = new StringWriter(); + public TestOutputMartenLogger(ITestOutputHelper output) { _output = output ?? _noopTestOutputHelper; @@ -23,6 +26,11 @@ public IMartenSessionLogger StartSession(IQuerySession session) return this; } + public string ExecutedSql() + { + return _writer.ToString(); + } + public void SchemaChange(string sql) { _output.WriteLine("Executing DDL change:"); @@ -47,6 +55,8 @@ public void LogSuccess(NpgsqlCommand command) { Debug.WriteLine($" {p.ParameterName}: {p.Value}"); } + + _writer.WriteLine(command.CommandText); } public void LogFailure(NpgsqlCommand command, Exception ex) @@ -72,6 +82,8 @@ public void OnBeforeExecute(NpgsqlCommand command) } + + private class NoopTestOutputHelper : ITestOutputHelper { public void WriteLine(string message) diff --git a/src/Marten.sln b/src/Marten.sln index b48ca909933..1a67bde3890 100644 --- a/src/Marten.sln +++ b/src/Marten.sln @@ -81,6 +81,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalAPI", "samples\Minim EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marten.CommandLine.Tests", "Marten.CommandLine.Tests\Marten.CommandLine.Tests.csproj", "{0962E83F-482B-4316-A8AB-3B714EEEC3AA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqTests", "LinqTests\LinqTests.csproj", "{94EF979D-F2C0-4479-9D1D-63647042E915}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -195,6 +197,10 @@ Global {0962E83F-482B-4316-A8AB-3B714EEEC3AA}.Debug|Any CPU.Build.0 = Debug|Any CPU {0962E83F-482B-4316-A8AB-3B714EEEC3AA}.Release|Any CPU.ActiveCfg = Release|Any CPU {0962E83F-482B-4316-A8AB-3B714EEEC3AA}.Release|Any CPU.Build.0 = Release|Any CPU + {94EF979D-F2C0-4479-9D1D-63647042E915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94EF979D-F2C0-4479-9D1D-63647042E915}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94EF979D-F2C0-4479-9D1D-63647042E915}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94EF979D-F2C0-4479-9D1D-63647042E915}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -227,5 +233,6 @@ Global {3688AF80-FB24-4C3C-95FD-A2AB4680CD67} = {91D87D73-EC07-4067-8A64-26A2E4F6BC83} {7B710A53-373B-4A7D-B49E-53C15E6A8CA8} = {79961196-DB50-4AD3-B749-D231799BCF2E} {0962E83F-482B-4316-A8AB-3B714EEEC3AA} = {DA7EC300-12F5-4B80-B5DF-B7B71E344E24} + {94EF979D-F2C0-4479-9D1D-63647042E915} = {91D87D73-EC07-4067-8A64-26A2E4F6BC83} EndGlobalSection EndGlobal diff --git a/src/Marten/Events/Aggregation/AggregateVersioning.cs b/src/Marten/Events/Aggregation/AggregateVersioning.cs index 379d3b95dab..e3f84f237b9 100644 --- a/src/Marten/Events/Aggregation/AggregateVersioning.cs +++ b/src/Marten/Events/Aggregation/AggregateVersioning.cs @@ -10,9 +10,9 @@ using JasperFx.Core.Reflection; using Marten.Events.CodeGeneration; using Marten.Events.Projections; +using Marten.Linq.Parsing; using Marten.Schema; using Marten.Util; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten.Events.Aggregation; @@ -169,12 +169,12 @@ private Expression determineBody(ParameterExpression aggregate, MethodCallExpres public void Override(Expression> expression) { - VersionMember = FindMembers.Determine(expression).Single(); + VersionMember = MemberFinder.Determine(expression).Single(); } public void Override(Expression> expression) { - VersionMember = FindMembers.Determine(expression).Single(); + VersionMember = MemberFinder.Determine(expression).Single(); } public long GetVersion(T aggregate) diff --git a/src/Marten/Events/Archiving/MaybeArchivedMethodCallParser.cs b/src/Marten/Events/Archiving/MaybeArchivedMethodCallParser.cs index ca3d959005a..dbeef2ca6ca 100644 --- a/src/Marten/Events/Archiving/MaybeArchivedMethodCallParser.cs +++ b/src/Marten/Events/Archiving/MaybeArchivedMethodCallParser.cs @@ -1,6 +1,7 @@ using System.Linq.Expressions; using System.Reflection; -using Marten.Linq.Fields; +using Marten.Linq; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Weasel.Postgresql.SqlGeneration; @@ -19,7 +20,8 @@ public bool Matches(MethodCallExpression expression) return expression.Method == _method; } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { return _whereFragment; } diff --git a/src/Marten/Events/Daemon/Progress/ProjectionProgressStatement.cs b/src/Marten/Events/Daemon/Progress/ProjectionProgressStatement.cs index 6a47c199c52..74bc9932958 100644 --- a/src/Marten/Events/Daemon/Progress/ProjectionProgressStatement.cs +++ b/src/Marten/Events/Daemon/Progress/ProjectionProgressStatement.cs @@ -1,3 +1,4 @@ +using Marten.Linq; using Marten.Linq.SqlGeneration; using Weasel.Postgresql; @@ -7,7 +8,7 @@ internal class ProjectionProgressStatement: Statement { private readonly EventGraph _events; - public ProjectionProgressStatement(EventGraph events): base(null) + public ProjectionProgressStatement(EventGraph events) { _events = events; } diff --git a/src/Marten/Events/EventDocumentStorage.cs b/src/Marten/Events/EventDocumentStorage.cs index 08ce761b90b..c6dc67c1ef1 100644 --- a/src/Marten/Events/EventDocumentStorage.cs +++ b/src/Marten/Events/EventDocumentStorage.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Threading; @@ -10,15 +11,14 @@ using Marten.Internal; using Marten.Internal.Operations; using Marten.Linq; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; using Marten.Services; using Marten.Storage; -using Remotion.Linq; using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; @@ -45,7 +45,6 @@ public EventDocumentStorage(StoreOptions options) _mapping = new EventQueryMapping(options); FromObject = _mapping.TableName.QualifiedName; - Fields = _mapping; _serializer = options.Serializer(); @@ -66,6 +65,9 @@ public EventDocumentStorage(StoreOptions options) : IsNotArchivedFilter.Instance; } + public IQueryableMemberCollection QueryMembers => _mapping.QueryMembers; + public ISelectClause SelectClauseWithDuplicatedFields => this; + public EventGraph Events { get; } public void TruncateDocumentStorage(IMartenDatabase database) @@ -103,7 +105,7 @@ public IDeletion HardDeleteForDocument(IEvent document, string tenantId) public string FromObject { get; } public Type SelectedType => typeof(IEvent); - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { sql.Append(_selectClause); } @@ -118,10 +120,10 @@ public ISelector BuildSelector(IMartenSession session) return this; } - public IQueryHandler BuildHandler(IMartenSession session, Statement topStatement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment topStatement, + ISqlFragment currentStatement) { - return LinqHandlerBuilder.BuildHandler(this, topStatement); + return LinqQueryParser.BuildHandler(this, topStatement); } public ISelectClause UseStatistics(QueryStatistics statistics) @@ -130,9 +132,8 @@ public ISelectClause UseStatistics(QueryStatistics statistics) } public Type SourceType => typeof(IEvent); - public IFieldMapping Fields { get; } - public ISqlFragment FilterDocuments(QueryModel model, ISqlFragment query, IMartenSession session) + public ISqlFragment FilterDocuments(ISqlFragment query, IMartenSession session) { var shouldBeTenanted = Events.TenancyStyle == TenancyStyle.Conjoined && !query.SpecifiesTenant(); if (shouldBeTenanted) @@ -153,7 +154,7 @@ public ISqlFragment DefaultWhereFragment() public bool UseOptimisticConcurrency { get; } = false; public IOperationFragment DeleteFragment => throw new NotSupportedException(); public IOperationFragment HardDeleteFragment => throw new NotSupportedException(); - public DuplicatedField[] DuplicatedFields { get; } = Array.Empty(); + public IReadOnlyList DuplicatedFields { get; } = Array.Empty(); public DbObjectName TableName => _mapping.TableName; public Type DocumentType => typeof(IEvent); @@ -279,4 +280,9 @@ private EventMapping eventMappingForDotNetTypeName(string dotnetTypeName, string return Events.EventMappingFor(type); } + + bool ISqlFragment.Contains(string sqlText) + { + return false; + } } diff --git a/src/Marten/Events/EventMapping.cs b/src/Marten/Events/EventMapping.cs index 4035b534a25..99272f4da88 100644 --- a/src/Marten/Events/EventMapping.cs +++ b/src/Marten/Events/EventMapping.cs @@ -12,24 +12,22 @@ using Marten.Internal.Operations; using Marten.Internal.Storage; using Marten.Linq; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; using Marten.Schema; using Marten.Services; using Marten.Services.Json.Transformations; using Marten.Storage; using Marten.Util; using NpgsqlTypes; -using Remotion.Linq; using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; using static Marten.Events.EventMappingExtensions; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten.Events; @@ -78,7 +76,7 @@ protected EventMapping(EventGraph parent, Type eventType) public NpgsqlDbType IdType { get; } = NpgsqlDbType.Uuid; public TenancyStyle TenancyStyle { get; } = TenancyStyle.Single; - public DuplicatedField[] DuplicatedFields { get; } + public IReadOnlyList DuplicatedFields { get; } public DeleteStyle DeleteStyle { get; } public PropertySearching PropertySearching { get; } = PropertySearching.JSON_Locator_Only; @@ -102,27 +100,7 @@ public string[] SelectFields() return new[] { "id", "data" }; } - public IField FieldFor(Expression expression) - { - return FieldFor(FindMembers.Determine(expression)); - } - - public IField FieldFor(IEnumerable members) - { - return _inner.FieldFor(members); - } - - public IField FieldFor(MemberInfo member) - { - return _inner.FieldFor(member); - } - - public IField FieldFor(string memberName) - { - throw new NotSupportedException(); - } - - public ISqlFragment FilterDocuments(QueryModel model, ISqlFragment query, IMartenSession martenSession) + public ISqlFragment FilterDocuments(ISqlFragment query, IMartenSession martenSession) { var extras = extraFilters(query).ToList(); @@ -210,8 +188,13 @@ public EventMapping(EventGraph parent): base(parent, typeof(T)) _tableName = schemaName == SchemaConstants.DefaultSchema ? "mt_events" : $"{schemaName}.mt_events"; _idType = parent.StreamIdentity == StreamIdentity.AsGuid ? typeof(Guid) : typeof(string); + + QueryMembers = new DocumentQueryableMemberCollection(this, parent.Options); } + public IQueryableMemberCollection QueryMembers { get; } + public ISelectClause SelectClauseWithDuplicatedFields => this; + public void TruncateDocumentStorage(IMartenDatabase database) { database.RunSql($"delete from table {_tableName} where type = '{Alias}'"); @@ -230,24 +213,29 @@ public Task TruncateDocumentStorageAsync(IMartenDatabase database, CancellationT Type ISelectClause.SelectedType => typeof(T); - void ISelectClause.WriteSelectClause(CommandBuilder sql) + void ISqlFragment.Apply(CommandBuilder sql) { sql.Append("select data from "); sql.Append(_tableName); sql.Append(" as d"); } + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + ISelector ISelectClause.BuildSelector(IMartenSession session) { return new EventSelector(session.Serializer); } - IQueryHandler ISelectClause.BuildHandler(IMartenSession session, Statement topStatement, - Statement currentStatement) + IQueryHandler ISelectClause.BuildHandler(IMartenSession session, ISqlFragment topStatement, + ISqlFragment currentStatement) { var selector = new EventSelector(session.Serializer); - return LinqHandlerBuilder.BuildHandler(selector, topStatement); + return LinqQueryParser.BuildHandler(selector, topStatement); } ISelectClause ISelectClause.UseStatistics(QueryStatistics statistics) @@ -263,7 +251,6 @@ object IDocumentStorage.IdentityFor(T document) } Type IDocumentStorage.IdType => _idType; - public IFieldMapping Fields => _inner; Guid? IDocumentStorage.VersionFor(T document, IMartenSession session) { diff --git a/src/Marten/Events/EventQueryMapping.cs b/src/Marten/Events/EventQueryMapping.cs index ab869ef677a..ad8fe2ba7b2 100644 --- a/src/Marten/Events/EventQueryMapping.cs +++ b/src/Marten/Events/EventQueryMapping.cs @@ -1,8 +1,7 @@ using System; -using System.Linq; using System.Linq.Expressions; -using Marten.Linq.Fields; -using Marten.Linq.Parsing; +using System.Reflection; +using JasperFx.Core.Reflection; using Marten.Schema; using Weasel.Core; using Weasel.Postgresql; @@ -19,42 +18,42 @@ public EventQueryMapping(StoreOptions storeOptions): base(typeof(IEvent), storeO TableName = new PostgresqlObjectName(DatabaseSchemaName, "mt_events"); - duplicateField(x => x.Sequence, "seq_id"); + registerQueryableMember(x => x.Sequence, "seq_id"); if (storeOptions.Events.StreamIdentity == StreamIdentity.AsGuid) { - duplicateField(x => x.StreamId, "stream_id"); + registerQueryableMember(x => x.StreamId, "stream_id"); } else { - duplicateField(x => x.StreamKey, "stream_id"); + registerQueryableMember(x => x.StreamKey, "stream_id"); } - duplicateField(x => x.Version, "version"); - duplicateField(x => x.Timestamp, "timestamp"); - duplicateField(x => x.IsArchived, "is_archived"); + registerQueryableMember(x => x.Version, "version"); + registerQueryableMember(x => x.Timestamp, "timestamp"); + registerQueryableMember(x => x.IsArchived, "is_archived"); - duplicateField(x => x.EventTypeName, "type"); - duplicateField(x => x.DotNetTypeName, SchemaConstants.DotNetTypeColumn); + registerQueryableMember(x => x.EventTypeName, "type"); + registerQueryableMember(x => x.DotNetTypeName, SchemaConstants.DotNetTypeColumn); if (storeOptions.EventGraph.Metadata.CorrelationId.Enabled) { - duplicateField(x => x.CorrelationId, storeOptions.EventGraph.Metadata.CorrelationId.Name); + registerQueryableMember(x => x.CorrelationId, storeOptions.EventGraph.Metadata.CorrelationId.Name); } if (storeOptions.EventGraph.Metadata.CausationId.Enabled) { - duplicateField(x => x.CausationId, storeOptions.EventGraph.Metadata.CausationId.Name); + registerQueryableMember(x => x.CausationId, storeOptions.EventGraph.Metadata.CausationId.Name); } } public override DbObjectName TableName { get; } - private DuplicatedField duplicateField(Expression> property, string columnName) + private void registerQueryableMember(Expression> property, string columnName) { - var finder = new FindMembers(); - finder.Visit(property); + var member = ReflectionHelper.GetProperty(property); - return DuplicateField(finder.Members.ToArray(), columnName: columnName); + var field = DuplicateField(new MemberInfo[] { member }, columnName: columnName); + QueryMembers.ReplaceMember(member, field); } } diff --git a/src/Marten/Events/EventStatement.cs b/src/Marten/Events/EventStatement.cs index 55314383363..2f0e4342e93 100644 --- a/src/Marten/Events/EventStatement.cs +++ b/src/Marten/Events/EventStatement.cs @@ -4,6 +4,7 @@ using JasperFx.Core; using Marten.Events.Archiving; using Marten.Events.Daemon; +using Marten.Linq; using Marten.Linq.SqlGeneration; using Marten.Storage; using Weasel.Postgresql; @@ -11,12 +12,12 @@ namespace Marten.Events; -internal class EventStatement: Statement +internal class EventStatement: SelectorStatement { private const string ALL_TENANTS = "~ALL~"; private readonly IEventStorage _storage; - public EventStatement(IEventStorage storage): base(storage.Fields) + public EventStatement(IEventStorage storage) { _storage = storage; } @@ -39,7 +40,7 @@ public EventStatement(IEventStorage storage): base(storage.Fields) protected override void configure(CommandBuilder builder) { - _storage.WriteSelectClause(builder); + _storage.Apply(builder); var wheres = filters().ToArray(); switch (wheres.Length) diff --git a/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs b/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs index c68a6e1a269..7df72dfdc92 100644 --- a/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs +++ b/src/Marten/Events/Projections/Flattened/FlatTableProjection.cs @@ -14,7 +14,6 @@ using Weasel.Postgresql.Tables; using JasperFx.Core.Reflection; using Weasel.Postgresql; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten.Events.Projections.Flattened; @@ -89,7 +88,7 @@ public void Project(Action> configure, Expression() - : FindMembers.Determine(tablePrimaryKeySource); + : MemberFinder.Determine(tablePrimaryKeySource); var map = new StatementMap(this, members); @@ -128,7 +127,7 @@ public void Delete(Expression>? tablePrimaryKeySource = null) var members = tablePrimaryKeySource == null ? Array.Empty() - : FindMembers.Determine(tablePrimaryKeySource); + : MemberFinder.Determine(tablePrimaryKeySource); _handlers.Add(new EventDeleter(typeof(T), members)); } diff --git a/src/Marten/Events/Projections/Flattened/MemberMap.cs b/src/Marten/Events/Projections/Flattened/MemberMap.cs index 37fd0277d90..6fa9664c896 100644 --- a/src/Marten/Events/Projections/Flattened/MemberMap.cs +++ b/src/Marten/Events/Projections/Flattened/MemberMap.cs @@ -18,7 +18,7 @@ internal class MemberMap: IColumnMap public MemberMap(Expression> members, string? tableColumn, ColumnMapType columnMapType) { - _members = FindMembers.Determine(members); + _members = MemberFinder.Determine(members); _mapType = columnMapType; ColumnName = tableColumn ?? _members.Select(x => x.Name.ToKebabCase()).Join("_"); diff --git a/src/Marten/Events/Querying/SingleEventQueryHandler.cs b/src/Marten/Events/Querying/SingleEventQueryHandler.cs index 6779d252cfb..a462c48d840 100644 --- a/src/Marten/Events/Querying/SingleEventQueryHandler.cs +++ b/src/Marten/Events/Querying/SingleEventQueryHandler.cs @@ -23,7 +23,7 @@ public SingleEventQueryHandler(Guid id, IEventStorage selector) public void ConfigureCommand(CommandBuilder sql, IMartenSession session) { - _selector.WriteSelectClause(sql); + _selector.Apply(sql); sql.Append(" where id = "); sql.AppendParameter(_id); diff --git a/src/Marten/Events/Schema/EventTableColumn.cs b/src/Marten/Events/Schema/EventTableColumn.cs index c9add5140c9..3199366c31a 100644 --- a/src/Marten/Events/Schema/EventTableColumn.cs +++ b/src/Marten/Events/Schema/EventTableColumn.cs @@ -12,7 +12,6 @@ using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.Tables; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten.Events.Schema; @@ -24,7 +23,7 @@ internal class EventTableColumn: TableColumn, IEventTableColumn public EventTableColumn(string name, Expression> eventMemberExpression): base(name, "varchar") { _eventMemberExpression = eventMemberExpression; - _member = FindMembers.Determine(eventMemberExpression).Single(); + _member = MemberFinder.Determine(eventMemberExpression).Single(); var memberType = _member.GetMemberType(); Type = PostgresqlProvider.Instance.GetDatabaseType(memberType, EnumStorage.AsInteger); NpgsqlDbType = PostgresqlProvider.Instance.ToParameterType(memberType); diff --git a/src/Marten/Events/Schema/StreamsTable.cs b/src/Marten/Events/Schema/StreamsTable.cs index 551292af720..d304f8f77da 100644 --- a/src/Marten/Events/Schema/StreamsTable.cs +++ b/src/Marten/Events/Schema/StreamsTable.cs @@ -13,7 +13,6 @@ using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.Tables; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten.Events.Schema; @@ -82,7 +81,7 @@ public StreamTableColumn(string name, Expression> mem "varchar") { _memberExpression = memberExpression; - _member = FindMembers.Determine(memberExpression).Single(); + _member = MemberFinder.Determine(memberExpression).Single(); var memberType = _member.GetMemberType(); Type = PostgresqlProvider.Instance.GetDatabaseType(memberType, EnumStorage.AsInteger); NpgsqlDbType = PostgresqlProvider.Instance.ToParameterType(memberType); diff --git a/src/Marten/Exceptions/BadLinqExpressionException.cs b/src/Marten/Exceptions/BadLinqExpressionException.cs index 60a93a284ae..37f9bd56c51 100644 --- a/src/Marten/Exceptions/BadLinqExpressionException.cs +++ b/src/Marten/Exceptions/BadLinqExpressionException.cs @@ -1,4 +1,5 @@ using System; +using System.Linq.Expressions; namespace Marten.Exceptions; #if SERIALIZE @@ -15,6 +16,10 @@ public BadLinqExpressionException(string message): base(message) { } + public BadLinqExpressionException(Expression expression) : this($"Marten can not (yet) support the Linq expression '{expression}'") + { + } + #if SERIALIZE protected BadLinqExpressionException(SerializationInfo info, StreamingContext context) : base(info, context) { diff --git a/src/Marten/IReadOnlyStoreOptions.cs b/src/Marten/IReadOnlyStoreOptions.cs index 074bd2aa255..3da729f7ae8 100644 --- a/src/Marten/IReadOnlyStoreOptions.cs +++ b/src/Marten/IReadOnlyStoreOptions.cs @@ -87,4 +87,6 @@ public interface IReadOnlyStoreOptions /// /// IDocumentType FindOrResolveDocumentType(Type documentType); + + void AssertDocumentTypeIsSoftDeleted(Type documentType); } diff --git a/src/Marten/Internal/CodeGeneration/FrameCollectionExtensions.cs b/src/Marten/Internal/CodeGeneration/FrameCollectionExtensions.cs index cb85b3c0500..a6c75fc9cc9 100644 --- a/src/Marten/Internal/CodeGeneration/FrameCollectionExtensions.cs +++ b/src/Marten/Internal/CodeGeneration/FrameCollectionExtensions.cs @@ -9,10 +9,10 @@ using JasperFx.CodeGeneration.Model; using JasperFx.Core; using JasperFx.Core.Reflection; +using Marten.Linq.Parsing; using Marten.Schema; using Marten.Util; using Weasel.Postgresql; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten.Internal.CodeGeneration; @@ -162,7 +162,7 @@ public static void AssignMemberFromReader(this GeneratedMethod method, Genera int index, Expression> memberExpression) { - var member = FindMembers.Determine(memberExpression).Single(); + var member = MemberFinder.Determine(memberExpression).Single(); var variableName = member.Name.ToCamelCase(); method.Frames.Code( $"var {variableName} = reader.GetFieldValue<{member.GetMemberType().FullNameInCode()}>({index});"); @@ -185,7 +185,7 @@ public static void AssignMemberFromReaderAsync(this GeneratedMethod method, G int index, Expression> memberExpression) { - var member = FindMembers.Determine(memberExpression).Single(); + var member = MemberFinder.Determine(memberExpression).Single(); var variableName = member.Name.ToCamelCase(); method.Frames.Code( $"var {variableName} = await reader.GetFieldValueAsync<{member.GetMemberType().FullNameInCode()}>({index}, {{0}}).ConfigureAwait(false);", @@ -244,7 +244,7 @@ public static void IfDbReaderValueIsNotNullAsync(this GeneratedMethod method, in public static void SetParameterFromMemberNonNullableString(this GeneratedMethod method, int index, Expression> memberExpression) { - var member = FindMembers.Determine(memberExpression).Single(); + var member = MemberFinder.Determine(memberExpression).Single(); method.Frames.Code($"parameters[{index}].Value = {{0}}.{member.Name};", Use.Type()); method.Frames.Code($"parameters[{index}].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;"); @@ -253,7 +253,7 @@ public static void SetParameterFromMemberNonNullableString(this GeneratedMeth public static void SetParameterFromMember(this GeneratedMethod method, int index, Expression> memberExpression) { - var member = FindMembers.Determine(memberExpression).Single(); + var member = MemberFinder.Determine(memberExpression).Single(); var memberType = member.GetMemberType(); var pgType = PostgresqlProvider.Instance.ToParameterType(memberType); diff --git a/src/Marten/Internal/CompiledQueries/ClonedCompiledQuery.cs b/src/Marten/Internal/CompiledQueries/ClonedCompiledQuery.cs index 06cfcc6d5d4..db37c6b68a4 100644 --- a/src/Marten/Internal/CompiledQueries/ClonedCompiledQuery.cs +++ b/src/Marten/Internal/CompiledQueries/ClonedCompiledQuery.cs @@ -45,7 +45,7 @@ public Task HandleAsync(DbDataReader reader, IMartenSession session, Cance protected string StartsWith(string value) { - return $"%{value}"; + return $"{value}%"; } protected string ContainsString(string value) @@ -55,6 +55,6 @@ protected string ContainsString(string value) protected string EndsWith(string value) { - return $"{value}%"; + return $"%{value}"; } } diff --git a/src/Marten/Internal/CompiledQueries/CompiledQueryCodeFile.cs b/src/Marten/Internal/CompiledQueries/CompiledQueryCodeFile.cs index d2659a87077..7e8ab2d4fa3 100644 --- a/src/Marten/Internal/CompiledQueries/CompiledQueryCodeFile.cs +++ b/src/Marten/Internal/CompiledQueries/CompiledQueryCodeFile.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -31,6 +32,7 @@ public void AssembleTypes(GeneratedAssembly assembly) { _builder = new CompiledQuerySourceBuilder(_plan, _store.Options, _documentTracking); _builder.AssembleTypes(assembly); + } public Task AttachTypes(GenerationRules rules, Assembly assembly, IServiceProvider services, diff --git a/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs b/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs index 930d63adf33..5f377a3b930 100644 --- a/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs +++ b/src/Marten/Internal/CompiledQueries/CompiledQueryPlan.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using JasperFx.CodeGeneration; using JasperFx.Core; using JasperFx.Core.Reflection; using Marten.Events.CodeGeneration; @@ -10,14 +9,16 @@ using Marten.Linq; using Marten.Linq.Includes; using Marten.Linq.QueryHandlers; +using Marten.Linq.SqlGeneration; using Marten.Schema.Arguments; -using Marten.Util; using Npgsql; namespace Marten.Internal.CompiledQueries; -public class CompiledQueryPlan +internal class CompiledQueryPlan { + public const string ParameterPlaceholder = "^"; + public CompiledQueryPlan(Type queryType, Type outputType) { QueryType = queryType; @@ -106,7 +107,7 @@ public string CorrectedCommandText() continue; } - text = text.Replace(":" + parameterName, "?"); + text = text.Replace(":" + parameterName, ParameterPlaceholder); } return text; @@ -154,9 +155,7 @@ private bool AreAllMemberValuesUnique(object query) public object TryCreateUniqueTemplate(Type type) { - var constructor = type.GetConstructors() - .OrderByDescending(x => x.GetParameters().Count()) - .FirstOrDefault(); + var constructor = type.GetConstructors().MaxBy(x => x.GetParameters().Count()); if (constructor == null) @@ -191,15 +190,20 @@ public object TryCreateUniqueTemplate(Type type) type.FullNameInCode()); } - public void ReadCommand(NpgsqlCommand command, StoreOptions storeOptions) + public void ReadCommand(NpgsqlCommand command, Statement statement, StoreOptions storeOptions) { Command = command; + var filters = statement.AllFilters().OfType().ToArray(); + var parameters = command.Parameters.ToList(); parameters.RemoveAll(x => x.ParameterName == TenantIdArgument.ArgName); - foreach (var parameter in Parameters) parameter.TryMatch(parameters, storeOptions); + foreach (var parameter in Parameters) + { + parameter.TryMatch(parameters, filters, storeOptions); + } - var missing = Parameters.Where(x => !x.ParameterIndexes.Any()); + var missing = Parameters.Where(x => !x.Usages.Any()); if (missing.Any()) { throw new InvalidCompiledQueryException( diff --git a/src/Marten/Internal/CompiledQueries/CompiledQuerySourceBuilder.cs b/src/Marten/Internal/CompiledQueries/CompiledQuerySourceBuilder.cs index affcfb4b006..e7e313d52d8 100644 --- a/src/Marten/Internal/CompiledQueries/CompiledQuerySourceBuilder.cs +++ b/src/Marten/Internal/CompiledQueries/CompiledQuerySourceBuilder.cs @@ -59,8 +59,6 @@ public ICompiledQuerySource Build(Type sourceType) private void buildSourceType(GeneratedAssembly assembly, CompiledSourceType handlerType, GeneratedType compiledHandlerType) { - var rules = _storeOptions.CreateGenerationRules(); - var sourceBaseType = typeof(CompiledQuerySource<,>).MakeGenericType(_plan.OutputType, _plan.QueryType); var sourceType = assembly.AddType(_typeName, sourceBaseType); @@ -185,7 +183,7 @@ private void configureCommandMethod(GeneratedType compiledType, HardCodedParamet var method = compiledType.MethodFor(nameof(IQueryHandler.ConfigureCommand)); var correctedCommandText = _plan.CorrectedCommandText(); - method.Frames.Code($"var parameters = {{0}}.{nameof(CommandBuilder.AppendWithParameters)}(@{{1}});", + method.Frames.Code($"var parameters = {{0}}.{nameof(CommandBuilder.AppendWithParameters)}(@{{1}}, '{CompiledQueryPlan.ParameterPlaceholder}');", Use.Type(), correctedCommandText); foreach (var parameter in _plan.Parameters) parameter.GenerateCode(method, _storeOptions); @@ -236,4 +234,5 @@ private CompiledSourceType determineHandlerType() return CompiledSourceType.Stateless; } + } diff --git a/src/Marten/Internal/CompiledQueries/FieldQueryMember.cs b/src/Marten/Internal/CompiledQueries/FieldQueryMember.cs index 73c471f5851..28ab7914c0f 100644 --- a/src/Marten/Internal/CompiledQueries/FieldQueryMember.cs +++ b/src/Marten/Internal/CompiledQueries/FieldQueryMember.cs @@ -2,7 +2,7 @@ namespace Marten.Internal.CompiledQueries; -public class FieldQueryMember: QueryMember +internal class FieldQueryMember: QueryMember { private readonly FieldInfo _field; diff --git a/src/Marten/Internal/CompiledQueries/HardCodedParameters.cs b/src/Marten/Internal/CompiledQueries/HardCodedParameters.cs index 46fa49b03d0..eadf1407596 100644 --- a/src/Marten/Internal/CompiledQueries/HardCodedParameters.cs +++ b/src/Marten/Internal/CompiledQueries/HardCodedParameters.cs @@ -10,7 +10,7 @@ public class HardCodedParameters { private readonly IDictionary _parameters = new Dictionary(); - public HardCodedParameters(CompiledQueryPlan plan) + internal HardCodedParameters(CompiledQueryPlan plan) { var parameters = plan.Command.Parameters; HasTenantId = parameters.Any(x => x.ParameterName == TenantIdArgument.ArgName); @@ -22,7 +22,7 @@ public HardCodedParameters(CompiledQueryPlan plan) for (var i = 0; i < parameters.Count; i++) { - if (plan.Parameters.All(x => !x.ParameterIndexes.Contains(i))) + if (plan.Parameters.All(x => !x.Usages.Any(x => x.Index == i))) { Record(i, parameters[i]); } diff --git a/src/Marten/Internal/CompiledQueries/ICompiledQueryAwareFilter.cs b/src/Marten/Internal/CompiledQueries/ICompiledQueryAwareFilter.cs new file mode 100644 index 00000000000..91b28268aae --- /dev/null +++ b/src/Marten/Internal/CompiledQueries/ICompiledQueryAwareFilter.cs @@ -0,0 +1,72 @@ +using System; +using System.Reflection; +using JasperFx.CodeGeneration; +using JasperFx.Core.Reflection; +using NpgsqlTypes; +using Weasel.Core; +using Weasel.Postgresql; + +namespace Marten.Internal.CompiledQueries; + +/// +/// This marker interface is used for SQL fragment filters where +/// there needs to be some special handling within compiled queries +/// +public interface ICompiledQueryAwareFilter +{ + bool TryMatchValue(object value, MemberInfo member); + void GenerateCode(GeneratedMethod method, int parameterIndex); + + string ParameterName { get; } +} + + +internal record CompiledParameterApplication(int Index, ICompiledQueryAwareFilter? Filter) +{ + public void GenerateCode(GeneratedMethod method, StoreOptions storeOptions, MemberInfo member) + { + if (Filter != null) + { + Filter.GenerateCode(method, Index); + } + else + { + var memberType = member.GetRawMemberType(); + + if (memberType!.IsEnum) + { + generateEnumCode(method, storeOptions, member); + } + else + { + generateSimpleCode(method, member, memberType); + } + } + } + + private void generateSimpleCode(GeneratedMethod method, MemberInfo member, Type memberType) + { + method.Frames.Code($@" +parameters[{Index}].NpgsqlDbType = {{0}}; +parameters[{Index}].Value = _query.{member.Name}; +", PostgresqlProvider.Instance.ToParameterType(memberType)); + } + + private void generateEnumCode(GeneratedMethod method, StoreOptions storeOptions, MemberInfo member) + { + if (storeOptions.Serializer().EnumStorage == EnumStorage.AsInteger) + { + method.Frames.Code($@" +parameters[{Index}].NpgsqlDbType = {{0}}; +parameters[{Index}].Value = (int)_query.{member.Name}; +", NpgsqlDbType.Integer); + } + else + { + method.Frames.Code($@" +parameters[{Index}].NpgsqlDbType = {{0}}; +parameters[{Index}].Value = _query.{member.Name}.ToString(); +", NpgsqlDbType.Varchar); + } + } +} diff --git a/src/Marten/Internal/CompiledQueries/IQueryMember.cs b/src/Marten/Internal/CompiledQueries/IQueryMember.cs index f863572479f..acb8aeeac5d 100644 --- a/src/Marten/Internal/CompiledQueries/IQueryMember.cs +++ b/src/Marten/Internal/CompiledQueries/IQueryMember.cs @@ -6,16 +6,17 @@ namespace Marten.Internal.CompiledQueries; -public interface IQueryMember +internal interface IQueryMember { Type Type { get; } MemberInfo Member { get; } - IList ParameterIndexes { get; } + List Usages { get; } bool CanWrite(); void GenerateCode(GeneratedMethod method, StoreOptions storeOptions); void StoreValue(object query); - void TryMatch(List parameters, StoreOptions storeOptions); + void TryMatch(List parameters, ICompiledQueryAwareFilter[] filters, + StoreOptions storeOptions); void TryWriteValue(UniqueValueSource valueSource, object query); object GetValueAsObject(object query); } diff --git a/src/Marten/Internal/CompiledQueries/PropertyQueryMember.cs b/src/Marten/Internal/CompiledQueries/PropertyQueryMember.cs index 8b31a9747c9..e17a4ea51e2 100644 --- a/src/Marten/Internal/CompiledQueries/PropertyQueryMember.cs +++ b/src/Marten/Internal/CompiledQueries/PropertyQueryMember.cs @@ -2,7 +2,7 @@ namespace Marten.Internal.CompiledQueries; -public class PropertyQueryMember: QueryMember +internal class PropertyQueryMember: QueryMember { private readonly PropertyInfo _property; diff --git a/src/Marten/Internal/CompiledQueries/QueryCompiler.cs b/src/Marten/Internal/CompiledQueries/QueryCompiler.cs index 8fb78b8a807..d5582e1a089 100644 --- a/src/Marten/Internal/CompiledQueries/QueryCompiler.cs +++ b/src/Marten/Internal/CompiledQueries/QueryCompiler.cs @@ -10,8 +10,10 @@ using Marten.Linq; using Marten.Linq.Includes; using Marten.Linq.Parsing; +using Marten.Linq.SqlGeneration; using Marten.Util; using Npgsql; +using Weasel.Postgresql; namespace Marten.Internal.CompiledQueries; @@ -152,7 +154,7 @@ public static CompiledQueryPlan BuildPlan(QuerySession session, ICom var queryTemplate = plan.CreateQueryTemplate(query); var statistics = plan.GetStatisticsIfAny(query); - var builder = BuildDatabaseCommand(session, queryTemplate, statistics, out var command); + var (builder, statement) = BuildDatabaseCommand(session, queryTemplate, statistics, out var command); plan.IncludePlans.AddRange(new List()); var handler = builder.BuildHandler(); @@ -163,26 +165,31 @@ public static CompiledQueryPlan BuildPlan(QuerySession session, ICom plan.HandlerPrototype = handler; - plan.ReadCommand(command, storeOptions); + plan.ReadCommand(command, statement, storeOptions); return plan; } - internal static LinqHandlerBuilder BuildDatabaseCommand(QuerySession session, + internal static (LinqQueryParser, Statement) BuildDatabaseCommand(QuerySession session, ICompiledQuery queryTemplate, QueryStatistics statistics, out NpgsqlCommand command) { Expression expression = queryTemplate.QueryIs(); - var invocation = Expression.Invoke(expression, Expression.Parameter(typeof(IMartenQueryable))); + if (expression is LambdaExpression lambda) expression = lambda.Body; - var builder = new LinqHandlerBuilder(new MartenLinqQueryProvider(session) { Statistics = statistics }, session, - invocation, forCompiled: true); + var parser = new LinqQueryParser( + new MartenLinqQueryProvider(session, typeof(TDoc)) { Statistics = statistics }, session, + expression); - command = builder.BuildDatabaseCommand(statistics); + var statements = parser.BuildStatements(); + var builder = new CommandBuilder(); + var topStatement = statements.Top; + topStatement.Apply(builder); + command = builder.Compile(); - return builder; + return (parser, topStatement); } private static void eliminateStringNulls(object query) diff --git a/src/Marten/Internal/CompiledQueries/QueryMember.cs b/src/Marten/Internal/CompiledQueries/QueryMember.cs index 8075c0090b7..fe72553c9a9 100644 --- a/src/Marten/Internal/CompiledQueries/QueryMember.cs +++ b/src/Marten/Internal/CompiledQueries/QueryMember.cs @@ -13,14 +13,14 @@ namespace Marten.Internal.CompiledQueries; -public interface IQueryMember: IQueryMember +internal interface IQueryMember: IQueryMember { T Value { get; } T GetValue(object query); void SetValue(object query, T value); } -public abstract class QueryMember: IQueryMember +internal abstract class QueryMember: IQueryMember { protected QueryMember(MemberInfo member) { @@ -45,7 +45,8 @@ public void StoreValue(object query) Value = GetValue(query); } - public void TryMatch(List parameters, StoreOptions storeOptions) + public void TryMatch(List parameters, ICompiledQueryAwareFilter[] filters, + StoreOptions storeOptions) { if (Type.IsEnum) { @@ -53,26 +54,10 @@ public void TryMatch(List parameters, StoreOptions storeOptions ? Value.As() : (object)Value.ToString(); - tryToFind(parameters, parameterValue); + tryToFind(parameters, filters, parameterValue); } - // These methods are on the ClonedCompiledQuery base class, and are - // used to set the right parameters - if (!tryToFind(parameters, Value) && Type == typeof(string)) - { - if (tryToFind(parameters, $"%{Value}")) - { - Mask = "StartsWith({0})"; - } - else if (tryToFind(parameters, $"%{Value}%")) - { - Mask = "ContainsString({0})"; - } - else if (tryToFind(parameters, $"{Value}%")) - { - Mask = "EndsWith({0})"; - } - } + tryToFind(parameters, filters, Value); } public void TryWriteValue(UniqueValueSource valueSource, object query) @@ -91,78 +76,38 @@ public void TryWriteValue(UniqueValueSource valueSource, object query) public MemberInfo Member { get; } - public IList ParameterIndexes { get; } = new List(); + public List Usages { get; } = new(); public void GenerateCode(GeneratedMethod method, StoreOptions storeOptions) { - if (Type.IsEnum) - { - generateEnumSetter(method, storeOptions); - } - else if (Mask == null) - { - generateBasicSetter(method); - } - else - { - generateMaskedStringCode(method); - } - } - - private bool tryToFind(List parameters, object value) - { - var matching = parameters.Where(x => value.Equals(x.Value)); - foreach (var parameter in matching) + foreach (var usage in Usages) { - var index = parameters.IndexOf(parameter); - ParameterIndexes.Add(index); + usage.GenerateCode(method, storeOptions, Member); } - - return ParameterIndexes.Any(); } - private void generateEnumSetter(GeneratedMethod method, StoreOptions storeOptions) + private bool tryToFind(List parameters, ICompiledQueryAwareFilter[] filters, + object value) { - foreach (var index in ParameterIndexes) + for (var i = 0; i < parameters.Count; i++) { - if (storeOptions.Serializer().EnumStorage == EnumStorage.AsInteger) + var parameter = parameters[i]; + if (filters.All(x => x.ParameterName != parameter.ParameterName) && value.Equals(parameter.Value)) { - method.Frames.Code($@" -parameters[{index}].NpgsqlDbType = {{0}}; -parameters[{index}].Value = (int)_query.{Member.Name}; -", NpgsqlDbType.Integer); - } - else - { - method.Frames.Code($@" -parameters[{index}].NpgsqlDbType = {{0}}; -parameters[{index}].Value = _query.{Member.Name}.ToString(); -", NpgsqlDbType.Varchar); + Usages.Add(new CompiledParameterApplication(i, null)); } } - } - private void generateMaskedStringCode(GeneratedMethod method) - { - var maskedValue = Mask.ToFormat($"_query.{Member.Name}"); - - foreach (var index in ParameterIndexes) + foreach (var filter in filters) { - method.Frames.Code($@" -parameters[{index}].NpgsqlDbType = {{0}}; -parameters[{index}].Value = {maskedValue}; -", PostgresqlProvider.Instance.ToParameterType(Member.GetMemberType())); + var parameter = parameters.FirstOrDefault(x => x.ParameterName == filter.ParameterName); + if (filter.TryMatchValue(value, Member)) + { + var index = parameters.IndexOf(parameter); + Usages.Add(new CompiledParameterApplication(index, filter)); + } } - } - private void generateBasicSetter(GeneratedMethod method) - { - foreach (var index in ParameterIndexes) - { - method.Frames.Code($@" -parameters[{index}].NpgsqlDbType = {{0}}; -parameters[{index}].Value = _query.{Member.Name}; -", PostgresqlProvider.Instance.ToParameterType(Member.GetMemberType())); - } + return Usages.Any(); } } diff --git a/src/Marten/Internal/Sessions/DocumentSessionBase.HardDeletes.cs b/src/Marten/Internal/Sessions/DocumentSessionBase.HardDeletes.cs index 5f9fd63396d..e7d7066285a 100644 --- a/src/Marten/Internal/Sessions/DocumentSessionBase.HardDeletes.cs +++ b/src/Marten/Internal/Sessions/DocumentSessionBase.HardDeletes.cs @@ -4,8 +4,8 @@ using System.Linq.Expressions; using Marten.Exceptions; using Marten.Internal.Storage; -using Marten.Linq.Filters; using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; using Weasel.Postgresql.SqlGeneration; namespace Marten.Internal.Sessions; diff --git a/src/Marten/Internal/Sessions/QuerySession.Querying.cs b/src/Marten/Internal/Sessions/QuerySession.Querying.cs index b14ad7a6044..948617f5e0f 100644 --- a/src/Marten/Internal/Sessions/QuerySession.Querying.cs +++ b/src/Marten/Internal/Sessions/QuerySession.Querying.cs @@ -33,7 +33,7 @@ public IReadOnlyList Query(string sql, params object[] parameters) Database.EnsureStorageExists(typeof(T)); } - var provider = new MartenLinqQueryProvider(this); + var provider = new MartenLinqQueryProvider(this, typeof(T)); return provider.ExecuteHandler(handler); } @@ -48,7 +48,7 @@ public async Task> QueryAsync(string sql, CancellationToken await Database.EnsureStorageExistsAsync(typeof(T), token).ConfigureAwait(false); } - var provider = new MartenLinqQueryProvider(this); + var provider = new MartenLinqQueryProvider(this, typeof(T)); return await provider.ExecuteHandlerAsync(handler, token).ConfigureAwait(false); } diff --git a/src/Marten/Internal/Storage/DocumentStorage.cs b/src/Marten/Internal/Storage/DocumentStorage.cs index 8c7e5227e42..702370aecc5 100644 --- a/src/Marten/Internal/Storage/DocumentStorage.cs +++ b/src/Marten/Internal/Storage/DocumentStorage.cs @@ -11,25 +11,31 @@ using Marten.Internal.Operations; using Marten.Internal.Sessions; using Marten.Linq; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; using Marten.Schema; using Marten.Services; using Marten.Storage; +using Marten.Storage.Metadata; using Npgsql; using NpgsqlTypes; -using Remotion.Linq; using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; namespace Marten.Internal.Storage; -public abstract class DocumentStorage: IDocumentStorage where T : notnull where TId : notnull + +internal interface IHaveMetadataColumns +{ + MetadataColumn[] MetadataColumns(); +} + +public abstract class DocumentStorage: IDocumentStorage, IHaveMetadataColumns where T : notnull where TId : notnull { private readonly NpgsqlDbType _idType; @@ -45,7 +51,6 @@ public DocumentStorage(StorageStyle storageStyle, DocumentMapping document) { _mapping = document; - Fields = document; TableName = document.TableName; determineDefaultWhereFragment(); @@ -54,10 +59,27 @@ public DocumentStorage(StorageStyle storageStyle, DocumentMapping document) var table = _mapping.Schema.Table; + DuplicatedFields = _mapping.DuplicatedFields; + _selectFields = table.SelectColumns(storageStyle).Select(x => $"d.{x.Name}").ToArray(); var fieldSelector = _selectFields.Join(", "); _selectClause = $"select {fieldSelector} from {document.TableName.QualifiedName} as d"; + + if (DuplicatedFields.Any()) + { + var duplicatedFields = DuplicatedFields.Select(x => "d." + x.ColumnName).Where(x => !_selectFields.Contains(x)); + var allFields = _selectFields.Concat(duplicatedFields).ToArray(); + SelectClauseWithDuplicatedFields = new DuplicatedFieldSelectClause(TableName.QualifiedName, $"select {allFields.Join(", ")} from {document.TableName.QualifiedName} as d", + allFields, typeof(T), this); + } + else + { + SelectClauseWithDuplicatedFields = this; + } + + + _loaderSql = $"select {fieldSelector} from {document.TableName.QualifiedName} as d where id = :id"; @@ -80,10 +102,17 @@ public DocumentStorage(StorageStyle storageStyle, DocumentMapping document) : new SoftDelete(this); HardDeleteFragment = new HardDelete(this); + } - DuplicatedFields = _mapping.DuplicatedFields; + public ISelectClause SelectClauseWithDuplicatedFields { get; } + + MetadataColumn[] IHaveMetadataColumns.MetadataColumns() + { + return _mapping.Schema.Table.Columns.OfType().ToArray(); } + public IQueryableMemberCollection QueryMembers => _mapping.QueryMembers; + public void TruncateDocumentStorage(IMartenDatabase database) { try @@ -105,7 +134,7 @@ public async Task TruncateDocumentStorageAsync(IMartenDatabase database, Cancell var sql = "truncate {0} cascade".ToFormat(TableName.QualifiedName); try { - await database.RunSqlAsync(sql, ct: ct).ConfigureAwait(false); + await database.RunSqlAsync(sql, ct).ConfigureAwait(false); } catch (PostgresException e) { @@ -126,7 +155,7 @@ public void SetIdentity(T document, TId identity) public Type DocumentType => _mapping.DocumentType; - public DuplicatedField[] DuplicatedFields { get; } + public IReadOnlyList DuplicatedFields { get; } public ISqlFragment ByIdFilter(TId id) { @@ -137,13 +166,13 @@ public IDeletion HardDeleteForId(TId id, string tenant) { if (TenancyStyle == TenancyStyle.Conjoined) { - return new Deletion(this, HardDeleteFragment) + return new Deletion(this, HardDeleteFragment, CompoundWhereFragment.And(new SpecificTenantFilter(tenant), ByIdFilter(id))) { - Where = CompoundWhereFragment.And(new SpecificTenantFilter(tenant), ByIdFilter(id)), Id = id + Id = id }; } - return new Deletion(this, HardDeleteFragment) { Where = ByIdFilter(id), Id = id }; + return new Deletion(this, HardDeleteFragment, ByIdFilter(id)) { Id = id }; } public void EjectById(IMartenSession session, object id) @@ -235,20 +264,23 @@ public IDeletion DeleteForId(TId id, string tenant) { if (TenancyStyle == TenancyStyle.Conjoined) { - return new Deletion(this, DeleteFragment) + return new Deletion(this, DeleteFragment, CompoundWhereFragment.And(new SpecificTenantFilter(tenant), ByIdFilter(id))) { - Where = CompoundWhereFragment.And(new SpecificTenantFilter(tenant), ByIdFilter(id)), Id = id + Id = id }; } - return new Deletion(this, DeleteFragment) { Where = ByIdFilter(id), Id = id }; + return new Deletion(this, DeleteFragment, ByIdFilter(id)) + { + Id = id + }; } public IOperationFragment DeleteFragment { get; } public IOperationFragment HardDeleteFragment { get; } - public ISqlFragment FilterDocuments(QueryModel? model, ISqlFragment query, IMartenSession session) + public ISqlFragment FilterDocuments(ISqlFragment query, IMartenSession session) { var extras = extraFilters(query, session).ToList(); @@ -266,8 +298,6 @@ public ISqlFragment FilterDocuments(QueryModel? model, ISqlFragment query, IMart return _defaultWhere; } - public IFieldMapping Fields { get; } - public abstract T? Load(TId id, IMartenSession session); public abstract Task LoadAsync(TId id, IMartenSession session, CancellationToken token); @@ -279,11 +309,16 @@ public ISqlFragment FilterDocuments(QueryModel? model, ISqlFragment query, IMart public abstract TId Identity(T document); - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { sql.Append(_selectClause); } + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + public string[] SelectFields() { return _selectFields; @@ -291,12 +326,12 @@ public string[] SelectFields() public abstract ISelector BuildSelector(IMartenSession session); - public IQueryHandler BuildHandler(IMartenSession session, Statement statement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment statement, + ISqlFragment currentStatement) { var selector = (ISelector)BuildSelector(session); - return LinqHandlerBuilder.BuildHandler(selector, statement); + return LinqQueryParser.BuildHandler(selector, statement); } public ISelectClause UseStatistics(QueryStatistics statistics) @@ -365,3 +400,54 @@ private IEnumerable defaultFilters() return session.As().LoadOneAsync(command, selector, token); } } + + +internal class DuplicatedFieldSelectClause: ISelectClause +{ + private readonly string _selector; + private readonly string[] _selectFields; + private readonly IDocumentStorage _parent; + + public DuplicatedFieldSelectClause(string fromObject, string selector, string[] selectFields, Type selectedType, + IDocumentStorage parent) + { + FromObject = fromObject; + _selector = selector; + _selectFields = selectFields; + _parent = parent; + SelectedType = selectedType; + } + + public void Apply(CommandBuilder builder) + { + builder.Append(_selector); + } + + public bool Contains(string sqlText) + { + return _selector.Contains(sqlText); + } + + public string FromObject { get; } + + public Type SelectedType { get; } + public string[] SelectFields() + { + return _selectFields; + } + + public ISelector BuildSelector(IMartenSession session) + { + return _parent.BuildSelector(session); + } + + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment topStatement, ISqlFragment currentStatement) + { + return _parent.BuildHandler(session, topStatement, currentStatement); + } + + public ISelectClause UseStatistics(QueryStatistics statistics) + { + throw new NotSupportedException(); + } +} diff --git a/src/Marten/Internal/Storage/IDocumentStorage.cs b/src/Marten/Internal/Storage/IDocumentStorage.cs index f175b97f059..75f706302b7 100644 --- a/src/Marten/Internal/Storage/IDocumentStorage.cs +++ b/src/Marten/Internal/Storage/IDocumentStorage.cs @@ -6,16 +6,16 @@ using JasperFx.CodeGeneration; using JasperFx.CodeGeneration.Model; using Marten.Internal.Operations; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq; +using Marten.Linq.Members; using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; using Marten.Schema; using Marten.Schema.Arguments; using Marten.Schema.BulkLoading; using Marten.Services; using Marten.Storage; using Npgsql; -using Remotion.Linq; using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; @@ -28,12 +28,10 @@ public interface IDocumentStorage: ISelectClause Type IdType { get; } - IFieldMapping Fields { get; } - bool UseOptimisticConcurrency { get; } IOperationFragment DeleteFragment { get; } IOperationFragment HardDeleteFragment { get; } - DuplicatedField[] DuplicatedFields { get; } + IReadOnlyList DuplicatedFields { get; } DbObjectName TableName { get; } Type DocumentType { get; } @@ -43,9 +41,16 @@ public interface IDocumentStorage: ISelectClause [Obsolete("Use async method instead.")] void TruncateDocumentStorage(IMartenDatabase database); - ISqlFragment FilterDocuments(QueryModel? model, ISqlFragment query, IMartenSession session); + ISqlFragment FilterDocuments(ISqlFragment query, IMartenSession session); ISqlFragment? DefaultWhereFragment(); + + IQueryableMemberCollection QueryMembers { get; } + + /// + /// Necessary (maybe) for usage within the temporary tables when using Includes() + /// + ISelectClause SelectClauseWithDuplicatedFields { get; } } internal class CreateFromDocumentMapping: Variable diff --git a/src/Marten/Internal/Storage/SubClassDocumentStorage.cs b/src/Marten/Internal/Storage/SubClassDocumentStorage.cs index 82ca4f2c6a7..dc501a837a1 100644 --- a/src/Marten/Internal/Storage/SubClassDocumentStorage.cs +++ b/src/Marten/Internal/Storage/SubClassDocumentStorage.cs @@ -4,26 +4,27 @@ using System.Threading; using System.Threading.Tasks; using JasperFx.Core; +using JasperFx.Core.Reflection; using Marten.Internal.Operations; using Marten.Linq; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; using Marten.Schema; using Marten.Services; using Marten.Storage; +using Marten.Storage.Metadata; using Npgsql; -using Remotion.Linq; using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; namespace Marten.Internal.Storage; -internal class SubClassDocumentStorage: IDocumentStorage +internal class SubClassDocumentStorage: IDocumentStorage, IHaveMetadataColumns where T : TRoot { private readonly ISqlFragment _defaultWhere; @@ -42,6 +43,9 @@ public SubClassDocumentStorage(IDocumentStorage parent, SubClassMapp _fields = _parent.SelectFields(); } + public IQueryableMemberCollection QueryMembers => _mapping.QueryMembers; + public ISelectClause SelectClauseWithDuplicatedFields => _parent.SelectClauseWithDuplicatedFields; + public void TruncateDocumentStorage(IMartenDatabase database) { database.RunSql( @@ -65,9 +69,14 @@ object IDocumentStorage.IdentityFor(T document) public string FromObject { get; } public Type SelectedType => typeof(T); - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) + { + _parent.Apply(sql); + } + + public bool Contains(string sqlText) { - _parent.WriteSelectClause(sql); + return false; } public string[] SelectFields() @@ -81,12 +90,12 @@ public ISelector BuildSelector(IMartenSession session) return new CastingSelector((ISelector)inner); } - public IQueryHandler BuildHandler(IMartenSession session, Statement statement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment statement, + ISqlFragment currentStatement) { var selector = (ISelector)BuildSelector(session); - return LinqHandlerBuilder.BuildHandler(selector, statement); + return LinqQueryParser.BuildHandler(selector, statement); } public ISelectClause UseStatistics(QueryStatistics statistics) @@ -95,9 +104,8 @@ public ISelectClause UseStatistics(QueryStatistics statistics) } public Type SourceType => typeof(TRoot); - public IFieldMapping Fields => _mapping.Parent; - public ISqlFragment FilterDocuments(QueryModel model, ISqlFragment query, IMartenSession session) + public ISqlFragment FilterDocuments(ISqlFragment query, IMartenSession session) { var extras = extraFilters(query).ToArray(); @@ -113,7 +121,7 @@ public ISqlFragment DefaultWhereFragment() public bool UseOptimisticConcurrency => _parent.UseOptimisticConcurrency; public IOperationFragment DeleteFragment => _parent.DeleteFragment; public IOperationFragment HardDeleteFragment { get; } - public DuplicatedField[] DuplicatedFields => _parent.DuplicatedFields; + public IReadOnlyList DuplicatedFields => _parent.DuplicatedFields; public DbObjectName TableName => _parent.TableName; public Type DocumentType => typeof(T); @@ -302,4 +310,9 @@ private WhereFragment toBasicWhere() var sql = _mapping.Alias.Length > 1 ? $"({aliasValues})" : aliasValues; return new WhereFragment(sql); } + + public MetadataColumn[] MetadataColumns() + { + return _parent.As().MetadataColumns(); + } } diff --git a/src/Marten/Linq/CollectionUsage.Compilation.cs b/src/Marten/Linq/CollectionUsage.Compilation.cs new file mode 100644 index 00000000000..cd68fe1195d --- /dev/null +++ b/src/Marten/Linq/CollectionUsage.Compilation.cs @@ -0,0 +1,300 @@ +#nullable enable + +using System; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Internal; +using Marten.Internal.Storage; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; + +namespace Marten.Linq; + +public partial class CollectionUsage +{ + private bool _hasCompiledMany; + + public Statement BuildTopStatement(IMartenSession session, IQueryableMemberCollection collection, + IDocumentStorage storage) + { + var statement = new SelectorStatement + { + SelectClause = storage, Limit = _limit, Offset = _offset, IsDistinct = IsDistinct + }; + + foreach (var ordering in OrderingExpressions) + statement.Ordering.Expressions.Add(ordering.BuildExpression(collection)); + + statement.ParseWhereClause(WhereExpressions, session, collection, storage); + + if (SelectExpression != null) + { + var visitor = new SelectorVisitor(statement, collection, _options.Serializer()); + visitor.Visit(SelectExpression); + + if (Inner != null) + { + IsAny = IsAny || Inner.IsAny; + SingleValueMode ??= Inner.SingleValueMode; + IsDistinct = Inner.IsDistinct; + statement.Limit ??= Inner._limit; + statement.Offset ??= Inner._offset; + } + } + + ProcessSingleValueModeIfAny(statement); + + compileNext(session, collection, statement); + + if (IsDistinct) + { + statement.ApplySqlOperator("DISTINCT"); + } + + return statement.Top(); + } + + + public Statement BuildStatement(IMartenSession session, IQueryableMemberCollection collection, + ISelectClause selectClause) + { + var statement = new SelectorStatement + { + SelectClause = selectClause ?? throw new ArgumentNullException(nameof(selectClause)), + Limit = _limit, + Offset = _offset, + IsDistinct = IsDistinct + }; + + foreach (var ordering in OrderingExpressions) + statement.Ordering.Expressions.Add(ordering.BuildExpression(collection)); + + statement.ParseWhereClause(WhereExpressions, session, collection); + + if (SelectExpression != null) + { + var visitor = new SelectorVisitor(statement, collection, _options.Serializer()); + visitor.Visit(SelectExpression); + + if (Inner != null) + { + IsAny = IsAny || Inner.IsAny; + SingleValueMode ??= Inner.SingleValueMode; + IsDistinct = Inner.IsDistinct; + statement.Limit ??= Inner._limit; + statement.Offset ??= Inner._offset; + } + } + + ProcessSingleValueModeIfAny(statement); + + compileNext(session, collection, statement); + + if (IsDistinct) + { + statement.ApplySqlOperator("DISTINCT"); + } + + return statement.Top(); + } + + + private void compileNext(IMartenSession session, IQueryableMemberCollection collection, + SelectorStatement statement) + { + if (SelectMany != null) + { + var selection = statement.SelectorStatement(); + var collectionMember = (ICollectionMember)collection.MemberFor(SelectMany); + + // You might now already have another collection usage if the statement ends with + // SelectMany() + + if (Inner == null) + { + if (SingleValueMode == Marten.Linq.Parsing.SingleValueMode.Any) + { + var filter = new CollectionIsNotEmpty(collectionMember); + selection.Wheres.Add(filter); + selection.SelectClause = new AnySelectClause(selection.SelectClause.FromObject); + } + else if (SingleValueMode == Marten.Linq.Parsing.SingleValueMode.Count) + { + selection.SelectClause = new NewScalarSelectClause( + $"jsonb_array_length({collectionMember.JSONBLocator})", selection.SelectClause.FromObject); + + selection.ApplyAggregateOperator("SUM"); + } + else + { + var next = new CollectionUsage(_options, collectionMember.MemberType); + next.CompileSelectMany(session, this, selection, collectionMember); + } + } + else + { + Inner.CompileSelectMany(session, this, selection, collectionMember); + } + } + else + { + Inner?.CompileAsChild(this, statement); + } + } + + public void CompileSelectMany(IMartenSession session, CollectionUsage parent, + SelectorStatement parentStatement, ICollectionMember collectionMember) + { + if (_hasCompiledMany) + { + return; + } + + _hasCompiledMany = true; + + parentStatement.Mode = StatementMode.CommonTableExpression; + parentStatement.ExportName = session.NextTempTableName() + "CTE"; + + parentStatement.SelectClause = + collectionMember.BuildSelectClauseForExplosion(parentStatement.SelectClause.FromObject); + + + // THINK THIS IS TOO SOON. MUCH OF THE LOGIC NEEDS TO GO IN THIS INSTEAD!!! + var childStatement = collectionMember.BuildChildStatement(this, session, parentStatement); + + childStatement.IsDistinct = IsDistinct; + childStatement.Limit = _limit; + childStatement.Offset = _offset; + + if (IsDistinct) + { + if (childStatement.SelectClause is IScalarSelectClause c) + { + c.ApplyOperator("DISTINCT"); + parentStatement.InsertAfter(childStatement.SelectorStatement()); + } + else if (childStatement.SelectClause is ICountClause count) + { + if (collectionMember is IQueryableMemberCollection members) + { + // It places itself at the back in this constructor function + var distinct = new DistinctSelectionStatement(parentStatement, count, session); + compileNext(session, members, distinct.SelectorStatement()); + } + else + { + throw new BadLinqExpressionException("See https://github.com/JasperFx/marten/issues/2704"); + } + + + + return; + } + } + else + { + parentStatement.InsertAfter(childStatement); + } + + compileNext(session, collectionMember as IQueryableMemberCollection, childStatement); + } + + public void CompileAsChild(CollectionUsage parent, SelectorStatement parentStatement) + { + if (ElementType.IsSimple() || ElementType == typeof(Guid) || ElementType == typeof(Guid?)) + { + if (IsDistinct) + { + parent.IsDistinct = IsDistinct; + } + } + } + + internal void ProcessSingleValueModeIfAny(SelectorStatement statement) + { + if (IsAny || SingleValueMode == Marten.Linq.Parsing.SingleValueMode.Any) + { + statement.SelectClause = new AnySelectClause(statement.SelectClause.FromObject); + statement.Limit = 1; + return; + } + + if (SingleValueMode.HasValue) + { + switch (SingleValueMode) + { + case Marten.Linq.Parsing.SingleValueMode.First: + statement.SingleValue = true; + statement.CanBeMultiples = true; + statement.ReturnDefaultWhenEmpty = false; + statement.Limit ??= 1; + break; + + case Marten.Linq.Parsing.SingleValueMode.FirstOrDefault: + statement.SingleValue = true; + statement.CanBeMultiples = true; + statement.ReturnDefaultWhenEmpty = true; + statement.Limit ??= 1; + break; + + case Marten.Linq.Parsing.SingleValueMode.Single: + statement.SingleValue = true; + statement.CanBeMultiples = false; + statement.ReturnDefaultWhenEmpty = false; + statement.Limit ??= 2; + break; + + case Marten.Linq.Parsing.SingleValueMode.SingleOrDefault: + statement.SingleValue = true; + statement.CanBeMultiples = false; + statement.ReturnDefaultWhenEmpty = true; + statement.Limit ??= 2; + break; + + case Marten.Linq.Parsing.SingleValueMode.Count: + if (statement.IsDistinct) + { + throw new NotImplementedException("Not yet"); + // statement.ConvertToCommonTableExpression(_session); + // statement = new CountStatement(CurrentStatement); + } + + statement.SelectClause = new CountClause(statement.SelectClause.FromObject); + + break; + + case Marten.Linq.Parsing.SingleValueMode.LongCount: + if (statement.IsDistinct) + { + throw new NotImplementedException("Not yet"); + // statement.ConvertToCommonTableExpression(_session); + // statement = new CountStatement(CurrentStatement); + } + + statement.SelectClause = new CountClause(statement.SelectClause.FromObject); + break; + + case Marten.Linq.Parsing.SingleValueMode.Average: + statement.ApplyAggregateOperator("AVG"); + break; + + case Marten.Linq.Parsing.SingleValueMode.Max: + statement.ApplyAggregateOperator("MAX"); + break; + + case Marten.Linq.Parsing.SingleValueMode.Min: + statement.ApplyAggregateOperator("MIN"); + break; + + case Marten.Linq.Parsing.SingleValueMode.Sum: + statement.ApplyAggregateOperator("SUM"); + break; + + default: + throw new NotImplementedException($"Whoa pardner, don't have this {SingleValueMode} yet!"); + } + } + } +} diff --git a/src/Marten/Linq/CollectionUsage.Parsing.cs b/src/Marten/Linq/CollectionUsage.Parsing.cs new file mode 100644 index 00000000000..4962fc13237 --- /dev/null +++ b/src/Marten/Linq/CollectionUsage.Parsing.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using Marten.Linq.Parsing.Operators; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq; + +public partial class CollectionUsage +{ + public List OrderingExpressions { get; } = new(); + public List WhereExpressions { get; } = new(); + public Expression? SelectExpression { get; set; } + + public void AddWhereClause(MethodCallExpression expression) + { + if (expression.Arguments.Count == 1) + { + return; + } + + var where = expression.Arguments[1]; + if (where is UnaryExpression e) + { + where = e.Operand; + } + + if (where is LambdaExpression l) + { + where = l.Body; + } + + WhereExpressions.Add(where); + } + + public void AddSelectClause(MethodCallExpression expression) + { + var select = expression.Arguments[1]; + if (select is UnaryExpression e) + { + select = e.Operand; + } + + if (select is LambdaExpression l) + { + select = l.Body; + } + + SelectExpression = select; + } +} diff --git a/src/Marten/Linq/CollectionUsage.cs b/src/Marten/Linq/CollectionUsage.cs new file mode 100644 index 00000000000..5cab2e22c99 --- /dev/null +++ b/src/Marten/Linq/CollectionUsage.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using Marten.Linq.Parsing; + +namespace Marten.Linq; + +public partial class CollectionUsage +{ + private readonly StoreOptions _options; + + + private int? _limit; + + private int? _offset; + + public CollectionUsage(StoreOptions options, Type elementType) + { + _options = options; + ElementType = elementType; + } + + public Type ElementType { get; } + + public SingleValueMode? SingleValueMode { get; set; } + public bool IsAny { get; set; } + public bool IsDistinct { get; set; } + public CollectionUsage Inner { get; internal set; } + public Expression SelectMany { get; set; } + public List IncludeExpressions { get; } = new(); + + public void WriteLimit(int limit) + { + _limit ??= limit; // don't overwrite + } + + public void WriteOffset(int offset) + { + _offset ??= offset; // don't overwrite + } +} diff --git a/src/Marten/Linq/CreatedAt/CreatedBeforeParser.cs b/src/Marten/Linq/CreatedAt/CreatedBeforeParser.cs index a6d8ac579d7..a6a6f45b297 100644 --- a/src/Marten/Linq/CreatedAt/CreatedBeforeParser.cs +++ b/src/Marten/Linq/CreatedAt/CreatedBeforeParser.cs @@ -3,7 +3,7 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -20,7 +20,8 @@ public bool Matches(MethodCallExpression expression) return Equals(expression.Method, _method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { var time = expression.Arguments.Last().Value().As(); diff --git a/src/Marten/Linq/CreatedAt/CreatedSinceParser.cs b/src/Marten/Linq/CreatedAt/CreatedSinceParser.cs index 09be5a45cf3..4310c245890 100644 --- a/src/Marten/Linq/CreatedAt/CreatedSinceParser.cs +++ b/src/Marten/Linq/CreatedAt/CreatedSinceParser.cs @@ -3,7 +3,7 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -20,7 +20,8 @@ public bool Matches(MethodCallExpression expression) return Equals(expression.Method, _method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { var time = expression.Arguments.Last().Value().As(); diff --git a/src/Marten/Linq/Fields/ArrayField.cs b/src/Marten/Linq/Fields/ArrayField.cs deleted file mode 100644 index 2b9ef6a48ab..00000000000 --- a/src/Marten/Linq/Fields/ArrayField.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using JasperFx.Core; -using JasperFx.Core.Reflection; -using Marten.Util; -using Weasel.Core; -using Weasel.Postgresql; - -namespace Marten.Linq.Fields; - -public class ArrayField: FieldBase -{ - public ArrayField(string dataLocator, string pgType, ISerializer serializer, MemberInfo[] members): base( - dataLocator, pgType, serializer.Casing, members) - { - var rawLocator = RawLocator; - - RawLocator = $"CAST({rawLocator} as jsonb)"; - - var collectionType = members.Last().GetMemberType(); - ElementType = collectionType.DetermineElementType(); - var innerPgType = PostgresqlProvider.Instance.GetDatabaseType(ElementType, EnumStorage.AsInteger); - - - if (PostgresqlProvider.Instance.HasTypeMapping(ElementType)) - { - PgType = innerPgType + "[]"; - } - - if (PgType == "jsonb[]") - { - PgType = "jsonb"; - } - - TypedLocator = $"CAST({rawLocator} as {PgType})"; - - LocatorForIncludedDocumentId = - $"CAST(ARRAY(SELECT jsonb_array_elements_text(CAST({rawLocator} as jsonb))) as {innerPgType}[])"; - - LocatorForElements = PgType.EqualsIgnoreCase("JSONB") - ? $"CAST(ARRAY(SELECT jsonb_array_elements(CAST({rawLocator} as jsonb))) as jsonb[])" - : LocatorForIncludedDocumentId; - - LocatorForFlattenedElements = $"unnest({LocatorForElements})"; - } - - public Type ElementType { get; } - - public override string LocatorForIncludedDocumentId - { - get; - } - - public string LocatorForFlattenedElements { get; } - - public string LocatorForElements { get; } - - - public override string SelectorForDuplication(string pgType) - { - if (pgType.EqualsIgnoreCase("JSONB")) - { - return JSONBLocator.Replace("d.", ""); - } - - return $"CAST(ARRAY(SELECT jsonb_array_elements_text({RawLocator.Replace("d.", "")})) as {pgType})"; - } -} diff --git a/src/Marten/Linq/Fields/CollectionLengthField.cs b/src/Marten/Linq/Fields/CollectionLengthField.cs deleted file mode 100644 index 0406a8bdf39..00000000000 --- a/src/Marten/Linq/Fields/CollectionLengthField.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Reflection; - -namespace Marten.Linq.Fields; - -public class CollectionLengthField: FieldBase -{ - public CollectionLengthField(ArrayField inner, MemberInfo[] members): base( - $"jsonb_array_length({inner.JSONBLocator})", "int", Casing.Default, members) - { - TypedLocator = $"jsonb_array_length({inner.JSONBLocator})"; - } - - public override string SelectorForDuplication(string pgType) - { - throw new NotSupportedException(); - } -} diff --git a/src/Marten/Linq/Fields/DateTimeField.cs b/src/Marten/Linq/Fields/DateTimeField.cs deleted file mode 100644 index 40cee36e8e9..00000000000 --- a/src/Marten/Linq/Fields/DateTimeField.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Reflection; - -namespace Marten.Linq.Fields; - -public class DateTimeField: FieldBase -{ - public DateTimeField(string dataLocator, string schemaName, Casing casing, MemberInfo[] members): base(dataLocator, - "timestamp without time zone", casing, members) - { - TypedLocator = $"{schemaName}.mt_immutable_timestamp({RawLocator})"; - } - - public override string SelectorForDuplication(string pgType) - { - return TypedLocator.Replace("d.", ""); - } -} diff --git a/src/Marten/Linq/Fields/DateTimeOffsetField.cs b/src/Marten/Linq/Fields/DateTimeOffsetField.cs deleted file mode 100644 index 2280a0d6f48..00000000000 --- a/src/Marten/Linq/Fields/DateTimeOffsetField.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Reflection; - -namespace Marten.Linq.Fields; - -public class DateTimeOffsetField: FieldBase -{ - public DateTimeOffsetField(string dataLocator, string schemaName, Casing casing, MemberInfo[] members): base( - dataLocator, "timestamp with time zone", casing, members) - { - TypedLocator = $"{schemaName}.mt_immutable_timestamptz({RawLocator})"; - } - - public override string SelectorForDuplication(string pgType) - { - return TypedLocator.Replace("d.", ""); - } -} diff --git a/src/Marten/Linq/Fields/DictionaryField.cs b/src/Marten/Linq/Fields/DictionaryField.cs deleted file mode 100644 index 7d61b69e532..00000000000 --- a/src/Marten/Linq/Fields/DictionaryField.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core; -using JasperFx.Core.Reflection; -using Marten.Exceptions; -using Marten.Linq.Filters; -using Weasel.Core; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public class DictionaryField: FieldBase -{ - private readonly EnumStorage _enumStorage; - private readonly string _intermediateLocator; - private readonly bool _isStringValue; - private readonly bool _valueIsObject; - private readonly string _valuePgType; - - private ImHashMap _indexLocators = ImHashMap.Empty; - - public DictionaryField(string dataLocator, Casing casing, EnumStorage enumStorage, MemberInfo[] members): base( - dataLocator, "JSONB", casing, members) - { - TypedLocator = $"CAST({RawLocator} as {PgType})"; - _intermediateLocator = RawLocator.Replace("->>", "->"); - var valueType = FieldType.FindInterfaceThatCloses(typeof(IDictionary<,>))!.GenericTypeArguments[1]; - _valueIsObject = valueType == typeof(object); - _isStringValue = valueType == typeof(string); - _valuePgType = PostgresqlProvider.Instance.GetDatabaseType(valueType, enumStorage); - _enumStorage = enumStorage; - } - - public override string SelectorForDuplication(string pgType) - { - return $"CAST({RawLocator.Replace("d.", "")} as {pgType})"; - } - - private string locatorForField(string key) - { - if (_indexLocators.TryFind(key, out var locator)) - { - return locator; - } - - locator = $"{RawLocator.Replace("->>", "->")} ->> '{key}'"; - if (!_valueIsObject) - { - locator = $"CAST({locator} as {_valuePgType})"; - } - - _indexLocators = _indexLocators.AddOrUpdate(key, locator); - - return locator; - } - - public override ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - var key = memberExpression.As().Arguments[0].As().Value; - var locator = $"{RawLocator.Replace("->>", "->")} ->> '{key}'"; - - - if (value.Value == null) - { - return op == "=" ? new IsNullFilter(this) : new IsNotNullFilter(this); - } - - if (_valueIsObject) - { - var pgType = PostgresqlProvider.Instance.GetDatabaseType(value.Value.GetType(), _enumStorage); - locator = $"CAST({locator} as {pgType})"; - } - - var def = new CommandParameter(value); - return new ComparisonFilter(new WhereFragment(locator), def, op); - } - - public override string ToOrderExpression(Expression expression) - { - if (expression is MethodCallExpression m) - { - var value = m.Arguments[0]; - if (value is ConstantExpression item) - { - return _isStringValue - ? $"{_intermediateLocator} ->> '{item.Value}'" - : $"CAST({_intermediateLocator} ->> '{item.Value}' as {_valuePgType})"; - } - - throw new BadLinqExpressionException( - "Marten cannot determine the ORDER BY SQL for this usage of a Dictionary"); - } - - return base.ToOrderExpression(expression); - } -} diff --git a/src/Marten/Linq/Fields/EnumAsIntegerField.cs b/src/Marten/Linq/Fields/EnumAsIntegerField.cs deleted file mode 100644 index 842cbf223f0..00000000000 --- a/src/Marten/Linq/Fields/EnumAsIntegerField.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Linq.Expressions; -using System.Reflection; -using NpgsqlTypes; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public class EnumAsIntegerField: FieldBase -{ - public EnumAsIntegerField(string dataLocator, Casing casing, MemberInfo[] members): base(dataLocator, "integer", - casing, members) - { - PgType = "integer"; - TypedLocator = $"CAST({RawLocator} as {PgType})"; - } - - public override string SelectorForDuplication(string pgType) - { - return $"CAST({RawLocator.Replace("d.", "")} as {PgType})"; - } - - public override ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - var integer = (int)value.Value; - return new ComparisonFilter(this, new CommandParameter(integer, NpgsqlDbType.Integer), op); - } -} diff --git a/src/Marten/Linq/Fields/EnumAsStringField.cs b/src/Marten/Linq/Fields/EnumAsStringField.cs deleted file mode 100644 index 1fbbf583ed6..00000000000 --- a/src/Marten/Linq/Fields/EnumAsStringField.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.Reflection; -using Marten.Linq.Parsing; -using NpgsqlTypes; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public class EnumAsStringField: FieldBase -{ - public EnumAsStringField(string dataLocator, Casing casing, MemberInfo[] members) - : base(dataLocator, "varchar", casing, members) - { - if (!FieldType.IsEnum) - { - throw new ArgumentOutOfRangeException(nameof(members), "Not an Enum type"); - } - } - - public override object GetValueForCompiledQueryParameter(Expression expression) - { - var raw = expression.Value(); - - // This is to deal with Nullable enums - if (raw == null) - { - return null; - } - - return Enum.GetName(FieldType, raw); - } - - public override string SelectorForDuplication(string pgType) - { - return RawLocator.Replace("d.", ""); - } - - public override ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - var stringValue = Enum.GetName(FieldType, value.Value); - return new ComparisonFilter(this, new CommandParameter(stringValue, NpgsqlDbType.Varchar), op); - } -} diff --git a/src/Marten/Linq/Fields/FieldBase.cs b/src/Marten/Linq/Fields/FieldBase.cs deleted file mode 100644 index 769104eaa81..00000000000 --- a/src/Marten/Linq/Fields/FieldBase.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Text.Json.Serialization; -using JasperFx.Core.Reflection; -using Marten.Linq.Filters; -using Marten.Linq.Parsing; -using Marten.Util; -using Newtonsoft.Json; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public abstract class FieldBase: IField -{ - protected FieldBase(string dataLocator, string pgType, Casing casing, MemberInfo[] members) - { - if (members == null || members.Length == 0) - { - throw new ArgumentNullException(nameof(members)); - } - - Members = members; - - lastMember = members.Last(); - - FieldType = lastMember.GetMemberType(); - - var locator = dataLocator; - - for (var i = 0; i < members.Length - 1; i++) - { - var member = members[i]; - var memberLocator = determineMemberLocator(casing, member); - - locator += $" -> '{memberLocator}'"; - } - - parentLocator = locator; - lastMemberName = determineMemberLocator(casing, lastMember); - - RawLocator = TypedLocator = $"{parentLocator} ->> '{lastMemberName}'"; - - PgType = pgType; - - JSONBLocator = $"CAST({RawLocator} as jsonb)"; - } - - private static string determineMemberLocator(Casing casing, MemberInfo member) - { - var memberLocator = member.Name.FormatCase(casing); - if (member.TryGetAttribute(out var newtonsoftAtt) && newtonsoftAtt.PropertyName is not null) - { - memberLocator = newtonsoftAtt.PropertyName; - } - - if (member.TryGetAttribute(out var stjAtt)) - { - memberLocator = stjAtt.Name; - } - - return memberLocator; - } - - protected string lastMemberName { get; } - - protected string parentLocator { get; } - - protected MemberInfo lastMember { get; } - - public string PgType { get; set; } // settable so it can be overidden by users - - public virtual ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - if (value.Value == null) - { - return op == "=" ? new IsNullFilter(this) : new IsNotNullFilter(this); - } - - var def = new CommandParameter(value); - return new ComparisonFilter(this, def, op); - } - - [Obsolete("Try to eliminate this")] - public bool ShouldUseContainmentOperator() - { - return PostgresqlProvider.Instance.ContainmentOperatorTypes.Contains(FieldType); - } - - public abstract string SelectorForDuplication(string pgType); - - public virtual string ToOrderExpression(Expression expression) - { - return TypedLocator; - } - - public virtual string LocatorForIncludedDocumentId => TypedLocator; - - /// - /// Locate the data for this field as JSONB - /// - public string JSONBLocator { get; set; } - - public Type FieldType { get; } - - public MemberInfo[] Members { get; } - - public string RawLocator { get; protected set; } - - public string TypedLocator { get; protected set; } - - public virtual object GetValueForCompiledQueryParameter(Expression valueExpression) - { - return valueExpression.Value(); - } - - public string LocatorFor(string rootTableAlias) - { - // Super hokey. - return TypedLocator.Replace("d.", rootTableAlias + "."); - } - - void ISqlFragment.Apply(CommandBuilder builder) - { - builder.Append(TypedLocator); - } - - bool ISqlFragment.Contains(string sqlText) - { - return TypedLocator.Contains(sqlText); - } -} diff --git a/src/Marten/Linq/Fields/FieldCollection.cs b/src/Marten/Linq/Fields/FieldCollection.cs deleted file mode 100644 index d10c9dace4e..00000000000 --- a/src/Marten/Linq/Fields/FieldCollection.cs +++ /dev/null @@ -1,219 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core; -using JasperFx.Core.Reflection; -using Marten.Linq.Parsing; -using Marten.Linq.QueryHandlers; -using Marten.Schema; -using Marten.Util; -using Weasel.Core; -using Weasel.Postgresql; -using FindMembers = Marten.Linq.Parsing.FindMembers; - -namespace Marten.Linq.Fields; - -/// -/// Internal representation of queryable members within a Linq query -/// -public interface IFieldMapping -{ - PropertySearching PropertySearching { get; } - DeleteStyle DeleteStyle { get; } - IField FieldFor(Expression expression); - IField FieldFor(IEnumerable members); - IField FieldFor(MemberInfo member); - public IField FieldFor(string memberName); -} - -public class FieldMapping: IFieldMapping -{ - private readonly string _dataLocator; - private readonly Type _documentType; - private readonly ConcurrentDictionary _fields = new(); - private readonly StoreOptions _options; - private readonly ISerializer _serializer; - - internal FieldMapping(string dataLocator, Type documentType, StoreOptions options) - { - _dataLocator = dataLocator; - _documentType = documentType; - _options = options; - _serializer = options.Serializer(); - } - - public PropertySearching PropertySearching { get; set; } = PropertySearching.JSON_Locator_Only; - public DeleteStyle DeleteStyle { get; set; } = DeleteStyle.Remove; - - public IField FieldFor(Expression expression) - { - return FieldFor(FindMembers.Determine(expression)); - } - - - public IField FieldFor(IEnumerable members) - { - if (members.Count() == 1) - { - return FieldFor(members.Single()); - } - - var key = members.Select(x => x.Name).Join("."); - - return _fields.GetOrAdd(key, - _ => resolveField(members.ToArray())); - } - - - public IField FieldFor(MemberInfo member) - { - return _fields.GetOrAdd(member.Name, - _ => resolveField(new[] { member })); - } - - public IField FieldFor(string memberName) - { - return _fields.GetOrAdd(memberName, name => - { - var member = _documentType.GetProperties().FirstOrDefault(x => x.Name == name).As() ?? - _documentType.GetFields().FirstOrDefault(x => x.Name == name); - - if (member == null) - { - return null; - } - - - return resolveField(new MemberInfo[] { member }); - }); - } - - - protected void removeIdField() - { - var idFields = _fields.Where(x => x.Value is IdField).ToArray(); - foreach (var pair in idFields) _fields.TryRemove(pair.Key, out _); - } - - protected void setField(string name, IField field) - { - _fields[name] = field; - } - - protected IEnumerable fields() - { - return _fields.Values; - } - - protected IField resolveField(MemberInfo[] members) - { - if (!members.Any()) - { - if (_documentType.IsSimple()) - { - return new SimpleDataField(_documentType); - } - - throw new ArgumentOutOfRangeException(nameof(members), "No members found in this Expression"); - } - - foreach (var source in _options.Linq.FieldSources) - { - if (source.TryResolve(_dataLocator, _options, _serializer, _documentType, members, out var field)) - { - return field; - } - } - - // List.Count - if (members.Length > 1 && members.Last().Name == "Count") - { - if (members[members.Length - 2].GetMemberType().IsEnumerable()) - { - var inner = (ArrayField)FieldFor(members.Take(members.Length - 1).ToArray()); - return new CollectionLengthField(inner, members); - } - } - - // Array.Length - if (members.Last().Equals(LinqConstants.ArrayLength)) - { - var inner = (ArrayField)FieldFor(members.Take(members.Length - 1).ToArray()); - return new CollectionLengthField(inner, members); - } - - var fieldType = members.Last().GetRawMemberType(); - - - if (fieldType.IsNullable()) - { - var innerFieldType = fieldType.GetGenericArguments()[0]; - var innerField = createFieldByFieldType(members, innerFieldType); - - return new NullableTypeField(innerField); - } - - - return createFieldByFieldType(members, fieldType); - } - - private IField createFieldByFieldType(MemberInfo[] members, Type fieldType) - { - if (fieldType == typeof(string)) - { - return new StringField(_dataLocator, _serializer.Casing, members); - } - - if (fieldType.Closes(typeof(IDictionary<,>))) - { - return new DictionaryField(_dataLocator, _serializer.Casing, _serializer.EnumStorage, members); - } - - if (fieldType.IsEnum) - { - return _serializer.EnumStorage == EnumStorage.AsInteger - ? new EnumAsIntegerField(_dataLocator, _serializer.Casing, members) - : new EnumAsStringField(_dataLocator, _serializer.Casing, members); - } - - if (fieldType == typeof(DateTime)) - { - return new DateTimeField(_dataLocator, _options.DatabaseSchemaName, _serializer.Casing, members); - } - - if (fieldType == typeof(DateTimeOffset)) - { - return new DateTimeOffsetField(_dataLocator, _options.DatabaseSchemaName, _serializer.Casing, members); - } - - - var pgType = PostgresqlProvider.Instance.GetDatabaseType(fieldType, _serializer.EnumStorage); - - - if (fieldType.Closes(typeof(IDictionary<,>))) - { - return new SimpleCastField(_dataLocator, "JSONB", _serializer.Casing, members); - } - - if (isEnumerable(fieldType)) - { - return new ArrayField(_dataLocator, pgType, _serializer, members); - } - - if (pgType.IsNotEmpty()) - { - return new SimpleCastField(_dataLocator, pgType, _serializer.Casing, members); - } - - throw new NotSupportedException( - $"Marten does not support Linq expressions for this member. Was {_documentType.FullName}.{members.Select(x => x.Name).Join(".")}"); - } - - private static bool isEnumerable(Type fieldType) - { - return fieldType.IsArray || fieldType.Closes(typeof(IEnumerable<>)); - } -} diff --git a/src/Marten/Linq/Fields/HasValueField.cs b/src/Marten/Linq/Fields/HasValueField.cs deleted file mode 100644 index 1c7d0dc71f2..00000000000 --- a/src/Marten/Linq/Fields/HasValueField.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Linq.Expressions; -using Marten.Linq.Filters; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public class HasValueField: IComparableFragment -{ - private readonly IField _field; - - public HasValueField(IField field) - { - _field = field; - } - - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - var hasValue = (bool)value.Value; - return hasValue - ? new IsNotNullFilter(_field) - : new IsNullFilter(_field); - } -} diff --git a/src/Marten/Linq/Fields/IField.cs b/src/Marten/Linq/Fields/IField.cs deleted file mode 100644 index 914db3f7d78..00000000000 --- a/src/Marten/Linq/Fields/IField.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.Reflection; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public interface IField: IComparableFragment, ISqlFragment -{ - MemberInfo[] Members { get; } - - /// - /// Postgresql locator that also casts the raw string data to the proper Postgresql type - /// - string TypedLocator { get; } - - /// - /// Postgresql locator that returns the raw string value within the JSONB document - /// - string RawLocator { get; } - - /// - /// The .Net type of this IField - /// - Type FieldType { get; } - - /// - /// Locate the data for this field as JSONB - /// - string JSONBLocator { get; } - - string LocatorForIncludedDocumentId { get; } - - /// - /// May "correct" the raw value as appropriate for the constant parameter value - /// within a compiled query - /// - /// - /// - object GetValueForCompiledQueryParameter(Expression valueExpression); - - string LocatorFor(string rootTableAlias); - bool ShouldUseContainmentOperator(); - - string SelectorForDuplication(string pgType); - - string ToOrderExpression(Expression expression); -} diff --git a/src/Marten/Linq/Fields/IdField.cs b/src/Marten/Linq/Fields/IdField.cs deleted file mode 100644 index a639e68202c..00000000000 --- a/src/Marten/Linq/Fields/IdField.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core.Reflection; -using Marten.Linq.Parsing; -using Marten.Util; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public class IdField: IField -{ - private readonly MemberInfo _idMember; - - public IdField(MemberInfo idMember) - { - _idMember = idMember; - } - - public MemberInfo[] Members => new[] { _idMember }; - public string TypedLocator { get; } = "d.id"; - public string RawLocator { get; } = "d.id"; - - public object GetValueForCompiledQueryParameter(Expression valueExpression) - { - return valueExpression.Value(); - } - - public Type FieldType => _idMember.GetMemberType(); - public string JSONBLocator { get; } = null; - public string LocatorForIncludedDocumentId => TypedLocator; - - public string LocatorFor(string rootTableAlias) - { - return rootTableAlias + ".id"; - } - - public bool ShouldUseContainmentOperator() - { - return false; - } - - string IField.SelectorForDuplication(string pgType) - { - throw new NotSupportedException(); - } - - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - return new ComparisonFilter(this, new CommandParameter(value), op); - } - - void ISqlFragment.Apply(CommandBuilder builder) - { - builder.Append(TypedLocator); - } - - bool ISqlFragment.Contains(string sqlText) - { - return TypedLocator.Contains(sqlText); - } - - public string ToOrderExpression(Expression expression) - { - return TypedLocator; - } -} diff --git a/src/Marten/Linq/Fields/NotField.cs b/src/Marten/Linq/Fields/NotField.cs deleted file mode 100644 index a9914b5be4d..00000000000 --- a/src/Marten/Linq/Fields/NotField.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Linq.Expressions; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public class NotField: IComparableFragment -{ - private readonly IField _inner; - - public NotField(IField inner) - { - _inner = inner; - } - - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - var opposite = ComparisonFilter.NotOperators[op]; - return _inner.CreateComparison(opposite, value, memberExpression); - } -} diff --git a/src/Marten/Linq/Fields/NullableTypeField.cs b/src/Marten/Linq/Fields/NullableTypeField.cs deleted file mode 100644 index e7a24141ab3..00000000000 --- a/src/Marten/Linq/Fields/NullableTypeField.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.CodeGeneration; -using JasperFx.Core.Reflection; -using Marten.Exceptions; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -public class NullableTypeField: IField -{ - private readonly string _isNotNullSql; - private readonly string _isNullSql; - - public NullableTypeField(IField innerField) - { - InnerField = innerField; - - Members = innerField.Members; - TypedLocator = innerField.TypedLocator; - RawLocator = innerField.RawLocator; - FieldType = innerField.FieldType; - JSONBLocator = innerField.JSONBLocator; - LocatorForIncludedDocumentId = innerField.LocatorForIncludedDocumentId; - - _isNullSql = $"{RawLocator} is null"; - _isNotNullSql = $"{RawLocator} is not null"; - } - - public IField InnerField { get; } - - public MemberInfo[] Members { get; } - public string TypedLocator { get; } - public string RawLocator { get; } - - public object GetValueForCompiledQueryParameter(Expression valueExpression) - { - return InnerField.GetValueForCompiledQueryParameter(valueExpression); - } - - public Type FieldType { get; } - public string JSONBLocator { get; } - public string LocatorForIncludedDocumentId { get; } - - public string LocatorFor(string rootTableAlias) - { - return InnerField.LocatorFor(rootTableAlias); - } - - public bool ShouldUseContainmentOperator() - { - return InnerField.ShouldUseContainmentOperator(); - } - - public string SelectorForDuplication(string pgType) - { - return InnerField.SelectorForDuplication(pgType); - } - - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - if (value.Value == null) - { - switch (op) - { - case "=": - return new WhereFragment(_isNullSql); - - case "!=": - return new WhereFragment(_isNotNullSql); - - default: - throw new BadLinqExpressionException( - $"Can only compare property type {FieldType.FullNameInCode()} by '=' or '!='"); - } - } - - return InnerField.CreateComparison(op, value, memberExpression); - } - - void ISqlFragment.Apply(CommandBuilder builder) - { - builder.Append(TypedLocator); - } - - bool ISqlFragment.Contains(string sqlText) - { - return TypedLocator.Contains(sqlText); - } - - public string ToOrderExpression(Expression expression) - { - return TypedLocator; - } -} diff --git a/src/Marten/Linq/Fields/SimpleCastField.cs b/src/Marten/Linq/Fields/SimpleCastField.cs deleted file mode 100644 index f687803fb99..00000000000 --- a/src/Marten/Linq/Fields/SimpleCastField.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Reflection; - -namespace Marten.Linq.Fields; - -public class SimpleCastField: FieldBase -{ - public SimpleCastField(string dataLocator, string pgType, Casing casing, MemberInfo[] members): base(dataLocator, - pgType, casing, members) - { - TypedLocator = $"CAST({RawLocator} as {PgType})"; - } - - public override string SelectorForDuplication(string pgType) - { - return $"CAST({RawLocator.Replace("d.", "")} as {pgType})"; - } -} diff --git a/src/Marten/Linq/Fields/SimpleDataField.cs b/src/Marten/Linq/Fields/SimpleDataField.cs deleted file mode 100644 index 76bb248d20a..00000000000 --- a/src/Marten/Linq/Fields/SimpleDataField.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.Reflection; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Fields; - -/// -/// Represents a literal field in a sub query that selects a simple or primitive type -/// -public class SimpleDataField: IField -{ - public SimpleDataField(Type sourceType) - { - FieldType = sourceType; - } - - public MemberInfo[] Members => new MemberInfo[0]; - public string TypedLocator => "data"; - public string RawLocator => "data"; - - public object GetValueForCompiledQueryParameter(Expression valueExpression) - { - throw new NotSupportedException(); - } - - public Type FieldType { get; } - - public string JSONBLocator => "data"; - public string LocatorForIncludedDocumentId => throw new NotSupportedException(); - - public string LocatorFor(string rootTableAlias) - { - throw new NotSupportedException(); - } - - public bool ShouldUseContainmentOperator() - { - return false; - } - - public string SelectorForDuplication(string pgType) - { - throw new NotSupportedException(); - } - - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - return new ComparisonFilter(this, new CommandParameter(value), op); - } - - void ISqlFragment.Apply(CommandBuilder builder) - { - builder.Append(TypedLocator); - } - - bool ISqlFragment.Contains(string sqlText) - { - return TypedLocator.Contains(sqlText); - } - - public string ToOrderExpression(Expression expression) - { - return TypedLocator; - } -} diff --git a/src/Marten/Linq/Fields/StringField.cs b/src/Marten/Linq/Fields/StringField.cs deleted file mode 100644 index 23a02cd4640..00000000000 --- a/src/Marten/Linq/Fields/StringField.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Reflection; - -namespace Marten.Linq.Fields; - -public class StringField: FieldBase -{ - public StringField(string dataLocator, Casing casing, MemberInfo[] members): base(dataLocator, "varchar", casing, - members) - { - } - - public override string SelectorForDuplication(string pgType) - { - return RawLocator.Replace("d.", ""); - } -} diff --git a/src/Marten/Linq/Filters/CollectionIsEmpty.cs b/src/Marten/Linq/Filters/CollectionIsEmpty.cs deleted file mode 100644 index e75acf1f351..00000000000 --- a/src/Marten/Linq/Filters/CollectionIsEmpty.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Marten.Linq.Fields; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Filters; - -internal class CollectionIsEmpty: ISqlFragment -{ - private readonly ArrayField _field; - - public CollectionIsEmpty(ArrayField field) - { - _field = field; - } - - public void Apply(CommandBuilder builder) - { - builder.Append("("); - builder.Append(_field.RawLocator); - builder.Append(" is null or jsonb_array_length("); - builder.Append(_field.RawLocator); - builder.Append(") = 0)"); - } - - public bool Contains(string sqlText) - { - return false; - } -} diff --git a/src/Marten/Linq/Filters/CollectionIsNotEmpty.cs b/src/Marten/Linq/Filters/CollectionIsNotEmpty.cs deleted file mode 100644 index 7a92c7267d6..00000000000 --- a/src/Marten/Linq/Filters/CollectionIsNotEmpty.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Marten.Linq.Fields; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Filters; - -internal class CollectionIsNotEmpty: IReversibleWhereFragment -{ - private readonly ArrayField _field; - - public CollectionIsNotEmpty(ArrayField field) - { - _field = field; - } - - public void Apply(CommandBuilder builder) - { - builder.Append("("); - builder.Append(_field.RawLocator); - builder.Append(" is not null and jsonb_array_length("); - builder.Append(_field.RawLocator); - builder.Append(") > 0)"); - } - - public bool Contains(string sqlText) - { - return false; - } - - public ISqlFragment Reverse() - { - return new CollectionIsEmpty(_field); - } -} diff --git a/src/Marten/Linq/Filters/ContainmentWhereFragment.cs b/src/Marten/Linq/Filters/ContainmentWhereFragment.cs deleted file mode 100644 index ce8f74b003a..00000000000 --- a/src/Marten/Linq/Filters/ContainmentWhereFragment.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core; -using Marten.Linq.Parsing; -using JasperFx.Core.Reflection; -using NpgsqlTypes; -using Weasel.Core; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; -using FindMembers = Marten.Linq.Parsing.FindMembers; - -namespace Marten.Linq.Filters; - -public class ContainmentWhereFragment: ISqlFragment -{ - private readonly IDictionary _dictionary; - private readonly ISerializer _serializer; - private readonly string _wherePrefix; - - public ContainmentWhereFragment(ISerializer serializer, IDictionary dictionary, - string wherePrefix = null) - { - _serializer = serializer; - _dictionary = dictionary; - _wherePrefix = wherePrefix; - } - - public ContainmentWhereFragment(ISerializer serializer, BinaryExpression binary, string wherePrefix = null) - : this(serializer, new Dictionary(), wherePrefix) - { - CreateDictionaryForSearch(binary, _dictionary, _serializer); - } - - public void Apply(CommandBuilder builder) - { - var json = _serializer.ToCleanJson(_dictionary); - - builder.Append($"{_wherePrefix}d.data @> "); - builder.AppendParameter(json, NpgsqlDbType.Jsonb); - } - - public bool Contains(string sqlText) - { - return false; - } - - public static void CreateDictionaryForSearch(BinaryExpression binary, IDictionary dict, - ISerializer serializer) - { - var expressionValue = binary.Right.Value(); - var memberExpression = binary.Left; - - CreateDictionaryForSearch(dict, memberExpression, expressionValue, serializer); - } - - public static void CreateDictionaryForSearch(IDictionary dict, Expression memberExpression, - object expressionValue, ISerializer serializer) - { - var visitor = new FindMembers(); - visitor.Visit(memberExpression); - - var members = visitor.Members; - - if (members.Count > 1) - { - var temp = new Dictionary(); - var member = members.Last(); - var value = GetMemberValue(member, expressionValue, serializer.EnumStorage); - - temp.Add(member.Name, value); - - members.Reverse().Skip(1).Each(m => { temp = new Dictionary { { m.Name, temp } }; }); - - var topMemberName = members.First().Name; - dict.Add(topMemberName, temp[topMemberName]); - } - else - { - var member = members.Single(); - var value = GetMemberValue(member, expressionValue, serializer.EnumStorage); - - dict.Add(member.Name, value); - } - } - - public static ISqlFragment SimpleArrayContains(MemberInfo[] members, ISerializer serializer, Expression from, - object value) - { - if (value != null) - { - var array = Array.CreateInstance(value.GetType(), 1); - array.SetValue(value, 0); - - var dict = new Dictionary { { members.Last().Name, array } }; - - members.Reverse().Skip(1).Each(m => { dict = new Dictionary { { m.Name, dict } }; }); - - return new ContainmentWhereFragment(serializer, dict); - } - - throw new NotSupportedException(); - } - - private static object GetMemberValue(MemberInfo member, object expressionValue, EnumStorage enumStorage) - { - var value = expressionValue; - - var memberType = member.GetMemberType(); - - if (memberType.IsEnum && enumStorage == EnumStorage.AsString) - { - value = Enum.GetName(memberType, value); - } - - return value; - } -} diff --git a/src/Marten/Linq/ILinqQuery.cs b/src/Marten/Linq/ILinqQuery.cs new file mode 100644 index 00000000000..2db3f313094 --- /dev/null +++ b/src/Marten/Linq/ILinqQuery.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq.Expressions; + +namespace Marten.Linq; + +public interface ILinqQuery +{ + CollectionUsage CurrentUsage { get; } + CollectionUsage CollectionUsageFor(MethodCallExpression expression); + CollectionUsage CollectionUsageForArgument(Expression argument); + CollectionUsage StartNewCollectionUsageFor(MethodCallExpression expression); + CollectionUsage CollectionUsageFor(Type elementType); +} diff --git a/src/Marten/Linq/IMethodCallMatcher.cs b/src/Marten/Linq/IMethodCallMatcher.cs deleted file mode 100644 index d5f9e0817a0..00000000000 --- a/src/Marten/Linq/IMethodCallMatcher.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Linq.Expressions; -using Remotion.Linq.Clauses; - -namespace Marten.Linq; - -/// -/// Extension point to Marten's Linq support to add custom MethodInfo handling -/// in the query creation -/// -internal interface IMethodCallMatcher -{ - bool TryMatch(MethodCallExpression expression, ExpressionVisitor selectorVisitor, - out ResultOperatorBase op); -} diff --git a/src/Marten/Linq/Includes/DictionaryIncludePlan.cs b/src/Marten/Linq/Includes/DictionaryIncludePlan.cs new file mode 100644 index 00000000000..88cb75da4a8 --- /dev/null +++ b/src/Marten/Linq/Includes/DictionaryIncludePlan.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using Marten.Internal.Storage; +using Marten.Linq.Members; + +namespace Marten.Linq.Includes; + +internal class DictionaryIncludePlan: IncludePlan +{ + public DictionaryIncludePlan(IDocumentStorage storage, IQueryableMember connectingMember, + IDictionary dictionary): base(storage, connectingMember, BuildAction(storage, dictionary)) + { + } + + public static Action BuildAction(IDocumentStorage storage, IDictionary dictionary) + { + void Callback(T item) + { + var id = (TId)storage.IdentityFor(item); + dictionary[id] = item; + } + + return Callback; + } +} diff --git a/src/Marten/Linq/Includes/IIncludePlan.cs b/src/Marten/Linq/Includes/IIncludePlan.cs index 2b1c88081d4..926a4398f7d 100644 --- a/src/Marten/Linq/Includes/IIncludePlan.cs +++ b/src/Marten/Linq/Includes/IIncludePlan.cs @@ -1,18 +1,12 @@ using System; using Marten.Internal; -using Marten.Linq.SqlGeneration; namespace Marten.Linq.Includes; internal interface IIncludePlan { - string IdAlias { get; } - string TempTableSelector { get; } - int Index { set; } - string ExpressionName { get; } - Type DocumentType { get; } IIncludeReader BuildReader(IMartenSession session); - bool IsIdCollection(); - Statement BuildStatement(string tempTableName, IPagedStatement paging, IMartenSession session); + + void AppendStatement(TemporaryTableStatement tempTable, IMartenSession martenSession); } diff --git a/src/Marten/Linq/Includes/IdInIncludedDocumentIdentifierFilter.cs b/src/Marten/Linq/Includes/IdInIncludedDocumentIdentifierFilter.cs new file mode 100644 index 00000000000..e1662b80c27 --- /dev/null +++ b/src/Marten/Linq/Includes/IdInIncludedDocumentIdentifierFilter.cs @@ -0,0 +1,31 @@ +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Includes; + +internal class IdInIncludedDocumentIdentifierFilter: ISqlFragment +{ + private readonly IQueryableMember _connectingMember; + private readonly string _fromObject; + + public IdInIncludedDocumentIdentifierFilter(string fromObject, IQueryableMember connectingMember) + { + _fromObject = fromObject; + _connectingMember = connectingMember; + } + + public void Apply(CommandBuilder builder) + { + builder.Append("d.id in (select "); + builder.Append(_connectingMember.LocatorForIncludedDocumentId); + builder.Append(" from "); + builder.Append(_fromObject); + builder.Append(" as d)"); + } + + public bool Contains(string sqlText) + { + return false; + } +} diff --git a/src/Marten/Linq/Includes/InTempTableWhereFragment.cs b/src/Marten/Linq/Includes/InTempTableWhereFragment.cs deleted file mode 100644 index 66a196caf16..00000000000 --- a/src/Marten/Linq/Includes/InTempTableWhereFragment.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Marten.Linq.SqlGeneration; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Includes; - -internal class InTempTableWhereFragment: ISqlFragment -{ - private readonly bool _isIdCollection; - private readonly IPagedStatement _paging; - private readonly string _tempTableColumn; - private readonly string _tempTableName; - - public InTempTableWhereFragment(string tempTableName, string tempTableColumn, IPagedStatement paging, - bool isIdCollection) - { - _tempTableName = tempTableName; - _tempTableColumn = tempTableColumn; - _paging = paging; - _isIdCollection = isIdCollection; - } - - public void Apply(CommandBuilder builder) - { - builder.Append("id in (select "); - builder.Append(_isIdCollection ? $"unnest({_tempTableColumn})" : _tempTableColumn); - builder.Append($" from (select {_tempTableColumn} from "); - builder.Append(_tempTableName); - - if (_paging.Offset > 0) - { - builder.Append(" OFFSET "); - builder.Append(_paging.Offset); - } - - if (_paging.Limit > 0) - { - builder.Append(" LIMIT "); - builder.Append(_paging.Limit); - } - - builder.Append($") as {_tempTableName}"); - builder.Append(")"); - } - - public bool Contains(string sqlText) - { - return false; - } -} diff --git a/src/Marten/Linq/Includes/IncludeIdentitySelectorStatement.cs b/src/Marten/Linq/Includes/IncludeIdentitySelectorStatement.cs deleted file mode 100644 index e2cb14c102e..00000000000 --- a/src/Marten/Linq/Includes/IncludeIdentitySelectorStatement.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Marten.Internal; -using Marten.Linq.QueryHandlers; -using Marten.Linq.Selectors; -using Marten.Linq.SqlGeneration; -using Weasel.Postgresql; -using StringExtensions = JasperFx.Core.StringExtensions; - -namespace Marten.Linq.Includes; - -// This is also used as an ISelectClause inside the statement structure -internal class IncludeIdentitySelectorStatement: Statement, ISelectClause -{ - private readonly SelectorStatement _clonedEnd; - private readonly IList _includes; - private readonly SelectorStatement _innerEnd; - - public IncludeIdentitySelectorStatement(Statement original, IList includes, - IMartenSession session): base(null) - { - ExportName = session.NextTempTableName(); - - OriginalPaging = new PagedStatement(original); - - _includes = includes; - - _innerEnd = (SelectorStatement)original.Current(); - FromObject = _innerEnd.SelectClause.FromObject; - - _clonedEnd = _innerEnd.UseAsEndOfTempTableAndClone(this); - _clonedEnd.SingleValue = _innerEnd.SingleValue; - - Inner = original; - Inner.Limit = 0; // Watch this! - Inner.Offset = 0; - - Statement current = this; - foreach (var include in includes) - { - var includeStatement = include.BuildStatement(ExportName, OriginalPaging, session); - - current.InsertAfter(includeStatement); - current = includeStatement; - } - - current.InsertAfter(_clonedEnd); - } - - public IPagedStatement OriginalPaging { get; } - - public Statement Inner { get; private set; } - - public bool IncludeDataInTempTable { get; set; } - - public Type SelectedType => typeof(void); - - public void WriteSelectClause(CommandBuilder sql) - { - if (IncludeDataInTempTable) - { - // Basically if the data for the Include is coming from a - // SelectMany() clause - sql.Append("select data, "); - } - else - { - sql.Append("select id, "); - } - - sql.Append(StringExtensions.Join(_includes.Select(x => x.TempTableSelector), ", ")); - sql.Append(" from "); - sql.Append(FromObject); - sql.Append(" as d "); - } - - public string[] SelectFields() - { - return _includes.Select(x => x.TempTableSelector).ToArray(); - } - - public ISelector BuildSelector(IMartenSession session) - { - throw new NotSupportedException(); - } - - public IQueryHandler BuildHandler(IMartenSession session, Statement topStatement, - Statement currentStatement) - { - // It's wrapped in LinqHandlerBuilder - return _clonedEnd.SelectClause.BuildHandler(session, topStatement, currentStatement); - } - - public ISelectClause UseStatistics(QueryStatistics statistics) - { - throw new NotSupportedException(); - } - - - public override void CompileLocal(IMartenSession session) - { - Inner.CompileStructure(session); - Inner = Inner.Top(); - } - - protected override void configure(CommandBuilder sql) - { - sql.Append("drop table if exists "); - sql.Append(ExportName); - sql.Append(";\n"); - sql.Append("create temp table "); - sql.Append(ExportName); - sql.Append(" as (\n"); - Inner.Configure(sql); - sql.Append("\n);"); - } -} diff --git a/src/Marten/Linq/Includes/IncludePlan.cs b/src/Marten/Linq/Includes/IncludePlan.cs index 8864cbd672a..b3709334be3 100644 --- a/src/Marten/Linq/Includes/IncludePlan.cs +++ b/src/Marten/Linq/Includes/IncludePlan.cs @@ -1,81 +1,41 @@ using System; using Marten.Internal; using Marten.Internal.Storage; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Selectors; using Marten.Linq.SqlGeneration; -using Weasel.Postgresql; namespace Marten.Linq.Includes; internal class IncludePlan: IIncludePlan { private readonly Action _callback; + private readonly IQueryableMember _connectingMember; private readonly IDocumentStorage _storage; - public IncludePlan(IDocumentStorage storage, IField connectingField, Action callback) + public IncludePlan(IDocumentStorage storage, IQueryableMember connectingMember, Action callback) { _storage = storage; - ConnectingField = connectingField; + _connectingMember = connectingMember; _callback = callback; } - public IField ConnectingField { get; } - - public string LeftJoinExpression => - $"LEFT JOIN LATERAL {ConnectingField.LocatorForIncludedDocumentId} WITH ORDINALITY as {ExpressionName}({IdAlias}) ON TRUE"; - public Type DocumentType => typeof(T); - public int Index - { - set - { - IdAlias = "id" + (value + 1); - ExpressionName = "include" + (value + 1); - TempTableSelector = $"{ConnectingField.LocatorForIncludedDocumentId} as {IdAlias}"; - } - } - - public bool IsIdCollection() - { - return ConnectingField is ArrayField; - } - - public string ExpressionName { get; private set; } - - public string IdAlias { get; private set; } - public string TempTableSelector { get; private set; } - - public Statement BuildStatement(string tempTableName, IPagedStatement paging, IMartenSession session) - { - return new IncludedDocumentStatement(_storage, this, tempTableName, paging, session); - } - public IIncludeReader BuildReader(IMartenSession session) { var selector = (ISelector)_storage.BuildSelector(session); return new IncludeReader(_callback, selector); } - public class IncludedDocumentStatement: SelectorStatement + public void AppendStatement(TemporaryTableStatement tempTable, IMartenSession martenSession) { - public IncludedDocumentStatement( - IDocumentStorage storage, - IncludePlan includePlan, - string tempTableName, - IPagedStatement paging, - IMartenSession session): base(storage, storage.Fields) - { - var initial = new InTempTableWhereFragment(tempTableName, includePlan.IdAlias, paging, - includePlan.IsIdCollection()); - Where = storage.FilterDocuments(null, initial, session); - } + var selector = new SelectorStatement { SelectClause = _storage }; + var filter = new IdInIncludedDocumentIdentifierFilter(tempTable.ExportName, _connectingMember); + + var wrapped = _storage.FilterDocuments(filter, martenSession); + selector.Wheres.Add(wrapped); - protected override void configure(CommandBuilder sql) - { - base.configure(sql); - sql.Append(";\n"); - } + tempTable.AddToEnd(selector); } } diff --git a/src/Marten/Linq/Includes/ListIncludePlan.cs b/src/Marten/Linq/Includes/ListIncludePlan.cs new file mode 100644 index 00000000000..ad41d51fbae --- /dev/null +++ b/src/Marten/Linq/Includes/ListIncludePlan.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Marten.Internal.Storage; +using Marten.Linq.Members; + +namespace Marten.Linq.Includes; + +internal class ListIncludePlan: IncludePlan +{ + public ListIncludePlan(IDocumentStorage storage, IQueryableMember connectingMember, IList list): base(storage, + connectingMember, list.Add) + { + } +} diff --git a/src/Marten/Linq/Includes/PassthroughSelectStatement.cs b/src/Marten/Linq/Includes/PassthroughSelectStatement.cs new file mode 100644 index 00000000000..002bed5cdae --- /dev/null +++ b/src/Marten/Linq/Includes/PassthroughSelectStatement.cs @@ -0,0 +1,24 @@ +using Marten.Linq.SqlGeneration; +using Weasel.Postgresql; + +namespace Marten.Linq.Includes; + +internal class PassthroughSelectStatement: Statement +{ + private readonly ISelectClause _innerSelectClause; + + public PassthroughSelectStatement(string tableName, ISelectClause innerSelectClause) + { + _innerSelectClause = innerSelectClause; + TableName = tableName; + } + + public string TableName { get; set; } + + protected override void configure(CommandBuilder sql) + { + sql.Append("select * from "); + sql.Append(TableName); + sql.Append(" as d;"); + } +} diff --git a/src/Marten/Linq/Includes/TemporaryTableStatement.cs b/src/Marten/Linq/Includes/TemporaryTableStatement.cs new file mode 100644 index 00000000000..61b747d5306 --- /dev/null +++ b/src/Marten/Linq/Includes/TemporaryTableStatement.cs @@ -0,0 +1,31 @@ +using Marten.Internal; +using Marten.Linq.SqlGeneration; +using Weasel.Postgresql; + +namespace Marten.Linq.Includes; + +internal class TemporaryTableStatement: Statement +{ + public TemporaryTableStatement(Statement inner, IMartenSession session) + { + Inner = inner; + + Inner.SelectorStatement().Mode = StatementMode.Inner; + + ExportName = session.NextTempTableName(); + } + + public Statement Inner { get; } + + protected override void configure(CommandBuilder sql) + { + sql.Append("drop table if exists "); + sql.Append(ExportName); + sql.Append(";\n"); + sql.Append("create temp table "); + sql.Append(ExportName); + sql.Append(" as (\n"); + Inner.Apply(sql); + sql.Append("\n);\n"); + } +} diff --git a/src/Marten/Linq/LastModified/ModifiedBeforeParser.cs b/src/Marten/Linq/LastModified/ModifiedBeforeParser.cs index b0b60a3d086..958f730357b 100644 --- a/src/Marten/Linq/LastModified/ModifiedBeforeParser.cs +++ b/src/Marten/Linq/LastModified/ModifiedBeforeParser.cs @@ -3,7 +3,7 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -20,7 +20,8 @@ public bool Matches(MethodCallExpression expression) return Equals(expression.Method, _method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { var time = expression.Arguments.Last().Value().As(); diff --git a/src/Marten/Linq/LastModified/ModifiedSinceParser.cs b/src/Marten/Linq/LastModified/ModifiedSinceParser.cs index 0d49adfbc1f..a13e6e6fb78 100644 --- a/src/Marten/Linq/LastModified/ModifiedSinceParser.cs +++ b/src/Marten/Linq/LastModified/ModifiedSinceParser.cs @@ -3,7 +3,7 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -20,7 +20,8 @@ public bool Matches(MethodCallExpression expression) return Equals(expression.Method, _method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { var time = expression.Arguments.Last().Value().As(); diff --git a/src/Marten/Linq/MartenLinqQueryProvider.cs b/src/Marten/Linq/MartenLinqQueryProvider.cs index a80b0883fa2..71affef3b5a 100644 --- a/src/Marten/Linq/MartenLinqQueryProvider.cs +++ b/src/Marten/Linq/MartenLinqQueryProvider.cs @@ -13,7 +13,6 @@ using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Marten.Util; -using Remotion.Linq.Clauses; namespace Marten.Linq; @@ -21,11 +20,14 @@ internal class MartenLinqQueryProvider: IQueryProvider { private readonly QuerySession _session; - public MartenLinqQueryProvider(QuerySession session) + public MartenLinqQueryProvider(QuerySession session, Type type) { _session = session; + SourceType = type; } + public Type SourceType { get; } + internal QueryStatistics Statistics { get; set; } internal IList AllIncludes { get; } = new List(); @@ -47,55 +49,41 @@ public object Execute(Expression expression) public TResult Execute(Expression expression) { - var builder = new LinqHandlerBuilder(this, _session, expression); - var handler = builder.BuildHandler(); + var parser = new LinqQueryParser(this, _session, expression); + var handler = parser.BuildHandler(); - ensureStorageExists(builder); + ensureStorageExists(parser); return ExecuteHandler(handler); } - private void ensureStorageExists(LinqHandlerBuilder builder) + private void ensureStorageExists(LinqQueryParser parser) { - foreach (var documentType in builder.DocumentTypes()) _session.Database.EnsureStorageExists(documentType); + foreach (var documentType in parser.DocumentTypes()) + { + _session.Database.EnsureStorageExists(documentType); + } } - private async ValueTask ensureStorageExistsAsync(LinqHandlerBuilder builder, + internal async ValueTask EnsureStorageExistsAsync(LinqQueryParser parser, CancellationToken cancellationToken) { - foreach (var documentType in builder.DocumentTypes()) + foreach (var documentType in parser.DocumentTypes()) + { await _session.Database.EnsureStorageExistsAsync(documentType, cancellationToken).ConfigureAwait(false); + } } - public async Task ExecuteAsync(Expression expression, CancellationToken token) - { - var builder = new LinqHandlerBuilder(this, _session, expression); - var handler = builder.BuildHandler(); - - await ensureStorageExistsAsync(builder, token).ConfigureAwait(false); - - return await ExecuteHandlerAsync(handler, token).ConfigureAwait(false); - } - - public TResult Execute(Expression expression, ResultOperatorBase op) - { - var builder = new LinqHandlerBuilder(this, _session, expression, op); - var handler = builder.BuildHandler(); - - ensureStorageExists(builder); - - return ExecuteHandler(handler); - } public async Task ExecuteAsync(Expression expression, CancellationToken token, - ResultOperatorBase op) + SingleValueMode valueMode) { try { - var builder = new LinqHandlerBuilder(this, _session, expression, op); - var handler = builder.BuildHandler(); + var parser = new LinqQueryParser(this, _session, expression, valueMode); + var handler = parser.BuildHandler(); - await ensureStorageExistsAsync(builder, token).ConfigureAwait(false); + await EnsureStorageExistsAsync(parser, token).ConfigureAwait(false); return await ExecuteHandlerAsync(handler, token).ConfigureAwait(false); } @@ -108,14 +96,15 @@ public async Task ExecuteAsync(Expression expression, Cancella } public async Task StreamJson(Stream stream, Expression expression, CancellationToken token, - ResultOperatorBase op) + SingleValueMode mode) { try { - var builder = new LinqHandlerBuilder(this, _session, expression, op); - var handler = builder.BuildHandler(); + var parser = new LinqQueryParser(this, _session, expression, mode); - await ensureStorageExistsAsync(builder, token).ConfigureAwait(false); + var handler = parser.BuildHandler(); + + await EnsureStorageExistsAsync(parser, token).ConfigureAwait(false); var cmd = _session.BuildCommand(handler); _session.TrySetTenantId(cmd); @@ -169,13 +158,13 @@ public T ExecuteHandler(IQueryHandler handler) public async IAsyncEnumerable ExecuteAsyncEnumerable(Expression expression, [EnumeratorCancellation] CancellationToken token) { - var builder = new LinqHandlerBuilder(this, _session, expression); - builder.BuildDatabaseStatement(); + var parser = new LinqQueryParser(this, _session, expression); + var statements = parser.BuildStatements(); - await ensureStorageExistsAsync(builder, token).ConfigureAwait(false); + await EnsureStorageExistsAsync(parser, token).ConfigureAwait(false); - var selector = (ISelector)builder.CurrentStatement.SelectClause.BuildSelector(_session); - var statement = builder.TopStatement; + var selector = (ISelector)statements.MainSelector.SelectClause.BuildSelector(_session); + var statement = statements.Top; var cmd = _session.BuildCommand(statement); _session.TrySetTenantId(cmd); @@ -189,37 +178,27 @@ public async IAsyncEnumerable ExecuteAsyncEnumerable(Expression expression public async Task StreamMany(Expression expression, Stream destination, CancellationToken token) { - var builder = BuildLinqHandler(expression); + var parser = new LinqQueryParser(this, _session, expression); + + await EnsureStorageExistsAsync(parser, token).ConfigureAwait(false); - await ensureStorageExistsAsync(builder, token).ConfigureAwait(false); + var statements = parser.BuildStatements(); - var command = builder.TopStatement.BuildCommand(); + var command = statements.Top.BuildCommand(); _session.TrySetTenantId(command); return await _session.StreamMany(command, destination, token).ConfigureAwait(false); } - /// - /// Builds out a LinqHandlerBuilder for this MartenQueryable - /// - /// - /// - internal LinqHandlerBuilder BuildLinqHandler(Expression expression) - { - var builder = new LinqHandlerBuilder(this, _session, expression); - builder.BuildDatabaseStatement(); - return builder; - } - public async Task StreamOne(Expression expression, Stream destination, CancellationToken token) { - var builder = new LinqHandlerBuilder(this, _session, expression); - builder.BuildDatabaseStatement(); + var parser = new LinqQueryParser(this, _session, expression); + var statements = parser.BuildStatements(); - await ensureStorageExistsAsync(builder, token).ConfigureAwait(false); + await EnsureStorageExistsAsync(parser, token).ConfigureAwait(false); - var statement = builder.TopStatement; - statement.Current().Limit = 1; + var statement = statements.Top; + statements.MainSelector.Limit = 1; var command = statement.BuildCommand(); _session.TrySetTenantId(command); diff --git a/src/Marten/Linq/MartenLinqQueryable.cs b/src/Marten/Linq/MartenLinqQueryable.cs index 739a4d98715..a2bfb4e544e 100644 --- a/src/Marten/Linq/MartenLinqQueryable.cs +++ b/src/Marten/Linq/MartenLinqQueryable.cs @@ -1,12 +1,13 @@ #nullable enable using System; +using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using JasperFx.Core; -using JasperFx.Core.Reflection; using Marten.Exceptions; using Marten.Internal.Sessions; using Marten.Internal.Storage; @@ -15,8 +16,6 @@ using Marten.Linq.QueryHandlers; using Marten.Services; using Npgsql; -using Remotion.Linq; -using Remotion.Linq.Clauses; using Weasel.Postgresql; namespace Marten.Linq; @@ -27,51 +26,69 @@ internal interface IMartenLinqQueryable QuerySession Session { get; } Expression Expression { get; } - - LinqHandlerBuilder BuildLinqHandler(); + LinqQueryParser BuildLinqParser(); } -internal class MartenLinqQueryable: QueryableBase, IMartenQueryable, IMartenLinqQueryable +internal class MartenLinqQueryable: IOrderedQueryable, IMartenQueryable, IMartenLinqQueryable { - public MartenLinqQueryable(QuerySession session, MartenLinqQueryProvider provider, Expression expression): base( - provider, - expression) + public MartenLinqQueryable(QuerySession session, MartenLinqQueryProvider provider, Expression expression) { + Provider = provider; Session = session; MartenProvider = provider; + Expression = expression; } - public MartenLinqQueryable(QuerySession session): base(new MartenLinqQueryProvider(session)) + public MartenLinqQueryable(QuerySession session) { Session = session; - MartenProvider = Provider.As(); + MartenProvider = new MartenLinqQueryProvider(session, typeof(T)); + Provider = MartenProvider; + Expression = Expression.Constant(this); } - public MartenLinqQueryable(QuerySession session, Expression expression): base(new MartenLinqQueryProvider(session), - expression) + public MartenLinqQueryable(QuerySession session, Expression expression) : this(session, new MartenLinqQueryProvider(session, typeof(T)), expression) { - Session = session; - MartenProvider = Provider.As(); + } - public LinqHandlerBuilder BuildLinqHandler() + public IEnumerator GetEnumerator () { - return MartenProvider.BuildLinqHandler(Expression); + return Provider.Execute> (Expression).GetEnumerator(); } + IEnumerator IEnumerable.GetEnumerator () + { + return Provider.Execute (Expression).GetEnumerator(); + } + + public Type ElementType => typeof(T); + public IQueryProvider Provider { get; } + public MartenLinqQueryProvider MartenProvider { get; } + public Expression Expression { get; } public QuerySession Session { get; } + public LinqQueryParser BuildLinqParser() + { + return new LinqQueryParser(MartenProvider, Session, Expression); + } + public QueryStatistics Statistics { get => MartenProvider.Statistics; set => MartenProvider.Statistics = value; } - public Task> ToListAsync(CancellationToken token) + public async Task> ToListAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync>(Expression, token); + var builder = new LinqQueryParser(MartenProvider, Session, Expression); + var handler = builder.BuildListHandler(); + + await MartenProvider.EnsureStorageExistsAsync(builder, token).ConfigureAwait(false); + + return await MartenProvider.ExecuteHandlerAsync(handler, token).ConfigureAwait(false); } public IAsyncEnumerable ToAsyncEnumerable(CancellationToken token = default) @@ -81,57 +98,57 @@ public IAsyncEnumerable ToAsyncEnumerable(CancellationToken token = default) public Task AnyAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.AnyOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Any); } public Task CountAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.CountOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Count); } public Task CountLongAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.LongCountOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.LongCount); } public Task FirstAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.FirstOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.First); } public Task FirstOrDefaultAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.FirstOrDefaultOperator)!; + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.FirstOrDefault)!; } public Task SingleAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.SingleOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Single); } public Task SingleOrDefaultAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.SingleOrDefaultOperator)!; + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.SingleOrDefault)!; } public Task SumAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.SumOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Sum); } public Task MinAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.MinOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Min); } public Task MaxAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.MaxOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Max); } public Task AverageAsync(CancellationToken token) { - return MartenProvider.ExecuteAsync(Expression, token, LinqConstants.AverageOperator); + return MartenProvider.ExecuteAsync(Expression, token, SingleValueMode.Average); } public QueryPlan Explain(FetchType fetchType = FetchType.FetchMany, @@ -175,10 +192,10 @@ public IMartenQueryable Stats(out QueryStatistics stats) return this; } - internal IQueryHandler BuildHandler(ResultOperatorBase? op = null) + internal IQueryHandler BuildHandler(SingleValueMode? mode = null) { - var builder = new LinqHandlerBuilder(MartenProvider, Session, Expression, op); - return builder.BuildHandler(); + var parser = new LinqQueryParser(MartenProvider, Session, Expression, mode); + return parser.BuildHandler(); } public Task StreamJsonArray(Stream destination, CancellationToken token) @@ -190,9 +207,9 @@ internal IIncludePlan BuildInclude(Expression> idSourc where TInclude : notnull { var storage = (IDocumentStorage)Session.StorageFor(typeof(TInclude)); - var identityField = Session.StorageFor(typeof(T)).Fields.FieldFor(idSource); + var identityMember = Session.StorageFor(typeof(T)).QueryMembers.MemberFor(idSource); - var include = new IncludePlan(storage, identityField, callback); + var include = new IncludePlan(storage, identityMember, callback); return include; } @@ -203,7 +220,7 @@ internal IIncludePlan BuildInclude(Expression> i if (storage is IDocumentStorage s) { - var identityField = Session.StorageFor(typeof(T)).Fields.FieldFor(idSource); + var identityMember = Session.StorageFor(typeof(T)).QueryMembers.MemberFor(idSource); void Callback(TInclude item) { @@ -211,7 +228,7 @@ void Callback(TInclude item) dictionary[id] = item; } - return new IncludePlan(storage, identityField, Callback); + return new IncludePlan(storage, identityMember, Callback); } throw new DocumentIdTypeMismatchException(storage, typeof(TKey)); @@ -219,15 +236,16 @@ void Callback(TInclude item) public NpgsqlCommand ToPreviewCommand(FetchType fetchType) { - var builder = new LinqHandlerBuilder(MartenProvider, Session, Expression); + var parser = new LinqQueryParser(MartenProvider, Session, Expression); + var command = new NpgsqlCommand(); var sql = new CommandBuilder(command); - builder.BuildDiagnosticCommand(fetchType, sql); + parser.BuildDiagnosticCommand(fetchType, sql); command.CommandText = sql.ToString(); - foreach (var documentType in builder.DocumentTypes()) Session.Database.EnsureStorageExists(documentType); + foreach (var documentType in parser.DocumentTypes()) Session.Database.EnsureStorageExists(documentType); Session._connection.Apply(command); @@ -244,22 +262,22 @@ public async Task ToJsonArray(CancellationToken token) public Task StreamJsonFirst(Stream destination, CancellationToken token) { - return MartenProvider.StreamJson(destination, Expression, token, LinqConstants.FirstOperator); + return MartenProvider.StreamJson(destination, Expression, token, SingleValueMode.First); } public Task StreamJsonFirstOrDefault(Stream destination, CancellationToken token) { - return MartenProvider.StreamJson(destination, Expression, token, LinqConstants.FirstOrDefaultOperator); + return MartenProvider.StreamJson(destination, Expression, token, SingleValueMode.FirstOrDefault); } public Task StreamJsonSingle(Stream destination, CancellationToken token) { - return MartenProvider.StreamJson(destination, Expression, token, LinqConstants.SingleOperator); + return MartenProvider.StreamJson(destination, Expression, token, SingleValueMode.Single); } public Task StreamJsonSingleOrDefault(Stream destination, CancellationToken token) { - return MartenProvider.StreamJson(destination, Expression, token, LinqConstants.SingleOrDefaultOperator); + return MartenProvider.StreamJson(destination, Expression, token, SingleValueMode.SingleOrDefault); } public async Task ToJsonFirst(CancellationToken token) diff --git a/src/Marten/Linq/MatchesSql/MatchesSqlParser.cs b/src/Marten/Linq/MatchesSql/MatchesSqlParser.cs index 432d6363c4b..66462e1f748 100644 --- a/src/Marten/Linq/MatchesSql/MatchesSqlParser.cs +++ b/src/Marten/Linq/MatchesSql/MatchesSqlParser.cs @@ -1,7 +1,7 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Weasel.Postgresql.SqlGeneration; @@ -22,7 +22,8 @@ public bool Matches(MethodCallExpression expression) return Equals(expression.Method, _sqlMethod) || Equals(expression.Method, _fragmentMethod); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { if (expression.Method.Equals(_sqlMethod)) { diff --git a/src/Marten/Linq/Members/BooleanMember.cs b/src/Marten/Linq/Members/BooleanMember.cs new file mode 100644 index 00000000000..71bae1f74f0 --- /dev/null +++ b/src/Marten/Linq/Members/BooleanMember.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class BooleanMember: QueryableMember, IComparableMember, IBooleanField +{ + public BooleanMember(IQueryableMember parent, Casing casing, MemberInfo member, string pgType): base(parent, + casing, member) + { + TypedLocator = $"CAST({RawLocator} as {pgType})"; + } + + public ISqlFragment BuildIsTrueFragment() + { + return new BooleanFieldIsTrue(this); + } +} diff --git a/src/Marten/Linq/Members/ChildCollectionCount.cs b/src/Marten/Linq/Members/ChildCollectionCount.cs new file mode 100644 index 00000000000..78e776509fc --- /dev/null +++ b/src/Marten/Linq/Members/ChildCollectionCount.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Marten.Exceptions; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class ChildCollectionCount: IComparableMember, IWhereFragmentHolder +{ + private readonly ICollectionMember _collection; + private readonly ISerializer _serializer; + + public ChildCollectionCount(ICollectionMember collection, ISerializer serializer) + { + _collection = collection; + _serializer = serializer; + } + + public List Wheres { get; } = new(); + + public ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (Wheres.All(x => x is ICollectionAware aware && aware.CanBeJsonPathFilter())) + { + return new ChildCollectionJsonPathCountFilter(_collection, _serializer, Wheres.OfType(), + op, constant); + } + + throw new BadLinqExpressionException( + "Marten does not (yet) support this pattern for child collection.Count() queries"); + } + + void IWhereFragmentHolder.Register(ISqlFragment fragment) + { + Wheres.Add(fragment); + } +} diff --git a/src/Marten/Linq/Members/ChildCollectionJsonPathCountFilter.cs b/src/Marten/Linq/Members/ChildCollectionJsonPathCountFilter.cs new file mode 100644 index 00000000000..279651a45fe --- /dev/null +++ b/src/Marten/Linq/Members/ChildCollectionJsonPathCountFilter.cs @@ -0,0 +1,106 @@ +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.CodeGeneration; +using Marten.Internal.CompiledQueries; +using Marten.Linq.Parsing; +using Marten.Linq.SqlGeneration.Filters; +using NpgsqlTypes; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class ChildCollectionJsonPathCountFilter: ISqlFragment, ICompiledQueryAwareFilter +{ + private readonly ConstantExpression _constant; + private readonly ICollectionAware[] _filters; + private readonly ICollectionMember _member; + private readonly string _op; + private readonly ISerializer _serializer; + private List? _usages; + + public ChildCollectionJsonPathCountFilter(ICollectionMember member, ISerializer serializer, + IEnumerable filters, string op, ConstantExpression constant) + { + _member = member; + _serializer = serializer; + _op = op; + _constant = constant; + _filters = filters.ToArray(); + } + + public void Apply(CommandBuilder builder) + { + builder.Append("jsonb_array_length(jsonb_path_query_array(d.data, '$."); + _member.WriteJsonPath(builder); + builder.Append(" ? ("); + + + _dict = new Dictionary(); + _filters[0].BuildJsonPathFilter(builder, _dict); + + for (var i = 1; i < _filters.Length; i++) + { + builder.Append(" && "); + _filters[i].BuildJsonPathFilter(builder, _dict); + } + + if (_dict.Count == 0) + { + builder.Append(")')) "); + } + else + { + builder.Append(")', "); + builder.AppendParameter(_serializer.ToCleanJson(_dict), NpgsqlDbType.Jsonb); + ParameterName = builder.LastParameterName; + + builder.Append(")) "); + } + + builder.Append(_op); + builder.Append(" "); + builder.AppendParameter(_constant.Value()); + } + + public bool Contains(string sqlText) + { + return false; + } + + public bool TryMatchValue(object value, MemberInfo member) + { + _usages ??= _filters.SelectMany(x => x.Values()).ToList(); + + var usage = _usages.FirstOrDefault(x => x.Value.Equals(value)); + if (usage != null) + { + usage.QueryMember = member; + return true; + } + + return false; + } + + private bool _hasGenerated; + private Dictionary _dict; + + public void GenerateCode(GeneratedMethod method, int parameterIndex) + { + if (_hasGenerated) + { + return; + } + + _hasGenerated = true; + + var top = new DictionaryDeclaration(); + top.ReadDictionary(_dict, _usages); + + method.Frames.Add(new WriteSerializedJsonParameterFrame(parameterIndex, top)); + } + + public string? ParameterName { get; private set; } +} diff --git a/src/Marten/Linq/Members/ChildCollectionMember.cs b/src/Marten/Linq/Members/ChildCollectionMember.cs new file mode 100644 index 00000000000..5d0b0d4a6b6 --- /dev/null +++ b/src/Marten/Linq/Members/ChildCollectionMember.cs @@ -0,0 +1,301 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Internal; +using Marten.Linq.Parsing; +using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class ChildCollectionMember: QueryableMember, ICollectionMember, IQueryableMemberCollection +{ + private readonly IQueryableMember _count; + private readonly StoreOptions _options; + private readonly RootMember _root; + private ImHashMap _members = ImHashMap.Empty; + + public ChildCollectionMember(StoreOptions options, IQueryableMember parent, Casing casing, MemberInfo member): base( + parent, casing, member) + { + _options = options; + TypedLocator = $"{parent.RawLocator} -> '{MemberName}'"; + ElementType = MemberType.DetermineElementType(); + + _root = new RootMember(ElementType) { Ancestors = Array.Empty() }; + + _count = new CollectionLengthMember(this); + + JsonPathSegment = MemberName + "[*]"; + + ArrayLocator = $"CAST(ARRAY(SELECT jsonb_array_elements(CAST({RawLocator} as jsonb))) as jsonb[])"; + ExplodeLocator = $"unnest({ArrayLocator})"; + } + + public string ArrayLocator { get; set; } + + public Type ElementType { get; } + + public ISqlFragment ParseWhereForAny(Expression body, IReadOnlyStoreOptions options) + { + var whereClause = new ChildCollectionWhereClause(); + var parser = new WhereClauseParser((StoreOptions)options, this, whereClause); + parser.Visit(body); + + return whereClause.CompileFragment(this, options.Serializer()); + } + + public string ExplodeLocator { get; } + + public SelectorStatement BuildChildStatement(CollectionUsage collectionUsage, IMartenSession session, + SelectorStatement parentStatement) + { + var selectClause = + typeof(DataSelectClause<>).CloseAndBuildAs(parentStatement.ExportName, ElementType); + return (SelectorStatement)collectionUsage.BuildStatement(session, this, selectClause); + } + + public ISelectClause BuildSelectClauseForExplosion(string fromObject) + { + var selection = $"jsonb_array_elements({JSONBLocator})"; + return typeof(DataSelectClause<>).CloseAndBuildAs(fromObject, selection, + ElementType); + } + + public IComparableMember ParseComparableForCount(Expression body) + { + if (body is LambdaExpression l) + { + body = l.Body; + } + + var countComparable = new ChildCollectionCount(this, _options.Serializer()); + var parser = new WhereClauseParser(_options, this, countComparable); + parser.Visit(body); + + return countComparable; + } + + public ISqlFragment ParseWhereForAll(MethodCallExpression method, IReadOnlyStoreOptions options) + { + if (method.Arguments.Last() is LambdaExpression l) + { + var body = l.Body; + var filter = new AllCollectionConditionFilter(this); + var parser = new WhereClauseParser(_options, this, filter); + parser.Visit(body); + + filter.Compile(method); + + return filter; + } + else + { + throw new BadLinqExpressionException($"Marten cannot derive a Collection.All() filter for expression '{method}'"); + } + + + } + + public ISqlFragment ParseWhereForContains(MethodCallExpression body, IReadOnlyStoreOptions options) + { + throw new NotImplementedException(); + } + + + public override IQueryableMember FindMember(MemberInfo member) + { + if (_members.TryFind(member.Name, out var m)) + { + return m; + } + + if (member.Name == "Count" || member.Name == "Length") + { + _members = _members.AddOrUpdate(member.Name, _count); + return _count; + } + + m = _options.CreateQueryableMember(member, _root); + _members = _members.AddOrUpdate(member.Name, m); + + return m; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return _members.Enumerate().Select(x => x.Value).GetEnumerator(); + } +} + +internal class AllCollectionConditionFilter: ISubQueryFilter, IWhereFragmentHolder +{ + private ISqlFragment _filter; + private string _exportName; + public ICollectionMember Member { get; } + + public AllCollectionConditionFilter(ICollectionMember member) + { + Member = member; + } + + public List Wheres { get; } = new(); + + public void Apply(CommandBuilder builder) + { + if (Not) + { + builder.Append("NOT("); + } + + builder.Append("d.ctid in (select ctid from "); + builder.Append(_exportName); + builder.Append(")"); + + if (Not) + { + builder.Append(")"); + } + } + + public bool Contains(string sqlText) + { + return false; + } + + /// + /// Psych! Should there be a NOT in front of the sub query + /// + public bool Not { get; set; } + + public ISqlFragment Reverse() + { + Not = !Not; + return this; + } + + public void PlaceUnnestAbove(IMartenSession session, SelectorStatement statement, ISqlFragment topLevelWhere = null) + { + // First need to unnest the collection into its own recordset + var unnest = new ExplodeCollectionStatement(session, statement, Member.ArrayLocator) { Where = topLevelWhere }; + + // Second, filter the collection + var filter = new FilterStatement(session, unnest, _filter); + + _exportName = filter.ExportName; + } + + public void Register(ISqlFragment fragment) + { + Wheres.Add(fragment); + } + + public void Compile(MethodCallExpression methodCallExpression) + { + if (Wheres.Count() == 1) + { + switch (Wheres.Single()) + { + case MemberComparisonFilter { Right: CommandParameter } filter: + _filter = new CompareAllWithinCollectionFilter(filter); + return; + case IsNullFilter nf: + _filter = new AllMembersAreNullFilter(nf.Member); + return; + case IsNotNullFilter notnull: + _filter = new AllMembersAreNotNullFilter(notnull.Member); + return; + } + } + + throw new BadLinqExpressionException($"Marten can not (yet) parse the expression '{methodCallExpression}'"); + } +} + +internal class CompareAllWithinCollectionFilter: ISqlFragment +{ + private readonly MemberComparisonFilter _inner; + + public CompareAllWithinCollectionFilter(MemberComparisonFilter inner) + { + _inner = inner; + } + + public void Apply(CommandBuilder builder) + { + _inner.Right.Apply(builder); + builder.Append(" "); + builder.Append(_inner.Op); + + builder.Append(" ALL (array(select "); + var locator = _inner.Member.TypedLocator.Replace("d.data", "unnest(data)"); + builder.Append(locator); + builder.Append("))"); + } + + public bool Contains(string sqlText) + { + return false; + } +} + + +internal class AllMembersAreNullFilter: ISqlFragment +{ + private readonly IQueryableMember _member; + + public AllMembersAreNullFilter(IQueryableMember member) + { + _member = member; + } + + public void Apply(CommandBuilder builder) + { + builder.Append("true = ALL (select unnest(array(select "); + var locator = _member.TypedLocator.Replace("d.data", "unnest(data)"); + builder.Append(locator); + builder.Append(" )) is null)"); + } + + public bool Contains(string sqlText) + { + return false; + } +} + +internal class AllMembersAreNotNullFilter: ISqlFragment +{ + private readonly IQueryableMember _member; + + public AllMembersAreNotNullFilter(IQueryableMember member) + { + _member = member; + } + + public void Apply(CommandBuilder builder) + { + builder.Append("true = ALL (array(select "); + var locator = _member.TypedLocator.Replace("d.data", "unnest(data)"); + builder.Append(locator); + builder.Append(" )) is not null)"); + } + + public bool Contains(string sqlText) + { + return false; + } +} + diff --git a/src/Marten/Linq/Members/ChildCollectionWhereClause.cs b/src/Marten/Linq/Members/ChildCollectionWhereClause.cs new file mode 100644 index 00000000000..86bd90f54e1 --- /dev/null +++ b/src/Marten/Linq/Members/ChildCollectionWhereClause.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; +using JasperFx.Core; +using Marten.Exceptions; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class ChildCollectionWhereClause: IWhereFragmentHolder +{ + private ISqlFragment _fragment; + + public void Register(ISqlFragment fragment) + { + _fragment = fragment; + } + + public static bool TryBuildInlineFragment(ISqlFragment fragment, ICollectionMember collectionMember, + ISerializer serializer, out ICollectionAwareFilter filter) + { + if (fragment is ICollectionAware collectionAware && collectionAware.CanReduceInChildCollection()) + { + filter = collectionAware.BuildFragment(collectionMember, serializer); + + return true; + } + + if (fragment is CompoundWhereFragment compound) + { + if (compound.Children.All(x => x is ICollectionAware aware && aware.CanReduceInChildCollection())) + { + var children = compound.Children.OfType().ToArray(); + if (compound.Separator.ContainsIgnoreCase("and")) + { + if (children.All(x => x.SupportsContainment())) + { + var containment = new ContainmentWhereFilter(collectionMember, serializer) + { + Usage = ContainmentUsage.Collection + }; + + foreach (var child in children) child.PlaceIntoContainmentFilter(containment); + + filter = containment; + return true; + } + } + } + } + + filter = default; + return false; + } + + public ISqlFragment CompileFragment(ICollectionMember collectionMember, ISerializer serializer) + { + if (_fragment is ICollectionAwareFilter awareFilter && awareFilter.CollectionMember != collectionMember) + { + return awareFilter.MoveUnder(collectionMember); + } + + if (TryBuildInlineFragment(_fragment, collectionMember, serializer, out var filter)) + { + return filter; + } + + return new SubQueryFilter(collectionMember, _fragment); + } +} diff --git a/src/Marten/Linq/Members/ChildDocument.cs b/src/Marten/Linq/Members/ChildDocument.cs new file mode 100644 index 00000000000..d7c5e8a7e30 --- /dev/null +++ b/src/Marten/Linq/Members/ChildDocument.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class ChildDocument: QueryableMember, IQueryableMemberCollection, IComparableMember +{ + private readonly StoreOptions _options; + private ImHashMap _members = ImHashMap.Empty; + + + public ChildDocument(StoreOptions options, IQueryableMember parent, Casing casing, MemberInfo member): base( + parent, casing, member) + { + _options = options; + + RawLocator = TypedLocator = $"{parent.RawLocator} -> '{MemberName}'"; + + NullTestLocator = $"{parent.RawLocator} ->> '{MemberName}'"; + + ElementType = member.GetMemberType(); + } + + public override ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (constant == null || constant.Value == null) + { + switch (op) + { + case "=": + return new IsNullFilter(this); + + case "!=": + return new IsNotNullFilter(this); + } + } + + throw new BadLinqExpressionException( + "Marten cannot support custom value types in Linq expression. Please query on either simple properties of the value type, or register a custom IMemberSource for this value type."); + } + + public Type ElementType { get; } + + + public override IQueryableMember FindMember(MemberInfo member) + { + if (_members.TryFind(member.Name, out var m)) + { + return m; + } + + m = _options.CreateQueryableMember(member, this); + _members = _members.AddOrUpdate(member.Name, m); + + return m; + } + + public override void ReplaceMember(MemberInfo member, IQueryableMember queryableMember) + { + _members = _members.AddOrUpdate(member.Name, queryableMember); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return _members.Enumerate().Select(x => x.Value).GetEnumerator(); + } +} diff --git a/src/Marten/Linq/Members/CollectionLengthMember.cs b/src/Marten/Linq/Members/CollectionLengthMember.cs new file mode 100644 index 00000000000..05fb29c52c3 --- /dev/null +++ b/src/Marten/Linq/Members/CollectionLengthMember.cs @@ -0,0 +1,21 @@ +using System.Linq.Expressions; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class CollectionLengthMember: QueryableMember, IComparableMember +{ + public CollectionLengthMember(ICollectionMember parent): base(parent, "Count", typeof(int)) + { + RawLocator = TypedLocator = $"jsonb_array_length({parent.JSONBLocator})"; + Parent = parent; + } + + public ICollectionMember Parent { get; } + + public override ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + var def = new CommandParameter(constant); + return new ComparisonFilter(this, def, op); + } +} diff --git a/src/Marten/Linq/Members/DateTimeMember.cs b/src/Marten/Linq/Members/DateTimeMember.cs new file mode 100644 index 00000000000..4b086de9767 --- /dev/null +++ b/src/Marten/Linq/Members/DateTimeMember.cs @@ -0,0 +1,17 @@ +using System.Reflection; + +namespace Marten.Linq.Members; + +public class DateTimeMember: QueryableMember, IComparableMember +{ + public DateTimeMember(StoreOptions options, IQueryableMember parent, Casing casing, MemberInfo member): base(parent, + casing, member) + { + TypedLocator = $"{options.DatabaseSchemaName}.mt_immutable_timestamp({RawLocator})"; + } + + public override string SelectorForDuplication(string pgType) + { + return TypedLocator.Replace("d.", ""); + } +} diff --git a/src/Marten/Linq/Members/DateTimeOffsetMember.cs b/src/Marten/Linq/Members/DateTimeOffsetMember.cs new file mode 100644 index 00000000000..74a759a61a8 --- /dev/null +++ b/src/Marten/Linq/Members/DateTimeOffsetMember.cs @@ -0,0 +1,17 @@ +using System.Reflection; + +namespace Marten.Linq.Members; + +public class DateTimeOffsetMember: QueryableMember, IComparableMember +{ + public DateTimeOffsetMember(StoreOptions options, IQueryableMember parent, Casing casing, MemberInfo member): base( + parent, casing, member) + { + TypedLocator = $"{options.DatabaseSchemaName}.mt_immutable_timestamptz({RawLocator})"; + } + + public override string SelectorForDuplication(string pgType) + { + return TypedLocator.Replace("d.", ""); + } +} diff --git a/src/Marten/Linq/Members/DictionaryMember.cs b/src/Marten/Linq/Members/DictionaryMember.cs new file mode 100644 index 00000000000..52770eb6444 --- /dev/null +++ b/src/Marten/Linq/Members/DictionaryMember.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using Marten.Exceptions; +using Marten.Internal; +using Marten.Linq.Parsing; +using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Core; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal interface IDictionaryMember +{ + IQueryableMember MemberForKey(object keyValue); +} + +internal class DictionaryMember: QueryableMember, IComparableMember, IDictionaryMember, ICollectionMember +{ + public DictionaryMember(IQueryableMember parent, Casing casing, MemberInfo member): base(parent, casing, member) + { + RawLocator = $"{parent.JSONBLocator} ->> '{MemberName}'"; + TypedLocator = $"{parent.JSONBLocator} -> '{MemberName}'"; + } + + public IQueryableMember MemberForKey(object keyValue) + { + var key = (TKey)keyValue; + return new DictionaryItemMember(this, key); + } + + public override void PlaceValueInDictionaryForContainment(Dictionary dict, + ConstantExpression constant) + { + if (constant.Value is TValue) + { + base.PlaceValueInDictionaryForContainment(dict, constant); + } + else if (constant.Value is KeyValuePair pair) + { + var childDict = new Dictionary(); + childDict[pair.Key] = pair.Value; + + dict[MemberName] = childDict; + } + else + { + throw new BadLinqExpressionException("Marten can not (yet) support value " + constant.Value + + " in a search involving a dictionary member"); + } + } + + Type ICollectionMember.ElementType => typeof(KeyValuePair); + + string ICollectionMember.ExplodeLocator => throw new NotImplementedException(); + + string ICollectionMember.ArrayLocator => throw new NotImplementedException(); + + SelectorStatement ICollectionMember.BuildChildStatement(CollectionUsage collectionUsage, IMartenSession session, + SelectorStatement parentStatement) + { + throw new NotImplementedException(); + } + + ISelectClause ICollectionMember.BuildSelectClauseForExplosion(string fromObject) + { + throw new NotImplementedException(); + } + + ISqlFragment ICollectionMember.ParseWhereForAny(Expression body, IReadOnlyStoreOptions options) + { + throw new NotImplementedException(); + } + + IComparableMember ICollectionMember.ParseComparableForCount(Expression body) + { + throw new NotImplementedException(); + } + + ISqlFragment ICollectionMember.ParseWhereForAll(MethodCallExpression body, IReadOnlyStoreOptions options) + { + throw new NotImplementedException(); + } + + ISqlFragment ICollectionMember.ParseWhereForContains(MethodCallExpression body, IReadOnlyStoreOptions options) + { + var constant = body.Arguments.Single().ReduceToConstant(); + + return new ContainmentWhereFilter(this, constant, options.Serializer()); + } +} + +internal class DictionaryItemMember: QueryableMember, IComparableMember +{ + public DictionaryItemMember(DictionaryMember parent, TKey key) + : base(parent, key.ToString(), typeof(TValue)) + { + Parent = parent; + Key = key; + + RawLocator = TypedLocator = $"{Parent.TypedLocator} ->> '{key}'"; + + if (typeof(TValue) != typeof(string)) + { + // Not supporting enums here anyway + var pgType = PostgresqlProvider.Instance.GetDatabaseType(MemberType, EnumStorage.AsInteger); + + TypedLocator = $"CAST({TypedLocator} as {pgType})"; + } + } + + public DictionaryMember Parent { get; } + public TKey Key { get; } + + public override ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (typeof(TValue) == typeof(object)) + { + var value = constant.Value(); + if (value == null) + { + return base.CreateComparison(op, constant); + } + + var valueType = value.GetType(); + if (valueType.IsEnum) + { + throw new BadLinqExpressionException( + "Marten does not (yet) support enumeration values as Dictionary values"); + } + + var pgType = PostgresqlProvider.Instance.GetDatabaseType(valueType, EnumStorage.AsInteger); + return new WhereFragment($"CAST({TypedLocator} as {pgType}) {op} ?", value); + } + + return base.CreateComparison(op, constant); + } +} diff --git a/src/Marten/Linq/Members/DocumentQueryableMemberCollection.cs b/src/Marten/Linq/Members/DocumentQueryableMemberCollection.cs new file mode 100644 index 00000000000..53800f3edce --- /dev/null +++ b/src/Marten/Linq/Members/DocumentQueryableMemberCollection.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core; +using Marten.Linq.Parsing.Operators; +using Marten.Schema; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class DocumentQueryableMemberCollection: IQueryableMemberCollection, IQueryableMember +{ + private readonly StoreOptions _options; + private ImHashMap _members = ImHashMap.Empty; + + public DocumentQueryableMemberCollection(IDocumentMapping mapping, StoreOptions options) + { + _options = options; + ElementType = mapping.DocumentType; + } + + public string MemberName => string.Empty; + + public string JsonPathSegment => ""; + + void ISqlFragment.Apply(CommandBuilder builder) + { + builder.Append("d.data"); + } + + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + + Type IQueryableMember.MemberType => ElementType; + + string IQueryableMember.TypedLocator => "d.data"; + + string IQueryableMember.RawLocator => "d.data"; + + string IQueryableMember.JSONBLocator => "d.data"; + + string IQueryableMember.BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + throw new NotSupportedException(); + } + + IQueryableMember[] IQueryableMember.Ancestors => Array.Empty(); + + Dictionary IQueryableMember.FindOrPlaceChildDictionaryForContainment( + Dictionary dict) + { + throw new NotSupportedException(); + } + + void IQueryableMember.PlaceValueInDictionaryForContainment(Dictionary dict, + ConstantExpression constant) + { + throw new NotSupportedException(); + } + + string IQueryableMember.LocatorForIncludedDocumentId => throw new NotSupportedException(); + public string NullTestLocator { get; } = "d.data"; + + public string SelectorForDuplication(string pgType) + { + throw new NotSupportedException(); + } + + public Type ElementType { get; } + + public IQueryableMember FindMember(MemberInfo member) + { + if (_members.TryFind(member.Name, out var m)) + { + return m; + } + + m = _options.CreateQueryableMember(member, this); + _members = _members.AddOrUpdate(member.Name, m); + + return m; + } + + public void ReplaceMember(MemberInfo member, IQueryableMember queryableMember) + { + _members = _members.AddOrUpdate(member.Name, queryableMember); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return _members.Enumerate().Select(x => x.Value).GetEnumerator(); + } +} diff --git a/src/Marten/Linq/Members/DuplicatedArrayField.cs b/src/Marten/Linq/Members/DuplicatedArrayField.cs new file mode 100644 index 00000000000..0fe9036c5e9 --- /dev/null +++ b/src/Marten/Linq/Members/DuplicatedArrayField.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Internal; +using Marten.Linq.Parsing; +using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Core; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class DuplicatedArrayField: DuplicatedField, ICollectionMember, IQueryableMemberCollection +{ + public DuplicatedArrayField(EnumStorage enumStorage, QueryableMember innerMember, bool useTimestampWithoutTimeZoneForDateTime = true, bool notNull = false) : base(enumStorage, innerMember, useTimestampWithoutTimeZoneForDateTime, notNull) + { + if (innerMember is not ValueCollectionMember) + throw new ArgumentOutOfRangeException(nameof(innerMember), + $"Only collections of simple types can be duplicated. Actual element type: {innerMember.MemberType.FullNameInCode()}"); + + ElementType = InnerMember.As().ElementType; + ExplodeLocator = + $"UNNEST({ArrayLocator})"; + + _wholeDataMember = new WholeDataMember(ElementType); + + var innerPgType = PostgresqlProvider.Instance.GetDatabaseType(ElementType, EnumStorage.AsInteger); + var pgType = PostgresqlProvider.Instance.HasTypeMapping(ElementType) ? innerPgType + "[]" : "jsonb"; + ElementMember = new SimpleElementMember(ElementType, pgType); + + _count = new CollectionLengthMember(this); + } + + private readonly WholeDataMember _wholeDataMember; + private readonly CollectionLengthMember _count; + public Type ElementType { get; } + public string ExplodeLocator { get; } + public string ArrayLocator => TypedLocator; + public IQueryableMember ElementMember { get; } + + public SelectorStatement BuildChildStatement(CollectionUsage collectionUsage, IMartenSession session, + SelectorStatement parentStatement) + { + var statement = ElementType == typeof(string) + ? new ScalarSelectManyStringStatement(parentStatement) + : typeof(ScalarSelectManyStatement<>).CloseAndBuildAs(parentStatement, + session.Serializer, ElementType); + + collectionUsage.ProcessSingleValueModeIfAny(statement); + + return statement; + } + + public ISelectClause BuildSelectClauseForExplosion(string fromObject) + { + var selection = $"jsonb_array_elements_text({JSONBLocator})"; + + return typeof(DataSelectClause<>).CloseAndBuildAs(fromObject, selection, + ElementType); + } + + public ISqlFragment ParseWhereForAny(Expression body, IReadOnlyStoreOptions options) + { + var whereClause = new ChildCollectionWhereClause(); + var parser = new WhereClauseParser((StoreOptions)options, this, whereClause); + parser.Visit(body); + + return whereClause.CompileFragment(this, options.Serializer()); + } + + public IComparableMember ParseComparableForCount(Expression body) + { + throw new BadLinqExpressionException( + "Marten does not (yet) support Linq filters within the Count() expression of a scalar value collection"); + } + + public ISqlFragment ParseWhereForAll(MethodCallExpression body, IReadOnlyStoreOptions options) + { + var constant = body.Arguments[1].ReduceToConstant(); + + if (constant.Value() == null) return new AllValuesAreNullFilter(this); + + return new AllValuesEqualFilter(constant, this); + } + + public ISqlFragment ParseWhereForContains(MethodCallExpression body, IReadOnlyStoreOptions options) + { + return new WhereFragment($"? = ANY({TypedLocator})", body.Arguments.Last().Value()); + } + + public IQueryableMember FindMember(MemberInfo member) + { + if (member.Name == "Count" || member.Name == "Length") + { + return _count; + } + + return _wholeDataMember; + } + + public void ReplaceMember(MemberInfo member, IQueryableMember queryableMember) + { + throw new NotSupportedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + throw new NotSupportedException(); + } +} diff --git a/src/Marten/Linq/Fields/DuplicatedField.cs b/src/Marten/Linq/Members/DuplicatedField.cs similarity index 59% rename from src/Marten/Linq/Fields/DuplicatedField.cs rename to src/Marten/Linq/Members/DuplicatedField.cs index 54316fa846b..10f60795083 100644 --- a/src/Marten/Linq/Fields/DuplicatedField.cs +++ b/src/Marten/Linq/Members/DuplicatedField.cs @@ -1,12 +1,14 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; using JasperFx.Core; using JasperFx.Core.Reflection; using Marten.Exceptions; -using Marten.Linq.Filters; using Marten.Linq.Parsing; +using Marten.Linq.Parsing.Operators; +using Marten.Linq.SqlGeneration.Filters; using Marten.Schema; using Marten.Schema.Arguments; using Marten.Util; @@ -16,50 +18,63 @@ using Weasel.Postgresql.SqlGeneration; using Weasel.Postgresql.Tables; -namespace Marten.Linq.Fields; +namespace Marten.Linq.Members; -public class DuplicatedField: IField +public class DuplicatedField: IQueryableMember, IComparableMember { - private readonly Func _parseObject = expression => expression.Value(); + private readonly Func _parseObject = o => o; private readonly bool useTimestampWithoutTimeZoneForDateTime; private string _columnName; - public DuplicatedField(EnumStorage enumStorage, IField innerField, + public DuplicatedField(EnumStorage enumStorage, QueryableMember innerMember, bool useTimestampWithoutTimeZoneForDateTime = true, bool notNull = false) { - InnerField = innerField; - MemberName = InnerField.Members.Select(x => x.Name).Join(""); + InnerMember = innerMember; + MemberName = InnerMember.Ancestors.OfType().Select(x => x.MemberName).Append(InnerMember.MemberName).Join(""); + + Members = InnerMember.Ancestors.OfType().Append(InnerMember).Select(x => x.Member).ToArray(); + NotNull = notNull; ColumnName = MemberName.ToTableAlias(); this.useTimestampWithoutTimeZoneForDateTime = useTimestampWithoutTimeZoneForDateTime; - PgType = PostgresqlProvider.Instance.GetDatabaseType(FieldType, enumStorage); + PgType = PostgresqlProvider.Instance.GetDatabaseType(MemberType, enumStorage); - if (FieldType.IsEnum) + if (MemberType.IsEnum || MemberType.IsNullable() && MemberType.GetGenericArguments()[0].IsEnum) { + var enumType = MemberType.IsEnum ? MemberType : MemberType.GetGenericArguments()[0]; + if (enumStorage == EnumStorage.AsString) { DbType = NpgsqlDbType.Varchar; PgType = "varchar"; - _parseObject = expression => + _parseObject = raw => { - var raw = expression.Value(); if (raw == null) { return null; } - return Enum.GetName(FieldType, raw); + return Enum.GetName(enumType, raw); }; } else { DbType = NpgsqlDbType.Integer; PgType = "integer"; + _parseObject = raw => + { + if (raw == null) + { + return null; + } + + return (int)raw; + }; } } - else if (FieldType.IsDateTime()) + else if (MemberType.IsDateTime()) { PgType = this.useTimestampWithoutTimeZoneForDateTime ? "timestamp without time zone" @@ -68,18 +83,42 @@ public DuplicatedField(EnumStorage enumStorage, IField innerField, ? NpgsqlDbType.Timestamp : NpgsqlDbType.TimestampTz; } - else if (FieldType == typeof(DateTimeOffset) || FieldType == typeof(DateTimeOffset?)) + else if (MemberType == typeof(DateTimeOffset) || MemberType == typeof(DateTimeOffset?)) { PgType = "timestamp with time zone"; DbType = NpgsqlDbType.TimestampTz; } else { - DbType = PostgresqlProvider.Instance.ToParameterType(FieldType); + DbType = PostgresqlProvider.Instance.ToParameterType(MemberType); } } - public bool NotNull { get; } + public MemberInfo[] Members { get; } + + public string JsonPathSegment => throw new NotSupportedException(); + public string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + // TODO -- memoize or intern this. Watch if this is a string!!! + if (ordering.Direction == OrderingDirection.Desc) return "d.id desc"; + + return TypedLocator; + } + + public IQueryableMember[] Ancestors => InnerMember.Ancestors; + public Dictionary FindOrPlaceChildDictionaryForContainment(Dictionary dict) + { + throw new NotSupportedException(); + } + + public void PlaceValueInDictionaryForContainment(Dictionary dict, ConstantExpression constant) + { + throw new NotSupportedException(); + } + + public string NullTestLocator => RawLocator; + + public bool NotNull { get; internal set; } public bool OnlyForSearching { get; set; } = false; @@ -109,7 +148,7 @@ public string ColumnName } } - internal IField InnerField { get; } + internal QueryableMember InnerMember { get; } public string MemberName { get; } public string PgType { get; set; } // settable so it can be overidden by users @@ -119,7 +158,8 @@ public string ColumnName public object GetValueForCompiledQueryParameter(Expression valueExpression) { - return _parseObject(valueExpression); + var value = valueExpression.Value(); + return _parseObject(value); } public bool ShouldUseContainmentOperator() @@ -127,14 +167,14 @@ public bool ShouldUseContainmentOperator() return false; } - string IField.SelectorForDuplication(string pgType) + string IQueryableMember.SelectorForDuplication(string pgType) { throw new NotSupportedException(); } - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) + public ISqlFragment CreateComparison(string op, ConstantExpression constant) { - if (value.Value == null) + if (constant.Value == null) { return op switch { @@ -145,7 +185,7 @@ public ISqlFragment CreateComparison(string op, ConstantExpression value, Expres }; } - return new ComparisonFilter(this, new CommandParameter(_parseObject(value), DbType), op); + return new ComparisonFilter(this, new CommandParameter(_parseObject(constant.Value), DbType), op); } public string JSONBLocator { get; set; } @@ -168,9 +208,7 @@ bool ISqlFragment.Contains(string sqlText) return TypedLocator.Contains(sqlText); } - public Type FieldType => InnerField.FieldType; - - public MemberInfo[] Members => InnerField.Members; + public Type MemberType => InnerMember.MemberType; public string ToOrderExpression(Expression expression) { @@ -179,21 +217,15 @@ public string ToOrderExpression(Expression expression) public string UpdateSqlFragment() { - return $"{ColumnName} = {InnerField.SelectorForDuplication(PgType)}"; + return $"{ColumnName} = {InnerMember.SelectorForDuplication(PgType)}"; } public static DuplicatedField For(StoreOptions options, Expression> expression, bool useTimestampWithoutTimeZoneForDateTime = true) { - var inner = new DocumentMapping(options).FieldFor(expression); + var inner = new DocumentMapping(options).QueryMembers.MemberFor(expression); - // Hokey, but it's just for testing for now. - if (inner.Members.Length > 1) - { - throw new NotSupportedException("Not yet supporting deep properties yet. Soon."); - } - - return new DuplicatedField(options.EnumStorage, inner, useTimestampWithoutTimeZoneForDateTime); + return new DuplicatedField(options.EnumStorage, (QueryableMember)inner, useTimestampWithoutTimeZoneForDateTime); } // I say you don't need a ForeignKey @@ -201,4 +233,6 @@ public virtual TableColumn ToColumn() { return new TableColumn(ColumnName, PgType); } + + } diff --git a/src/Marten/Linq/Members/EnumAsIntegerMember.cs b/src/Marten/Linq/Members/EnumAsIntegerMember.cs new file mode 100644 index 00000000000..30e6297eec6 --- /dev/null +++ b/src/Marten/Linq/Members/EnumAsIntegerMember.cs @@ -0,0 +1,36 @@ +using System.Linq.Expressions; +using System.Reflection; +using Marten.Exceptions; +using Marten.Linq.SqlGeneration.Filters; +using NpgsqlTypes; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +public class EnumAsIntegerMember: QueryableMember, IComparableMember +{ + public EnumAsIntegerMember(IQueryableMember parent, Casing casing, MemberInfo member): base(parent, casing, member) + { + PgType = "integer"; + TypedLocator = $"CAST({RawLocator} as {PgType})"; + } + + public string PgType { get; set; } + + public override ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (constant == null || constant.Value == null) + { + return op switch + { + "=" => new IsNullFilter(this), + "!=" => new IsNotNullFilter(this), + _ => throw new BadLinqExpressionException( + $"Unable to create a SQL filter for member {Member.Name} {op} NULL") + }; + } + + var integer = (int)constant.Value; + return new MemberComparisonFilter(this, new CommandParameter(integer, NpgsqlDbType.Integer), op); + } +} diff --git a/src/Marten/Linq/Members/EnumAsStringMember.cs b/src/Marten/Linq/Members/EnumAsStringMember.cs new file mode 100644 index 00000000000..0066fd1f1e6 --- /dev/null +++ b/src/Marten/Linq/Members/EnumAsStringMember.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq.Expressions; +using System.Reflection; +using Marten.Exceptions; +using Marten.Linq.SqlGeneration.Filters; +using NpgsqlTypes; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +public class EnumAsStringMember: QueryableMember, IComparableMember +{ + public EnumAsStringMember(IQueryableMember parent, Casing casing, MemberInfo member): base(parent, casing, member) + { + if (!MemberType.IsEnum) + { + throw new ArgumentOutOfRangeException(nameof(member), "Not an Enum type"); + } + } + + public override ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (constant == null || constant.Value == null) + { + return op switch + { + "=" => new IsNullFilter(this), + "!=" => new IsNotNullFilter(this), + _ => throw new BadLinqExpressionException( + $"Unable to create a SQL filter for member {Member.Name} {op} NULL") + }; + } + + var stringValue = Enum.GetName(MemberType, constant.Value); + return new MemberComparisonFilter(this, new CommandParameter(stringValue, NpgsqlDbType.Varchar), op); + } + + public override string SelectorForDuplication(string pgType) + { + return RawLocator.Replace("d.", ""); + } +} diff --git a/src/Marten/Linq/Members/HasValueMember.cs b/src/Marten/Linq/Members/HasValueMember.cs new file mode 100644 index 00000000000..0b27227071c --- /dev/null +++ b/src/Marten/Linq/Members/HasValueMember.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using Marten.Exceptions; +using Marten.Linq.Parsing; +using Marten.Linq.Parsing.Operators; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class HasValueMember: IQueryableMember, IComparableMember, IBooleanField +{ + private readonly string _isNotNullSql; + private readonly string _isNullSql; + + public HasValueMember(IQueryableMember inner) + { + Inner = inner; + + TypedLocator = inner.TypedLocator; + RawLocator = inner.RawLocator; + MemberType = inner.MemberType; + JSONBLocator = inner.JSONBLocator; + + _isNullSql = $"{RawLocator} is null"; + _isNotNullSql = $"{RawLocator} is not null"; + + Ancestors = inner.Ancestors; + } + + public IQueryableMember Inner { get; } + + public ISqlFragment BuildIsTrueFragment() + { + return new IsNotNullFilter(Inner); + } + + public ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + var isTrue = (bool)constant.Value(); + + if (op == "==" || op == "=") + { + return isTrue ? new IsNotNullFilter(Inner) : new IsNullFilter(Inner); + } + + if (op == "!=") + { + return isTrue ? new IsNullFilter(Inner) : new IsNotNullFilter(Inner); + } + + throw new BadLinqExpressionException( + $"Marten does not support the '{op}' operator for Nullable HasValue members"); + } + + public string NullTestLocator => RawLocator; + + public void Apply(CommandBuilder builder) + { + builder.Append(_isNotNullSql); + } + + public bool Contains(string sqlText) + { + return false; + } + + public string JsonPathSegment => ""; + public string MemberName => "HasValue"; + + public Type MemberType { get; } + public string TypedLocator { get; } + public string RawLocator { get; } + public string JSONBLocator { get; } + + public string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + return _isNotNullSql; + } + + public IQueryableMember[] Ancestors { get; } + + public Dictionary FindOrPlaceChildDictionaryForContainment(Dictionary dict) + { + throw new NotSupportedException(); + } + + public void PlaceValueInDictionaryForContainment(Dictionary dict, ConstantExpression constant) + { + throw new NotSupportedException(); + } + + string IQueryableMember.LocatorForIncludedDocumentId => throw new NotSupportedException(); + + public string SelectorForDuplication(string pgType) + { + throw new NotSupportedException(); + } +} diff --git a/src/Marten/Linq/Members/IBooleanField.cs b/src/Marten/Linq/Members/IBooleanField.cs new file mode 100644 index 00000000000..e05d31256db --- /dev/null +++ b/src/Marten/Linq/Members/IBooleanField.cs @@ -0,0 +1,8 @@ +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal interface IBooleanField +{ + ISqlFragment BuildIsTrueFragment(); +} diff --git a/src/Marten/Linq/Members/ICollectionMember.cs b/src/Marten/Linq/Members/ICollectionMember.cs new file mode 100644 index 00000000000..f54cbb83329 --- /dev/null +++ b/src/Marten/Linq/Members/ICollectionMember.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq.Expressions; +using Marten.Internal; +using Marten.Linq.SqlGeneration; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +public interface ICollectionMember: IQueryableMember +{ + Type ElementType { get; } + + /// + /// Locator against the parent JSONB data that will "explode" the elements into a record set + /// + string ExplodeLocator { get; } + + string ArrayLocator { get; } + + SelectorStatement BuildChildStatement(CollectionUsage collectionUsage, IMartenSession session, + SelectorStatement parentStatement); + + ISelectClause BuildSelectClauseForExplosion(string fromObject); + ISqlFragment ParseWhereForAny(Expression body, IReadOnlyStoreOptions options); + + IComparableMember ParseComparableForCount(Expression body); + + ISqlFragment ParseWhereForAll(MethodCallExpression body, IReadOnlyStoreOptions options); + + ISqlFragment ParseWhereForContains(MethodCallExpression body, IReadOnlyStoreOptions options); +} diff --git a/src/Marten/Linq/Fields/IComparableFragment.cs b/src/Marten/Linq/Members/IComparableMember.cs similarity index 57% rename from src/Marten/Linq/Fields/IComparableFragment.cs rename to src/Marten/Linq/Members/IComparableMember.cs index fbbbad406ef..80f0cfc02ef 100644 --- a/src/Marten/Linq/Fields/IComparableFragment.cs +++ b/src/Marten/Linq/Members/IComparableMember.cs @@ -1,9 +1,9 @@ using System.Linq.Expressions; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Fields; +namespace Marten.Linq.Members; -public interface IComparableFragment +public interface IComparableMember { - ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression); + ISqlFragment CreateComparison(string op, ConstantExpression constant); } diff --git a/src/Marten/Linq/Members/IHasChildrenMembers.cs b/src/Marten/Linq/Members/IHasChildrenMembers.cs new file mode 100644 index 00000000000..471581e71ee --- /dev/null +++ b/src/Marten/Linq/Members/IHasChildrenMembers.cs @@ -0,0 +1,9 @@ +using System.Reflection; + +namespace Marten.Linq.Members; + +public interface IHasChildrenMembers +{ + IQueryableMember FindMember(MemberInfo member); + void ReplaceMember(MemberInfo member, IQueryableMember queryableMember); +} diff --git a/src/Marten/Linq/Fields/IFieldSource.cs b/src/Marten/Linq/Members/IMemberSource.cs similarity index 69% rename from src/Marten/Linq/Fields/IFieldSource.cs rename to src/Marten/Linq/Members/IMemberSource.cs index 4f5a6289b7d..6fe26dba1e6 100644 --- a/src/Marten/Linq/Fields/IFieldSource.cs +++ b/src/Marten/Linq/Members/IMemberSource.cs @@ -1,13 +1,13 @@ using System; using System.Reflection; -namespace Marten.Linq.Fields; +namespace Marten.Linq.Members; /// /// An extension point to "teach" Marten how to support new member types in the Linq support /// -public interface IFieldSource +public interface IMemberSource { bool TryResolve(string dataLocator, StoreOptions options, ISerializer serializer, Type documentType, - MemberInfo[] members, out IField field); + MemberInfo memberInfo, out IQueryableMember member); } diff --git a/src/Marten/Linq/Members/IQueryableMember.cs b/src/Marten/Linq/Members/IQueryableMember.cs new file mode 100644 index 00000000000..70cb636787f --- /dev/null +++ b/src/Marten/Linq/Members/IQueryableMember.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using Marten.Linq.Parsing.Operators; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +public interface IQueryableMember: ISqlFragment +{ + Type MemberType { get; } + + /// + /// JSONPath segment name + /// + string JsonPathSegment { get; } + + string MemberName { get; } + + /// + /// Postgresql locator that also casts the raw string data to the proper Postgresql type + /// + string TypedLocator { get; } + + /// + /// Postgresql locator that returns the raw string value within the JSONB document + /// + string RawLocator { get; } + + /// + /// Locate the data for this field as JSONB + /// + string JSONBLocator { get; } + + IQueryableMember[] Ancestors { get; } + + /// + /// Locator for usage in "include" operations to get at the potential identifiers + /// of the included documents + /// + string LocatorForIncludedDocumentId { get; } + + /// + /// Locator for usage in is null / is not null checks + /// + string NullTestLocator { get; } + + /// + /// Build the locator or expression for usage within "ORDER BY" clauses + /// + /// + /// + /// + string BuildOrderingExpression(Ordering ordering, CasingRule casingRule); + + /// + /// This facilitates containment operator filters as an ancestor member + /// + /// + /// + Dictionary FindOrPlaceChildDictionaryForContainment(Dictionary dict); + + /// + /// This facilitates containment operator filters as the leaf member + /// + /// + /// + void PlaceValueInDictionaryForContainment(Dictionary dict, ConstantExpression constant); + + string SelectorForDuplication(string pgType); +} diff --git a/src/Marten/Linq/Members/IQueryableMemberCollection.cs b/src/Marten/Linq/Members/IQueryableMemberCollection.cs new file mode 100644 index 00000000000..f663dba8638 --- /dev/null +++ b/src/Marten/Linq/Members/IQueryableMemberCollection.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; + +namespace Marten.Linq.Members; + +public interface IQueryableMemberCollection: IHasChildrenMembers, IEnumerable +{ + Type ElementType { get; } +} diff --git a/src/Marten/Linq/Members/IdMember.cs b/src/Marten/Linq/Members/IdMember.cs new file mode 100644 index 00000000000..5a4bd70b0f8 --- /dev/null +++ b/src/Marten/Linq/Members/IdMember.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core.Reflection; +using Marten.Linq.Parsing.Operators; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class IdMember: IQueryableMember, IComparableMember +{ + private const string _orderDescending = "d.id desc"; + + public IdMember(MemberInfo member) + { + MemberType = member.GetMemberType(); + + JSONBLocator = $"CAST({RawLocator} as jsonb)"; + Ancestors = Array.Empty(); + + MemberName = member.Name; + Member = member; + } + + public MemberInfo Member { get; } + + public ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (constant.Value == null) + { + return op == "=" ? new IsNullFilter(this) : new IsNotNullFilter(this); + } + + var def = new CommandParameter(constant); + return new ComparisonFilter(this, def, op); + } + + public string MemberName { get; } + + public string NullTestLocator => RawLocator; + + public string SelectorForDuplication(string pgType) + { + throw new NotSupportedException(); + } + + public void Apply(CommandBuilder builder) + { + builder.Append(TypedLocator); + } + + public bool Contains(string sqlText) + { + return false; + } + + public string JsonPathSegment => ""; + + public Type MemberType { get; } + public string TypedLocator => "d.id"; + public string RawLocator => "d.id"; + public string JSONBLocator { get; set; } = "d.id"; + + public string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + if (ordering.Direction == OrderingDirection.Desc) + { + return _orderDescending; + } + + return TypedLocator; + } + + public IQueryableMember[] Ancestors { get; } + + Dictionary IQueryableMember.FindOrPlaceChildDictionaryForContainment( + Dictionary dict) + { + throw new NotSupportedException(); + } + + void IQueryableMember.PlaceValueInDictionaryForContainment(Dictionary dict, + ConstantExpression constant) + { + throw new NotSupportedException(); + } + + string IQueryableMember.LocatorForIncludedDocumentId => throw new NotImplementedException(); +} diff --git a/src/Marten/Linq/Parsing/ModuloFragment.cs b/src/Marten/Linq/Members/ModuloComparison.cs similarity index 56% rename from src/Marten/Linq/Parsing/ModuloFragment.cs rename to src/Marten/Linq/Members/ModuloComparison.cs index b64ee2d1187..f5567eb3d14 100644 --- a/src/Marten/Linq/Parsing/ModuloFragment.cs +++ b/src/Marten/Linq/Members/ModuloComparison.cs @@ -1,24 +1,24 @@ using System.Linq.Expressions; -using Marten.Linq.Fields; +using Marten.Linq.Parsing; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Parsing; +namespace Marten.Linq.Members; -internal class ModuloFragment: IComparableFragment, ISqlFragment +internal class ModuloOperator: IComparableMember, ISqlFragment { private readonly ISqlFragment _left; private readonly ISqlFragment _right; private string _op; private CommandParameter _value; - public ModuloFragment(BinaryExpression expression, IFieldMapping fields) + public ModuloOperator(BinaryExpression expression, IQueryableMemberCollection members) { - _left = analyze(expression.Left, fields); - _right = analyze(expression.Right, fields); + _left = analyze(expression.Left, members); + _right = analyze(expression.Right, members); } - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) + public ISqlFragment CreateComparison(string op, ConstantExpression value) { _op = " " + op + " "; _value = new CommandParameter(value); @@ -40,13 +40,13 @@ public bool Contains(string sqlText) return false; } - private ISqlFragment analyze(Expression expression, IFieldMapping fields) + private ISqlFragment analyze(Expression expression, IQueryableMemberCollection members) { - if (expression is ConstantExpression c) + if (expression.TryToParseConstant(out var constant)) { - return new CommandParameter(c); + return new CommandParameter(constant.Value()); } - return fields.FieldFor(expression); + return members.MemberFor(expression); } } diff --git a/src/Marten/Linq/Members/NotMember.cs b/src/Marten/Linq/Members/NotMember.cs new file mode 100644 index 00000000000..2c0e9725500 --- /dev/null +++ b/src/Marten/Linq/Members/NotMember.cs @@ -0,0 +1,20 @@ +using System.Linq.Expressions; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class NotMember: IComparableMember +{ + public NotMember(IComparableMember inner) + { + Inner = inner; + } + + public IComparableMember Inner { get; } + + public ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + var opposite = ComparisonFilter.NotOperators[op]; + return Inner.CreateComparison(opposite, constant); + } +} diff --git a/src/Marten/Linq/Members/QueryableMember.cs b/src/Marten/Linq/Members/QueryableMember.cs new file mode 100644 index 00000000000..236a31fced6 --- /dev/null +++ b/src/Marten/Linq/Members/QueryableMember.cs @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Linq.Parsing; +using Marten.Linq.Parsing.Operators; +using Marten.Linq.SqlGeneration.Filters; +using Marten.Util; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +public abstract class QueryableMember: IQueryableMember, IHasChildrenMembers +{ + private HasValueMember? _hasValue; + private string _nullTestLocator; + private string _descendingOrderLocator; + + /// + /// + /// JSONB location of the parent element + /// + protected QueryableMember(IQueryableMember parent, Casing casing, MemberInfo member) + { + Member = member; + MemberType = member.GetMemberType(); + + JsonPathSegment = MemberName = member.ToJsonKey(casing); + RawLocator = TypedLocator = $"{parent.RawLocator} ->> '{MemberName}'"; + + JSONBLocator = $"CAST({RawLocator} as jsonb)"; + Ancestors = parent.Ancestors.Append(parent); + _descendingOrderLocator = $"{TypedLocator} desc"; + } + + protected QueryableMember(IQueryableMember parent, string memberName, Type memberType) + { + MemberName = memberName; + MemberType = memberType; + + RawLocator = TypedLocator = $"{parent.RawLocator} ->> '{MemberName}'"; + + JSONBLocator = $"CAST({RawLocator} as jsonb)"; + + Ancestors = parent.Ancestors.Append(parent); + _descendingOrderLocator = $"{TypedLocator} desc"; + } + + public MemberInfo Member { get; } + + public virtual IQueryableMember FindMember(MemberInfo member) + { + if (member.Name == "Value") + { + return this; + } + + if (member.Name == "HasValue") + { + _hasValue ??= new HasValueMember(this); + return _hasValue; + } + + throw new BadLinqExpressionException( + $"Marten does not (yet) support member {MemberType.ShortNameInCode()}.{member.Name}"); + } + + public virtual void ReplaceMember(MemberInfo member, IQueryableMember queryableMember) + { + throw new NotSupportedException(); + } + + public string JsonPathSegment { get; protected set; } + + public string MemberName { get; } + + public IQueryableMember[] Ancestors { get; } + + public string RawLocator { get; protected set; } + + + public string NullTestLocator + { + get => _nullTestLocator ?? RawLocator; + protected set => _nullTestLocator = value; + } + + public string TypedLocator { get; protected set; } + + /// + /// Locate the data for this field as JSONB + /// + public string JSONBLocator { get; set; } + + public Type MemberType { get; } + + public virtual string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + return ordering.Direction == OrderingDirection.Desc ? _descendingOrderLocator : TypedLocator; + } + + void ISqlFragment.Apply(CommandBuilder builder) + { + builder.Append(TypedLocator); + } + + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + + public virtual Dictionary FindOrPlaceChildDictionaryForContainment(Dictionary dict) + { + if (dict.TryGetValue(MemberName, out var child)) + { + if (child is Dictionary c) + { + return c; + } + } + + var newDict = new Dictionary(); + dict[MemberName] = newDict; + + return newDict; + } + + public virtual void PlaceValueInDictionaryForContainment(Dictionary dict, + ConstantExpression constant) + { + dict[MemberName] = constant.Value(); + } + + public virtual string LocatorForIncludedDocumentId => TypedLocator; + + + public virtual string SelectorForDuplication(string pgType) + { + return $"CAST({RawLocator.Replace("d.", "")} as {pgType})"; + } + + public virtual ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (constant.Value == null) + { + return op == "=" ? new IsNullFilter(this) : new IsNotNullFilter(this); + } + + var def = new CommandParameter(constant); + return new MemberComparisonFilter(this, def, op); + } +} diff --git a/src/Marten/Linq/SqlGeneration/ScalarSelectManyStatement.cs b/src/Marten/Linq/Members/ScalarSelectManyStatement.cs similarity index 67% rename from src/Marten/Linq/SqlGeneration/ScalarSelectManyStatement.cs rename to src/Marten/Linq/Members/ScalarSelectManyStatement.cs index b13dd7851ce..81d615c26d5 100644 --- a/src/Marten/Linq/SqlGeneration/ScalarSelectManyStatement.cs +++ b/src/Marten/Linq/Members/ScalarSelectManyStatement.cs @@ -1,12 +1,13 @@ +using Marten.Linq.SqlGeneration; using Weasel.Postgresql; -namespace Marten.Linq.SqlGeneration; +namespace Marten.Linq.Members; internal class ScalarSelectManyStatement: SelectorStatement where T : struct { - public ScalarSelectManyStatement(SelectorStatement parent, ISerializer serializer): base( - new ScalarSelectClause(ToLocator(serializer), parent.ExportName), null) + public ScalarSelectManyStatement(SelectorStatement parent, ISerializer serializer) { + SelectClause = new ScalarSelectClause(ToLocator(serializer), parent.ExportName); } public static string ToLocator(ISerializer serializer) diff --git a/src/Marten/Linq/Members/ScalarSelectManyStringStatement.cs b/src/Marten/Linq/Members/ScalarSelectManyStringStatement.cs new file mode 100644 index 00000000000..ea12e81ae7d --- /dev/null +++ b/src/Marten/Linq/Members/ScalarSelectManyStringStatement.cs @@ -0,0 +1,11 @@ +using Marten.Linq.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class ScalarSelectManyStringStatement: SelectorStatement +{ + public ScalarSelectManyStringStatement(SelectorStatement parent) + { + SelectClause = new ScalarStringSelectClause("data", parent.ExportName); + } +} diff --git a/src/Marten/Linq/Members/SimpleCastMember.cs b/src/Marten/Linq/Members/SimpleCastMember.cs new file mode 100644 index 00000000000..8516bb3124b --- /dev/null +++ b/src/Marten/Linq/Members/SimpleCastMember.cs @@ -0,0 +1,14 @@ +using System.Reflection; + +namespace Marten.Linq.Members; + +internal class SimpleCastMember: QueryableMember, IComparableMember +{ + private HasValueMember _hasValue; + + public SimpleCastMember(IQueryableMember parent, Casing casing, MemberInfo member, string pgType): base(parent, + casing, member) + { + TypedLocator = $"CAST({RawLocator} as {pgType})"; + } +} diff --git a/src/Marten/Linq/Members/StringMember.cs b/src/Marten/Linq/Members/StringMember.cs new file mode 100644 index 00000000000..f23bb27e389 --- /dev/null +++ b/src/Marten/Linq/Members/StringMember.cs @@ -0,0 +1,32 @@ +using System.Reflection; +using Marten.Linq.Parsing.Operators; + +namespace Marten.Linq.Members; + +internal class StringMember: QueryableMember, IComparableMember +{ + private readonly string _lowerLocator; + + public StringMember(IQueryableMember parent, Casing casing, MemberInfo member): base(parent, casing, member) + { + TypedLocator = RawLocator; + _lowerLocator = $"lower({RawLocator})"; + } + + public override string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + var expression = casingRule == CasingRule.CaseSensitive ? RawLocator : _lowerLocator; + + if (ordering.Direction == OrderingDirection.Desc) + { + return $"{expression} desc"; + } + + return expression; + } + + public override string SelectorForDuplication(string pgType) + { + return RawLocator.Replace("d.", ""); + } +} diff --git a/src/Marten/Linq/Members/ValueCollectionMember.cs b/src/Marten/Linq/Members/ValueCollectionMember.cs new file mode 100644 index 00000000000..2465d596dc5 --- /dev/null +++ b/src/Marten/Linq/Members/ValueCollectionMember.cs @@ -0,0 +1,300 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Internal; +using Marten.Linq.Parsing; +using Marten.Linq.Parsing.Operators; +using Marten.Linq.SqlGeneration; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Core; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Members; + +internal class ValueCollectionMember: QueryableMember, ICollectionMember, IQueryableMemberCollection +{ + private readonly IQueryableMember _count; + private readonly WholeDataMember _wholeDataMember; + + public ValueCollectionMember(IQueryableMember parent, Casing casing, MemberInfo member): base(parent, casing, + member) + { + ElementType = MemberType.DetermineElementType(); + var rawLocator = RawLocator; + var innerPgType = PostgresqlProvider.Instance.GetDatabaseType(ElementType, EnumStorage.AsInteger); + var pgType = PostgresqlProvider.Instance.HasTypeMapping(ElementType) ? innerPgType + "[]" : "jsonb"; + + RawLocator = $"CAST({rawLocator} as jsonb)"; + TypedLocator = $"CAST({rawLocator} as {pgType})"; + + _count = new CollectionLengthMember(this); + + + ArrayLocator = $"CAST(ARRAY(SELECT jsonb_array_elements_text(CAST({rawLocator} as jsonb))) as {innerPgType}[])"; + + + LocatorForIncludedDocumentId = + $"UNNEST({ArrayLocator})"; + + ExplodeLocator = LocatorForIncludedDocumentId; + + _wholeDataMember = new WholeDataMember(ElementType); + + ElementMember = new SimpleElementMember(ElementType, pgType); + } + + public IQueryableMember ElementMember { get; } + + public string ArrayLocator { get; set; } + + public IComparableMember ParseComparableForCount(Expression body) + { + throw new BadLinqExpressionException( + "Marten does not (yet) support Linq filters within the Count() expression of a scalar value collection"); + } + + public ISqlFragment ParseWhereForAll(MethodCallExpression expression, IReadOnlyStoreOptions options) + { + var constant = expression.Arguments[1].ReduceToConstant(); + + if (constant.Value() == null) return new AllValuesAreNullFilter(this); + + return new AllValuesEqualFilter(constant, this); + } + + public ISqlFragment ParseWhereForContains(MethodCallExpression body, IReadOnlyStoreOptions options) + { + var value = body.Arguments.Last().ReduceToConstant(); + + return new ContainmentWhereFilter(this, value, options.Serializer()); + } + + public string LocatorForIncludedDocumentId { get; } + + public Type ElementType { get; } + + public string ExplodeLocator { get; } + + public ISqlFragment ParseWhereForAny(Expression body, IReadOnlyStoreOptions options) + { + var whereClause = new ChildCollectionWhereClause(); + var parser = new WhereClauseParser((StoreOptions)options, this, whereClause); + parser.Visit(body); + + return whereClause.CompileFragment(this, options.Serializer()); + } + + public SelectorStatement BuildChildStatement(CollectionUsage collectionUsage, IMartenSession session, + SelectorStatement parentStatement) + { + var statement = ElementType == typeof(string) + ? new ScalarSelectManyStringStatement(parentStatement) + : typeof(ScalarSelectManyStatement<>).CloseAndBuildAs(parentStatement, + session.Serializer, ElementType); + + collectionUsage.ProcessSingleValueModeIfAny(statement); + + return statement; + } + + public ISelectClause BuildSelectClauseForExplosion(string fromObject) + { + var selection = $"jsonb_array_elements_text({JSONBLocator})"; + + return typeof(DataSelectClause<>).CloseAndBuildAs(fromObject, selection, + ElementType); + } + + public override void PlaceValueInDictionaryForContainment(Dictionary dict, + ConstantExpression constant) + { + dict[MemberName] = new[] { constant.Value }; + } + + public override Dictionary FindOrPlaceChildDictionaryForContainment(Dictionary dict) + { + throw new NotSupportedException(); + } + + public override string SelectorForDuplication(string pgType) + { + if (pgType.EqualsIgnoreCase("JSONB")) + { + return JSONBLocator.Replace("d.", ""); + } + + return $"CAST(ARRAY(SELECT jsonb_array_elements_text({RawLocator.Replace("d.", "")})) as {pgType})"; + } + + + public override IQueryableMember FindMember(MemberInfo member) + { + if (member.Name == "Count" || member.Name == "Length") + { + return _count; + } + + return _wholeDataMember; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + throw new NotSupportedException(); + } +} + +internal class SimpleElementMember: IQueryableMember, IComparableMember +{ + public SimpleElementMember(Type memberType, string pgType) + { + MemberType = memberType; + PgType = pgType; + TypedLocator = $"CAST(data as {pgType})"; + MemberName = "Element"; + } + + public string PgType { get; } + + public ISqlFragment CreateComparison(string op, ConstantExpression constant) + { + if (constant.Value == null) + { + throw new BadLinqExpressionException("Marten cannot search for null values in collections"); + } + + return new ElementComparisonFilter(constant.Value(), op); + } + + public string MemberName { get; } + + public Type MemberType { get; } + + public void Apply(CommandBuilder builder) + { + builder.Append("data"); + } + + public bool Contains(string sqlText) + { + return false; + } + + public string NullTestLocator => RawLocator; + public string JsonPathSegment { get; } = "data"; + public string TypedLocator { get; } + public string RawLocator { get; } = "data"; + public string JSONBLocator { get; } = "data"; + + public string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + return "data"; + } + + public IQueryableMember[] Ancestors { get; } = Array.Empty(); + + public Dictionary FindOrPlaceChildDictionaryForContainment(Dictionary dict) + { + throw new NotSupportedException(); + } + + public void PlaceValueInDictionaryForContainment(Dictionary dict, ConstantExpression constant) + { + throw new NotSupportedException(); + } + + public string LocatorForIncludedDocumentId => TypedLocator; + + public virtual string SelectorForDuplication(string pgType) + { + return $"CAST({RawLocator.Replace("d.", "")} as {pgType})"; + } +} + +internal class ElementComparisonFilter: ISqlFragment, ICollectionAware +{ + public ElementComparisonFilter(object value, string op) + { + Value = value; + Op = op; + } + + public object Value { get; } + public string Op { get; } + + public IEnumerable Values() + { + yield return new DictionaryValueUsage(Value); + } + + bool ICollectionAware.CanReduceInChildCollection() + { + if (Value == null) return false; + if (Value.GetType().IsDateTime()) return false; + if (Value.GetType() == typeof(DateTimeOffset)) return false; + return true; + } + + ICollectionAwareFilter ICollectionAware.BuildFragment(ICollectionMember member, ISerializer serializer) + { + switch (Op) + { + case "=": + return ContainmentWhereFilter.ForValue(member, Value, serializer); + + case "!=": + return (ICollectionAwareFilter)ContainmentWhereFilter.ForValue(member, Value, serializer).Reverse(); + + default: + throw new BadLinqExpressionException( + $"Marten does not (yet) support the {Op} operator in element member queries"); + } + } + + bool ICollectionAware.SupportsContainment() + { + // Little goofy. Make it do its own thing + return false; + } + + void ICollectionAware.PlaceIntoContainmentFilter(ContainmentWhereFilter filter) + { + throw new NotSupportedException(); + } + + public bool CanBeJsonPathFilter() + { + return true; + } + + public void BuildJsonPathFilter(CommandBuilder builder, Dictionary parameters) + { + var parameter = parameters.AddJsonPathParameter(Value); + + builder.Append("@ "); + builder.Append(Op); + builder.Append(" "); + builder.Append(parameter); + } + + void ISqlFragment.Apply(CommandBuilder builder) + { + throw new NotSupportedException(); + } + + bool ISqlFragment.Contains(string sqlText) + { + throw new NotSupportedException(); + } +} diff --git a/src/Marten/Linq/Members/WholeDataMember.cs b/src/Marten/Linq/Members/WholeDataMember.cs new file mode 100644 index 00000000000..213826834bc --- /dev/null +++ b/src/Marten/Linq/Members/WholeDataMember.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using Marten.Linq.Parsing.Operators; +using Weasel.Postgresql; + +namespace Marten.Linq.Members; + +internal class WholeDataMember: IQueryableMember +{ + public WholeDataMember(Type sourceType) + { + MemberType = sourceType; + } + + public IQueryableMember[] Ancestors { get; } = Array.Empty(); + + public void Apply(CommandBuilder builder) + { + builder.Append("data"); + } + + public bool Contains(string sqlText) + { + return false; + } + + public string MemberName => string.Empty; + + public string JsonPathSegment => string.Empty; + public string NullTestLocator => RawLocator; + + public string SelectorForDuplication(string pgType) + { + throw new NotSupportedException(); + } + + public Type MemberType { get; } + public string TypedLocator => "data"; + public string RawLocator => "data"; + public string JSONBLocator { get; set; } = "data"; + + public string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + return "data"; + } + + Dictionary IQueryableMember.FindOrPlaceChildDictionaryForContainment( + Dictionary dict) + { + throw new NotSupportedException(); + } + + void IQueryableMember.PlaceValueInDictionaryForContainment(Dictionary dict, + ConstantExpression constant) + { + throw new NotSupportedException(); + } + + string IQueryableMember.LocatorForIncludedDocumentId => throw new NotSupportedException(); +} + +internal class RootMember: IQueryableMember +{ + public RootMember(Type sourceType) + { + MemberType = sourceType; + } + + public IQueryableMember[] Ancestors { get; set; } = Array.Empty(); + + public void Apply(CommandBuilder builder) + { + builder.Append("d.data"); + } + + public bool Contains(string sqlText) + { + return false; + } + + public string SelectorForDuplication(string pgType) + { + throw new NotSupportedException(); + } + + public string NullTestLocator => RawLocator; + + public string JsonPathSegment => string.Empty; + public string MemberName => string.Empty; + public Type MemberType { get; } + public string TypedLocator => "d.data"; + public string RawLocator => "d.data"; + public string JSONBLocator { get; set; } = "d.data"; + + public string BuildOrderingExpression(Ordering ordering, CasingRule casingRule) + { + return "d.data"; + } + + Dictionary IQueryableMember.FindOrPlaceChildDictionaryForContainment( + Dictionary dict) + { + return dict; + } + + void IQueryableMember.PlaceValueInDictionaryForContainment(Dictionary dict, + ConstantExpression constant) + { + throw new NotSupportedException(); + } + + string IQueryableMember.LocatorForIncludedDocumentId => throw new NotSupportedException(); +} diff --git a/src/Marten/Linq/Operators/IncludeExpressionNode.cs b/src/Marten/Linq/Operators/IncludeExpressionNode.cs deleted file mode 100644 index 6259e325304..00000000000 --- a/src/Marten/Linq/Operators/IncludeExpressionNode.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Remotion.Linq.Clauses; -using Remotion.Linq.Parsing.Structure.IntermediateModel; - -namespace Marten.Linq.Operators; - -internal class IncludeExpressionNode: ResultOperatorExpressionNodeBase -{ - public static MethodInfo[] SupportedMethods = - typeof(QueryableExtensions).GetMethods().Where(m => m.Name == "Include") - .Concat(typeof(IMartenQueryable<>).GetMethods().Where(m => m.Name == "Include")).ToArray(); - - - public IncludeExpressionNode( - MethodCallExpressionParseInfo parseInfo, Expression connectingField, ConstantExpression include) - : base(parseInfo, null, null) - { - ConnectingField = connectingField; - IncludeExpression = include; - } - - public ConstantExpression IncludeExpression { get; set; } - - public Expression ConnectingField { get; set; } - - protected override ResultOperatorBase CreateResultOperator( - ClauseGenerationContext clauseGenerationContext) - { - return new IncludeResultOperator(ConnectingField, IncludeExpression); - } - - public override Expression Resolve( - ParameterExpression inputParameter, - Expression expressionToBeResolved, - ClauseGenerationContext clauseGenerationContext) - { - return Source.Resolve( - inputParameter, - expressionToBeResolved, - clauseGenerationContext); - } -} diff --git a/src/Marten/Linq/Operators/IncludeResultOperator.cs b/src/Marten/Linq/Operators/IncludeResultOperator.cs deleted file mode 100644 index 03c78b0cfe4..00000000000 --- a/src/Marten/Linq/Operators/IncludeResultOperator.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using JasperFx.Core.Reflection; -using Marten.Exceptions; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Linq.Fields; -using Marten.Linq.Includes; -using Remotion.Linq.Clauses; -using Remotion.Linq.Clauses.ResultOperators; -using Remotion.Linq.Clauses.StreamedData; - -namespace Marten.Linq.Operators; - -internal class IncludeResultOperator - : SequenceTypePreservingResultOperatorBase -{ - public IncludeResultOperator(Expression connectingField, ConstantExpression includeExpression) - { - ConnectingField = connectingField; - IncludeExpression = includeExpression; - } - - public Expression ConnectingField { get; } - public ConstantExpression IncludeExpression { get; } - - public override ResultOperatorBase Clone(CloneContext cloneContext) - { - return new IncludeResultOperator(ConnectingField, IncludeExpression); - } - - public override void TransformExpressions( - Func transformation) - { - throw new NotSupportedException(); - } - - public override StreamedSequence ExecuteInMemory(StreamedSequence input) - { - return input; - } - - public IIncludePlan BuildInclude(IMartenSession session, IFieldMapping sourceFields) - { - var value = IncludeExpression.Value; - var connectingField = sourceFields.FieldFor(ConnectingField); - - var valueType = value.GetType(); - if (valueType.Closes(typeof(IDictionary<,>))) - { - // It's funky, but the generic arguments need to be reversed between the dictionary and the - // builder here - var builder = typeof(DictionaryIncludeBuilder<,>) - .CloseAndBuildAs(valueType.GetGenericArguments().Reverse().ToArray()); - - return builder.Build(session, connectingField, value); - } - - if (valueType.Closes(typeof(Action<>)) || valueType.Closes(typeof(IList<>))) - { - var builder = typeof(ActionIncludeBuilder<>) - .CloseAndBuildAs(valueType.GetGenericArguments()[0]); - - return builder.Build(session, connectingField, value); - } - - throw new ArgumentOutOfRangeException(nameof(valueType)); - } - - internal interface IIncludeBuilder - { - IIncludePlan Build(IMartenSession session, IField connectingField, object value); - } - - internal class DictionaryIncludeBuilder: IIncludeBuilder - { - public IIncludePlan Build(IMartenSession session, IField connectingField, object value) - { - var storage = session.StorageFor(); - if (storage is IDocumentStorage typed) - { - if (!(value is Dictionary dict)) - { - throw new ArgumentOutOfRangeException(nameof(value)); - } - - return new IncludePlan(storage, connectingField, doc => dict[typed.Identity(doc)] = doc); - } - - throw new DocumentIdTypeMismatchException(storage, typeof(TId)); - } - } - - internal class ActionIncludeBuilder: IIncludeBuilder - { - public IIncludePlan Build(IMartenSession session, IField connectingField, object value) - { - var storage = session.StorageFor(); - if (value is IList list) - { - return new IncludePlan(storage, connectingField, list.Add); - } - - if (value is Action action) - { - return new IncludePlan(storage, connectingField, action); - } - - throw new InvalidOperationException(); - } - } -} diff --git a/src/Marten/Linq/Operators/OrderByComparerClause.cs b/src/Marten/Linq/Operators/OrderByComparerClause.cs deleted file mode 100644 index dd638f16a4f..00000000000 --- a/src/Marten/Linq/Operators/OrderByComparerClause.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using Remotion.Linq; -using Remotion.Linq.Clauses; - -namespace Marten.Linq.Operators; - -internal class OrderByComparerClause: IBodyClause -{ - private OrderByComparerClause(bool caseInsensitive) - { - CaseInsensitive = caseInsensitive; - } - - public OrderByComparerClause(bool caseInsensitive, Ordering ordering) - { - CaseInsensitive = caseInsensitive; - Orderings.Add(ordering); - } - - public bool CaseInsensitive { get; } - public List Orderings { get; } = new(); - - public void TransformExpressions(Func transformation) - { - throw new NotImplementedException(); - } - - public void Accept(IQueryModelVisitor visitor, QueryModel queryModel, int index) - { - throw new NotImplementedException(); - } - - public IBodyClause Clone(CloneContext cloneContext) - { - var clone = new OrderByComparerClause(CaseInsensitive); - - foreach (var ordering in Orderings) - { - var clonedOrdering = ordering.Clone(cloneContext); - clone.Orderings.Add(clonedOrdering); - } - - return clone; - } -} diff --git a/src/Marten/Linq/Operators/OrderByComparerExpressionNode.cs b/src/Marten/Linq/Operators/OrderByComparerExpressionNode.cs deleted file mode 100644 index 3f00a2ac571..00000000000 --- a/src/Marten/Linq/Operators/OrderByComparerExpressionNode.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Remotion.Linq; -using Remotion.Linq.Clauses; -using Remotion.Linq.Parsing.Structure.IntermediateModel; - -namespace Marten.Linq.Operators; - -internal class OrderByComparerExpressionNode: MethodCallExpressionNodeBase -{ - public static readonly MethodInfo[] SupportedMethods = - typeof(Queryable).GetMethods() - .Where(m => m.Name == nameof(Queryable.OrderBy) || m.Name == nameof(Queryable.OrderByDescending) || - m.Name == nameof(Queryable.ThenBy) || m.Name == nameof(Queryable.ThenByDescending)) - .Where(x => x.GetParameters().Length == 3) - .ToArray(); - - private readonly ResolvedExpressionCache _cachedSelector; - private readonly LambdaExpression _keySelector; - - private readonly OrderingDirection _orderingDirection; - - public OrderByComparerExpressionNode(MethodCallExpressionParseInfo parseInfo, LambdaExpression keySelector, - ConstantExpression constantExpression) - : base(parseInfo) - { - _keySelector = keySelector; - _cachedSelector = new ResolvedExpressionCache(this); - - _orderingDirection = parseInfo.ParsedExpression.Method.Name == nameof(Queryable.OrderBy) || - parseInfo.ParsedExpression.Method.Name == nameof(Queryable.ThenBy) - ? OrderingDirection.Asc - : OrderingDirection.Desc; - - ConstantExpression = constantExpression; - } - - public ConstantExpression ConstantExpression { get; } - - public override Expression Resolve(ParameterExpression inputParameter, Expression expressionToBeResolved, - ClauseGenerationContext clauseGenerationContext) - { - return Source.Resolve(inputParameter, expressionToBeResolved, clauseGenerationContext); - } - - protected override void ApplyNodeSpecificSemantics(QueryModel queryModel, - ClauseGenerationContext clauseGenerationContext) - { - if (_keySelector.ReturnType != typeof(string)) - { - throw new ArgumentException("Only strings are supported when providing order comparer"); - } - - bool caseInsensitive; - if (ReferenceEquals(ConstantExpression.Value, StringComparer.InvariantCultureIgnoreCase) - || ReferenceEquals(ConstantExpression.Value, StringComparer.OrdinalIgnoreCase)) - { - caseInsensitive = true; - } - else if (ReferenceEquals(ConstantExpression.Value, StringComparer.InvariantCulture) - || ReferenceEquals(ConstantExpression.Value, StringComparer.Ordinal)) - { - caseInsensitive = false; - } - else - { - throw new ArgumentException( - "Only ordinal and invariant StringComparer static comparer members are allowed as comparer"); - } - - var orderByClause = new OrderByComparerClause(caseInsensitive, - new Ordering(GetResolvedKeySelector(clauseGenerationContext), _orderingDirection)); - queryModel.BodyClauses.Add(orderByClause); - } - - private Expression GetResolvedKeySelector(ClauseGenerationContext clauseGenerationContext) - { - return _cachedSelector.GetOrCreate(r => - r.GetResolvedExpression(_keySelector.Body, _keySelector.Parameters[0], clauseGenerationContext)); - } -} diff --git a/src/Marten/Linq/Operators/StatsExpressionNode.cs b/src/Marten/Linq/Operators/StatsExpressionNode.cs deleted file mode 100644 index 7aad63f5c84..00000000000 --- a/src/Marten/Linq/Operators/StatsExpressionNode.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Remotion.Linq.Clauses; -using Remotion.Linq.Parsing.Structure.IntermediateModel; - -namespace Marten.Linq.Operators; - -internal class StatsExpressionNode: ResultOperatorExpressionNodeBase -{ - public static MethodInfo[] SupportedMethods = - typeof(IMartenQueryable<>).GetMethods().Where(m => m.Name == nameof(IMartenQueryable.Stats)).ToArray(); - - public StatsExpressionNode( - MethodCallExpressionParseInfo parseInfo, LambdaExpression stats) - : base(parseInfo, null, null) - { - Stats = stats; - } - - public LambdaExpression Stats { get; set; } - - protected override ResultOperatorBase CreateResultOperator( - ClauseGenerationContext clauseGenerationContext) - { - return new StatsResultOperator(Stats); - } - - public override Expression Resolve( - ParameterExpression inputParameter, - Expression expressionToBeResolved, - ClauseGenerationContext clauseGenerationContext) - { - return Source.Resolve( - inputParameter, - expressionToBeResolved, - clauseGenerationContext); - } -} diff --git a/src/Marten/Linq/Operators/StatsResultOperator.cs b/src/Marten/Linq/Operators/StatsResultOperator.cs deleted file mode 100644 index e73d6fc022b..00000000000 --- a/src/Marten/Linq/Operators/StatsResultOperator.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Linq.Expressions; -using Remotion.Linq.Clauses; -using Remotion.Linq.Clauses.ResultOperators; -using Remotion.Linq.Clauses.StreamedData; - -namespace Marten.Linq.Operators; - -internal class StatsResultOperator - : SequenceTypePreservingResultOperatorBase -{ - public StatsResultOperator(Expression parameter) - { - Parameter = parameter; - } - - public StatsResultOperator(LambdaExpression stats) - { - Stats = stats; - } - - public LambdaExpression Stats { get; set; } - - public Expression Parameter { get; private set; } - - public override ResultOperatorBase Clone(CloneContext cloneContext) - { - return new StatsResultOperator(Parameter); - } - - public override void TransformExpressions( - Func transformation) - { - Parameter = transformation(Parameter); - } - - public override StreamedSequence ExecuteInMemory(StreamedSequence input) - { - return input; - } -} diff --git a/src/Marten/Linq/OrderingDirection.cs b/src/Marten/Linq/OrderingDirection.cs new file mode 100644 index 00000000000..99127c6c150 --- /dev/null +++ b/src/Marten/Linq/OrderingDirection.cs @@ -0,0 +1,16 @@ +namespace Marten.Linq; + +/// +/// Specifies the direction used to sort the result items in a query using an . +/// +public enum OrderingDirection +{ + /// + /// Sorts the items in an ascending way, from smallest to largest. + /// + Asc, + /// + /// Sorts the items in an descending way, from largest to smallest. + /// + Desc, +} diff --git a/src/Marten/Linq/Parsing/DictionaryExpressions.cs b/src/Marten/Linq/Parsing/DictionaryExpressions.cs deleted file mode 100644 index 839a75b4a6d..00000000000 --- a/src/Marten/Linq/Parsing/DictionaryExpressions.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using NpgsqlTypes; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing; - -public class DictionaryExpressions: IMethodCallParser -{ - public bool Matches(MethodCallExpression expression) - { - return IsCollectionContainsWithStringKey(expression.Method) - || IsDictionaryContainsKey(expression.Method); - } - - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) - { - var fieldlocator = mapping.FieldFor(expression).TypedLocator; - - if (IsCollectionContainsWithStringKey(expression.Method)) - { - return QueryFromICollectionContains(expression, fieldlocator, options.Serializer()); - } - - if (IsDictionaryContainsKey(expression.Method)) - { - return QueryFromDictionaryContainsKey(expression, fieldlocator); - } - - throw new InvalidOperationException("Could not understand the format of the dictionary access"); - } - - private static bool IsCollectionContainsWithStringKey(MethodInfo m) - { - return m.Name == nameof(IDictionary.Contains) - && m.DeclaringType != null && m.DeclaringType.IsConstructedGenericType - && m.DeclaringType.GetGenericTypeDefinition() == typeof(ICollection<>) - && m.DeclaringType.GenericTypeArguments[0].IsConstructedGenericType - && m.DeclaringType.GenericTypeArguments[0].GetGenericTypeDefinition() == typeof(KeyValuePair<,>) - && (m.DeclaringType.GenericTypeArguments[0].GenericTypeArguments[0] == typeof(string) - || m.DeclaringType.GenericTypeArguments[0].GenericTypeArguments[0].IsValueType); - } - - private static bool IsDictionaryContainsKey(MethodInfo m) - { - return m.Name == nameof(IDictionary.ContainsKey) - && m.DeclaringType != null && m.DeclaringType.IsConstructedGenericType - && m.DeclaringType.Closes(typeof(IDictionary<,>)) - && (m.DeclaringType.GenericTypeArguments[0] == typeof(string) - || m.DeclaringType.GenericTypeArguments[0].IsValueType); - } - - private static ISqlFragment QueryFromDictionaryContainsKey(MethodCallExpression expression, string fieldLocator) - { - var key = expression.Arguments[0].Value().ToString()!; - // have to use different token here because we actually want the `?` character as the operator! - return new CustomizableWhereFragment($"{fieldLocator} ? @1", "@1", - new CommandParameter(key, NpgsqlDbType.Text)); - } - - private static ISqlFragment QueryFromICollectionContains(MethodCallExpression expression, string fieldPath, - ISerializer serializer) - { - var constant = (ConstantExpression)expression.Arguments[0]; - var kvp = constant.Value; // is kvp - var kvpType = kvp.GetType(); - var key = kvpType.GetProperty("Key").GetValue(kvp); - var value = kvpType.GetProperty("Value").GetValue(kvp); - var dictType = - typeof(Dictionary<,>).MakeGenericType(kvpType.GenericTypeArguments[0], kvpType.GenericTypeArguments[1]); - var dict = dictType.GetConstructors()[0].Invoke(null); - dictType.GetMethod("Add").Invoke(dict, new[] { key, value }); - var json = serializer.ToJson(dict); - return new CustomizableWhereFragment($"{fieldPath} @> ?", "?", new CommandParameter(json, NpgsqlDbType.Jsonb)); - } -} diff --git a/src/Marten/Linq/Parsing/EnumerableContains.cs b/src/Marten/Linq/Parsing/EnumerableContains.cs deleted file mode 100644 index d8af6d451b0..00000000000 --- a/src/Marten/Linq/Parsing/EnumerableContains.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using Marten.Linq.Filters; -using Marten.Linq.QueryHandlers; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing; - -public class EnumerableContains: IMethodCallParser -{ - public bool Matches(MethodCallExpression expression) - { - return expression.Method.Name == LinqConstants.CONTAINS && - typeMatches(expression.Object.Type) && - expression.Arguments.Single().IsValueExpression(); - } - - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) - { - var value = expression.Arguments.Single().Value(); - return ContainmentWhereFragment.SimpleArrayContains(FindMembers.Determine(expression.Object), options.Serializer(), - expression.Object, value); - } - - private static bool typeMatches(Type type) - { - if (type.IsGenericEnumerable()) - { - return true; - } - - return type.Closes(typeof(IReadOnlyList<>)); - } -} diff --git a/src/Marten/Linq/Parsing/ExpressionExtensions.cs b/src/Marten/Linq/Parsing/ExpressionExtensions.cs deleted file mode 100644 index 1cd85342be8..00000000000 --- a/src/Marten/Linq/Parsing/ExpressionExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using JasperFx.Core.Reflection; -using Marten.Exceptions; -using Remotion.Linq.Clauses.Expressions; - -namespace Marten.Linq.Parsing; - -[Obsolete("Goes away in v4")] -public static class ExpressionExtensions -{ - public static object Value(this Expression expression) - { - if (expression is PartialEvaluationExceptionExpression) - { - var partialEvaluationExceptionExpression = expression.As(); - var inner = partialEvaluationExceptionExpression.Exception; - - throw new BadLinqExpressionException( - $"Error in value expression inside of the query for '{partialEvaluationExceptionExpression.EvaluatedExpression}'. See the inner exception:", - inner); - } - - if (expression is ConstantExpression c) - { - return c.Value; - } - - throw new NotSupportedException($"The Expression is {expression} of type {expression.GetType().Name}"); - } - - public static bool IsValueExpression(this Expression expression) - { - Type[] valueExpressionTypes = { typeof(ConstantExpression), typeof(PartialEvaluationExceptionExpression) }; - return valueExpressionTypes.Any(t => t.IsInstanceOfType(expression)); - } -} diff --git a/src/Marten/Linq/Parsing/FindMembers.cs b/src/Marten/Linq/Parsing/FindMembers.cs deleted file mode 100644 index 1a30e79ee19..00000000000 --- a/src/Marten/Linq/Parsing/FindMembers.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Marten.Exceptions; -using Marten.Linq.QueryHandlers; -using Remotion.Linq.Clauses.Expressions; -using Remotion.Linq.Clauses.ResultOperators; -using Remotion.Linq.Parsing; - -namespace Marten.Linq.Parsing; - -public class FindMembers: RelinqExpressionVisitor -{ - public readonly IList Members = new List(); - - public static MemberInfo Member(Expression> expression) - { - var finder = new FindMembers(); - finder.Visit(expression); - - return finder.Members.LastOrDefault(); - } - - protected override Expression VisitMember(MemberExpression node) - { - Members.Insert(0, node.Member); - - return base.VisitMember(node); - } - - protected override Expression VisitBinary(BinaryExpression node) - { - throw new ArgumentOutOfRangeException(nameof(node), - $"Unsupported operator '{node.NodeType}' in a field member expression"); - } - - - protected override Expression VisitMethodCall(MethodCallExpression node) - { - if (node.Method.Name == "Count" && node.Method.ReturnType == typeof(int)) - { - Members.Insert(0, LinqConstants.ArrayLength); - } - - return base.VisitMethodCall(node); - } - - protected sealed override Expression VisitUnary(UnaryExpression node) - { - if (node.NodeType == ExpressionType.ArrayLength) - { - Members.Insert(0, LinqConstants.ArrayLength); - } - - return base.VisitUnary(node); - } - - public static MemberInfo[] Determine(Expression expression) - { - var visitor = new FindMembers(); - - if (expression is SubQueryExpression subquery) - { - visitor.Visit(subquery.QueryModel.MainFromClause.FromExpression); - if (subquery.QueryModel.ResultOperators.FirstOrDefault() is CountResultOperator) - { - visitor.Members.Add(LinqConstants.ArrayLength); - } - else - { - throw new BadLinqExpressionException($"FindMembers does not understand expression '{expression}'"); - } - } - else - { - visitor.Visit(expression); - } - - - return visitor.Members.ToArray(); - } -} diff --git a/src/Marten/Linq/Parsing/IExpressionParser.cs b/src/Marten/Linq/Parsing/IExpressionParser.cs deleted file mode 100644 index 255abd39012..00000000000 --- a/src/Marten/Linq/Parsing/IExpressionParser.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Linq.Expressions; -using Marten.Linq.Fields; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing; - -public interface IExpressionParser where T : Expression -{ - /// - /// Can this parser create a Sql where clause - /// from part of a Linq expression - /// - bool Matches(T expression); - - /// - /// Creates an ISqlFragment object that Marten - /// uses to help construct the underlying Sql - /// command - /// - ISqlFragment Parse(IFieldMapping mapping, ISerializer serializer, T expression); -} diff --git a/src/Marten/Linq/Parsing/IMethodCallParser.cs b/src/Marten/Linq/Parsing/IMethodCallParser.cs index f0e849b7766..d4baacb61bc 100644 --- a/src/Marten/Linq/Parsing/IMethodCallParser.cs +++ b/src/Marten/Linq/Parsing/IMethodCallParser.cs @@ -1,5 +1,5 @@ using System.Linq.Expressions; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.Parsing; @@ -27,11 +27,13 @@ public interface IMethodCallParser /// uses to help construct the underlying Sql /// command /// - /// - /// + /// + /// /// + /// /// - ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression); + ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression); } #endregion diff --git a/src/Marten/Linq/Parsing/LinqHandlerBuilder.cs b/src/Marten/Linq/Parsing/LinqHandlerBuilder.cs deleted file mode 100644 index 001434b29dc..00000000000 --- a/src/Marten/Linq/Parsing/LinqHandlerBuilder.cs +++ /dev/null @@ -1,336 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Runtime.CompilerServices; -using JasperFx.CodeGeneration; -using JasperFx.Core; -using JasperFx.Core.Reflection; -using Marten.Exceptions; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Linq.Fields; -using Marten.Linq.Includes; -using Marten.Linq.Operators; -using Marten.Linq.QueryHandlers; -using Marten.Linq.Selectors; -using Marten.Linq.SqlGeneration; -using Marten.Util; -using Npgsql; -using Remotion.Linq; -using Remotion.Linq.Clauses; -using Remotion.Linq.Clauses.Expressions; -using Remotion.Linq.Clauses.ResultOperators; -using Weasel.Postgresql; - -namespace Marten.Linq.Parsing; - -internal partial class LinqHandlerBuilder -{ - private readonly Type _documentType; - - - private readonly MartenLinqQueryProvider _provider; - private readonly IMartenSession _session; - - // START HERE -- TRACK WHICH DOCUMENTS ARE INVOLVED - internal LinqHandlerBuilder(MartenLinqQueryProvider provider, IMartenSession session, - Expression expression, ResultOperatorBase additionalOperator = null, bool forCompiled = false) - { - _session = session; - _provider = provider; - Model = forCompiled - ? MartenQueryParser.TransformQueryFlyweight.GetParsedQuery(expression) - : MartenQueryParser.Flyweight.GetParsedQuery(expression); - - if (additionalOperator != null) - { - Model.ResultOperators.Add(additionalOperator); - } - - _documentType = Model.MainFromClause.ItemType; - var storage = session.StorageFor(_documentType); - TopStatement = CurrentStatement = new DocumentStatement(storage); - - - if (Model.MainFromClause.FromExpression is SubQueryExpression sub) - { - readQueryModel(Model, storage, false, storage.Fields); - readQueryModel(sub.QueryModel, storage, true, - _session.Options.ChildTypeMappingFor(sub.QueryModel.MainFromClause.ItemType)); - } - else - { - readQueryModel(Model, storage, true, storage.Fields); - } - - wrapIncludes(_provider.AllIncludes); - } - - - public SelectorStatement CurrentStatement { get; set; } - - public Statement TopStatement { get; private set; } - - - public QueryModel Model { get; } - - public IEnumerable DocumentTypes() - { - yield return _documentType; - - foreach (var plan in _provider.AllIncludes) yield return plan.DocumentType; - } - - private void readQueryModel(QueryModel queryModel, IDocumentStorage storage, bool considerSelectors, - IFieldMapping fields) - { - readBodyClauses(queryModel, storage); - - - if (considerSelectors && !(Model.SelectClause.Selector is QuerySourceReferenceExpression)) - { - var visitor = new SelectorVisitor(this); - visitor.Visit(Model.SelectClause.Selector); - } - - foreach (var resultOperator in queryModel.ResultOperators) AddResultOperator(resultOperator, fields); - } - - private void readBodyClauses(QueryModel queryModel, IDocumentStorage storage) - { - for (var i = 0; i < queryModel.BodyClauses.Count; i++) - { - var clause = queryModel.BodyClauses[i]; - switch (clause) - { - case WhereClause where: - CurrentStatement.WhereClauses.Add(where); - break; - case OrderByClause orderBy: - CurrentStatement.Orderings.AddRange(orderBy.Orderings.Select(x => (x, false))); - break; - case OrderByComparerClause orderBy: - CurrentStatement.Orderings.AddRange(orderBy.Orderings.Select(x => (x, orderBy.CaseInsensitive))); - break; - case AdditionalFromClause additional: - var isComplex = queryModel.BodyClauses.Count > i + 1 || queryModel.ResultOperators.Any() || - _provider.AllIncludes.Any(); - var elementType = additional.ItemType; - var collectionField = storage.Fields.FieldFor(additional.FromExpression); - - CurrentStatement = CurrentStatement.ToSelectMany(collectionField, _session, isComplex, elementType); - - - break; - - default: - throw new NotSupportedException(); - } - } - } - - private void AddResultOperator(ResultOperatorBase resultOperator, IFieldMapping fields) - { - switch (resultOperator) - { - case TakeResultOperator take: - CurrentStatement.Limit = (int)take.Count.Value(); - break; - - case SkipResultOperator skip: - CurrentStatement.Offset = (int)skip.Count.Value(); - break; - - case AnyResultOperator _: - CurrentStatement.ToAny(); - break; - - case CountResultOperator _: - if (CurrentStatement.IsDistinct) - { - CurrentStatement.ConvertToCommonTableExpression(_session); - CurrentStatement = new CountStatement(CurrentStatement); - } - else - { - CurrentStatement.ToCount(); - } - - break; - - case LongCountResultOperator _: - if (CurrentStatement.IsDistinct) - { - CurrentStatement.ConvertToCommonTableExpression(_session); - CurrentStatement = new CountStatement(CurrentStatement); - } - else - { - CurrentStatement.ToCount(); - } - - break; - - case FirstResultOperator first: - CurrentStatement.Limit = 1; - CurrentStatement.SingleValue = true; - CurrentStatement.ReturnDefaultWhenEmpty = first.ReturnDefaultWhenEmpty; - CurrentStatement.CanBeMultiples = true; - break; - - case SingleResultOperator single: - if (CurrentStatement.Limit == 0) - { - CurrentStatement.Limit = 2; - } - - CurrentStatement.SingleValue = true; - CurrentStatement.ReturnDefaultWhenEmpty = single.ReturnDefaultWhenEmpty; - CurrentStatement.CanBeMultiples = false; - break; - - case DistinctResultOperator _: - CurrentStatement.IsDistinct = true; - CurrentStatement.ApplySqlOperator("distinct"); - break; - - case AverageResultOperator _: - CurrentStatement.ApplyAggregateOperator("AVG"); - break; - - case SumResultOperator _: - CurrentStatement.ApplyAggregateOperator("SUM"); - break; - - case MinResultOperator _: - CurrentStatement.ApplyAggregateOperator("MIN"); - break; - - case MaxResultOperator _: - CurrentStatement.ApplyAggregateOperator("MAX"); - break; - - case LastResultOperator _: - throw new InvalidOperationException( - "Marten does not support Last() or LastOrDefault() queries. Please reverse the ordering and use First()/FirstOrDefault() instead"); - - case IncludeResultOperator includeOp: - var include = includeOp.BuildInclude(_session, fields); - _provider.AllIncludes.Add(include); - break; - - default: - throw new NotSupportedException("Don't yet know how to deal with " + resultOperator); - } - } - - public IQueryHandler BuildHandler() - { - try - { - BuildDatabaseStatement(); - - var handler = buildHandlerForCurrentStatement(); - - return _provider.AllIncludes.Any() - ? new IncludeQueryHandler(handler, - _provider.AllIncludes.Select(x => x.BuildReader(_session)).ToArray()) - : handler; - } - catch (NotSupportedException e) - { - if (e.Message.StartsWith("Can't infer NpgsqlDbType for type")) - { - throw new BadLinqExpressionException( - "Marten cannot support custom value types in Linq expression. Please query on either simple properties of the value type, or register a custom IFieldSource for this value type.", - e); - } - - throw; - } - } - - public void BuildDatabaseStatement() - { - if (_provider.Statistics != null) - { - CurrentStatement.UseStatistics(_provider.Statistics); - } - - var topStatement = TopStatement; - topStatement.CompileStructure(_session); - - TopStatement = topStatement.Top(); - } - - private void wrapIncludes(IList includes) - { - if (!includes.Any()) - { - return; - } - - // Just need to guarantee that each include has an index - for (var i = 0; i < includes.Count; i++) - { - includes[i].Index = i; - } - - var statement = new IncludeIdentitySelectorStatement(TopStatement, includes, _session); - TopStatement = statement.Top(); - CurrentStatement = (SelectorStatement)statement.Current(); - } - - private IQueryHandler buildHandlerForCurrentStatement() - { - if (CurrentStatement.SingleValue) - { - return CurrentStatement.BuildSingleResultHandler(_session, TopStatement); - } - - return CurrentStatement.SelectClause.BuildHandler(_session, TopStatement, CurrentStatement); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IQueryHandler BuildHandler(ISelector selector, - Statement statement) - { - if (typeof(TResult).CanBeCastTo>()) - { - return (IQueryHandler)new ListQueryHandler(statement, selector); - } - - throw new NotSupportedException("Marten does not know how to use result type " + - typeof(TResult).FullNameInCode()); - } - - public void BuildDiagnosticCommand(FetchType fetchType, CommandBuilder sql) - { - BuildDatabaseStatement(); - - switch (fetchType) - { - case FetchType.Any: - CurrentStatement.ToAny(); - break; - - case FetchType.Count: - CurrentStatement.ToCount(); - break; - - case FetchType.FetchOne: - CurrentStatement.Limit = 1; - break; - } - - TopStatement.Configure(sql); - } - - public NpgsqlCommand BuildDatabaseCommand(QueryStatistics statistics) - { - BuildDatabaseStatement(); - - return _session.BuildCommand(TopStatement); - } -} diff --git a/src/Marten/Linq/Parsing/LinqInternalExtensions.cs b/src/Marten/Linq/Parsing/LinqInternalExtensions.cs new file mode 100644 index 00000000000..a908873a389 --- /dev/null +++ b/src/Marten/Linq/Parsing/LinqInternalExtensions.cs @@ -0,0 +1,296 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using FastExpressionCompiler; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing; + +internal static class LinqInternalExtensions +{ + // private static Type[] _valueTypes = new Type[] + // { + // typeof(Guid), typeof(DateTime), typeof(DateTimeOffset), typeof(DateOnly), typeof(TimeOnly) + // }; + + private static readonly List _valueTypes = new(); + + static LinqInternalExtensions() + { + addValueType(); + addValueType(); + addValueType(); + addValueType(); + addValueType(); + + _valueTypes.Add(typeof(string)); + } + + private static void addValueType() where T : struct + { + _valueTypes.Add(typeof(T)); + _valueTypes.Add(typeof(T?)); + } + + public static string CorrectJsonPathOperator(this string op) + { + return op == "=" ? "==" : op; + } + + public static bool IsValueTypeForQuerying(this Type type) + { + return type.IsSimple() || _valueTypes.Contains(type) || type.IsEnum || + (type.IsNullable() && type.GetInnerTypeFromNullable().IsEnum); + } + + public static IQueryableMember MemberFor(this IQueryableMemberCollection collection, + Expression> propertyExpression) + { + var members = MemberFinder.Determine(propertyExpression); + return collection.MemberFor(members); + } + + public static IQueryableMember MemberFor(this IQueryableMemberCollection collection, + string memberName) + { + var member = collection.ElementType.GetProperty(memberName) ?? + (MemberInfo)collection.ElementType.GetField(memberName); + + return collection.FindMember(member); + } + + // Assume there's a separate member for the usage of a member with methods + // i.e., StringMember.ToLower() + // Dictionary fields will create a separate "dictionary value field" + public static IQueryableMember MemberFor(this IHasChildrenMembers collection, Expression expression) + { + if (expression is ParameterExpression) + { + return new RootMember(expression.Type); + } + + var members = MemberFinder.Determine(expression); + if (!members.Any()) + { + throw new BadLinqExpressionException("Unable to find any queryable members in expression " + expression); + } + + var member = collection.FindMember(members[0]); + + for (var i = 1; i < members.Length; i++) + { + if (member is IHasChildrenMembers m) + { + member = m.FindMember(members[i]); + } + else + { + throw new BadLinqExpressionException("Marten can not (yet) deal with " + expression); + } + } + + return member; + } + + // Assume there's a separate member for the usage of a member with methods + // i.e., StringMember.ToLower() + // Dictionary fields will create a separate "dictionary value field" + public static IQueryableMember MemberFor(this IHasChildrenMembers collection, Expression expression, + string invalidExpression) + { + if (expression is ParameterExpression) + { + return new RootMember(expression.Type); + } + + var members = MemberFinder.Determine(expression, invalidExpression); + if (!members.Any()) + { + throw new BadLinqExpressionException("Unable to find any queryable members in expression " + expression); + } + + var member = collection.FindMember(members[0]); + + for (var i = 1; i < members.Length; i++) + { + if (member is IHasChildrenMembers m) + { + member = m.FindMember(members[i]); + } + else + { + throw new BadLinqExpressionException("Marten can not (yet) deal with " + expression); + } + } + + return member; + } + + public static IQueryableMember MemberFor(this IHasChildrenMembers collection, MemberInfo[] members) + { + var member = collection.FindMember(members[0]); + for (var i = 1; i < members.Length; i++) + { + if (member is IHasChildrenMembers m) + { + member = m.FindMember(members[i]); + } + else + { + throw new BadLinqExpressionException("Marten does not (yet) support using member chain: " + + members.Select(x => x.Name).Join(".")); + } + } + + return member; + } + + public static ISqlFragment ReduceToValue(this IQueryableMemberCollection collection, Expression expression) + { + if (expression is ConstantExpression c) + { + return new CommandParameter(c); + } + + if (expression is MemberExpression m) + { + if (m.Expression is ConstantExpression) + { + var lambdaWithoutParameters = + Expression.Lambda>(Expression.Convert(expression, typeof(object))); + var compiledLambda = lambdaWithoutParameters.CompileFast(); + + var value = compiledLambda(); + return new CommandParameter(value); + } + + return collection.MemberFor(expression); + } + + throw new BadLinqExpressionException("Marten does not (yet) know how to process a Linq value for " + + expression); + } + + public static bool IsCompilableExpression(this MemberExpression node) + { + return (node.Expression is ConstantExpression || node.Expression != null) && + node.Expression.ToString().StartsWith("value("); + } + + public static bool TryToParseConstant(this Expression expression, out ConstantExpression constant) + { + if (expression == null) + { + constant = default; + return false; + } + + if (expression is ConstantExpression c) + { + constant = ReduceToConstant(expression); + return true; + } + + if (expression is MemberExpression m && m.IsCompilableExpression()) + { + constant = ReduceToConstant(expression); + return true; + } + + constant = default; + return false; + } + + /// + /// Write out the JSONPath locator for the current member within its collection + /// + /// + /// + public static void WriteJsonPath(this IQueryableMember member, CommandBuilder builder) + { + foreach (var ancestor in member.Ancestors) + { + if (ancestor.JsonPathSegment.IsNotEmpty()) + { + builder.Append(ancestor.JsonPathSegment); + builder.Append("."); + } + + builder.Append(member.JsonPathSegment); + } + } + + public static string AddJsonPathParameter(this IDictionary dict, object value) + { + var name = "val" + (dict.Count + 1); + dict[name] = value; + return "$" + name; + } + + private static readonly Type[] valueExpressionTypes = + { + typeof(ConstantExpression) + }; + + public static object Value(this Expression expression) + { + if (expression is ConstantExpression c) + { + return c.Value; + } + + return ReduceToConstant(expression).Value; + } + + public static bool IsValueExpression(this Expression expression) + { + if (expression == null) + { + return false; + } + + return valueExpressionTypes.Any(t => t.IsInstanceOfType(expression)) || + expression.NodeType == ExpressionType.Lambda; + } + + internal static ConstantExpression ReduceToConstant(this Expression expression) + { + if (expression is LambdaExpression l) + { + expression = l.Body.As().Right; + } + + if (expression.NodeType == ExpressionType.Constant) + { + var constantExpression = (ConstantExpression)expression; + var valueAsIQueryable = constantExpression.Value as IQueryable; + if (valueAsIQueryable != null && valueAsIQueryable.Expression != constantExpression) + { + return (ConstantExpression)valueAsIQueryable.Expression; + } + + return constantExpression; + } + + var lambdaWithoutParameters = Expression.Lambda>(Expression.Convert(expression, typeof(object))); + var compiledLambda = lambdaWithoutParameters.CompileFast(); + + try + { + var value = compiledLambda(); + return Expression.Constant(value, expression.Type); + } + catch (Exception e) + { + throw new BadLinqExpressionException( + "Error while trying to find a value for the Linq expression " + expression, e); + } + } +} diff --git a/src/Marten/Linq/Parsing/LinqQueryParser.cs b/src/Marten/Linq/Parsing/LinqQueryParser.cs new file mode 100644 index 00000000000..21ed0545ed7 --- /dev/null +++ b/src/Marten/Linq/Parsing/LinqQueryParser.cs @@ -0,0 +1,313 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Linq.Expressions; +using System.Runtime.CompilerServices; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Internal; +using Marten.Internal.Storage; +using Marten.Linq.Includes; +using Marten.Linq.Members; +using Marten.Linq.Parsing.Operators; +using Marten.Linq.QueryHandlers; +using Marten.Linq.Selectors; +using Marten.Linq.SqlGeneration; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing; + +internal class LinqQueryParser: ExpressionVisitor, ILinqQuery +{ + // TODO -- inject somehow later. See https://github.com/JasperFx/marten/issues/2709 + private static readonly OperatorLibrary _operators = new(); + private readonly List _collectionUsages = new(); + + private readonly MartenLinqQueryProvider _provider; + + + private bool _hasParsedIncludes; + + public LinqQueryParser(MartenLinqQueryProvider provider, IMartenSession session, + Expression expression, SingleValueMode? valueMode = null) + { + ValueMode = valueMode; + _provider = provider; + Session = session; + + Visit(expression); + } + + public SingleValueMode? ValueMode { get; } + + public IMartenSession Session { get; } + + public CollectionUsage CollectionUsageFor(MethodCallExpression expression) + { + var argument = expression.Arguments.First(); + return CollectionUsageForArgument(argument); + } + + public CollectionUsage CollectionUsageForArgument(Expression argument) + { + var elementType = argument.Type.GetGenericArguments()[0]; + if (CurrentUsage == null || CurrentUsage.ElementType != elementType) + { + CurrentUsage = new CollectionUsage(Session.Options, elementType); + _collectionUsages.Insert(0, CurrentUsage); + + return CurrentUsage; + } + + return CurrentUsage; + } + + public CollectionUsage StartNewCollectionUsageFor(MethodCallExpression expression) + { + var elementType = expression.Arguments[0].Type.GetGenericArguments()[0]; + CurrentUsage = new CollectionUsage(Session.Options, elementType); + _collectionUsages.Insert(0, CurrentUsage); + + return CurrentUsage; + } + + public CollectionUsage CollectionUsageFor(Type elementType) + { + if (CurrentUsage == null || CurrentUsage.ElementType != elementType) + { + CurrentUsage = new CollectionUsage(Session.Options, elementType); + _collectionUsages.Insert(0, CurrentUsage); + + return CurrentUsage; + } + + return CurrentUsage; + } + + public CollectionUsage CurrentUsage { get; private set; } + + public IQueryHandler> BuildListHandler() + { + if (!_collectionUsages.Any()) + { + var usage = new CollectionUsage(Session.Options, _provider.SourceType); + _collectionUsages.Insert(0, usage); + } + + var statements = BuildStatements(); + + var handler = + statements.MainSelector.SelectClause.BuildHandler>(Session, statements.Top, + statements.MainSelector); + + if (_provider.AllIncludes.Any()) + { + return new IncludeQueryHandler>(handler, + _provider.AllIncludes.Select(x => x.BuildReader(Session)).ToArray()); + } + + return handler; + } + + public IQueryHandler BuildHandler() + { + if (!_collectionUsages.Any()) + { + var usage = new CollectionUsage(Session.Options, _provider.SourceType); + _collectionUsages.Insert(0, usage); + } + + var statements = BuildStatements(); + + var handler = buildHandlerForCurrentStatement(statements.Top, statements.MainSelector); + + if (_provider.AllIncludes.Any()) + { + return new IncludeQueryHandler(handler, + _provider.AllIncludes.Select(x => x.BuildReader(Session)).ToArray()); + } + + return handler; + } + + private IQueryHandler buildHandlerForCurrentStatement(Statement top, SelectorStatement selector) + { + if (selector.SingleValue) + { + return selector.BuildSingleResultHandler(Session, top); + } + + return selector.SelectClause.BuildHandler(Session, top, selector); + } + + public IEnumerable DocumentTypes() + { + if (_collectionUsages.Any()) + { + yield return _collectionUsages[0].ElementType; + } + + foreach (var plan in _provider.AllIncludes) + { + yield return plan.DocumentType; + } + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + if (_operators.TryFind(node.Method.Name, out var op)) + { + op.Apply(this, node); + + // Do NOT visit deep into the inner expression of a WHERE or ORDER BY + return Visit(node.Arguments[0]); + } + + throw new BadLinqExpressionException($"Marten does not (yet) support Linq operator '{node.Method.Name}'"); + } + + internal StatementQuery BuildStatements() + { + if (!_collectionUsages.Any()) + { + var usage = new CollectionUsage(Session.Options, _provider.SourceType); + _collectionUsages.Insert(0, usage); + } + + var top = _collectionUsages[0]; + + for (var i = 1; i < _collectionUsages.Count; i++) + { + _collectionUsages[i - 1].Inner = _collectionUsages[i]; + } + + var documentStorage = Session.StorageFor(top.ElementType); + var collection = documentStorage.QueryMembers; + + // In case the single value mode is passed through by the MartenLinqProvider + if (ValueMode != null) + { + _collectionUsages.Last().SingleValueMode = ValueMode; + } + + var statement = top.BuildTopStatement(Session, collection, documentStorage); + var selectionStatement = statement.SelectorStatement(); + + // Deal with query statistics + if (_provider.Statistics != null) + { + selectionStatement.SelectClause = selectionStatement.SelectClause.UseStatistics(_provider.Statistics); + } + + parseIncludeExpressions(top, collection); + + if (_provider.AllIncludes.Any()) + { + var inner = statement.Top(); + + if (inner is SelectorStatement { SelectClause: IDocumentStorage storage } select) + { + select.SelectClause = storage.SelectClauseWithDuplicatedFields; + } + + var temp = new TemporaryTableStatement(inner, Session); + foreach (var include in _provider.AllIncludes) include.AppendStatement(temp, Session); + + temp.AddToEnd(new PassthroughSelectStatement(temp.ExportName, selectionStatement.SelectClause)); + + return new StatementQuery(selectionStatement, temp); + } + + return new StatementQuery(selectionStatement, selectionStatement.Top()); + } + + private void parseIncludeExpressions(CollectionUsage top, IQueryableMemberCollection collection) + { + if (_hasParsedIncludes) + { + return; + } + + _hasParsedIncludes = true; + + foreach (var expression in top.IncludeExpressions) + { + var member = expression.Arguments.Count == 3 + ? collection.MemberFor(expression.Arguments[1]) + : collection.MemberFor(expression.Arguments[0]); + var receiver = expression.Arguments.Last().Value(); + + var genericArguments = receiver.GetType().GetGenericArguments(); + if (receiver.GetType().Closes(typeof(IList<>))) + { + var includedType = genericArguments[0]; + var storage = Session.StorageFor(includedType); + + var type = typeof(ListIncludePlan<>).MakeGenericType(includedType); + var plan = (IIncludePlan)Activator.CreateInstance(type, storage, member, receiver); + + _provider.AllIncludes.Add(plan); + } + else if (receiver.GetType().Closes(typeof(Action<>))) + { + var includedType = genericArguments[0]; + var storage = Session.StorageFor(includedType); + + var type = typeof(IncludePlan<>).MakeGenericType(includedType); + var plan = (IIncludePlan)Activator.CreateInstance(type, storage, member, receiver); + + _provider.AllIncludes.Add(plan); + } + else + { + var idType = genericArguments[0]; + var includedType = genericArguments[1]; + var storage = Session.StorageFor(includedType); + + var type = typeof(DictionaryIncludePlan<,>).MakeGenericType(includedType, idType); + var plan = (IIncludePlan)Activator.CreateInstance(type, storage, member, receiver); + + _provider.AllIncludes.Add(plan); + } + } + } + + public void BuildDiagnosticCommand(FetchType fetchType, CommandBuilder sql) + { + var statements = BuildStatements(); + + switch (fetchType) + { + case FetchType.Any: + statements.MainSelector.ToAny(); + break; + + case FetchType.Count: + statements.MainSelector.ToCount(); + break; + + case FetchType.FetchOne: + statements.MainSelector.Limit = 1; + break; + } + + statements.Top.Apply(sql); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static IQueryHandler BuildHandler(ISelector selector, + ISqlFragment statement) + { + if (typeof(TResult).CanBeCastTo>()) + { + return (IQueryHandler)new ListQueryHandler(statement, selector); + } + + throw new NotSupportedException("Marten does not know how to use result type " + + typeof(TResult).FullNameInCode()); + } + + internal record struct StatementQuery(SelectorStatement MainSelector, Statement Top); +} diff --git a/src/Marten/Linq/Parsing/MartenQueryParser.cs b/src/Marten/Linq/Parsing/MartenQueryParser.cs deleted file mode 100644 index d835a899a51..00000000000 --- a/src/Marten/Linq/Parsing/MartenQueryParser.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Linq.Expressions; -using Marten.Exceptions; -using Marten.Linq.Operators; -using Marten.Pagination; -using Remotion.Linq; -using Remotion.Linq.Parsing.ExpressionVisitors.Transformation; -using Remotion.Linq.Parsing.Structure; -using Remotion.Linq.Parsing.Structure.NodeTypeProviders; - -namespace Marten.Linq.Parsing; - -public class MartenQueryParser: IQueryParser -{ - public static readonly MartenQueryParser Flyweight = new(r => - { - r.Register(IncludeExpressionNode.SupportedMethods, typeof(IncludeExpressionNode)); - r.Register(OrderByComparerExpressionNode.SupportedMethods, typeof(OrderByComparerExpressionNode)); - }); - - public static readonly MartenQueryParser TransformQueryFlyweight = new(r => - { - r.Register(IncludeExpressionNode.SupportedMethods, typeof(IncludeExpressionNode)); - r.Register(OrderByComparerExpressionNode.SupportedMethods, typeof(OrderByComparerExpressionNode)); - r.Register(StatsExpressionNode.SupportedMethods, typeof(StatsExpressionNode)); - }); - - private readonly QueryParser _parser; - - public MartenQueryParser(Action registerNodeTypes = null) - { - var transformerRegistry = ExpressionTransformerRegistry.CreateDefault(); - - var processor = ExpressionTreeParser.CreateDefaultProcessor(transformerRegistry); - - var nodeTypeRegistry = MethodInfoBasedNodeTypeRegistry.CreateFromRelinqAssembly(); - registerNodeTypes?.Invoke(nodeTypeRegistry); - - var expressionTreeParser = - new ExpressionTreeParser(nodeTypeRegistry, processor); - _parser = new QueryParser(expressionTreeParser); - } - - public QueryModel GetParsedQuery(Expression expressionTreeRoot) - { - try - { - return _parser.GetParsedQuery(expressionTreeRoot); - } - catch (NotSupportedException e) - { - if (e.Message.Contains("PagedList")) - { - throw new BadLinqExpressionException( - $"The {nameof(PagedListQueryableExtensions.ToPagedList)}() operators cannot be used in compiled queries. Use {nameof(QueryStatistics)} instead."); - } - - throw; - } - } -} diff --git a/src/Marten/Linq/Parsing/MemberFinder.cs b/src/Marten/Linq/Parsing/MemberFinder.cs new file mode 100644 index 00000000000..e2af3b2abe4 --- /dev/null +++ b/src/Marten/Linq/Parsing/MemberFinder.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using Marten.Exceptions; +using Marten.Linq.QueryHandlers; + +namespace Marten.Linq.Parsing; + +// TODO -- this needs to account for Methods too!. See https://github.com/JasperFx/marten/issues/2707 +public class MemberFinder: ExpressionVisitor +{ + public readonly List InvalidNodeTypes = new(); + public readonly IList Members = new List(); + + public bool FoundParameterAtFront { get; private set; } + + protected override Expression VisitMember(MemberExpression node) + { + Members.Insert(0, node.Member); + + try + { + return base.VisitMember(node); + } + catch (Exception e) + { + Console.WriteLine(e); + } + + return null; + } + + protected override Expression VisitBinary(BinaryExpression node) + { + InvalidNodeTypes.Add(node.NodeType); + return base.VisitBinary(node); + } + + protected override Expression VisitParameter(ParameterExpression node) + { + FoundParameterAtFront = true; + return base.VisitParameter(node); + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + if (node.Method.Name == "Count" && node.Method.ReturnType == typeof(int)) + { + Members.Insert(0, LinqConstants.ArrayLength); + } + + return base.VisitMethodCall(node); + } + + protected sealed override Expression VisitUnary(UnaryExpression node) + { + if (node.NodeType == ExpressionType.ArrayLength) + { + Members.Insert(0, LinqConstants.ArrayLength); + } + + return base.VisitUnary(node); + } + + public static MemberInfo[] Determine(Expression expression) + { + var visitor = new MemberFinder(); + + visitor.Visit(expression); + + return visitor.Members.ToArray(); + } + + public static MemberInfo[] Determine(Expression expression, string invalidMessage) + { + var visitor = new MemberFinder(); + + visitor.Visit(expression); + + if (!visitor.FoundParameterAtFront) + { + throw new BadLinqExpressionException($"{invalidMessage}: '{expression}'"); + } + + if (visitor.InvalidNodeTypes.Any()) + { + throw new BadLinqExpressionException($"{invalidMessage}: '{expression}'"); + } + + return visitor.Members.ToArray(); + } +} diff --git a/src/Marten/Linq/Parsing/MethodCallParser.cs b/src/Marten/Linq/Parsing/MethodCallParser.cs deleted file mode 100644 index 894d15aae86..00000000000 --- a/src/Marten/Linq/Parsing/MethodCallParser.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing; - -public abstract class MethodCallParser: IMethodCallParser -{ - private readonly MethodInfo _method; - - public MethodCallParser(Expression> method) - { - _method = ReflectionHelper.GetMethod(method); - } - - public bool Matches(MethodCallExpression expression) - { - // You cannot use the Equals() method on any Reflection objects, they - // only check for reference equality. Ask me how I know that;) - return expression.Object?.Type == typeof(T) && expression.Method.Name == _method.Name; - } - - public abstract ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, - MethodCallExpression expression); -} diff --git a/src/Marten/Linq/Parsing/Methods/AllMethodParser.cs b/src/Marten/Linq/Parsing/Methods/AllMethodParser.cs new file mode 100644 index 00000000000..e11fceea496 --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/AllMethodParser.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Linq.Members; +using Marten.Linq.QueryHandlers; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods; + +internal class AllMethodParser: IMethodCallParser +{ + public bool Matches(MethodCallExpression expression) + { + var member = expression.Object ?? expression.Arguments[0]; + + return expression.Method.Name == LinqConstants.ALL && + typeMatches(member.Type); + } + + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + var member = memberCollection.MemberFor(expression.Arguments[0]); + + if (member is ICollectionMember cm) + { + return cm.ParseWhereForAll(expression, options); + } + + throw new BadLinqExpressionException("Marten does not know how to handle expression " + expression); + } + + private static bool typeMatches(Type type) + { + return type.IsGenericEnumerable() || type.Closes(typeof(IReadOnlyList<>)) || type.IsArray; + } +} diff --git a/src/Marten/Linq/Parsing/Methods/AnySubQueryParser.cs b/src/Marten/Linq/Parsing/Methods/AnySubQueryParser.cs new file mode 100644 index 00000000000..5b167750711 --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/AnySubQueryParser.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Linq.Members; +using Marten.Linq.QueryHandlers; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods; + +internal class AnySubQueryParser: IMethodCallParser +{ + public bool Matches(MethodCallExpression expression) + { + var member = expression.Object ?? expression.Arguments[0]; + + return expression.Method.Name == LinqConstants.ANY && + typeMatches(member.Type); + } + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + Expression memberExpression = null; + Expression body = null; + + ICollectionMember member = null; + + if (expression.Arguments.Count == 1) + { + // Where(filter).Any() + if (expression.Arguments[0] is MethodCallExpression method) + { + // Where(filter).Any() + memberExpression = method.Arguments[0]; + body = method.Arguments.Last(); + } + else + { + // Any(filter) + memberExpression = expression.Object ?? expression.Arguments[0]; + member = (ICollectionMember)memberCollection.MemberFor(memberExpression); + return new CollectionIsNotEmpty(member); + } + } + + + memberExpression ??= expression.Object ?? expression.Arguments[0]; + + if (memberExpression.TryToParseConstant(out var constant)) + { + throw new BadLinqExpressionException($"Marten cannot parse this expression: '{expression}'"); + } + + body ??= expression.Arguments.Last(); + + member = (ICollectionMember)memberCollection.MemberFor(memberExpression); + if (body is LambdaExpression l) + { + body = l.Body; + } + + return member.ParseWhereForAny(body, options); + } + + private static bool typeMatches(Type type) + { + if (type.IsGenericEnumerable()) + { + return true; + } + + return type.Closes(typeof(IReadOnlyList<>)); + } +} diff --git a/src/Marten/Linq/Parsing/Methods/AnyTenant.cs b/src/Marten/Linq/Parsing/Methods/AnyTenant.cs index a85cc3c742d..534c792ecca 100644 --- a/src/Marten/Linq/Parsing/Methods/AnyTenant.cs +++ b/src/Marten/Linq/Parsing/Methods/AnyTenant.cs @@ -1,6 +1,6 @@ using System.Linq.Expressions; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.Parsing.Methods; @@ -17,7 +17,8 @@ public bool Matches(MethodCallExpression expression) && expression.Method.DeclaringType == typeof(LinqExtensions); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { return this; } diff --git a/src/Marten/Linq/Parsing/Methods/DictionaryContains.cs b/src/Marten/Linq/Parsing/Methods/DictionaryContains.cs new file mode 100644 index 00000000000..48fca1803c0 --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/DictionaryContains.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods; + +[Obsolete] +internal class DictionaryContains: IMethodCallParser +{ + public bool Matches(MethodCallExpression expression) + { + var m = expression.Method; + return m.Name == nameof(IDictionary.Contains) + && m.DeclaringType != null && m.DeclaringType.IsConstructedGenericType + && m.DeclaringType.GetGenericTypeDefinition() == typeof(ICollection<>) + && m.DeclaringType.GenericTypeArguments[0].IsConstructedGenericType + && m.DeclaringType.GenericTypeArguments[0].GetGenericTypeDefinition() == typeof(KeyValuePair<,>) + && (m.DeclaringType.GenericTypeArguments[0].GenericTypeArguments[0] == typeof(string) + || m.DeclaringType.GenericTypeArguments[0].GenericTypeArguments[0].IsValueType); + } + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + var member = memberCollection.MemberFor(expression.Arguments.First()); + var constant = expression.Arguments.Last().ReduceToConstant(); + + return new ContainmentWhereFilter(member, constant, options.Serializer()); + } +} diff --git a/src/Marten/Linq/Parsing/Methods/DictionaryContainsKey.cs b/src/Marten/Linq/Parsing/Methods/DictionaryContainsKey.cs new file mode 100644 index 00000000000..142ea3c6e1e --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/DictionaryContainsKey.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using JasperFx.Core.Reflection; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods; + +[Obsolete] +internal class DictionaryContainsKey: IMethodCallParser +{ + public bool Matches(MethodCallExpression expression) + { + var method = expression.Method; + + return method.Name == nameof(IDictionary.ContainsKey) + && method.DeclaringType != null && method.DeclaringType.IsConstructedGenericType + && method.DeclaringType.Closes(typeof(IDictionary<,>)) + && (method.DeclaringType.GenericTypeArguments[0] == typeof(string) + || method.DeclaringType.GenericTypeArguments[0].IsValueType); + } + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + var member = memberCollection.MemberFor(expression.Object); + var constant = expression.Arguments.Single().ReduceToConstant(); + + return new ContainmentWhereFilter(member, constant, options.Serializer()); + } +} diff --git a/src/Marten/Linq/Parsing/Methods/EnumerableContains.cs b/src/Marten/Linq/Parsing/Methods/EnumerableContains.cs new file mode 100644 index 00000000000..a3b438484fa --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/EnumerableContains.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using JasperFx.Core.Reflection; +using Marten.Linq.Members; +using Marten.Linq.QueryHandlers; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods; + +internal class EnumerableContains: IMethodCallParser +{ + public bool Matches(MethodCallExpression expression) + { + var member = expression.Object ?? expression.Arguments[0]; + + return expression.Method.Name == LinqConstants.CONTAINS && (member.Type.IsEnumerable() || + member.Type.IsGenericEnumerable() || + member.Type.Closes(typeof(IDictionary<,>))); + } + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + if ((expression.Object ?? expression.Arguments[0]).TryToParseConstant(out var constant)) + { + // This is the value.Contains() pattern + var collectionMember = memberCollection.MemberFor(expression.Arguments.Last()); + + return new WhereFragment($"{collectionMember.TypedLocator} = ANY(?)", constant.Value); + } + + var member = memberCollection.MemberFor(expression.Object ?? expression.Arguments[0]); + var collection = (ICollectionMember)member; + + return collection.ParseWhereForContains(expression, options); + } +} diff --git a/src/Marten/Linq/Parsing/Methods/FullTextSearchMethodCallParser.cs b/src/Marten/Linq/Parsing/Methods/FullText/FullTextSearchMethodCallParser.cs similarity index 84% rename from src/Marten/Linq/Parsing/Methods/FullTextSearchMethodCallParser.cs rename to src/Marten/Linq/Parsing/Methods/FullText/FullTextSearchMethodCallParser.cs index 31d301c7be7..d6e191aedc0 100644 --- a/src/Marten/Linq/Parsing/Methods/FullTextSearchMethodCallParser.cs +++ b/src/Marten/Linq/Parsing/Methods/FullText/FullTextSearchMethodCallParser.cs @@ -1,11 +1,11 @@ using System; using System.Linq.Expressions; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Parsing.Methods; +namespace Marten.Linq.Parsing.Methods.FullText; internal enum FullTextSearchFunction { @@ -33,7 +33,8 @@ public bool Matches(MethodCallExpression expression) && expression.Method.DeclaringType == typeof(LinqExtensions); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { if (expression.Arguments.Count < 2 || expression.Arguments[1].Value() == null) { @@ -57,7 +58,7 @@ public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, : FullTextIndex.DefaultRegConfig; return new FullTextWhereFragment( - mapping as DocumentMapping, + memberCollection as DocumentMapping, searchFunction, searchTerm, regConfig); diff --git a/src/Marten/Linq/Parsing/Methods/FullText/NgramSearch.cs b/src/Marten/Linq/Parsing/Methods/FullText/NgramSearch.cs new file mode 100644 index 00000000000..aef383f1a1f --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/FullText/NgramSearch.cs @@ -0,0 +1,26 @@ +using System.Linq; +using System.Linq.Expressions; +using Marten.Linq.Members; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods.FullText; + +public class NgramSearch: IMethodCallParser +{ + public bool Matches(MethodCallExpression expression) + { + return expression.Method.Name == nameof(LinqExtensions.NgramSearch) + && expression.Method.DeclaringType == typeof(LinqExtensions); + } + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + var locator = memberCollection.MemberFor(expression.Arguments[0]).RawLocator; + var values = expression.Arguments.Last().Value(); + + return new WhereFragment( + $"{options.DatabaseSchemaName}.mt_grams_vector({locator}) @@ {options.DatabaseSchemaName}.mt_grams_query(?)", + values); + } +} diff --git a/src/Marten/Linq/Parsing/Methods/PhraseSearch.cs b/src/Marten/Linq/Parsing/Methods/FullText/PhraseSearch.cs similarity index 79% rename from src/Marten/Linq/Parsing/Methods/PhraseSearch.cs rename to src/Marten/Linq/Parsing/Methods/FullText/PhraseSearch.cs index 3db6c3ab239..8afe85bade4 100644 --- a/src/Marten/Linq/Parsing/Methods/PhraseSearch.cs +++ b/src/Marten/Linq/Parsing/Methods/FullText/PhraseSearch.cs @@ -1,4 +1,4 @@ -namespace Marten.Linq.Parsing.Methods; +namespace Marten.Linq.Parsing.Methods.FullText; internal class PhraseSearch: FullTextSearchMethodCallParser { diff --git a/src/Marten/Linq/Parsing/Methods/PlainTextSearch.cs b/src/Marten/Linq/Parsing/Methods/FullText/PlainTextSearch.cs similarity index 80% rename from src/Marten/Linq/Parsing/Methods/PlainTextSearch.cs rename to src/Marten/Linq/Parsing/Methods/FullText/PlainTextSearch.cs index 42608ca4d2a..b929f68e3ec 100644 --- a/src/Marten/Linq/Parsing/Methods/PlainTextSearch.cs +++ b/src/Marten/Linq/Parsing/Methods/FullText/PlainTextSearch.cs @@ -1,4 +1,4 @@ -namespace Marten.Linq.Parsing.Methods; +namespace Marten.Linq.Parsing.Methods.FullText; internal class PlainTextSearch: FullTextSearchMethodCallParser { diff --git a/src/Marten/Linq/Parsing/Methods/Search.cs b/src/Marten/Linq/Parsing/Methods/FullText/Search.cs similarity index 77% rename from src/Marten/Linq/Parsing/Methods/Search.cs rename to src/Marten/Linq/Parsing/Methods/FullText/Search.cs index a54588dc7db..4e9e8ad70a5 100644 --- a/src/Marten/Linq/Parsing/Methods/Search.cs +++ b/src/Marten/Linq/Parsing/Methods/FullText/Search.cs @@ -1,4 +1,4 @@ -namespace Marten.Linq.Parsing.Methods; +namespace Marten.Linq.Parsing.Methods.FullText; internal class Search: FullTextSearchMethodCallParser { diff --git a/src/Marten/Linq/Parsing/Methods/WebStyleSearch.cs b/src/Marten/Linq/Parsing/Methods/FullText/WebStyleSearch.cs similarity index 80% rename from src/Marten/Linq/Parsing/Methods/WebStyleSearch.cs rename to src/Marten/Linq/Parsing/Methods/FullText/WebStyleSearch.cs index 8b2bac3bce3..949b137ea08 100644 --- a/src/Marten/Linq/Parsing/Methods/WebStyleSearch.cs +++ b/src/Marten/Linq/Parsing/Methods/FullText/WebStyleSearch.cs @@ -1,4 +1,4 @@ -namespace Marten.Linq.Parsing.Methods; +namespace Marten.Linq.Parsing.Methods.FullText; internal class WebStyleSearch: FullTextSearchMethodCallParser { diff --git a/src/Marten/Linq/Parsing/Methods/IsEmpty.cs b/src/Marten/Linq/Parsing/Methods/IsEmpty.cs index 142852774e5..b82713697b0 100644 --- a/src/Marten/Linq/Parsing/Methods/IsEmpty.cs +++ b/src/Marten/Linq/Parsing/Methods/IsEmpty.cs @@ -1,5 +1,5 @@ using System.Linq.Expressions; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.Parsing.Methods; @@ -12,10 +12,12 @@ public bool Matches(MethodCallExpression expression) && expression.Method.DeclaringType == typeof(LinqExtensions); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - var field = mapping.FieldFor(expression); + var field = memberCollection.MemberFor(expression); - return new WhereFragment($"({field.RawLocator} is null or jsonb_array_length({field.RawLocator}) = 0)"); + // TODO -- memoize this off of ICollectionMember. Part of https://github.com/JasperFx/marten/issues/2703 + return new WhereFragment($"({field.RawLocator} is null or jsonb_array_length({field.JSONBLocator}) = 0)"); } } diff --git a/src/Marten/Linq/Parsing/Methods/IsInGenericEnumerable.cs b/src/Marten/Linq/Parsing/Methods/IsInGenericEnumerable.cs deleted file mode 100644 index 64895ec8a43..00000000000 --- a/src/Marten/Linq/Parsing/Methods/IsInGenericEnumerable.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Linq; -using System.Linq.Expressions; -using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using Marten.Linq.QueryHandlers; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing.Methods; - -internal class IsInGenericEnumerable: IMethodCallParser -{ - public bool Matches(MethodCallExpression expression) - { - return expression.Method.Name == LinqConstants.CONTAINS && - expression.Object.Type.IsGenericEnumerable() && - !expression.Arguments.Single().IsValueExpression(); - } - - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) - { - var locator = mapping.FieldFor(expression).TypedLocator; - var values = expression.Object.Value(); - - return new WhereFragment($"{locator} = ANY(?)", values); - } -} diff --git a/src/Marten/Linq/Parsing/Methods/IsNotOneOf.cs b/src/Marten/Linq/Parsing/Methods/IsNotOneOf.cs index 76521df10aa..cf488e1f9c3 100644 --- a/src/Marten/Linq/Parsing/Methods/IsNotOneOf.cs +++ b/src/Marten/Linq/Parsing/Methods/IsNotOneOf.cs @@ -1,8 +1,6 @@ using System.Linq; using System.Linq.Expressions; -using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using Marten.Util; +using Marten.Linq.Members; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.Parsing.Methods; @@ -16,14 +14,14 @@ public bool Matches(MethodCallExpression expression) && expression.Method.DeclaringType == typeof(LinqExtensions); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - var members = FindMembers.Determine(expression); - - var locator = mapping.FieldFor(expression).TypedLocator; + var queryableMember = memberCollection.MemberFor(expression); + var locator = queryableMember.TypedLocator; var values = expression.Arguments.Last().Value(); - if (members.Last().GetMemberType().IsEnum) + if (queryableMember.MemberType.IsEnum) { return new EnumIsNotOneOfWhereFragment(values, options.Serializer().EnumStorage, locator); } diff --git a/src/Marten/Linq/Parsing/Methods/IsOneOf.cs b/src/Marten/Linq/Parsing/Methods/IsOneOf.cs index b5898866a2b..41c4ff2b8a3 100644 --- a/src/Marten/Linq/Parsing/Methods/IsOneOf.cs +++ b/src/Marten/Linq/Parsing/Methods/IsOneOf.cs @@ -1,8 +1,7 @@ using System.Linq; using System.Linq.Expressions; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using Marten.Util; +using Marten.Linq.Members; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.Parsing.Methods; @@ -17,14 +16,14 @@ public bool Matches(MethodCallExpression expression) && expression.Method.DeclaringType == typeof(LinqExtensions); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - var members = FindMembers.Determine(expression); + var queryableMember = memberCollection.MemberFor(expression.Arguments[0]); + var locator = queryableMember.TypedLocator; + var values = expression.Arguments[1].ReduceToConstant().Value; - var locator = mapping.FieldFor(members).TypedLocator; - var values = expression.Arguments.Last().Value(); - - if (members.Last().GetMemberType().IsEnum) + if (queryableMember.MemberType.IsEnum) { return new EnumIsOneOfWhereFragment(values, options.Serializer().EnumStorage, locator); } diff --git a/src/Marten/Linq/Parsing/Methods/IsSubsetOf.cs b/src/Marten/Linq/Parsing/Methods/IsSubsetOf.cs index 0c999f67764..fde2aeb982c 100644 --- a/src/Marten/Linq/Parsing/Methods/IsSubsetOf.cs +++ b/src/Marten/Linq/Parsing/Methods/IsSubsetOf.cs @@ -2,7 +2,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using NpgsqlTypes; using Weasel.Postgresql.SqlGeneration; @@ -13,25 +13,28 @@ internal class IsSubsetOf: IMethodCallParser public bool Matches(MethodCallExpression expression) { var method = expression.Method; - return IsMartenLinqExtension(method) || - IsISetMethod(method); + return isMartenLinqExtension(method) || + isISetMethod(method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - var locator = mapping.FieldFor(expression).JSONBLocator; + var member = memberCollection.MemberFor(expression.Object ?? expression.Arguments[0]); + + var locator = member.JSONBLocator; var values = expression.Arguments.Last().Value(); var json = options.Serializer().ToJson(values); return new CustomizableWhereFragment($"{locator} <@ ?", "?", new CommandParameter(json, NpgsqlDbType.Jsonb)); } - private static bool IsMartenLinqExtension(MethodInfo method) + private static bool isMartenLinqExtension(MethodInfo method) { return method.Name == nameof(LinqExtensions.IsSubsetOf) && method.DeclaringType == typeof(LinqExtensions); } - private static bool IsISetMethod(MethodInfo method) + private static bool isISetMethod(MethodInfo method) { return method.Name == "IsSubsetOf" && method.DeclaringType diff --git a/src/Marten/Linq/Parsing/Methods/IsSupersetOf.cs b/src/Marten/Linq/Parsing/Methods/IsSupersetOf.cs index 5cf76270504..666ed62a2ba 100644 --- a/src/Marten/Linq/Parsing/Methods/IsSupersetOf.cs +++ b/src/Marten/Linq/Parsing/Methods/IsSupersetOf.cs @@ -2,7 +2,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using NpgsqlTypes; using Weasel.Postgresql.SqlGeneration; @@ -13,25 +13,27 @@ internal class IsSupersetOf: IMethodCallParser public bool Matches(MethodCallExpression expression) { var method = expression.Method; - return IsMartenLinqExtension(method) || - IsISetMethod(method); + return isMartenLinqExtension(method) || + isISetMethod(method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - var locator = mapping.FieldFor(expression).JSONBLocator; + var member = memberCollection.MemberFor(expression.Object ?? expression.Arguments[0]); + var locator = member.JSONBLocator; var values = expression.Arguments.Last().Value(); var json = options.Serializer().ToJson(values); return new CustomizableWhereFragment($"{locator} @> ?", "?", new CommandParameter(json, NpgsqlDbType.Jsonb)); } - private static bool IsMartenLinqExtension(MethodInfo method) + private static bool isMartenLinqExtension(MethodInfo method) { return method.Name == nameof(LinqExtensions.IsSupersetOf) && method.DeclaringType == typeof(LinqExtensions); } - private static bool IsISetMethod(MethodInfo method) + private static bool isISetMethod(MethodInfo method) { return method.Name == "IsSupersetOf" && method.DeclaringType diff --git a/src/Marten/Linq/Parsing/Methods/NgramSearch.cs b/src/Marten/Linq/Parsing/Methods/NgramSearch.cs deleted file mode 100644 index 03c242ccfad..00000000000 --- a/src/Marten/Linq/Parsing/Methods/NgramSearch.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Linq; -using System.Linq.Expressions; -using Marten.Linq.Fields; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing.Methods; - -public class NgramSearch: IMethodCallParser -{ - public bool Matches(MethodCallExpression expression) - { - return expression.Method.Name == nameof(LinqExtensions.NgramSearch) - && expression.Method.DeclaringType == typeof(LinqExtensions); - } - - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) - { - var members = FindMembers.Determine(expression); - - var locator = mapping.FieldFor(members).RawLocator; - var values = expression.Arguments.Last().Value(); - - return new WhereFragment($"{options.DatabaseSchemaName}.mt_grams_vector({locator}) @@ {options.DatabaseSchemaName}.mt_grams_query(?)", values); - } -} diff --git a/src/Marten/Linq/Parsing/Methods/SimpleEqualsParser.cs b/src/Marten/Linq/Parsing/Methods/SimpleEqualsParser.cs index 86b78f06caf..84e64c1c21a 100644 --- a/src/Marten/Linq/Parsing/Methods/SimpleEqualsParser.cs +++ b/src/Marten/Linq/Parsing/Methods/SimpleEqualsParser.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Linq.Expressions; -using JasperFx.Core; +using JasperFx.Core.Reflection; using Marten.Exceptions; -using Marten.Linq.Fields; -using Marten.Linq.Filters; -using Marten.Schema; +using Marten.Linq.Members; using NpgsqlTypes; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; @@ -56,83 +53,24 @@ public bool Matches(MethodCallExpression expression) expression.Method.Name.Equals("Equals", StringComparison.Ordinal); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - var serializer = options.Serializer(); - var field = GetField(mapping, expression); - var locator = field.TypedLocator; + var leftType = expression.Object?.Type; + var rightType = expression.Arguments[0].Type; - ConstantExpression value; - if (expression.Object?.NodeType == ExpressionType.Constant) + if (leftType != null) { - value = (ConstantExpression)expression.Object; - } - else - { - value = expression.Arguments.OfType().FirstOrDefault(); - } - - if (value == null) - { - throw new BadLinqExpressionException("Could not extract value from {0}.".ToFormat(expression), null); - } - - var valueToQuery = value.Value; - - if (valueToQuery == null) - { - return new WhereFragment($"({field.RawLocator}) {_isOperator} null"); - } - - if (valueToQuery.GetType() != expression.Method.DeclaringType) - { - try - { - valueToQuery = Convert.ChangeType(value.Value, expression.Method.DeclaringType); - } - catch (Exception e) + if (!rightType.CanBeCastTo(leftType)) { throw new BadLinqExpressionException( - $"Could not convert {value.Value.GetType().FullName} to {expression.Method.DeclaringType}", e); + $"Mismatched types in Equals() usage in expression '{expression}'"); } } - if (_supportContainment && (mapping.PropertySearching == PropertySearching.ContainmentOperator || - field.ShouldUseContainmentOperator())) - { - var dict = new Dictionary(); - ContainmentWhereFragment.CreateDictionaryForSearch(dict, expression, valueToQuery, serializer); - return new ContainmentWhereFragment(serializer, dict); - } - - return new WhereFragment($"{locator} {_equalsOperator} ?", valueToQuery); - } - - private static IField GetField(IFieldMapping mapping, MethodCallExpression expression) - { - IField GetField(Expression e) - { - var visitor = new FindMembers(); - visitor.Visit(e); - - var field = mapping.FieldFor(visitor.Members); - return field; - } - - if (!expression.Method.IsStatic && expression.Object != null && - expression.Object.NodeType != ExpressionType.Constant) - { - // x.member.Equals(...) - return GetField(expression.Object); - } - - if (expression.Arguments[0].NodeType == ExpressionType.Constant) - { - // type.Equals("value", x.member) [decimal] - return GetField(expression.Arguments[1]); - } + var left = new SimpleExpression(memberCollection, expression.Object); + var right = new SimpleExpression(memberCollection, expression.Arguments[0]); - // type.Equals(x.member, "value") [decimal] - return GetField(expression.Arguments[0]); + return left.CompareTo(right, _equalsOperator); } } diff --git a/src/Marten/Linq/Parsing/Methods/StringComparisonParser.cs b/src/Marten/Linq/Parsing/Methods/StringComparisonParser.cs deleted file mode 100644 index f67b839b3a3..00000000000 --- a/src/Marten/Linq/Parsing/Methods/StringComparisonParser.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core; -using Marten.Exceptions; -using Marten.Linq.Fields; -using NpgsqlTypes; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing.Methods; - -internal abstract class StringComparisonParser: IMethodCallParser -{ - private readonly MethodInfo[] _supportedMethods; - - public StringComparisonParser(params MethodInfo[] supportedMethods) - { - _supportedMethods = supportedMethods; - } - - public bool Matches(MethodCallExpression expression) - { - return _supportedMethods.Any(m => AreMethodsEqual(m, expression.Method)); - } - - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) - { - var locator = GetLocator(mapping, expression); - - ConstantExpression value; - if (expression.Object?.NodeType == ExpressionType.Constant) - { - value = (ConstantExpression)expression.Object; - } - else - { - value = expression.Arguments.OfType().FirstOrDefault(); - } - - if (value == null) - { - throw new BadLinqExpressionException("Could not extract string value from {0}.".ToFormat(expression), null); - } - - var stringOperator = GetOperator(expression); - var parameterValue = FormatValue(expression.Method, value.Value as string); - var param = parameterValue == null - ? new CommandParameter(DBNull.Value, NpgsqlDbType.Varchar) - : new CommandParameter(parameterValue, NpgsqlDbType.Varchar); - - // Do not use escape char when using case insensitivity - // this way backslash does not have special meaning and works as string literal - var escapeChar = string.Empty; - if (stringOperator == "ILIKE") - { - escapeChar = " ESCAPE ''"; - } - - return new CustomizableWhereFragment($"{locator} {stringOperator} ?{escapeChar}", "?", param); - } - - protected bool AreMethodsEqual(MethodInfo method1, MethodInfo method2) - { - return method1.DeclaringType == method2.DeclaringType && method1.Name == method2.Name - && method1.GetParameters().Select(p => p.ParameterType) - .SequenceEqual(method2.GetParameters() - .Select(p => p.ParameterType)); - } - - /// - /// Formats the string value as appropriate for the comparison. - /// - /// - /// - /// - public abstract string FormatValue(MethodInfo method, string value); - - protected virtual bool IsCaseInsensitiveComparison(MethodCallExpression expression) - { - var comparison = expression.Arguments.OfType() - .Where(a => a.Type == typeof(StringComparison)).Select(c => (StringComparison)c.Value).FirstOrDefault(); - - var ignoreCaseComparisons = new[] - { - StringComparison.CurrentCultureIgnoreCase, StringComparison.InvariantCultureIgnoreCase, - StringComparison.OrdinalIgnoreCase - }; - if (ignoreCaseComparisons.Contains(comparison)) - { - return true; - } - - return false; - } - - /// - /// Returns the operator to emit (e.g. LIKE/ILIKE). - /// - /// - /// - protected virtual string GetOperator(MethodCallExpression expression) - { - return IsCaseInsensitiveComparison(expression) ? "ILIKE" : "LIKE"; - } - - /// - /// Returns a locator for the member being queried upon - /// - /// - /// - /// - protected string GetLocator(IFieldMapping mapping, MethodCallExpression expression) - { - var memberExpression = determineStringField(expression); - return mapping.FieldFor(memberExpression).RawLocator; - } - - private static Expression determineStringField(MethodCallExpression expression) - { - if (!expression.Method.IsStatic && expression.Object != null && - expression.Object.NodeType != ExpressionType.Constant) - { - // x.member.Equals(...) - return expression.Object; - } - - if (expression.Arguments[0].NodeType == ExpressionType.Constant) - { - // string.Equals("value", x.member) - return expression.Arguments[1]; - } - - // string.Equals(x.member, "value") - return expression.Arguments[0]; - } -} diff --git a/src/Marten/Linq/Parsing/Methods/StringContains.cs b/src/Marten/Linq/Parsing/Methods/StringContains.cs deleted file mode 100644 index 510654d297e..00000000000 --- a/src/Marten/Linq/Parsing/Methods/StringContains.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using JasperFx.Core.Reflection; - -namespace Marten.Linq.Parsing.Methods; - -internal class StringContains: StringComparisonParser -{ - public StringContains(): base(GetContainsMethods()) - { - } - - public override string FormatValue(MethodInfo method, string value) - { - return "%" + value + "%"; - } - - private static MethodInfo[] GetContainsMethods() - { - return new[] - { - typeof(string).GetMethod("Contains", new[] { typeof(string), typeof(StringComparison) }), - ReflectionHelper.GetMethod(s => s.Contains(null)), - ReflectionHelper.GetMethod(s => s.Contains(null, StringComparison.CurrentCulture)) - } - .Where(m => m != null) - .Distinct() - .ToArray(); - } -} diff --git a/src/Marten/Linq/Parsing/Methods/StringEndsWith.cs b/src/Marten/Linq/Parsing/Methods/StringEndsWith.cs deleted file mode 100644 index 2349fae857b..00000000000 --- a/src/Marten/Linq/Parsing/Methods/StringEndsWith.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using JasperFx.Core.Reflection; - -namespace Marten.Linq.Parsing.Methods; - -internal class StringEndsWith: StringComparisonParser -{ - private static readonly StringComparison[] CaseInsensitiveComparisons = - { - StringComparison.OrdinalIgnoreCase, StringComparison.CurrentCultureIgnoreCase - }; - - public StringEndsWith(): base( - ReflectionHelper.GetMethod(s => s.EndsWith(null)), - ReflectionHelper.GetMethod(s => s.EndsWith(null, StringComparison.CurrentCulture)) - ) - { - } - - public override string FormatValue(MethodInfo method, string value) - { - return "%" + value; - } - - protected override bool IsCaseInsensitiveComparison(MethodCallExpression expression) - { - if (AreMethodsEqual(expression.Method, - ReflectionHelper.GetMethod(s => s.StartsWith(null, StringComparison.OrdinalIgnoreCase)))) - { - if (expression.Arguments[1] is ConstantExpression constant && constant.Value is StringComparison comparison) - { - return CaseInsensitiveComparisons.Any(x => x == comparison); - } - } - - return base.IsCaseInsensitiveComparison(expression); - } -} diff --git a/src/Marten/Linq/Parsing/Methods/StringEquals.cs b/src/Marten/Linq/Parsing/Methods/StringEquals.cs deleted file mode 100644 index e19107407d7..00000000000 --- a/src/Marten/Linq/Parsing/Methods/StringEquals.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Reflection; -using JasperFx.Core.Reflection; - -namespace Marten.Linq.Parsing.Methods; - -internal class StringEquals: StringComparisonParser -{ - public StringEquals(): base( - ReflectionHelper.GetMethod(s => s.Equals(string.Empty)), - ReflectionHelper.GetMethod(s => s.Equals(string.Empty, StringComparison.CurrentCulture)), - ReflectionHelper.GetMethod(() => string.Equals(string.Empty, string.Empty)), - ReflectionHelper.GetMethod(() => string.Equals(string.Empty, string.Empty, StringComparison.CurrentCulture))) - { - } - - public override string FormatValue(MethodInfo method, string value) - { - return value; - } -} diff --git a/src/Marten/Linq/Parsing/Methods/EqualsIgnoreCaseParser.cs b/src/Marten/Linq/Parsing/Methods/Strings/EqualsIgnoreCaseParser.cs similarity index 65% rename from src/Marten/Linq/Parsing/Methods/EqualsIgnoreCaseParser.cs rename to src/Marten/Linq/Parsing/Methods/Strings/EqualsIgnoreCaseParser.cs index df0d03f81f2..448f6a3c81b 100644 --- a/src/Marten/Linq/Parsing/Methods/EqualsIgnoreCaseParser.cs +++ b/src/Marten/Linq/Parsing/Methods/Strings/EqualsIgnoreCaseParser.cs @@ -2,10 +2,10 @@ using System.Linq.Expressions; using JasperFx.Core; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Parsing.Methods; +namespace Marten.Linq.Parsing.Methods.Strings; internal class EqualsIgnoreCaseParser: IMethodCallParser { @@ -15,9 +15,10 @@ public bool Matches(MethodCallExpression expression) && expression.Method.DeclaringType == typeof(StringExtensions); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - var locator = mapping.FieldFor(expression).RawLocator; + var locator = memberCollection.MemberFor(expression.Arguments[0]).RawLocator; var value = expression.Arguments.Last().Value(); return new WhereFragment($"{locator} ~~* ?", value.As()); diff --git a/src/Marten/Linq/Parsing/Methods/Strings/StringComparisonParser.cs b/src/Marten/Linq/Parsing/Methods/Strings/StringComparisonParser.cs new file mode 100644 index 00000000000..460d3dbc1e7 --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/Strings/StringComparisonParser.cs @@ -0,0 +1,98 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using Marten.Exceptions; +using Marten.Linq.Members; +using NpgsqlTypes; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods.Strings; + +internal abstract class StringComparisonParser: IMethodCallParser +{ + public const string CaseSensitiveLike = " LIKE "; + public const string CaseInSensitiveLike = " ILIKE "; + + // Do not use escape char when using case insensitivity + // this way backslash does not have special meaning and works as string literal + public const string EscapeSuffix = " ESCAPE '' "; + + public static readonly StringComparison[] CaseInSensitiveComparisons = + { + StringComparison.CurrentCultureIgnoreCase, StringComparison.InvariantCultureIgnoreCase, + StringComparison.OrdinalIgnoreCase + }; + + private readonly MethodInfo[] _supportedMethods; + + public StringComparisonParser(params MethodInfo[] supportedMethods) + { + _supportedMethods = supportedMethods; + } + + public bool Matches(MethodCallExpression expression) + { + return _supportedMethods.Any(m => AreMethodsEqual(m, expression.Method)); + } + + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) + { + IQueryableMember member = null; + CommandParameter value = null; + var comparison = StringComparison.CurrentCulture; + + SimpleExpression left; + SimpleExpression right; + + if (expression.Object != null) + { + left = new SimpleExpression(memberCollection, expression.Object); + right = new SimpleExpression(memberCollection, expression.Arguments[0]); + } + else + { + left = new SimpleExpression(memberCollection, expression.Arguments[0]); + right = new SimpleExpression(memberCollection, expression.Arguments[1]); + } + + if (left.Member != null) + { + member = left.Member; + value = right.FindValueFragment() as CommandParameter; + } + else + { + member = right.Member; + value = left.FindValueFragment() as CommandParameter; + } + + if (member == null || value == null) + { + throw new BadLinqExpressionException("Marten was not able to create a string comparison for " + expression); + } + + if (expression.Arguments.Last().Type == typeof(StringComparison)) + { + comparison = (StringComparison)expression.Arguments.Last().Value(); + } + + var caseInsensitive = CaseInSensitiveComparisons.Contains(comparison); + + // TODO -- watch the NULL values! + return buildFilter(caseInsensitive, member, value); + } + + protected abstract ISqlFragment buildFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value); + + protected bool AreMethodsEqual(MethodInfo method1, MethodInfo method2) + { + return method1.DeclaringType == method2.DeclaringType && method1.Name == method2.Name + && method1.GetParameters().Select(p => p.ParameterType) + .SequenceEqual(method2.GetParameters() + .Select(p => p.ParameterType)); + } + +} + diff --git a/src/Marten/Linq/Parsing/Methods/Strings/StringContains.cs b/src/Marten/Linq/Parsing/Methods/Strings/StringContains.cs new file mode 100644 index 00000000000..ee22e421456 --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/Strings/StringContains.cs @@ -0,0 +1,93 @@ +using System; +using System.Linq; +using System.Reflection; +using JasperFx.CodeGeneration; +using JasperFx.Core.Reflection; +using Marten.Internal.CompiledQueries; +using Marten.Linq.Members; +using NpgsqlTypes; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods.Strings; + +internal class StringContains: StringComparisonParser +{ + public StringContains(): base(GetContainsMethods()) + { + } + + private static MethodInfo[] GetContainsMethods() + { + return new[] + { + typeof(string).GetMethod("Contains", new[] { typeof(string), typeof(StringComparison) }), + ReflectionHelper.GetMethod(s => s.Contains(null)), + ReflectionHelper.GetMethod(s => s.Contains(null, StringComparison.CurrentCulture)) + } + .Where(m => m != null) + .Distinct() + .ToArray(); + } + + protected override ISqlFragment buildFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value) + { + return new StringContainsFilter(caseInsensitive, member, value); + } +} + +internal class StringContainsFilter: ISqlFragment, ICompiledQueryAwareFilter +{ + private readonly bool _caseInsensitive; + private readonly IQueryableMember _member; + private readonly string _rawValue; + private MemberInfo _queryMember; + + public StringContainsFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value) + { + _caseInsensitive = caseInsensitive; + _member = member; + _rawValue = value.Value as string; + + } + + public void Apply(CommandBuilder builder) + { + builder.Append(_member.RawLocator); + builder.Append(_caseInsensitive ? StringComparisonParser.CaseInSensitiveLike : StringComparisonParser.CaseSensitiveLike); + + builder.AppendParameter($"%{_rawValue}%"); + + builder.Append(StringComparisonParser.EscapeSuffix); + + ParameterName = builder.LastParameterName; + } + + public bool Contains(string sqlText) + { + return false; + } + + public bool TryMatchValue(object value, MemberInfo member) + { + if (_rawValue.Equals(value)) + { + _queryMember = member; + return true; + } + + return false; + } + + public void GenerateCode(GeneratedMethod method, int parameterIndex) + { + var maskedValue = $"ContainsString(_query.{_queryMember.Name})"; + + method.Frames.Code($@" +parameters[{parameterIndex}].NpgsqlDbType = {{0}}; +parameters[{parameterIndex}].Value = {maskedValue}; +", NpgsqlDbType.Varchar); + } + + public string ParameterName { get; private set; } +} diff --git a/src/Marten/Linq/Parsing/Methods/Strings/StringEndsWith.cs b/src/Marten/Linq/Parsing/Methods/Strings/StringEndsWith.cs new file mode 100644 index 00000000000..bb4db7d106e --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/Strings/StringEndsWith.cs @@ -0,0 +1,92 @@ +using System; +using System.Reflection; +using JasperFx.CodeGeneration; +using JasperFx.Core.Reflection; +using Marten.Internal.CompiledQueries; +using Marten.Linq.Members; +using NpgsqlTypes; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods.Strings; + +internal class StringEndsWith: StringComparisonParser +{ + private static readonly StringComparison[] CaseInsensitiveComparisons = + { + StringComparison.OrdinalIgnoreCase, StringComparison.CurrentCultureIgnoreCase + }; + + public StringEndsWith(): base( + ReflectionHelper.GetMethod(s => s.EndsWith(null)), + ReflectionHelper.GetMethod(s => s.EndsWith(null, StringComparison.CurrentCulture)) + ) + { + } + + protected override ISqlFragment buildFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value) + { + return new StringEndsWithFilter(caseInsensitive, member, value); + } +} + +internal class StringEndsWithFilter: ISqlFragment, ICompiledQueryAwareFilter +{ + private readonly IQueryableMember _member; + private readonly string _operator; + private readonly object _rawValue; + private MemberInfo _queryMember; + + public StringEndsWithFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value) + { + _member = member; + _rawValue = value.Value; + + _operator = caseInsensitive + ? StringComparisonParser.CaseInSensitiveLike + : StringComparisonParser.CaseSensitiveLike; + } + + public void Apply(CommandBuilder builder) + { + builder.Append(_member.RawLocator); + builder.Append(_operator); + + var mask = "%" + _rawValue; + + builder.AppendParameter(mask); + builder.Append(StringComparisonParser.EscapeSuffix); + + ParameterName = builder.LastParameterName; + } + + public bool Contains(string sqlText) + { + return false; + } + + public bool TryMatchValue(object value, MemberInfo member) + { + if (_rawValue.Equals(value)) + { + _queryMember = member; + return true; + } + + return false; + } + + public void GenerateCode(GeneratedMethod method, int parameterIndex) + { + var maskedValue = $"EndsWith(_query.{_queryMember.Name})"; + + method.Frames.Code($@" +parameters[{parameterIndex}].NpgsqlDbType = {{0}}; +parameters[{parameterIndex}].Value = {maskedValue}; +", NpgsqlDbType.Varchar); + } + + public string ParameterName { get; private set; } +} + + diff --git a/src/Marten/Linq/Parsing/Methods/Strings/StringEquals.cs b/src/Marten/Linq/Parsing/Methods/Strings/StringEquals.cs new file mode 100644 index 00000000000..a32e47b838f --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/Strings/StringEquals.cs @@ -0,0 +1,51 @@ +using System; +using JasperFx.Core.Reflection; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods.Strings; + +internal class StringEquals: StringComparisonParser +{ + public StringEquals(): base( + ReflectionHelper.GetMethod(s => s.Equals(string.Empty)), + ReflectionHelper.GetMethod(s => s.Equals(string.Empty, StringComparison.CurrentCulture)), + ReflectionHelper.GetMethod(() => string.Equals(string.Empty, string.Empty)), + ReflectionHelper.GetMethod(() => string.Equals(string.Empty, string.Empty, StringComparison.CurrentCulture))) + { + } + + protected override ISqlFragment buildFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value) + { + return caseInsensitive + ? new StringEqualsIgnoreCaseFilter(member, value) + : new MemberComparisonFilter(member, value, "="); + } +} + +internal class StringEqualsIgnoreCaseFilter : ISqlFragment +{ + public IQueryableMember Member { get; } + public CommandParameter Value { get; } + + public StringEqualsIgnoreCaseFilter(IQueryableMember member, CommandParameter value) + { + Member = member; + Value = value; + } + + public void Apply(CommandBuilder builder) + { + builder.Append(Member.RawLocator); + builder.Append(StringComparisonParser.CaseInSensitiveLike); + Value.Apply(builder); + builder.Append(StringComparisonParser.EscapeSuffix); + } + + public bool Contains(string sqlText) + { + return false; + } +} diff --git a/src/Marten/Linq/Parsing/Methods/Strings/StringStartsWith.cs b/src/Marten/Linq/Parsing/Methods/Strings/StringStartsWith.cs new file mode 100644 index 00000000000..409775f2e79 --- /dev/null +++ b/src/Marten/Linq/Parsing/Methods/Strings/StringStartsWith.cs @@ -0,0 +1,82 @@ +using System; +using System.Reflection; +using JasperFx.CodeGeneration; +using JasperFx.Core.Reflection; +using Marten.Internal.CompiledQueries; +using Marten.Linq.Members; +using NpgsqlTypes; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing.Methods.Strings; + +internal class StringStartsWith: StringComparisonParser +{ + public StringStartsWith(): base( + ReflectionHelper.GetMethod(s => s.StartsWith(null)), + ReflectionHelper.GetMethod(s => s.StartsWith(null, StringComparison.CurrentCulture)) + ) + { + } + + protected override ISqlFragment buildFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value) + { + return new StringStartsWithFilter(caseInsensitive, member, value); + } +} + +internal class StringStartsWithFilter: ISqlFragment, ICompiledQueryAwareFilter +{ + private readonly IQueryableMember _member; + private readonly string _operator; + private readonly string _rawValue; + private MemberInfo _queryMember; + + public StringStartsWithFilter(bool caseInsensitive, IQueryableMember member, CommandParameter value) + { + _member = member; + _rawValue = value.Value as string; + _operator = caseInsensitive + ? StringComparisonParser.CaseInSensitiveLike + : StringComparisonParser.CaseSensitiveLike; + } + + public void Apply(CommandBuilder builder) + { + builder.Append(_member.RawLocator); + builder.Append(_operator); + builder.AppendParameter($"{_rawValue}%"); + builder.Append(StringComparisonParser.EscapeSuffix); + + ParameterName = builder.LastParameterName; + } + + public string ParameterName { get; private set; } + + public bool Contains(string sqlText) + { + return false; + } + + public bool TryMatchValue(object value, MemberInfo member) + { + if (_rawValue.Equals(value)) + { + _queryMember = member; + return true; + } + + return false; + } + + public void GenerateCode(GeneratedMethod method, int parameterIndex) + { + var maskedValue = $"StartsWith(_query.{_queryMember.Name})"; + + method.Frames.Code($@" +parameters[{parameterIndex}].NpgsqlDbType = {{0}}; +parameters[{parameterIndex}].Value = {maskedValue}; +", NpgsqlDbType.Varchar); + } +} + diff --git a/src/Marten/Linq/Parsing/Methods/TenantIsOneOf.cs b/src/Marten/Linq/Parsing/Methods/TenantIsOneOf.cs index 05f6ad873b3..571910fc661 100644 --- a/src/Marten/Linq/Parsing/Methods/TenantIsOneOf.cs +++ b/src/Marten/Linq/Parsing/Methods/TenantIsOneOf.cs @@ -1,8 +1,8 @@ using System.Linq; using System.Linq.Expressions; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using Marten.Linq.Filters; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.Parsing.Methods; @@ -15,7 +15,8 @@ public bool Matches(MethodCallExpression expression) && expression.Method.DeclaringType == typeof(LinqExtensions); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { var values = expression.Arguments.Last().Value().As(); return new TenantIsOneOfWhereFragment(values); diff --git a/src/Marten/Linq/Parsing/Operators/AnyOperator.cs b/src/Marten/Linq/Parsing/Operators/AnyOperator.cs new file mode 100644 index 00000000000..b06639eddad --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/AnyOperator.cs @@ -0,0 +1,17 @@ +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +internal class AnyOperator: LinqOperator +{ + public AnyOperator(): base("Any") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + usage.AddWhereClause(expression); + usage.IsAny = true; + } +} diff --git a/src/Marten/Linq/Parsing/Operators/CasingRule.cs b/src/Marten/Linq/Parsing/Operators/CasingRule.cs new file mode 100644 index 00000000000..86ecb119f21 --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/CasingRule.cs @@ -0,0 +1,7 @@ +namespace Marten.Linq.Parsing.Operators; + +public enum CasingRule +{ + CaseSensitive, + CaseInsensitive +} diff --git a/src/Marten/Linq/Parsing/Operators/DistinctOperator.cs b/src/Marten/Linq/Parsing/Operators/DistinctOperator.cs new file mode 100644 index 00000000000..5d22a94edbb --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/DistinctOperator.cs @@ -0,0 +1,16 @@ +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +internal class DistinctOperator: LinqOperator +{ + public DistinctOperator(): base("Distinct") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + usage.IsDistinct = true; + } +} diff --git a/src/Marten/Linq/Parsing/Operators/IncludeOperator.cs b/src/Marten/Linq/Parsing/Operators/IncludeOperator.cs new file mode 100644 index 00000000000..b7c6b4bda56 --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/IncludeOperator.cs @@ -0,0 +1,19 @@ +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +internal class IncludeOperator: LinqOperator +{ + public IncludeOperator(): base("Include") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + // Should be IMartenQueryable + var elementType = (expression.Object ?? expression.Arguments[0]).Type.GetGenericArguments()[0]; + + var usage = query.CollectionUsageFor(elementType); + usage.IncludeExpressions.Add(expression); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/LastOperator.cs b/src/Marten/Linq/Parsing/Operators/LastOperator.cs new file mode 100644 index 00000000000..6e82bb0476d --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/LastOperator.cs @@ -0,0 +1,30 @@ +using System; +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +public class LastOperator: LinqOperator +{ + public LastOperator(): base("Last") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + throw new InvalidOperationException( + "Marten does not support Last() or LastOrDefault() queries. Please reverse the ordering and use First()/FirstOrDefault() instead"); + } +} + +public class LastOrDefaultOperator: LinqOperator +{ + public LastOrDefaultOperator(): base("LastOrDefault") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + throw new InvalidOperationException( + "Marten does not support Last() or LastOrDefault() queries. Please reverse the ordering and use First()/FirstOrDefault() instead"); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/LinqOperator.cs b/src/Marten/Linq/Parsing/Operators/LinqOperator.cs new file mode 100644 index 00000000000..b7b854bbd30 --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/LinqOperator.cs @@ -0,0 +1,15 @@ +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +public abstract class LinqOperator +{ + public LinqOperator(string methodName) + { + MethodName = methodName; + } + + public string MethodName { get; } + + public abstract void Apply(ILinqQuery query, MethodCallExpression expression); +} diff --git a/src/Marten/Linq/Parsing/Operators/OperatorLibrary.cs b/src/Marten/Linq/Parsing/Operators/OperatorLibrary.cs new file mode 100644 index 00000000000..24d12cc0e0c --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/OperatorLibrary.cs @@ -0,0 +1,55 @@ +using System; +using JasperFx.Core; + +namespace Marten.Linq.Parsing.Operators; + +internal class OperatorLibrary +{ + private ImHashMap _operators = ImHashMap.Empty; + + public OperatorLibrary() + { + Add(); + Add(); + Add(); + + Add(); + Add(); + + AddOrdering("OrderBy", OrderingDirection.Asc); + AddOrdering("ThenBy", OrderingDirection.Asc); + + AddOrdering("OrderByDescending", OrderingDirection.Desc); + AddOrdering("ThenByDescending", OrderingDirection.Desc); + + Add(); + Add(); + Add(); + Add(); + Add(); + + foreach (var mode in Enum.GetValues()) addSingleValueMode(mode); + } + + public void Add() where T : LinqOperator, new() + { + var op = new T(); + _operators = _operators.AddOrUpdate(op.MethodName, op); + } + + private void addSingleValueMode(SingleValueMode mode) + { + var op = new SingleValueOperator(mode); + _operators = _operators.AddOrUpdate(mode.ToString(), op); + } + + public void AddOrdering(string methodName, OrderingDirection direction) + { + _operators = _operators.AddOrUpdate(methodName, new OrderingOperator(methodName, direction)); + } + + public bool TryFind(string methodName, out LinqOperator? op) + { + return _operators.TryFind(methodName, out op); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/Ordering.cs b/src/Marten/Linq/Parsing/Operators/Ordering.cs new file mode 100644 index 00000000000..d4cfb6993c1 --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/Ordering.cs @@ -0,0 +1,26 @@ +using System.Linq.Expressions; +using Marten.Linq.Members; + +namespace Marten.Linq.Parsing.Operators; + +public class Ordering +{ + public Ordering(Expression expression, OrderingDirection direction) + { + Expression = expression; + Direction = direction; + } + + public Expression Expression { get; } + + public OrderingDirection Direction { get; } + + public CasingRule CasingRule { get; set; } = CasingRule.CaseSensitive; + + public string BuildExpression(IQueryableMemberCollection collection) + { + var member = collection.MemberFor(Expression, "Invalid OrderBy() expression"); + + return member.BuildOrderingExpression(this, CasingRule); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/OrderingOperator.cs b/src/Marten/Linq/Parsing/Operators/OrderingOperator.cs new file mode 100644 index 00000000000..6f13cbb1933 --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/OrderingOperator.cs @@ -0,0 +1,32 @@ +using System; +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +public class OrderingOperator: LinqOperator +{ + public OrderingOperator(string methodName, OrderingDirection direction): base(methodName) + { + Direction = direction; + } + + public OrderingDirection Direction { get; } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + var newOrdering = new Ordering(expression.Arguments[1], Direction); + if (expression.Arguments.Count == 3) + { + var comparer = expression.Arguments[2].Value() as StringComparer; + + if (comparer == StringComparer.OrdinalIgnoreCase || comparer == StringComparer.CurrentCultureIgnoreCase || + comparer == StringComparer.InvariantCultureIgnoreCase) + { + newOrdering.CasingRule = CasingRule.CaseInsensitive; + } + } + + usage.OrderingExpressions.Insert(0, newOrdering); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/SelectManyOperator.cs b/src/Marten/Linq/Parsing/Operators/SelectManyOperator.cs new file mode 100644 index 00000000000..d620d55b5ec --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/SelectManyOperator.cs @@ -0,0 +1,17 @@ +using System.Linq; +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +public class SelectManyOperator: LinqOperator +{ + public SelectManyOperator(): base("SelectMany") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.StartNewCollectionUsageFor(expression); + usage.SelectMany = expression.Arguments.Last(); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/SelectOperator.cs b/src/Marten/Linq/Parsing/Operators/SelectOperator.cs new file mode 100644 index 00000000000..b09a98e2bac --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/SelectOperator.cs @@ -0,0 +1,28 @@ +using System.Linq; +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +public class SelectOperator: LinqOperator +{ + public SelectOperator(): base("Select") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + var select = expression.Arguments.Last(); + if (select is UnaryExpression e) + { + select = e.Operand; + } + + if (select is LambdaExpression l) + { + select = l.Body; + } + + usage.SelectExpression = select; + } +} diff --git a/src/Marten/Linq/Parsing/Operators/SingleValueOperator.cs b/src/Marten/Linq/Parsing/Operators/SingleValueOperator.cs new file mode 100644 index 00000000000..596d9e2262a --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/SingleValueOperator.cs @@ -0,0 +1,35 @@ +using System.Linq.Expressions; + +namespace Marten.Linq.Parsing.Operators; + +internal class SingleValueOperator: LinqOperator +{ + private readonly bool _isMathOperator; + + public SingleValueOperator(SingleValueMode mode): base(mode.ToString()) + { + Mode = mode; + _isMathOperator = (int)mode > 10; + } + + public SingleValueMode Mode { get; } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + + usage.SingleValueMode = Mode; + + if (expression.Arguments.Count > 1) + { + if (_isMathOperator) + { + usage.AddSelectClause(expression); + } + else + { + usage.AddWhereClause(expression); + } + } + } +} diff --git a/src/Marten/Linq/Parsing/Operators/SkipOperator.cs b/src/Marten/Linq/Parsing/Operators/SkipOperator.cs new file mode 100644 index 00000000000..cfdf94b3c77 --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/SkipOperator.cs @@ -0,0 +1,18 @@ +using System.Linq; +using System.Linq.Expressions; +using JasperFx.Core.Reflection; + +namespace Marten.Linq.Parsing.Operators; + +public class SkipOperator: LinqOperator +{ + public SkipOperator(): base("Skip") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + usage.WriteOffset(expression.Arguments.Last().Value().As()); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/TakeOperator.cs b/src/Marten/Linq/Parsing/Operators/TakeOperator.cs new file mode 100644 index 00000000000..89feb7e4464 --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/TakeOperator.cs @@ -0,0 +1,18 @@ +using System.Linq; +using System.Linq.Expressions; +using JasperFx.Core.Reflection; + +namespace Marten.Linq.Parsing.Operators; + +public class TakeOperator: LinqOperator +{ + public TakeOperator(): base("Take") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + usage.WriteLimit(expression.Arguments.Last().Value().As()); + } +} diff --git a/src/Marten/Linq/Parsing/Operators/WhereOperator.cs b/src/Marten/Linq/Parsing/Operators/WhereOperator.cs new file mode 100644 index 00000000000..ed0dde7ef0a --- /dev/null +++ b/src/Marten/Linq/Parsing/Operators/WhereOperator.cs @@ -0,0 +1,37 @@ +using System; +using System.Linq.Expressions; +using JasperFx.Core; +using JasperFx.Core.Reflection; + +namespace Marten.Linq.Parsing.Operators; + +public class WhereOperator: LinqOperator +{ + private readonly Cache _always + = new(type => typeof(FuncBuilder<>).CloseAndBuildAs(type).Build()); + + + public WhereOperator(): base("Where") + { + } + + public override void Apply(ILinqQuery query, MethodCallExpression expression) + { + var usage = query.CollectionUsageFor(expression); + usage.AddWhereClause(expression); + } + + private interface IFuncBuilder + { + object Build(); + } + + private class FuncBuilder: IFuncBuilder + { + public object Build() + { + Expression> filter = _ => true; + return filter; + } + } +} diff --git a/src/Marten/Linq/Parsing/SelectTransformBuilder.cs b/src/Marten/Linq/Parsing/SelectTransformBuilder.cs index 7eaa6a1505f..ee13e40bfc3 100644 --- a/src/Marten/Linq/Parsing/SelectTransformBuilder.cs +++ b/src/Marten/Linq/Parsing/SelectTransformBuilder.cs @@ -5,22 +5,21 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Util; -using Remotion.Linq.Parsing; namespace Marten.Linq.Parsing; -internal class SelectTransformBuilder: RelinqExpressionVisitor +internal class SelectTransformBuilder: ExpressionVisitor { private SelectedField _currentField; private TargetObject _target; - public SelectTransformBuilder(Expression clause, IFieldMapping fields, ISerializer serializer) + public SelectTransformBuilder(Expression clause, IQueryableMemberCollection members, ISerializer serializer) { // ReSharper disable once VirtualMemberCallInConstructor Visit(clause); - SelectedFieldExpression = _target.ToSelectField(fields, serializer); + SelectedFieldExpression = _target.ToSelectField(members, serializer); } public string SelectedFieldExpression { get; } @@ -78,7 +77,7 @@ public SelectedField StartBinding(string bindingName) return setter.Field; } - public string ToSelectField(IFieldMapping fields, ISerializer serializer) + public string ToSelectField(IQueryableMemberCollection fields, ISerializer serializer) { var jsonBuildObjectArgs = _setters.Select(x => x.ToJsonBuildObjectPair(fields, serializer)).Join(", "); return $"jsonb_build_object({jsonBuildObjectArgs})"; @@ -94,20 +93,21 @@ public SetterBinding(string name) private string Name { get; } public SelectedField Field { get; } = new(); - public string ToJsonBuildObjectPair(IFieldMapping mapping, ISerializer serializer) + public string ToJsonBuildObjectPair(IQueryableMemberCollection mapping, ISerializer serializer) { - var field = mapping.FieldFor(Field.ToArray()); + var field = mapping.MemberFor(Field.ToArray()); var locator = serializer.ValueCasting == ValueCasting.Relaxed ? field.RawLocator ?? field.TypedLocator : field.TypedLocator; - if (field is DictionaryField) + if (field is IDictionaryMember) { // DictionaryField.RawLocator does not have cast to JSONB so TypedLocator is used locator = field.TypedLocator; } - if (field.FieldType.IsClass && field.FieldType != typeof(string) && field.FieldType != typeof(decimal)) + if (field.MemberType.IsClass && field.MemberType != typeof(string) && + field.MemberType != typeof(decimal)) { // If the field is a class, we need to cast it to JSONB otherwise it will be serialized to plain string and fail to deserialize later on locator = field.JSONBLocator; diff --git a/src/Marten/Linq/Parsing/SelectorVisitor.cs b/src/Marten/Linq/Parsing/SelectorVisitor.cs index 1feef1aa0b1..854d4213e30 100644 --- a/src/Marten/Linq/Parsing/SelectorVisitor.cs +++ b/src/Marten/Linq/Parsing/SelectorVisitor.cs @@ -1,42 +1,83 @@ +using System; using System.Linq.Expressions; +using JasperFx.Core.Reflection; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration; namespace Marten.Linq.Parsing; -internal partial class LinqHandlerBuilder +public class SelectorVisitor: ExpressionVisitor { - public class SelectorVisitor: ExpressionVisitor + private readonly IQueryableMemberCollection _collection; + private readonly ISerializer _serializer; + private readonly SelectorStatement _statement; + + public SelectorVisitor(SelectorStatement statement, IQueryableMemberCollection collection, ISerializer serializer) { - private readonly LinqHandlerBuilder _parent; - private readonly ISerializer _serializer; + _statement = statement; + _collection = collection; + _serializer = serializer; + } - public SelectorVisitor(LinqHandlerBuilder parent) - { - _parent = parent; - _serializer = parent._session.Serializer; - } + protected override Expression VisitUnary(UnaryExpression node) + { + ToScalar(node); + return null; + } - protected override Expression VisitUnary(UnaryExpression node) - { - _parent.CurrentStatement.ToScalar(node); - return null; - } + protected override Expression VisitMember(MemberExpression node) + { + ToScalar(node); + return null; + } + + protected override Expression VisitMemberInit(MemberInitExpression node) + { + ToSelectTransform(node, _serializer); + return null; + } + + protected override Expression VisitNew(NewExpression node) + { + ToSelectTransform(node, _serializer); + return null; + } + + public void ToScalar(Expression selectClauseSelector) + { + var member = _collection.MemberFor(selectClauseSelector); - protected override Expression VisitMember(MemberExpression node) + if (member.MemberType == typeof(string)) { - _parent.CurrentStatement.ToScalar(node); - return null; + _statement.SelectClause = + new NewScalarStringSelectClause(member.RawLocator, _statement.SelectClause.FromObject); } - - protected override Expression VisitMemberInit(MemberInitExpression node) + else if (member.MemberType.IsSimple() || member.MemberType == typeof(Guid) || + member.MemberType == typeof(decimal) || + member.MemberType == typeof(DateTimeOffset)) { - _parent.CurrentStatement.ToSelectTransform(node, _serializer); - return null; + _statement.SelectClause = + typeof(NewScalarSelectClause<>).CloseAndBuildAs(member, + _statement.SelectClause.FromObject, + member.MemberType); } - - protected override Expression VisitNew(NewExpression node) + else { - _parent.CurrentStatement.ToSelectTransform(node, _serializer); - return null; + _statement.SelectClause = + typeof(DataSelectClause<>).CloseAndBuildAs(_statement.SelectClause.FromObject, + member.RawLocator, + member.MemberType); } } + + public void ToSelectTransform(Expression selectExpression, ISerializer serializer) + { + var builder = new SelectTransformBuilder(selectExpression, _collection, serializer); + var transformField = builder.SelectedFieldExpression; + + _statement.SelectClause = + typeof(DataSelectClause<>).CloseAndBuildAs(_statement.SelectClause.FromObject, + transformField, + selectExpression.Type); + } } diff --git a/src/Marten/Linq/Parsing/SimpleExpression.cs b/src/Marten/Linq/Parsing/SimpleExpression.cs new file mode 100644 index 00000000000..587011566db --- /dev/null +++ b/src/Marten/Linq/Parsing/SimpleExpression.cs @@ -0,0 +1,314 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.Core.Reflection; +using Marten.Exceptions; +using Marten.Linq.Members; +using Marten.Linq.QueryHandlers; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.Parsing; + + +internal class SimpleExpression: ExpressionVisitor +{ + private readonly Expression _expression; + private readonly IQueryableMemberCollection _queryableMembers; + + public List Members = new(); + + public SimpleExpression(IQueryableMemberCollection queryableMembers, Expression expression) + { + if (expression is LambdaExpression l) expression = l.Body; + + _expression = expression; + _queryableMembers = queryableMembers; + switch (expression) + { + case ConstantExpression c: + Constant = c; + HasConstant = true; + break; + + case NewExpression n: + Constant = n.ReduceToConstant(); + HasConstant = true; + break; + + // case PartialEvaluationExceptionExpression p: + // { + // var inner = p.Exception; + // + // throw new BadLinqExpressionException( + // $"Error in value expression inside of the query for '{p.EvaluatedExpression}'. See the inner exception:", + // inner); + // } + // case QuerySourceReferenceExpression: + // Member = new WholeDataMember(queryableMembers.ElementType); + // return; + case ParameterExpression: + if (queryableMembers is ValueCollectionMember collection) + { + Member = collection.ElementMember; + return; + } + + break; + default: + try + { + Visit(expression); + } + catch (Exception e) + { + throw new BadLinqExpressionException($"Whoa pardner, Marten could not parse '{expression}' with the SimpleExpression construct"); + } + break; + } + + if (HasConstant) + { + Members.Clear(); + } + else if (Comparable != null || Member != null) + { + return; + } + else if (!FoundParameterAtStart) + { + HasConstant = true; + Constant = _expression.ReduceToConstant(); + Members.Clear(); + } + else + { + Member = queryableMembers.MemberFor(Members.ToArray()); + } + } + + // Pretend for right now that there's only one of all of these + // obviously won't be true forever + public ConstantExpression Constant { get; set; } + public IQueryableMember Member { get; private set; } + public IComparableMember Comparable { get; private set; } + public bool FoundParameterAtStart { get; private set; } + public List Filters { get; } = new(); + + public bool HasConstant { get; set; } + + public ISqlFragment CompareTo(SimpleExpression right, string op) + { + if (Constant != null) + { + return right.CompareTo(this, ComparisonFilter.OppositeOperators[op]); + } + + Comparable ??= Member as IComparableMember; + if (Comparable != null && right.Constant != null) + { + return Comparable.CreateComparison(op, right.Constant); + } + + if (Member == null) + { + throw new BadLinqExpressionException( + $"Unsupported binary value expression in a Where() clause. {_expression} {op} {right._expression}"); + } + + if (right.Constant != null && Member is IComparableMember comparableMember) + { + return comparableMember.CreateComparison(op, right.Constant); + } + + if (right.Member != null) + { + // TODO -- this will need to evaluate extra methods in the comparison. Looking for StringProp.ToLower() == "foo" + // See https://github.com/JasperFx/marten/issues/2707 + return new MemberComparisonFilter(Member, right.Member, op); + } + + if (right.HasConstant) + { + if (op == "=") + { + return new IsNullFilter(Member); + } + + if (op == "!=") + { + return new IsNotNullFilter(Member); + } + } + + + throw new BadLinqExpressionException("Unsupported binary value expression in a Where() clause"); + } + + + protected override Expression VisitBinary(BinaryExpression node) + { + switch (node.NodeType) + { + case ExpressionType.Modulo: + Comparable = new ModuloOperator(node, _queryableMembers); + return null; + + case ExpressionType.ArrayIndex: + return base.VisitBinary(node); + + case ExpressionType.Equal: + var left = new SimpleExpression(_queryableMembers, node.Left); + var right = new SimpleExpression(_queryableMembers, node.Right); + var filter = left.CompareTo(right, "="); + Filters.Add(filter); + + return null; + + default: + throw new BadLinqExpressionException( + $"Unsupported nested operator '{node.NodeType}' as an operand in a binary expression"); + } + } + + protected override Expression VisitUnary(UnaryExpression node) + { + switch (node.NodeType) + { + case ExpressionType.Not: + var simple = new SimpleExpression(_queryableMembers, node.Operand); + if (simple.Member is IComparableMember cm) + { + Comparable = new NotMember(cm); + } + + return null; + + case ExpressionType.Convert: + if (node.Operand is ConstantExpression c) + { + HasConstant = true; + Constant = c; + } + + if (node.Operand is NewExpression) + { + HasConstant = true; + Constant = Expression.Constant(node.Operand.Value()); + } + else + { + Visit(node.Operand); + } + + + return null; + + case ExpressionType.ArrayLength: + Visit(node.Operand); + Members.Add(LinqConstants.ArrayLength); + + return null; + } + + throw new BadLinqExpressionException(node); + } + + protected override Expression VisitMember(MemberExpression node) + { + // Cannot use TryParseConstant + if (node.IsCompilableExpression()) + { + Constant = _expression.ReduceToConstant(); + HasConstant = true; + return null; + } + + Members.Insert(0, node.Member); + + if (node.Expression is ParameterExpression) + { + FoundParameterAtStart = true; + + // Gotta keep visiting to get at possible ! operators + Visit(node.Expression); + return null; + } + + Visit(node.Expression); + return null; + } + + protected override Expression VisitParameter(ParameterExpression node) + { + FoundParameterAtStart = true; + return base.VisitParameter(node); + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + // TODO -- add new IQueryableMember.TryResolveMemberForMethod(node.Method). See https://github.com/JasperFx/marten/issues/2707 + if (node.Method.Name == "Count" && node.Method.DeclaringType == typeof(Enumerable)) + { + if (node.Arguments.Count == 1) + { + Members.Insert(0, LinqConstants.ArrayLength); + + var finder = new MemberFinder(); + finder.Visit(node.Arguments[0]); + + FoundParameterAtStart = finder.FoundParameterAtFront; + Members = finder.Members.Concat(Members).ToList(); + return null; + } + + var collection = (ICollectionMember)_queryableMembers.MemberFor(node.Arguments[0]); + + Comparable = collection.ParseComparableForCount(node.Arguments.Last()); + return null; + } + else if (node.Method.Name == "get_Item" && node.Method.DeclaringType.Closes(typeof(IDictionary<,>))) + { + var dictMember = (IDictionaryMember)_queryableMembers.MemberFor(node.Object); + var key = node.Arguments[0].Value(); + Member = dictMember.MemberForKey(key); + return null; + } + + if (node.Object == null) + { + HasConstant = true; + Constant = node.ReduceToConstant(); + return null; + } + + Members.Insert(0, node.Method); + + foreach (var argument in node.Arguments) Visit(argument); + + if (node.Object != null) + { + Visit(node.Object); + } + + return null; + } + + public ISqlFragment FindValueFragment() + { + if (Member != null) + { + return Member; + } + + if (HasConstant) + { + return new CommandParameter(Constant.Value); + } + + throw new BadLinqExpressionException( + $"$Simple expression '{_expression}' does not refer to either a simple queryable member or a constant value"); + } +} diff --git a/src/Marten/Linq/Parsing/SingleValueMode.cs b/src/Marten/Linq/Parsing/SingleValueMode.cs new file mode 100644 index 00000000000..2a903a2dee3 --- /dev/null +++ b/src/Marten/Linq/Parsing/SingleValueMode.cs @@ -0,0 +1,17 @@ +namespace Marten.Linq.Parsing; + +public enum SingleValueMode +{ + First = 1, + FirstOrDefault = 2, + Single = 3, + SingleOrDefault = 4, + Count = 5, + LongCount = 6, + Any = 7, + + Average = 11, + Sum = 12, + Max = 13, + Min = 14 +} diff --git a/src/Marten/Linq/Parsing/StringStartsWith.cs b/src/Marten/Linq/Parsing/StringStartsWith.cs deleted file mode 100644 index d83179370c6..00000000000 --- a/src/Marten/Linq/Parsing/StringStartsWith.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Reflection; -using JasperFx.Core.Reflection; -using Marten.Linq.Parsing.Methods; - -namespace Marten.Linq.Parsing; - -internal class StringStartsWith: StringComparisonParser -{ - public StringStartsWith(): base( - ReflectionHelper.GetMethod(s => s.StartsWith(null)), - ReflectionHelper.GetMethod(s => s.StartsWith(null, StringComparison.CurrentCulture)) - ) - { - } - - public override string FormatValue(MethodInfo method, string value) - { - return value + "%"; - } -} diff --git a/src/Marten/Linq/Parsing/WhereClauseParser.BinaryExpressionVisitor.cs b/src/Marten/Linq/Parsing/WhereClauseParser.BinaryExpressionVisitor.cs deleted file mode 100644 index abe567272a7..00000000000 --- a/src/Marten/Linq/Parsing/WhereClauseParser.BinaryExpressionVisitor.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Linq.Expressions; -using Marten.Exceptions; -using Marten.Linq.Fields; -using Remotion.Linq.Clauses.Expressions; -using Remotion.Linq.Parsing; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing; - -internal partial class WhereClauseParser -{ - internal class BinaryExpressionVisitor: RelinqExpressionVisitor - { - private readonly WhereClauseParser _parent; - private BinarySide _left; - private BinarySide _right; - - public BinaryExpressionVisitor(WhereClauseParser parent) - { - _parent = parent; - } - - public ISqlFragment BuildWhereFragment(BinaryExpression node, string op) - { - _left = analyze(node.Left); - _right = analyze(node.Right); - - return _left.CompareTo(_right, op); - } - - private BinarySide analyze(Expression expression) - { - switch (expression) - { - case ConstantExpression c: - return new BinarySide(expression) { Constant = c }; - case PartialEvaluationExceptionExpression p: - { - var inner = p.Exception; - - throw new BadLinqExpressionException( - $"Error in value expression inside of the query for '{p.EvaluatedExpression}'. See the inner exception:", - inner); - } - case SubQueryExpression subQuery: - { - var parser = new SubQueryFilterParser(_parent, subQuery); - - return new BinarySide(expression) { Comparable = parser.BuildCountComparisonStatement() }; - } - case QuerySourceReferenceExpression source: - return new BinarySide(expression) { Field = new SimpleDataField(source.Type) }; - case BinaryExpression { NodeType: ExpressionType.Modulo } binary: - return new BinarySide(expression) - { - Comparable = new ModuloFragment(binary, _parent._statement.Fields) - }; - - case BinaryExpression { NodeType: ExpressionType.NotEqual } ne: - if (ne.Right is ConstantExpression v && v.Value == null) - { - var field = _parent._statement.Fields.FieldFor(ne.Left); - return new BinarySide(expression) { Comparable = new HasValueField(field) }; - } - - throw new BadLinqExpressionException("Invalid Linq Where() clause with expression: " + ne); - case BinaryExpression binary: - throw new BadLinqExpressionException( - $"Unsupported nested operator '{binary.NodeType}' as an operand in a binary expression"); - case UnaryExpression u when u.NodeType == ExpressionType.Not: - return new BinarySide(expression) - { - Comparable = new NotField(_parent._statement.Fields.FieldFor(u.Operand)) - }; - default: - return new BinarySide(expression) { Field = _parent._statement.Fields.FieldFor(expression) }; - } - } - } -} diff --git a/src/Marten/Linq/Parsing/WhereClauseParser.BinarySide.cs b/src/Marten/Linq/Parsing/WhereClauseParser.BinarySide.cs deleted file mode 100644 index 43a7d987302..00000000000 --- a/src/Marten/Linq/Parsing/WhereClauseParser.BinarySide.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Linq.Expressions; -using Marten.Exceptions; -using Marten.Linq.Fields; -using Remotion.Linq.Parsing; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.Parsing; - -internal partial class WhereClauseParser -{ - internal class BinarySide: RelinqExpressionVisitor - { - public BinarySide(Expression memberExpression) - { - MemberExpression = memberExpression; - } - - public ConstantExpression Constant { get; set; } - public IField Field { get; set; } - public IComparableFragment Comparable { get; set; } - - public Expression MemberExpression { get; } - - public ISqlFragment CompareTo(BinarySide right, string op) - { - if (Constant != null) - { - return right.CompareTo(this, ComparisonFilter.OppositeOperators[op]); - } - - if (Comparable != null && right.Constant != null) - { - return Comparable.CreateComparison(op, right.Constant, MemberExpression); - } - - if (Field == null) - { - throw new BadLinqExpressionException("Unsupported binary value expression in a Where() clause"); - } - - if (right.Constant != null) - { - return Field.CreateComparison(op, right.Constant, MemberExpression); - } - - if (right.Field != null) - { - return new ComparisonFilter(Field, right.Field, op); - } - - throw new BadLinqExpressionException("Unsupported binary value expression in a Where() clause"); - } - } -} diff --git a/src/Marten/Linq/Parsing/WhereClauseParser.cs b/src/Marten/Linq/Parsing/WhereClauseParser.cs index 2fa295a5077..afcda8c7032 100644 --- a/src/Marten/Linq/Parsing/WhereClauseParser.cs +++ b/src/Marten/Linq/Parsing/WhereClauseParser.cs @@ -1,24 +1,16 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Linq.Expressions; -using JasperFx.Core; using Marten.Exceptions; -using Marten.Internal; -using Marten.Linq.Fields; -using Marten.Linq.Filters; -using Marten.Linq.SqlGeneration; -using Remotion.Linq.Clauses; -using Remotion.Linq.Clauses.Expressions; -using Remotion.Linq.Clauses.ResultOperators; -using Remotion.Linq.Parsing; +using Marten.Linq.Members; +using Marten.Linq.SqlGeneration.Filters; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.Parsing; -internal partial class WhereClauseParser: RelinqExpressionVisitor, IWhereFragmentHolder +public class WhereClauseParser: ExpressionVisitor { - private static readonly IDictionary _operators = new Dictionary + private static readonly Dictionary _operators = new() { { ExpressionType.Equal, "=" }, { ExpressionType.NotEqual, "!=" }, @@ -28,65 +20,88 @@ internal partial class WhereClauseParser: RelinqExpressionVisitor, IWhereFragmen { ExpressionType.LessThanOrEqual, "<=" } }; + private readonly IQueryableMemberCollection _members; - private readonly IMartenSession _session; - private readonly Statement _statement; + + private readonly StoreOptions _options; private IWhereFragmentHolder _holder; - public WhereClauseParser(IMartenSession session, Statement statement) + public WhereClauseParser(StoreOptions options, IQueryableMemberCollection members, + IWhereFragmentHolder holder) { - _session = session; - _statement = statement; - _holder = this; + _options = options; + _members = members; + _holder = holder; } - public ISqlFragment Where { get; private set; } - public bool InSubQuery { get; set; } - - void IWhereFragmentHolder.Register(ISqlFragment fragment) + protected override Expression VisitConstant(ConstantExpression node) { - Where = fragment; + var value = node.Value; + if (value is bool b && b) + { + _holder.Register(new WhereFragment("1 = 1")); + } + + return null; } - public ISqlFragment Build(WhereClause clause) + protected override Expression VisitMember(MemberExpression node) { - _holder = this; - Where = null; - - Visit(clause.Predicate); - - if (Where == null) + if (node.Type == typeof(bool)) { - throw new BadLinqExpressionException($"Unsupported Where clause: '{clause.Predicate}'"); + var field = _members.MemberFor(node); + if (field is IBooleanField b) + { + _holder.Register(b.BuildIsTrueFragment()); + } + else + { + _holder.Register(new BooleanFieldIsTrue(field)); + } + + return null; } - return Where; + return base.VisitMember(node); } - protected override Expression VisitSubQuery(SubQueryExpression expression) + private IQueryableMember? findHoldingMember(SimpleExpression? @object, SimpleExpression[] arguments) { - var parser = new SubQueryFilterParser(this, expression); - var where = parser.BuildWhereFragment(); - _holder.Register(where); + if (@object?.Member != null) return @object.Member; + + foreach (var argument in arguments) + { + if (argument.Member != null) return argument.Member; + } return null; } protected override Expression VisitMethodCall(MethodCallExpression node) { - var where = _session.Options.Linq.BuildWhereFragment(_statement.Fields, node, _session.Options); - _holder.Register(where); + var parser = _options.Linq.FindMethodParser(node); + if (parser == null) + { + throw new NotSupportedException( + $"Marten does not (yet) support Linq queries using the {node.Method.DeclaringType.FullName}.{node.Method.Name}() method"); + } + + var fragment = parser.Parse(_members, _options, node); + _holder.Register(fragment); return null; } - protected override Expression VisitBinary(BinaryExpression node) { if (_operators.TryGetValue(node.NodeType, out var op)) { - var binary = new BinaryExpressionVisitor(this); - _holder.Register(binary.BuildWhereFragment(node, op)); + var left = new SimpleExpression(_members, node.Left); + var right = new SimpleExpression(_members, node.Right); + + var fragment = left.CompareTo(right, op); + + _holder.Register(fragment); return null; } @@ -148,236 +163,6 @@ protected override Expression VisitUnary(UnaryExpression node) return returnValue; } - return base.VisitUnary(node); - } - - protected override Expression VisitMember(MemberExpression node) - { - if (node.Type == typeof(bool)) - { - var field = _statement.Fields.FieldFor(node); - _holder.Register(new BooleanFieldIsTrue(field)); - return null; - } - - return base.VisitMember(node); - } - - protected override Expression VisitConstant(ConstantExpression node) - { - if (node.Type == typeof(bool)) - { - if (InSubQuery) - { - throw new BadLinqExpressionException("Unsupported Where() clause in a sub-collection expression"); - } - - _holder.Register(new WhereFragment(node.Value.ToString().ToLower())); - } - - return base.VisitConstant(node); - } - - - internal enum SubQueryUsage - { - Any, - Count, - Contains, - Intersect, - All - } - - internal class SubQueryFilterParser: RelinqExpressionVisitor - { - private readonly Expression _contains; - private readonly SubQueryExpression _expression; - private readonly WhereClauseParser _parent; - private readonly WhereClause[] _wheres; -#pragma warning disable 414 - private readonly bool _isDistinct; -#pragma warning restore 414 - - public SubQueryFilterParser(WhereClauseParser parent, SubQueryExpression expression) - { - _parent = parent; - _expression = expression; - - foreach (var @operator in expression.QueryModel.ResultOperators) - { - switch (@operator) - { - case AnyResultOperator _: - Usage = SubQueryUsage.Any; - break; - - case AllResultOperator _: - Usage = SubQueryUsage.All; - break; - - case CountResultOperator _: - Usage = SubQueryUsage.Count; - break; - - case LongCountResultOperator _: - Usage = SubQueryUsage.Count; - break; - - case DistinctResultOperator _: - _isDistinct = true; - break; - - case ContainsResultOperator op: - Usage = op.Item is QuerySourceReferenceExpression - ? SubQueryUsage.Intersect - : SubQueryUsage.Contains; - - _contains = op.Item; - break; - - default: - throw new BadLinqExpressionException( - $"Invalid result operator {@operator} in sub query '{expression}'"); - } - } - - if (Usage == SubQueryUsage.All) - { - _wheres = expression.QueryModel.ResultOperators.OfType() - .Select(o => new WhereClause(o.Predicate)) - .ToArray(); - } - else - { - _wheres = expression.QueryModel.BodyClauses.OfType().ToArray(); - } - } - - public SubQueryUsage Usage { get; } - - public ISqlFragment BuildWhereFragment() - { - switch (Usage) - { - case SubQueryUsage.Any: - return buildWhereForAny(findArrayField()); - - case SubQueryUsage.All: - var arrayField = findArrayField(); - return BuildWhereForAll(arrayField); - - case SubQueryUsage.Contains: - return buildWhereForContains(findArrayField()); - - case SubQueryUsage.Intersect: - return new WhereInArrayFilter("data", - (ConstantExpression)_expression.QueryModel.MainFromClause.FromExpression); - - default: - throw new NotSupportedException(); - } - } - - private ArrayField findArrayField() - { - ArrayField field; - try - { - var fetchedField = - _parent._statement.Fields.FieldFor(_expression.QueryModel.MainFromClause.FromExpression); - - if (fetchedField is DuplicatedField duplicatedField) - { - fetchedField = duplicatedField.InnerField; - } - - field = (ArrayField)fetchedField; - } - catch (Exception e) - { - throw new BadLinqExpressionException("The sub query is not sourced from a supported collection type", - e); - } - - return field; - } - - private ISqlFragment buildWhereForContains(ArrayField field) - { - if (_contains is ConstantExpression c) - { - var flattened = new SubQueryStatement(field.LocatorForFlattenedElements, _parent._session, - _parent._statement); - var idSelectorStatement = new ContainsIdSelectorStatement(flattened, _parent._session, c); - return new WhereCtIdInSubQuery(idSelectorStatement.ExportName, flattened); - } - - throw new NotSupportedException(); - } - - private ISqlFragment buildWhereForAny(ArrayField field) - { - if (_wheres.Any()) - { - var flattened = new SubQueryStatement(field.LocatorForFlattenedElements, _parent._session, - _parent._statement); - - - var itemType = _expression.QueryModel.MainFromClause.ItemType; - var elementFields = - _parent._session.Options.ChildTypeMappingFor(itemType); - - var idSelectorStatement = new IdSelectorStatement(_parent._session, elementFields, flattened); - idSelectorStatement.WhereClauses.AddRange(_wheres); - idSelectorStatement.CompileLocal(_parent._session); - - return new WhereCtIdInSubQuery(idSelectorStatement.ExportName, flattened); - } - - return new CollectionIsNotEmpty(field); - } - - private ISqlFragment BuildWhereForAll(ArrayField field) - { - if (!_wheres.Any()) - { - return new CollectionIsNotEmpty(field); - } - - var subQueryStatement = - new SubQueryStatement(field.LocatorForElements, _parent._session, _parent._statement); - var itemType = _expression.QueryModel.MainFromClause.ItemType; - var elementFields = - _parent._session.Options.ChildTypeMappingFor(itemType); - var allIdSelectorStatement = new AllIdSelectorStatement(_parent._session, elementFields, subQueryStatement); - - allIdSelectorStatement.WhereClauses.AddRange(_wheres); - allIdSelectorStatement.CompileLocal(_parent._session); - - return new WhereCtIdInSubQuery(allIdSelectorStatement.ExportName, subQueryStatement); - } - - public CountComparisonStatement BuildCountComparisonStatement() - { - if (Usage != SubQueryUsage.Count) - { - throw new BadLinqExpressionException("Invalid comparison"); - } - - var field = findArrayField(); - var flattened = - new SubQueryStatement(field.LocatorForFlattenedElements, _parent._session, _parent._statement); - - var elementFields = - _parent._session.Options.ChildTypeMappingFor(field.ElementType); - var statement = new CountComparisonStatement(_parent._session, field.ElementType, elementFields, flattened); - if (_wheres.Any()) - { - statement.WhereClauses.AddRange(_wheres); - statement.CompileLocal(_parent._session); - } - - return statement; - } + return null; } } diff --git a/src/Marten/Linq/QueryHandlers/LinqConstants.cs b/src/Marten/Linq/QueryHandlers/LinqConstants.cs index 4c11d168951..195908d0696 100644 --- a/src/Marten/Linq/QueryHandlers/LinqConstants.cs +++ b/src/Marten/Linq/QueryHandlers/LinqConstants.cs @@ -2,8 +2,6 @@ using System.Reflection; using Marten.Linq.Selectors; using Marten.Linq.SqlGeneration; -using Remotion.Linq.Clauses; -using Remotion.Linq.Clauses.ResultOperators; namespace Marten.Linq.QueryHandlers; @@ -15,20 +13,8 @@ internal class LinqConstants internal static readonly ISelector StringValueSelector = new ScalarStringSelectClause(string.Empty, string.Empty); - internal static readonly ResultOperatorBase AnyOperator = new AnyResultOperator(); - internal static readonly ResultOperatorBase CountOperator = new CountResultOperator(); - internal static readonly ResultOperatorBase LongCountOperator = new LongCountResultOperator(); - internal static readonly ResultOperatorBase SumOperator = new SumResultOperator(); - internal static readonly ResultOperatorBase MinOperator = new MinResultOperator(); - internal static readonly ResultOperatorBase MaxOperator = new MaxResultOperator(); - internal static readonly ResultOperatorBase AverageOperator = new AverageResultOperator(); - - internal static readonly ResultOperatorBase FirstOperator = new FirstResultOperator(false); - internal static readonly ResultOperatorBase SingleOperator = new SingleResultOperator(false); - internal static readonly ResultOperatorBase FirstOrDefaultOperator = new FirstResultOperator(true); - internal static readonly ResultOperatorBase SingleOrDefaultOperator = new SingleResultOperator(true); - - internal static readonly string CONTAINS = nameof(string.Contains); + internal static readonly string ANY = "Any"; + internal static readonly string ALL = "All"; internal static readonly PropertyInfo ArrayLength = typeof(Array).GetProperty(nameof(Array.Length)); } diff --git a/src/Marten/Linq/QueryHandlers/ListQueryHandler.cs b/src/Marten/Linq/QueryHandlers/ListQueryHandler.cs index e79bc8fd692..d891adef076 100644 --- a/src/Marten/Linq/QueryHandlers/ListQueryHandler.cs +++ b/src/Marten/Linq/QueryHandlers/ListQueryHandler.cs @@ -7,19 +7,19 @@ using Marten.Internal; using Marten.Internal.CodeGeneration; using Marten.Linq.Selectors; -using Marten.Linq.SqlGeneration; using Marten.Services; using Npgsql; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.QueryHandlers; internal class ListQueryHandler: IQueryHandler>, IQueryHandler>, IMaybeStatefulHandler { - private readonly Statement _statement; + private readonly ISqlFragment _statement; - public ListQueryHandler(Statement statement, ISelector selector) + public ListQueryHandler(ISqlFragment statement, ISelector selector) { _statement = statement; Selector = selector; @@ -55,7 +55,7 @@ IEnumerable IQueryHandler>.Handle(DbDataReader reader, IMarten public void ConfigureCommand(CommandBuilder builder, IMartenSession session) { - _statement.Configure(builder); + _statement.Apply(builder); } public IReadOnlyList Handle(DbDataReader reader, IMartenSession session) diff --git a/src/Marten/Linq/QueryHandlers/ListWithStatsQueryHandler.cs b/src/Marten/Linq/QueryHandlers/ListWithStatsQueryHandler.cs index 6edfa128eca..169fb5602ab 100644 --- a/src/Marten/Linq/QueryHandlers/ListWithStatsQueryHandler.cs +++ b/src/Marten/Linq/QueryHandlers/ListWithStatsQueryHandler.cs @@ -7,11 +7,11 @@ using Marten.Internal; using Marten.Internal.CodeGeneration; using Marten.Linq.Selectors; -using Marten.Linq.SqlGeneration; using Marten.Services; using Marten.Util; using Npgsql; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.QueryHandlers; @@ -20,10 +20,10 @@ internal class ListWithStatsQueryHandler: IQueryHandler>, IQ { private readonly int _countIndex; private readonly ISelector _selector; - private readonly Statement _statement; + private readonly ISqlFragment _statement; private readonly QueryStatistics _statistics; - public ListWithStatsQueryHandler(int countIndex, Statement statement, ISelector selector, + public ListWithStatsQueryHandler(int countIndex, ISqlFragment statement, ISelector selector, QueryStatistics statistics) { _countIndex = countIndex; @@ -60,7 +60,7 @@ IEnumerable IQueryHandler>.Handle(DbDataReader reader, IMarten public void ConfigureCommand(CommandBuilder builder, IMartenSession session) { - _statement.Configure(builder); + _statement.Apply(builder); } public IReadOnlyList Handle(DbDataReader reader, IMartenSession session) diff --git a/src/Marten/Linq/QueryHandlers/OneResultHandler.cs b/src/Marten/Linq/QueryHandlers/OneResultHandler.cs index 4759dae9342..65d2a6b496e 100644 --- a/src/Marten/Linq/QueryHandlers/OneResultHandler.cs +++ b/src/Marten/Linq/QueryHandlers/OneResultHandler.cs @@ -7,10 +7,10 @@ using Marten.Internal; using Marten.Internal.CodeGeneration; using Marten.Linq.Selectors; -using Marten.Linq.SqlGeneration; using Marten.Util; using Npgsql; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.QueryHandlers; @@ -21,9 +21,9 @@ internal class OneResultHandler: IQueryHandler, IMaybeStatefulHandler private readonly bool _canBeMultiples; private readonly bool _canBeNull; private readonly ISelector _selector; - private readonly Statement _statement; + private readonly ISqlFragment _statement; - public OneResultHandler(Statement statement, ISelector selector, + public OneResultHandler(ISqlFragment statement, ISelector selector, bool canBeNull = true, bool canBeMultiples = true) { _statement = statement; @@ -47,7 +47,7 @@ public IQueryHandler CloneForSession(IMartenSession session, QueryStatistics sta public void ConfigureCommand(CommandBuilder builder, IMartenSession session) { - _statement.Configure(builder); + _statement.Apply(builder); } public T Handle(DbDataReader reader, IMartenSession session) diff --git a/src/Marten/Linq/QueryHandlers/UserSuppliedQueryHandler.cs b/src/Marten/Linq/QueryHandlers/UserSuppliedQueryHandler.cs index 59263411c11..71a26e65064 100644 --- a/src/Marten/Linq/QueryHandlers/UserSuppliedQueryHandler.cs +++ b/src/Marten/Linq/QueryHandlers/UserSuppliedQueryHandler.cs @@ -38,9 +38,10 @@ public void ConfigureCommand(CommandBuilder builder, IMartenSession session) { if (!SqlContainsCustomSelect) { - _selectClause.WriteSelectClause(builder); + _selectClause.Apply(builder); - if (_sql.StartsWith("where", StringComparison.OrdinalIgnoreCase) || _sql.StartsWith("order", StringComparison.OrdinalIgnoreCase)) + if (_sql.StartsWith("where", StringComparison.OrdinalIgnoreCase) || + _sql.StartsWith("order", StringComparison.OrdinalIgnoreCase)) { builder.Append(" "); } diff --git a/src/Marten/Linq/SoftDeletes/DeletedBeforeParser.cs b/src/Marten/Linq/SoftDeletes/DeletedBeforeParser.cs index 73f1e9e7d1d..02c7921da79 100644 --- a/src/Marten/Linq/SoftDeletes/DeletedBeforeParser.cs +++ b/src/Marten/Linq/SoftDeletes/DeletedBeforeParser.cs @@ -3,7 +3,8 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Exceptions; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -20,13 +21,17 @@ public bool Matches(MethodCallExpression expression) return Equals(expression.Method, _method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - if (mapping.DeleteStyle != DeleteStyle.SoftDelete) + var documentType = memberCollection as DocumentQueryableMemberCollection; + if (documentType == null) { - throw new NotSupportedException($"Document DeleteStyle must be {DeleteStyle.SoftDelete}"); + throw new BadLinqExpressionException($"{_method.Name} can only be used to query against documents"); } + options.AssertDocumentTypeIsSoftDeleted(expression.Arguments[0].Type); + var time = expression.Arguments.Last().Value().As(); return new WhereFragment($"d.{SchemaConstants.DeletedColumn} and d.{SchemaConstants.DeletedAtColumn} < ?", diff --git a/src/Marten/Linq/SoftDeletes/DeletedSinceParser.cs b/src/Marten/Linq/SoftDeletes/DeletedSinceParser.cs index b139be7dd3d..4f27771326f 100644 --- a/src/Marten/Linq/SoftDeletes/DeletedSinceParser.cs +++ b/src/Marten/Linq/SoftDeletes/DeletedSinceParser.cs @@ -3,7 +3,8 @@ using System.Linq.Expressions; using System.Reflection; using JasperFx.Core.Reflection; -using Marten.Linq.Fields; +using Marten.Exceptions; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -20,13 +21,17 @@ public bool Matches(MethodCallExpression expression) return Equals(expression.Method, _method); } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { - if (mapping.DeleteStyle != DeleteStyle.SoftDelete) + var documentType = memberCollection as DocumentQueryableMemberCollection; + if (documentType == null) { - throw new NotSupportedException($"Document DeleteStyle must be {DeleteStyle.SoftDelete}"); + throw new BadLinqExpressionException($"{_method.Name} can only be used to query against documents"); } + options.AssertDocumentTypeIsSoftDeleted(expression.Arguments[0].Type); + var time = expression.Arguments.Last().Value().As(); return new WhereFragment($"d.{SchemaConstants.DeletedColumn} and d.{SchemaConstants.DeletedAtColumn} > ?", diff --git a/src/Marten/Linq/SoftDeletes/IsDeletedParser.cs b/src/Marten/Linq/SoftDeletes/IsDeletedParser.cs index baca77df430..e1fe121c31c 100644 --- a/src/Marten/Linq/SoftDeletes/IsDeletedParser.cs +++ b/src/Marten/Linq/SoftDeletes/IsDeletedParser.cs @@ -1,6 +1,6 @@ using System.Linq.Expressions; using System.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -19,8 +19,10 @@ public bool Matches(MethodCallExpression expression) return expression.Method == _method; } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { + options.AssertDocumentTypeIsSoftDeleted(expression.Arguments[0].Type); return _whereFragment; } } diff --git a/src/Marten/Linq/SoftDeletes/MaybeDeletedParser.cs b/src/Marten/Linq/SoftDeletes/MaybeDeletedParser.cs index 5872c3e2298..eff6993e75e 100644 --- a/src/Marten/Linq/SoftDeletes/MaybeDeletedParser.cs +++ b/src/Marten/Linq/SoftDeletes/MaybeDeletedParser.cs @@ -1,6 +1,6 @@ using System.Linq.Expressions; using System.Reflection; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Schema; using Weasel.Postgresql.SqlGeneration; @@ -19,8 +19,11 @@ public bool Matches(MethodCallExpression expression) return expression.Method == _method; } - public ISqlFragment Parse(IFieldMapping mapping, IReadOnlyStoreOptions options, MethodCallExpression expression) + public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, + MethodCallExpression expression) { + options.AssertDocumentTypeIsSoftDeleted(expression.Arguments[0].Type); + return _whereFragment; } } diff --git a/src/Marten/Linq/SqlGeneration/AllComparisonFilter.cs b/src/Marten/Linq/SqlGeneration/AllComparisonFilter.cs deleted file mode 100644 index 7cbdf4841fc..00000000000 --- a/src/Marten/Linq/SqlGeneration/AllComparisonFilter.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Linq; -using Marten.Linq.Fields; -using Marten.Linq.Filters; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.SqlGeneration; - -public class AllComparisionFilter: ISqlFragment -{ - private readonly ISqlFragment _nestedFilter; - - public AllComparisionFilter(ISqlFragment nestedFilter) - { - _nestedFilter = nestedFilter ?? throw new ArgumentNullException(nameof(nestedFilter)); - if (nestedFilter is not ComparisonFilter && - nestedFilter is not IsNullFilter) - { - throw new ArgumentOutOfRangeException(nameof(nestedFilter), "Unsupported type of filter."); - } - } - - public void Apply(CommandBuilder builder) - { - switch (_nestedFilter) - { - case ComparisonFilter comparisonFilter: - ApplyUsingComparisonFilter(builder, comparisonFilter); - return; - case IsNullFilter isNullFilter: - ApplyUsingIsNullFilter(builder, isNullFilter); - return; - default: - throw new ArgumentOutOfRangeException(nameof(_nestedFilter), "Unsupported type of filter."); - } - } - - public bool Contains(string sqlText) - { - return _nestedFilter.Contains(sqlText); - } - - private void ApplyUsingComparisonFilter(CommandBuilder builder, ComparisonFilter comparisonFilter) - { - switch (comparisonFilter.Left) - { - /* - * Query on primitive value - */ - case SimpleDataField leftOperand: - { - if (comparisonFilter.Right is CommandParameter { Value: null }) - { - builder.Append($" true = ALL (select unnest({leftOperand.RawLocator}) is null)"); - } - else - { - comparisonFilter.Right.Apply(builder); - builder.Append(" "); - builder.Append(comparisonFilter.Op); - builder.Append($" ALL ({leftOperand.RawLocator})"); - } - - break; - } - /* - * Query on nested object - */ - case FieldBase leftOperand: - { - var rawLocatorSegments = leftOperand.RawLocator - .Split(new[] { "->>" }, StringSplitOptions.RemoveEmptyEntries) - .Select(s => s.Trim()) - .ToArray(); - var parentLocator = rawLocatorSegments[0].Replace("d.", ""); - if (comparisonFilter.Right is CommandParameter { Value: null }) - { - builder.Append( - $" true = ALL (select unnest(array(select unnest({parentLocator}) ->> {rawLocatorSegments[1]})) is null)"); - } - else - { - comparisonFilter.Right.Apply(builder); - builder.Append(" "); - builder.Append(comparisonFilter.Op); - builder.Append($" ALL (array(select unnest({parentLocator}) ->> {rawLocatorSegments[1]}))"); - } - - break; - } - default: - throw new ArgumentOutOfRangeException(nameof(comparisonFilter.Left), "Unsupported type of operand."); - } - } - - private void ApplyUsingIsNullFilter(CommandBuilder builder, IsNullFilter comparisonFilter) - { - if (comparisonFilter.Field is not FieldBase field) - { - throw new ArgumentOutOfRangeException(nameof(comparisonFilter.Field), "Unsupported type of field."); - } - - /* - * Query on nested object - */ - var rawLocatorSegments = field.RawLocator.Split(new[] { "->>" }, StringSplitOptions.RemoveEmptyEntries) - .Select(s => s.Trim()) - .ToArray(); - var parentLocator = rawLocatorSegments[0].Replace("d.", ""); - builder.Append( - $" true = ALL (select unnest(array(select unnest({parentLocator}) ->> {rawLocatorSegments[1]})) is null)"); - } -} diff --git a/src/Marten/Linq/SqlGeneration/AllIdSelectorStatement.cs b/src/Marten/Linq/SqlGeneration/AllIdSelectorStatement.cs deleted file mode 100644 index 5845d2ae81c..00000000000 --- a/src/Marten/Linq/SqlGeneration/AllIdSelectorStatement.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Marten.Internal; -using Marten.Linq.Fields; -using Weasel.Postgresql; - -namespace Marten.Linq.SqlGeneration; - -internal class AllIdSelectorStatement: IdSelectorStatement -{ - public AllIdSelectorStatement(IMartenSession session, IFieldMapping fields, Statement parent): base(session, fields, - parent) - { - } - - protected override void writeWhereClause(CommandBuilder sql) - { - sql.Append(" where "); - Where = new AllComparisionFilter(Where); - Where.Apply(sql); - } -} diff --git a/src/Marten/Linq/SqlGeneration/AnySelectClause.cs b/src/Marten/Linq/SqlGeneration/AnySelectClause.cs index b895d1c10b4..de9046ccf31 100644 --- a/src/Marten/Linq/SqlGeneration/AnySelectClause.cs +++ b/src/Marten/Linq/SqlGeneration/AnySelectClause.cs @@ -7,12 +7,13 @@ using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; public class AnySelectClause: ISelectClause, IQueryHandler { - private Statement _topStatement; + private ISqlFragment _topStatement; public AnySelectClause(string from) { @@ -21,7 +22,7 @@ public AnySelectClause(string from) public void ConfigureCommand(CommandBuilder builder, IMartenSession session) { - _topStatement.Configure(builder); + _topStatement.Apply(builder); } public bool Handle(DbDataReader reader, IMartenSession session) @@ -51,7 +52,7 @@ public Task StreamJson(Stream stream, DbDataReader reader, CancellationToke public Type SelectedType => typeof(bool); - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { sql.Append("select TRUE as result"); sql.Append(" from "); @@ -59,6 +60,11 @@ public void WriteSelectClause(CommandBuilder sql) sql.Append(" as d"); } + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + public string[] SelectFields() { throw new NotSupportedException(); @@ -69,8 +75,8 @@ public ISelector BuildSelector(IMartenSession session) throw new NotSupportedException(); } - public IQueryHandler BuildHandler(IMartenSession session, Statement topStatement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment topStatement, + ISqlFragment currentStatement) { _topStatement = topStatement; return (IQueryHandler)this; diff --git a/src/Marten/Linq/SqlGeneration/ContainsIdSelectorStatement.cs b/src/Marten/Linq/SqlGeneration/ContainsIdSelectorStatement.cs deleted file mode 100644 index 95f987d827b..00000000000 --- a/src/Marten/Linq/SqlGeneration/ContainsIdSelectorStatement.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Linq.Expressions; -using Marten.Internal; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.SqlGeneration; - -/// -/// Used as an intermediate CTE in sub-collection Contains(primitive) queries -/// -internal class ContainsIdSelectorStatement: Statement -{ - private readonly string _from; - private readonly CommandParameter _parameter; - - public ContainsIdSelectorStatement(SubQueryStatement parent, IMartenSession session, ConstantExpression constant): - base(null) - { - ConvertToCommonTableExpression(session); - _from = parent.ExportName; - parent.InsertAfter(this); - - _parameter = new CommandParameter(constant); - } - - protected override void configure(CommandBuilder sql) - { - startCommonTableExpression(sql); - - sql.Append("select ctid from "); - sql.Append(_from); - sql.Append(" where data = "); - _parameter.Apply(sql); - - endCommonTableExpression(sql); - } -} diff --git a/src/Marten/Linq/SqlGeneration/CountClause.cs b/src/Marten/Linq/SqlGeneration/CountClause.cs index 7ab49a92c2c..65916bfc503 100644 --- a/src/Marten/Linq/SqlGeneration/CountClause.cs +++ b/src/Marten/Linq/SqlGeneration/CountClause.cs @@ -7,21 +7,32 @@ using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; -public class CountClause: ISelectClause, IQueryHandler +public interface ICountClause: ISelectClause { - private Statement _topStatement; + public void OverrideFromObject(Statement parent); +} + +public class CountClause: IQueryHandler, ICountClause +{ + private ISqlFragment _topStatement; public CountClause(string from) { FromObject = from; } + public void OverrideFromObject(Statement parent) + { + FromObject = parent.ExportName; + } + public void ConfigureCommand(CommandBuilder builder, IMartenSession session) { - _topStatement.Configure(builder); + _topStatement.Apply(builder); } public T Handle(DbDataReader reader, IMartenSession session) @@ -47,9 +58,9 @@ public Task StreamJson(Stream stream, DbDataReader reader, CancellationToke public Type SelectedType => typeof(T); - public string FromObject { get; } + public string FromObject { get; set; } - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { sql.Append("select count(*) as number"); sql.Append(" from "); @@ -57,6 +68,11 @@ public void WriteSelectClause(CommandBuilder sql) sql.Append(" as d"); } + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + public string[] SelectFields() { throw new NotSupportedException(); @@ -67,8 +83,8 @@ public ISelector BuildSelector(IMartenSession session) throw new NotSupportedException(); } - public IQueryHandler BuildHandler(IMartenSession session, Statement topStatement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment topStatement, + ISqlFragment currentStatement) { _topStatement = topStatement; return (IQueryHandler)this; @@ -78,4 +94,9 @@ public ISelectClause UseStatistics(QueryStatistics statistics) { throw new NotSupportedException("QueryStatistics are not valid with a Count()/CountAsync() query"); } + + public override string ToString() + { + return $"Count(*) from {FromObject}"; + } } diff --git a/src/Marten/Linq/SqlGeneration/CountComparisonStatement.cs b/src/Marten/Linq/SqlGeneration/CountComparisonStatement.cs deleted file mode 100644 index 0b8594e6095..00000000000 --- a/src/Marten/Linq/SqlGeneration/CountComparisonStatement.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Linq.Expressions; -using Marten.Internal; -using Marten.Linq.Fields; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.SqlGeneration; - -/// -/// Used when doing a Where(x => x.Children.Count(c => ....) > #) kind of filter -/// -internal class CountComparisonStatement: JsonStatement, IComparableFragment -{ - private readonly SubQueryStatement _flattened; - private readonly string _tableName; - - public CountComparisonStatement(IMartenSession session, Type documentType, IFieldMapping fields, - SubQueryStatement parent): base(documentType, fields, parent) - { - ConvertToCommonTableExpression(session); - parent.InsertAfter(this); - - _tableName = parent.ExportName; - - _flattened = parent; - } - - protected override bool IsSubQuery => true; - - public string Operator { get; private set; } = "="; - - public CommandParameter Value { get; private set; } - - public ISqlFragment CreateComparison(string op, ConstantExpression value, Expression memberExpression) - { - Value = new CommandParameter(value); - Operator = op; - return new WhereCtIdInSubQuery(ExportName, _flattened); - } - - protected override void configure(CommandBuilder sql) - { - startCommonTableExpression(sql); - - - sql.Append("select ctid, count(*) as data from "); - sql.Append(_tableName); - sql.Append(" as d"); - writeWhereClause(sql); - sql.Append(" group by ctid having count(*) "); - sql.Append(Operator); - - Value.Apply(sql); - - endCommonTableExpression(sql); - } -} diff --git a/src/Marten/Linq/SqlGeneration/CountStatement.cs b/src/Marten/Linq/SqlGeneration/CountStatement.cs deleted file mode 100644 index e42f21756cc..00000000000 --- a/src/Marten/Linq/SqlGeneration/CountStatement.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using Weasel.Postgresql; - -namespace Marten.Linq.SqlGeneration; - -internal class CountStatement: SelectorStatement where T : struct -{ - public CountStatement(Statement parent): base(new ScalarSelectClause("count(*)", parent.ExportName), - parent.Fields) - { - if (parent.Mode != StatementMode.CommonTableExpression) - { - throw new ArgumentOutOfRangeException(nameof(parent), - "CountStatement's parent must be a Common Table Expression statement"); - } - - parent.InsertAfter(this); - - TableName = parent.ExportName; - - SingleValue = true; - ReturnDefaultWhenEmpty = true; - CanBeMultiples = true; - } - - public string TableName { get; } - - protected override void configure(CommandBuilder sql) - { - sql.Append("select count(*) from "); - sql.Append(TableName); - } -} diff --git a/src/Marten/Linq/SqlGeneration/DataSelectClause.cs b/src/Marten/Linq/SqlGeneration/DataSelectClause.cs index a7849365bd5..8079efbad02 100644 --- a/src/Marten/Linq/SqlGeneration/DataSelectClause.cs +++ b/src/Marten/Linq/SqlGeneration/DataSelectClause.cs @@ -5,6 +5,7 @@ using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; @@ -18,36 +19,41 @@ public DataSelectClause(string from) public DataSelectClause(string from, string field) { FromObject = from; - FieldName = field; + MemberName = field; } - public string FieldName { get; set; } = "d.data"; + public string MemberName { get; set; } = "d.data"; public ISelectClause CloneToOtherTable(string tableName) { - return new DataSelectClause(tableName, FieldName); + return new DataSelectClause(tableName, MemberName); } public void ApplyOperator(string op) { - FieldName = $"{op}({FieldName})"; + MemberName = $"{op}({MemberName})"; } public ISelectClause CloneToDouble() { - return new DataSelectClause(FromObject, FieldName); + return new DataSelectClause(FromObject, MemberName); + } + + bool ISqlFragment.Contains(string sqlText) + { + return false; } public Type SelectedType => typeof(T); public string FromObject { get; } - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { - if (FieldName.IsNotEmpty()) + if (MemberName.IsNotEmpty()) { sql.Append("select "); - sql.Append(FieldName); + sql.Append(MemberName); sql.Append(" as data from "); } @@ -57,7 +63,7 @@ public void WriteSelectClause(CommandBuilder sql) public string[] SelectFields() { - return new[] { FieldName }; + return new[] { MemberName }; } public ISelector BuildSelector(IMartenSession session) @@ -65,16 +71,21 @@ public ISelector BuildSelector(IMartenSession session) return new SerializationSelector(session.Serializer); } - public IQueryHandler BuildHandler(IMartenSession session, Statement statement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment statement, + ISqlFragment currentStatement) { var selector = new SerializationSelector(session.Serializer); - return LinqHandlerBuilder.BuildHandler(selector, statement); + return LinqQueryParser.BuildHandler(selector, statement); } public ISelectClause UseStatistics(QueryStatistics statistics) { return new StatsSelectClause(this, statistics); } + + public override string ToString() + { + return $"Data from {FromObject}"; + } } diff --git a/src/Marten/Linq/SqlGeneration/Deletion.cs b/src/Marten/Linq/SqlGeneration/Deletion.cs index 9f0dadbcc5f..d33b44c5ffe 100644 --- a/src/Marten/Linq/SqlGeneration/Deletion.cs +++ b/src/Marten/Linq/SqlGeneration/Deletion.cs @@ -1,10 +1,16 @@ using Marten.Internal.Storage; using Marten.Services; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; internal class Deletion: StatementOperation, IDeletion { + public Deletion(IDocumentStorage storage, IOperationFragment operation, ISqlFragment where): base(storage, + operation, where) + { + } + public Deletion(IDocumentStorage storage, IOperationFragment operation): base(storage, operation) { } diff --git a/src/Marten/Linq/SqlGeneration/DistinctSelectionStatement.cs b/src/Marten/Linq/SqlGeneration/DistinctSelectionStatement.cs new file mode 100644 index 00000000000..216504ef406 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/DistinctSelectionStatement.cs @@ -0,0 +1,29 @@ +using Marten.Internal; +using Weasel.Postgresql; + +namespace Marten.Linq.SqlGeneration; + +internal class DistinctSelectionStatement: Statement +{ + public DistinctSelectionStatement(SelectorStatement parent, ICountClause selectClause, IMartenSession session) + { + parent.ConvertToCommonTableExpression(session); + + ConvertToCommonTableExpression(session); + + parent.InsertAfter(this); + + selectClause.OverrideFromObject(this); + var selector = new SelectorStatement { SelectClause = selectClause }; + InsertAfter(selector); + } + + protected override void configure(CommandBuilder sql) + { + startCommonTableExpression(sql); + sql.Append("select distinct(data) from "); + sql.Append(Previous.ExportName); + sql.Append(" as d"); + endCommonTableExpression(sql); + } +} diff --git a/src/Marten/Linq/SqlGeneration/DocumentStatement.cs b/src/Marten/Linq/SqlGeneration/DocumentStatement.cs deleted file mode 100644 index 3677cd6d108..00000000000 --- a/src/Marten/Linq/SqlGeneration/DocumentStatement.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Marten.Internal; -using Marten.Internal.Storage; -using Marten.Linq.Includes; -using Marten.Linq.Parsing; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.SqlGeneration; - -internal class DocumentStatement: SelectorStatement -{ - public DocumentStatement(IDocumentStorage storage): base(storage, storage.Fields) - { - Storage = storage; - } - - public IDocumentStorage Storage { get; } - - // TODO -- return IEnumerable instead - protected override ISqlFragment buildWhereFragment(IMartenSession session) - { - if (WhereClauses.Count == 0) - { - return Storage.DefaultWhereFragment(); - } - - var parser = new WhereClauseParser(session, this); - - ISqlFragment where = null; - - switch (WhereClauses.Count) - { - case 0: - where = Storage.DefaultWhereFragment(); - break; - - case 1: - where = parser.Build(WhereClauses.Single()); - break; - - default: - var wheres = WhereClauses.Select(x => parser.Build(x)).ToArray(); - - where = CompoundWhereFragment.And(wheres); - break; - } - - return Storage.FilterDocuments(null, where, session); - } - - public override void CompileLocal(IMartenSession session) - { - base.CompileLocal(session); - if (whereFragments().OfType().Any()) - { - var fragments = whereFragments().ToList(); - var subQueries = fragments.OfType().ToArray(); - // TODO -- combine the sub queries here if it's the same collection!!! - - if (subQueries.Length == 1) - { - // Need to set the remaining Where filters on DocumentStatement - Where = subQueries.CombineFragments(); - - fragments.RemoveAll(x => x is WhereCtIdInSubQuery); - - var topLevelWhere = fragments.CombineFragments(); - foreach (var subQuery in subQueries) subQuery.SubQueryStatement.Where = topLevelWhere; - } - } - } - - [Obsolete("return an enumeration instead")] - private IEnumerable whereFragments() - { - if (Where == null) - { - yield break; - } - - if (Where is CompoundWhereFragment c) - { - foreach (var fragment in c.Children) yield return fragment; - } - else - { - yield return Where; - } - } - - public override SelectorStatement UseAsEndOfTempTableAndClone( - IncludeIdentitySelectorStatement includeIdentitySelectorStatement) - { - var clone = new DocumentStatement(Storage) - { - SelectClause = SelectClause, - Orderings = Orderings, - Mode = StatementMode.Select, - ExportName = ExportName, - SingleValue = SingleValue, - CanBeMultiples = CanBeMultiples, - ReturnDefaultWhenEmpty = ReturnDefaultWhenEmpty, - Limit = Limit, - Offset = Offset - }; - - // Select the Ids only - SelectClause = includeIdentitySelectorStatement; - - // Don't do any paging here, or it'll break the Statistics - clone.Where = new InTempTableWhereFragment(includeIdentitySelectorStatement.ExportName, "id", - PagedStatement.Empty, false); - - return clone; - } -} diff --git a/src/Marten/Linq/SqlGeneration/ExplodeCollectionStatement.cs b/src/Marten/Linq/SqlGeneration/ExplodeCollectionStatement.cs new file mode 100644 index 00000000000..1f1e6ae68d6 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/ExplodeCollectionStatement.cs @@ -0,0 +1,58 @@ +using Marten.Internal; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration; + +/// +/// This statement explodes a collection element to a series +/// of rows +/// +internal class ExplodeCollectionStatement: Statement +{ + private readonly string _locator; + private readonly string _sourceTable; + + public ExplodeCollectionStatement(Statement parent, string locator, IMartenSession session) + { + _locator = locator; + _sourceTable = parent.ExportName; + parent.InsertAfter(this); + ConvertToCommonTableExpression(session); + } + + public ExplodeCollectionStatement(IMartenSession session, SelectorStatement selectorStatement, + string locator) + { + _locator = locator; + _sourceTable = selectorStatement.SelectClause.FromObject; + ConvertToCommonTableExpression(session); + + selectorStatement.InsertBefore(this); + } + + public ISqlFragment? Where { get; set; } + + protected override void configure(CommandBuilder sql) + { + startCommonTableExpression(sql); + + sql.Append("select ctid, "); + sql.Append(_locator); + sql.Append(" as data from "); + + sql.Append(_sourceTable); + + if (Where != null) + { + sql.Append(" as d WHERE "); + Where.Apply(sql); + + endCommonTableExpression(sql); + } + else + { + endCommonTableExpression(sql, " as d"); + } + } +} diff --git a/src/Marten/Linq/SqlGeneration/FilterStatement.cs b/src/Marten/Linq/SqlGeneration/FilterStatement.cs new file mode 100644 index 00000000000..a171c779c14 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/FilterStatement.cs @@ -0,0 +1,81 @@ +using System; +using System.Linq; +using Marten.Internal; +using Marten.Linq.QueryHandlers; +using Marten.Linq.Selectors; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration; + +internal class SelectCtidSelectClause: ISelectClause +{ + public SelectCtidSelectClause(Statement parent) + { + FromObject = parent.ExportName; + } + + public void Apply(CommandBuilder builder) + { + builder.Append("select distinct ctid from "); + builder.Append(FromObject); + builder.Append(" as d"); + } + + public bool Contains(string sqlText) + { + return false; + } + + public string FromObject { get; } + public Type SelectedType { get; } = typeof(long); + + public string[] SelectFields() + { + return new[] { "ctid" }; + } + + public ISelector BuildSelector(IMartenSession session) + { + throw new NotSupportedException(); + } + + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment topStatement, + ISqlFragment currentStatement) + { + throw new NotSupportedException(); + } + + public ISelectClause UseStatistics(QueryStatistics statistics) + { + throw new NotSupportedException(); + } +} + +/// +/// This is built to filter a child collection in a CTE query +/// +internal class FilterStatement: SelectorStatement +{ + public FilterStatement(IMartenSession session, Statement parent, ISqlFragment where) + { + if (where == null) + { + throw new ArgumentNullException(nameof(where)); + } + + Wheres.Add(where); + + SelectClause = new SelectCtidSelectClause(parent); + + ConvertToCommonTableExpression(session); + + parent.InsertAfter(this); + + // This *should* enable n-deep child collection queries. Let's hope. + if (Wheres.Any()) + { + compileAnySubQueries(session); + } + } +} diff --git a/src/Marten/Linq/SqlGeneration/Filters/AllValuesAreNullFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/AllValuesAreNullFilter.cs new file mode 100644 index 00000000000..b06bc1276de --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/AllValuesAreNullFilter.cs @@ -0,0 +1,67 @@ +using Marten.Internal; +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + + +internal class AllValuesAreNullFilter: ISubQueryFilter +{ + private static readonly ISqlFragment _filter = new WhereFragment("true = ALL (select unnest(data) is null)"); + + private string _exportName; + + public AllValuesAreNullFilter(ICollectionMember member) + { + Member = member; + } + + public ICollectionMember Member { get; } + + public void Apply(CommandBuilder builder) + { + if (Not) + { + builder.Append("NOT("); + } + + builder.Append("d.ctid in (select ctid from "); + builder.Append(_exportName); + builder.Append(")"); + + if (Not) + { + builder.Append(")"); + } + } + + public bool Contains(string sqlText) + { + return false; + } + + /// + /// Psych! Should there be a NOT in front of the sub query + /// + public bool Not { get; set; } + + public ISqlFragment Reverse() + { + Not = !Not; + return this; + } + + public void PlaceUnnestAbove(IMartenSession session, SelectorStatement statement, ISqlFragment topLevelWhere = null) + { + // First need to unnest the collection into its own recordset + var unnest = new ExplodeCollectionStatement(session, statement, Member.ArrayLocator) { Where = topLevelWhere }; + + // Second, filter the collection + var filter = new FilterStatement(session, unnest, _filter); + + _exportName = filter.ExportName; + } +} + + diff --git a/src/Marten/Linq/SqlGeneration/Filters/AllValuesEqualFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/AllValuesEqualFilter.cs new file mode 100644 index 00000000000..56f33097009 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/AllValuesEqualFilter.cs @@ -0,0 +1,31 @@ +using System.Linq.Expressions; +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +internal class AllValuesEqualFilter: ISqlFragment +{ + private readonly ConstantExpression _constant; + private readonly ICollectionMember _member; + + public AllValuesEqualFilter(ConstantExpression constant, ICollectionMember member) + { + _constant = constant; + _member = member; + } + + public void Apply(CommandBuilder builder) + { + builder.AppendParameter(_constant.Value); + builder.Append(" = ALL("); + builder.Append(_member.ArrayLocator); + builder.Append(")"); + } + + public bool Contains(string sqlText) + { + return false; + } +} diff --git a/src/Marten/Linq/Filters/BooleanFieldIsFalse.cs b/src/Marten/Linq/SqlGeneration/Filters/BooleanFieldIsFalse.cs similarity index 51% rename from src/Marten/Linq/Filters/BooleanFieldIsFalse.cs rename to src/Marten/Linq/SqlGeneration/Filters/BooleanFieldIsFalse.cs index 64fbda6d22d..8f41b8385cb 100644 --- a/src/Marten/Linq/Filters/BooleanFieldIsFalse.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/BooleanFieldIsFalse.cs @@ -1,34 +1,34 @@ -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; public class BooleanFieldIsFalse: IReversibleWhereFragment { - private readonly IField _field; + private readonly IQueryableMember _member; - public BooleanFieldIsFalse(IField field) + public BooleanFieldIsFalse(IQueryableMember member) { - _field = field; + _member = member; } public void Apply(CommandBuilder builder) { builder.Append("("); - builder.Append(_field.RawLocator); + builder.Append(_member.RawLocator); builder.Append(" is null or "); - builder.Append(_field.TypedLocator); + builder.Append(_member.TypedLocator); builder.Append(" = False)"); } public bool Contains(string sqlText) { - return _field.RawLocator.Contains(sqlText); + return _member.RawLocator.Contains(sqlText); } public ISqlFragment Reverse() { - return new BooleanFieldIsTrue(_field); + return new BooleanFieldIsTrue(_member); } } diff --git a/src/Marten/Linq/Filters/BooleanFieldIsTrue.cs b/src/Marten/Linq/SqlGeneration/Filters/BooleanFieldIsTrue.cs similarity index 51% rename from src/Marten/Linq/Filters/BooleanFieldIsTrue.cs rename to src/Marten/Linq/SqlGeneration/Filters/BooleanFieldIsTrue.cs index fd2b99fa479..aced44ab14f 100644 --- a/src/Marten/Linq/Filters/BooleanFieldIsTrue.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/BooleanFieldIsTrue.cs @@ -1,34 +1,34 @@ -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; public class BooleanFieldIsTrue: IReversibleWhereFragment { - private readonly IField _field; + private readonly IQueryableMember _member; - public BooleanFieldIsTrue(IField field) + public BooleanFieldIsTrue(IQueryableMember member) { - _field = field; + _member = member; } public void Apply(CommandBuilder builder) { builder.Append("("); - builder.Append(_field.RawLocator); + builder.Append(_member.RawLocator); builder.Append(" is not null and "); - builder.Append(_field.TypedLocator); + builder.Append(_member.TypedLocator); builder.Append(" = True)"); } public bool Contains(string sqlText) { - return _field.RawLocator.Contains(sqlText); + return _member.RawLocator.Contains(sqlText); } public ISqlFragment Reverse() { - return new BooleanFieldIsFalse(_field); + return new BooleanFieldIsFalse(_member); } } diff --git a/src/Marten/Linq/Filters/ByIdFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/ByIdFilter.cs similarity index 96% rename from src/Marten/Linq/Filters/ByIdFilter.cs rename to src/Marten/Linq/SqlGeneration/Filters/ByIdFilter.cs index 7951ecd99c1..c7849eea18f 100644 --- a/src/Marten/Linq/Filters/ByIdFilter.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/ByIdFilter.cs @@ -3,7 +3,7 @@ using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; public class ByIdFilter: ISqlFragment { diff --git a/src/Marten/Linq/SqlGeneration/Filters/CollectionIsEmpty.cs b/src/Marten/Linq/SqlGeneration/Filters/CollectionIsEmpty.cs new file mode 100644 index 00000000000..57937be9a72 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/CollectionIsEmpty.cs @@ -0,0 +1,34 @@ +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +internal class CollectionIsEmpty: ISqlFragment, IReversibleWhereFragment +{ + private readonly ICollectionMember _member; + + public CollectionIsEmpty(ICollectionMember member) + { + _member = member; + } + + public ISqlFragment Reverse() + { + return new CollectionIsNotEmpty(_member); + } + + public void Apply(CommandBuilder builder) + { + builder.Append("("); + builder.Append(_member.JSONBLocator); + builder.Append(" is null or jsonb_array_length("); + builder.Append(_member.JSONBLocator); + builder.Append(") = 0)"); + } + + public bool Contains(string sqlText) + { + return false; + } +} diff --git a/src/Marten/Linq/SqlGeneration/Filters/CollectionIsNotEmpty.cs b/src/Marten/Linq/SqlGeneration/Filters/CollectionIsNotEmpty.cs new file mode 100644 index 00000000000..1643e355865 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/CollectionIsNotEmpty.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +internal class CollectionIsNotEmpty: IReversibleWhereFragment, ICollectionAware, ICollectionAwareFilter +{ + public CollectionIsNotEmpty(ICollectionMember member) + { + CollectionMember = member; + } + + public bool CanReduceInChildCollection() + { + return true; + } + + public ICollectionAwareFilter BuildFragment(ICollectionMember member, ISerializer serializer) + { + return this; + } + + public bool SupportsContainment() + { + return false; + } + + public void PlaceIntoContainmentFilter(ContainmentWhereFilter filter) + { + throw new NotSupportedException(); + } + + public bool CanBeJsonPathFilter() + { + return false; + } + + public void BuildJsonPathFilter(CommandBuilder builder, Dictionary parameters) + { + // TODO -- come back to this later with + throw new NotSupportedException(); + } + + public IEnumerable Values() + { + yield break; + } + + public ICollectionMember CollectionMember { get; } + + public ISqlFragment MoveUnder(ICollectionMember ancestorCollection) + { + var path = new List(ancestorCollection.Ancestors); + path.Add(ancestorCollection); + path.Add(CollectionMember); + return new DeepCollectionIsNotEmpty(path); + } + + public void Apply(CommandBuilder builder) + { + builder.Append("("); + builder.Append(CollectionMember.JSONBLocator); + builder.Append(" is not null and jsonb_array_length("); + builder.Append(CollectionMember.JSONBLocator); + builder.Append(") > 0)"); + } + + public bool Contains(string sqlText) + { + return false; + } + + public ISqlFragment Reverse() + { + return new CollectionIsEmpty(CollectionMember); + } +} diff --git a/src/Marten/Linq/SqlGeneration/Filters/ContainmentWhereFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/ContainmentWhereFilter.cs new file mode 100644 index 00000000000..fc19fb48695 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/ContainmentWhereFilter.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JasperFx.CodeGeneration; +using Marten.Internal.CompiledQueries; +using Marten.Linq.Members; +using NpgsqlTypes; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +public enum ContainmentUsage +{ + Singular, + Collection +} + +public class ContainmentWhereFilter: ICollectionAwareFilter, ICollectionAware, ICompiledQueryAwareFilter, IReversibleWhereFragment +{ + private readonly string _locator; + private readonly ISerializer _serializer; + private Dictionary _data = new(); + private readonly List _usages = new(); + + public static ContainmentWhereFilter ForValue(ICollectionMember member, object value, ISerializer serializer) + { + return new ContainmentWhereFilter(member, Expression.Constant(value), serializer); + } + + public ContainmentWhereFilter(IQueryableMember member, ConstantExpression constant, ISerializer serializer) + { + _locator = member.Ancestors[0].RawLocator; + _serializer = serializer; + + _usages.Add(new DictionaryValueUsage(constant.Value)); + + PlaceMemberValue(member, constant); + } + + public ContainmentWhereFilter(ICollectionMember collection, ISerializer serializer) + { + _locator = collection.JSONBLocator; + _serializer = serializer; + CollectionMember = collection; + } + + public bool IsNot { get; set; } + + public ContainmentUsage Usage { get; set; } = ContainmentUsage.Singular; + + bool ICollectionAware.CanReduceInChildCollection() + { + return true; + } + + ICollectionAwareFilter ICollectionAware.BuildFragment(ICollectionMember member, ISerializer serializer) + { + var original = _data; + _data = new Dictionary(); + PlaceMemberValue(member, Expression.Constant(original)); + + return this; + } + + bool ICollectionAware.SupportsContainment() + { + return true; + } + + void ICollectionAware.PlaceIntoContainmentFilter(ContainmentWhereFilter filter) + { + var dict = filter._data; + foreach (var ancestor in CollectionMember.Ancestors) + dict = ancestor.FindOrPlaceChildDictionaryForContainment(dict); + + if (dict.TryGetValue(CollectionMember.MemberName, out var raw) && raw is object[] data) + { + if (data.Length == 1 && data[0] is Dictionary existing) + { + foreach (var pair in _data) existing[pair.Key] = pair.Value; + } + } + else + { + dict[CollectionMember.MemberName] = new object[] { _data }; + } + } + + public bool CanBeJsonPathFilter() + { + return false; + } + + public void BuildJsonPathFilter(CommandBuilder builder, Dictionary parameters) + { + throw new NotSupportedException(); + } + + public ICollectionMember CollectionMember { get; } + + public ISqlFragment MoveUnder(ICollectionMember ancestorCollection) + { + throw new NotSupportedException(); + } + + public void Apply(CommandBuilder builder) + { + var json = Usage == ContainmentUsage.Singular + ? _serializer.ToCleanJson(_data) + : _serializer.ToCleanJson(new object[] { _data }); + + if (IsNot) + { + builder.Append("NOT("); + } + + builder.Append($"{_locator} @> "); + builder.AppendParameter(json, NpgsqlDbType.Jsonb); + + ParameterName = builder.LastParameterName; + + if (IsNot) + { + builder.Append(")"); + } + } + + public bool Contains(string sqlText) + { + return false; + } + + public ISqlFragment Reverse() + { + IsNot = !IsNot; + return this; + } + + public void PlaceMemberValue(IQueryableMember member, ConstantExpression constant) + { + _usages.Add(new DictionaryValueUsage(constant.Value)); + + var dict = _data; + for (var i = 1; i < member.Ancestors.Length; i++) + { + dict = member.Ancestors[i].FindOrPlaceChildDictionaryForContainment(dict); + } + + member.PlaceValueInDictionaryForContainment(dict, constant); + } + + public bool TryMatchValue(object value, MemberInfo member) + { + var match = _usages.FirstOrDefault(x => x.Value.Equals(value)); + if (match != null) + { + match.QueryMember = member; + return true; + } + + return false; + } + + private bool _hasGenerated; + + public void GenerateCode(GeneratedMethod method, int parameterIndex) + { + if (_hasGenerated) + { + return; + } + + _hasGenerated = true; + + var top = new DictionaryDeclaration(); + top.ReadDictionary(_data, _usages); + + var part = Usage == ContainmentUsage.Singular ? (IDictionaryPart)top : new ArrayContainer(top); + + method.Frames.Add(new WriteSerializedJsonParameterFrame(parameterIndex, part)); + } + + public string ParameterName { get; private set; } + + public IEnumerable Values() + { + return _usages; + } +} diff --git a/src/Marten/Linq/Filters/CurrentTenantFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/CurrentTenantFilter.cs similarity index 94% rename from src/Marten/Linq/Filters/CurrentTenantFilter.cs rename to src/Marten/Linq/SqlGeneration/Filters/CurrentTenantFilter.cs index 1eedb0fb016..4d374deefd6 100644 --- a/src/Marten/Linq/Filters/CurrentTenantFilter.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/CurrentTenantFilter.cs @@ -4,7 +4,7 @@ using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; public class CurrentTenantFilter: ISqlFragment { diff --git a/src/Marten/Linq/SqlGeneration/Filters/DeepCollectionIsNotEmpty.cs b/src/Marten/Linq/SqlGeneration/Filters/DeepCollectionIsNotEmpty.cs new file mode 100644 index 00000000000..7e24f3eee04 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/DeepCollectionIsNotEmpty.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.Linq; +using JasperFx.Core; +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +internal class DeepCollectionIsNotEmpty: ISqlFragment +{ + public DeepCollectionIsNotEmpty(List path) + { + Path = path; + } + + public List Path { get; } + + public void Apply(CommandBuilder builder) + { + builder.Append("jsonb_array_length(jsonb_path_query_array(d.data, '$"); + foreach (var member in Path.Where(x => x.JsonPathSegment.IsNotEmpty())) + { + builder.Append("."); + builder.Append(member.JsonPathSegment); + } + + builder.Append("')) > 0"); + } + + public bool Contains(string sqlText) + { + return false; + } +} diff --git a/src/Marten/Linq/SqlGeneration/Filters/EqualsFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/EqualsFilter.cs new file mode 100644 index 00000000000..ff52f471b42 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/EqualsFilter.cs @@ -0,0 +1,19 @@ +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +public record EqualsFilter(string Locator, object Value): ISqlFragment +{ + public void Apply(CommandBuilder builder) + { + builder.Append(Locator); + builder.Append(" = "); + builder.AppendParameter(Value); + } + + public bool Contains(string sqlText) + { + return false; + } +} diff --git a/src/Marten/Linq/Filters/ExcludeSoftDeletedFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/ExcludeSoftDeletedFilter.cs similarity index 86% rename from src/Marten/Linq/Filters/ExcludeSoftDeletedFilter.cs rename to src/Marten/Linq/SqlGeneration/Filters/ExcludeSoftDeletedFilter.cs index d63fd48c25b..0a9644ceed6 100644 --- a/src/Marten/Linq/Filters/ExcludeSoftDeletedFilter.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/ExcludeSoftDeletedFilter.cs @@ -1,7 +1,7 @@ using Marten.Schema; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; public class ExcludeSoftDeletedFilter: WhereFragment { diff --git a/src/Marten/Linq/Filters/FullTextWhereFragment.cs b/src/Marten/Linq/SqlGeneration/Filters/FullTextWhereFragment.cs similarity index 94% rename from src/Marten/Linq/Filters/FullTextWhereFragment.cs rename to src/Marten/Linq/SqlGeneration/Filters/FullTextWhereFragment.cs index e96090c08d9..46f8b13ab6c 100644 --- a/src/Marten/Linq/Filters/FullTextWhereFragment.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/FullTextWhereFragment.cs @@ -1,10 +1,10 @@ using System.Linq; -using Marten.Linq.Parsing.Methods; +using Marten.Linq.Parsing.Methods.FullText; using Marten.Schema; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; internal class FullTextWhereFragment: ISqlFragment { diff --git a/src/Marten/Linq/SqlGeneration/Filters/ICollectionAware.cs b/src/Marten/Linq/SqlGeneration/Filters/ICollectionAware.cs new file mode 100644 index 00000000000..513fccc924f --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/ICollectionAware.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +public interface ICollectionAware +{ + bool CanReduceInChildCollection(); + + ICollectionAwareFilter BuildFragment(ICollectionMember member, ISerializer serializer); + bool SupportsContainment(); + + void PlaceIntoContainmentFilter(ContainmentWhereFilter filter); + + bool CanBeJsonPathFilter(); + void BuildJsonPathFilter(CommandBuilder builder, Dictionary parameters); + + IEnumerable Values(); + +} + +public interface ICollectionAwareFilter: ISqlFragment +{ + ICollectionMember CollectionMember { get; } + ISqlFragment MoveUnder(ICollectionMember ancestorCollection); + + +} diff --git a/src/Marten/Linq/Filters/ITenantWhereFragment.cs b/src/Marten/Linq/SqlGeneration/Filters/ITenantWhereFragment.cs similarity index 81% rename from src/Marten/Linq/Filters/ITenantWhereFragment.cs rename to src/Marten/Linq/SqlGeneration/Filters/ITenantWhereFragment.cs index 90e22f44274..29a02b2c473 100644 --- a/src/Marten/Linq/Filters/ITenantWhereFragment.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/ITenantWhereFragment.cs @@ -1,4 +1,4 @@ -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; /// /// Marker interface to help Marten track whether or not a Linq diff --git a/src/Marten/Linq/Filters/IsNotNullFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/IsNotNullFilter.cs similarity index 51% rename from src/Marten/Linq/Filters/IsNotNullFilter.cs rename to src/Marten/Linq/SqlGeneration/Filters/IsNotNullFilter.cs index efbaab08cf7..cb0e691379a 100644 --- a/src/Marten/Linq/Filters/IsNotNullFilter.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/IsNotNullFilter.cs @@ -1,31 +1,31 @@ -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; public class IsNotNullFilter: IReversibleWhereFragment { - public IsNotNullFilter(IField field) + public IsNotNullFilter(IQueryableMember member) { - Field = field; + Member = member; } - public IField Field { get; } + public IQueryableMember Member { get; } public void Apply(CommandBuilder builder) { - builder.Append(Field.RawLocator); + builder.Append(Member.NullTestLocator); builder.Append(" is not null"); } public bool Contains(string sqlText) { - return Field.Contains(sqlText); + return Member.Contains(sqlText); } public ISqlFragment Reverse() { - return new IsNullFilter(Field); + return new IsNullFilter(Member); } } diff --git a/src/Marten/Linq/Filters/IsNullFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/IsNullFilter.cs similarity index 50% rename from src/Marten/Linq/Filters/IsNullFilter.cs rename to src/Marten/Linq/SqlGeneration/Filters/IsNullFilter.cs index 64af3d1870e..bc075711ab2 100644 --- a/src/Marten/Linq/Filters/IsNullFilter.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/IsNullFilter.cs @@ -1,31 +1,31 @@ -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; public class IsNullFilter: IReversibleWhereFragment { - public IsNullFilter(IField field) + public IsNullFilter(IQueryableMember member) { - Field = field; + Member = member; } - public IField Field { get; } + public IQueryableMember Member { get; } public void Apply(CommandBuilder builder) { - builder.Append(Field.RawLocator); + builder.Append(Member.NullTestLocator); builder.Append(" is null"); } public bool Contains(string sqlText) { - return Field.Contains(sqlText); + return Member.Contains(sqlText); } public ISqlFragment Reverse() { - return new IsNotNullFilter(Field); + return new IsNotNullFilter(Member); } } diff --git a/src/Marten/Linq/SqlGeneration/Filters/MemberComparisonFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/MemberComparisonFilter.cs new file mode 100644 index 00000000000..182c5d98de9 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/MemberComparisonFilter.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.Linq.Expressions; +using JasperFx.Core.Reflection; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +internal class MemberComparisonFilter: ComparisonFilter, ICollectionAware +{ + public MemberComparisonFilter(IQueryableMember member, ISqlFragment right, string op): base(member, right, op) + { + Member = member; + } + + public IQueryableMember Member { get; } + + public bool CanReduceInChildCollection() + { + return Op == "=" && Right is CommandParameter; + } + + public ICollectionAwareFilter BuildFragment(ICollectionMember member, ISerializer serializer) + { + var fragment = new ContainmentWhereFilter(member, serializer); + var value = Right.As().Value; + fragment.PlaceMemberValue(Member, Expression.Constant(value)); + fragment.Usage = ContainmentUsage.Collection; + + return fragment; + } + + public bool SupportsContainment() + { + return Op == "=" && Right is CommandParameter; + } + + public void PlaceIntoContainmentFilter(ContainmentWhereFilter filter) + { + filter.PlaceMemberValue(Member, Expression.Constant(Right.As().Value)); + } + + public bool CanBeJsonPathFilter() + { + return Right is CommandParameter; + } + + public void BuildJsonPathFilter(CommandBuilder builder, Dictionary parameters) + { + var rawValue = Right.As().Value; + var parameter = parameters.AddJsonPathParameter(rawValue); + + builder.Append("@."); + Member.WriteJsonPath(builder); + builder.Append(" "); + + builder.Append(Op.CorrectJsonPathOperator()); + builder.Append(" "); + builder.Append(parameter); + } + + public IEnumerable Values() + { + var rawValue = Right.As().Value; + yield return new DictionaryValueUsage(rawValue); + } +} diff --git a/src/Marten/Linq/Filters/SpecificTenantFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/SpecificTenantFilter.cs similarity index 92% rename from src/Marten/Linq/Filters/SpecificTenantFilter.cs rename to src/Marten/Linq/SqlGeneration/Filters/SpecificTenantFilter.cs index a7aa7e4da96..bdeb9aa728b 100644 --- a/src/Marten/Linq/Filters/SpecificTenantFilter.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/SpecificTenantFilter.cs @@ -2,7 +2,7 @@ using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; /// /// SQL WHERE fragment for a specific tenant diff --git a/src/Marten/Linq/SqlGeneration/Filters/SubQueryFilter.cs b/src/Marten/Linq/SqlGeneration/Filters/SubQueryFilter.cs new file mode 100644 index 00000000000..993be99a9bf --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/SubQueryFilter.cs @@ -0,0 +1,71 @@ +using Marten.Internal; +using Marten.Linq.Members; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration.Filters; + +internal interface ISubQueryFilter : IReversibleWhereFragment +{ + void PlaceUnnestAbove(IMartenSession session, SelectorStatement statement, + ISqlFragment topLevelWhere = null); +} + +internal class SubQueryFilter: ISubQueryFilter +{ + private string _exportName; + + public SubQueryFilter(ICollectionMember member, ISqlFragment inner) + { + Member = member; + Inner = inner; + } + + public ICollectionMember Member { get; } + public ISqlFragment Inner { get; } + + /// + /// Psych! Should there be a NOT in front of the sub query + /// + public bool Not { get; set; } + + public ISqlFragment Reverse() + { + Not = !Not; + return this; + } + + void ISqlFragment.Apply(CommandBuilder builder) + { + if (Not) + { + builder.Append("NOT("); + } + + builder.Append("d.ctid in (select ctid from "); + builder.Append(_exportName); + builder.Append(")"); + + if (Not) + { + builder.Append(")"); + } + } + + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + + public void PlaceUnnestAbove(IMartenSession session, SelectorStatement statement, + ISqlFragment? topLevelWhere = null) + { + // First need to unnest the collection into its own recordset + var unnest = new ExplodeCollectionStatement(session, statement, Member.ExplodeLocator) { Where = topLevelWhere }; + + // Second, filter the collection + var filter = new FilterStatement(session, unnest, Inner); + + _exportName = filter.ExportName; + } +} diff --git a/src/Marten/Linq/Filters/TenantIsOneOfWhereFragment.cs b/src/Marten/Linq/SqlGeneration/Filters/TenantIsOneOfWhereFragment.cs similarity index 94% rename from src/Marten/Linq/Filters/TenantIsOneOfWhereFragment.cs rename to src/Marten/Linq/SqlGeneration/Filters/TenantIsOneOfWhereFragment.cs index e04e52a8083..c064d26c113 100644 --- a/src/Marten/Linq/Filters/TenantIsOneOfWhereFragment.cs +++ b/src/Marten/Linq/SqlGeneration/Filters/TenantIsOneOfWhereFragment.cs @@ -3,7 +3,7 @@ using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; -namespace Marten.Linq.Filters; +namespace Marten.Linq.SqlGeneration.Filters; internal class TenantIsOneOfWhereFragment: ISqlFragment, ITenantWhereFragment { diff --git a/src/Marten/Linq/SqlGeneration/Filters/WriteSerializedJsonParameterFrame.cs b/src/Marten/Linq/SqlGeneration/Filters/WriteSerializedJsonParameterFrame.cs new file mode 100644 index 00000000000..e13277e7175 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Filters/WriteSerializedJsonParameterFrame.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using JasperFx.CodeGeneration; +using JasperFx.CodeGeneration.Frames; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten.Linq.Members; +using Npgsql; +using NpgsqlTypes; + +namespace Marten.Linq.SqlGeneration.Filters; + +internal class WriteSerializedJsonParameterFrame: SyncFrame +{ + private readonly int _parameterIndex; + private readonly IDictionaryPart _declaration; + + public WriteSerializedJsonParameterFrame(int parameterIndex, IDictionaryPart declaration) + { + _parameterIndex = parameterIndex; + _declaration = declaration; + } + + public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) + { + writer.WriteLine($"parameters[{_parameterIndex}].Value = session.Serializer.ToCleanJson({_declaration.Write()});"); + writer.WriteLine($"parameters[{_parameterIndex}].{nameof(NpgsqlParameter.NpgsqlDbType)} = {typeof(NpgsqlDbType).FullNameInCode()}.{NpgsqlDbType.Jsonb};"); + + Next?.GenerateCode(method, writer); + } +} + +/// Tracks the usage of values within a serialized dictionary that is part of either +/// a JSONPath or containment operator query. This is used for compiled query tracking +public class DictionaryValueUsage +{ + public object Value { get; } + + public DictionaryValueUsage(object value) + { + Value = value; + } + + public MemberInfo? QueryMember { get; set; } +} + +internal interface IDictionaryPart +{ + string Write(); +} + + +internal record DictionaryValue(string Key, MemberInfo QueryMember) : IDictionaryPart +{ + public string Write() + { + return $"{{\"{Key}\", _query.{QueryMember.Name}}}"; + } +} + +internal class ArrayContainer: IDictionaryPart +{ + private readonly IDictionaryPart _inner; + + public ArrayContainer(IDictionaryPart inner) + { + _inner = inner; + } + + public string Write() + { + return "new object[]{" + _inner.Write() + "}"; + } +} + +internal class ArrayDeclaration : IDictionaryPart +{ + public string Key { get; } + public DictionaryDeclaration Inner { get; } + + public ArrayDeclaration(string key) + { + Key = key; + Inner = new DictionaryDeclaration(); + } + + public string Write() + { + return $"{{\"{Key}\", [{Inner.Write()}]}}"; + } +} + +internal record ArrayScalarValue(string Key, MemberInfo Member): IDictionaryPart +{ + public string Write() + { + return $"{{\"{Key}\", new object[]{{_query.{Member.Name}}}}}"; + } +} + + +internal class DictionaryDeclaration : IDictionaryPart +{ + public List Parts { get; } = new(); + + public string Write() + { + return $"new {typeof(Dictionary).FullNameInCode()}{{ {Parts.Select(x => x.Write()).Join(", ")} }}"; + } + + public void ReadDictionary(Dictionary data, List usages) + { + foreach (var pair in data) + { + if (pair.Value is object[] array) + { + if (array[0] is Dictionary inner) + { + var arrayDeclaration = new ArrayDeclaration(pair.Key); + Parts.Add(arrayDeclaration); + + arrayDeclaration.Inner.ReadDictionary(inner, usages); + } + else + { + var usage = usages.FirstOrDefault(x => x.Value.Equals(array[0])); + if (usage != null) + { + var arrayValue = new ArrayScalarValue(pair.Key, usage.QueryMember); + Parts.Add(arrayValue); + } + } + + + } + else if (pair.Value is Dictionary dict) + { + var child = new DictionaryDeclaration(); + Parts.Add(child); + child.ReadDictionary(dict, usages); + } + else + { + var usage = usages.FirstOrDefault(x => x.Value.Equals(pair.Value)); + if (usage != null) + { + var value = new DictionaryValue(pair.Key, usage.QueryMember); + Parts.Add(value); + } + else + { + throw new NotImplementedException("Not handling constants here yet:("); + } + } + } + } +} + diff --git a/src/Marten/Linq/SqlGeneration/FromFragment.cs b/src/Marten/Linq/SqlGeneration/FromFragment.cs new file mode 100644 index 00000000000..eaeca0377a8 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/FromFragment.cs @@ -0,0 +1,34 @@ +using JasperFx.Core; +using Weasel.Core; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration; + +internal class FromFragment: ISqlFragment +{ + private readonly string _text; + + public FromFragment(DbObjectName name, string? alias = null) + { + _text = $" from {name.QualifiedName}"; + if (alias.IsNotEmpty()) + { + _text += $" as {alias} "; + } + else + { + _text += " "; + } + } + + public void Apply(CommandBuilder builder) + { + builder.Append(_text); + } + + public bool Contains(string sqlText) + { + return false; + } +} diff --git a/src/Marten/Linq/SqlGeneration/IScalarSelectClause.cs b/src/Marten/Linq/SqlGeneration/IScalarSelectClause.cs index f4f848c07f2..293acad2254 100644 --- a/src/Marten/Linq/SqlGeneration/IScalarSelectClause.cs +++ b/src/Marten/Linq/SqlGeneration/IScalarSelectClause.cs @@ -2,7 +2,7 @@ namespace Marten.Linq.SqlGeneration; internal interface IScalarSelectClause { - string FieldName { get; } + string MemberName { get; } void ApplyOperator(string op); ISelectClause CloneToDouble(); diff --git a/src/Marten/Linq/SqlGeneration/ISelectClause.cs b/src/Marten/Linq/SqlGeneration/ISelectClause.cs index 8f6c73fd481..0c4a41f28f2 100644 --- a/src/Marten/Linq/SqlGeneration/ISelectClause.cs +++ b/src/Marten/Linq/SqlGeneration/ISelectClause.cs @@ -3,24 +3,23 @@ using Marten.Internal; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; -using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; /// /// Internal interface for the Linq subsystem /// -public interface ISelectClause +public interface ISelectClause: ISqlFragment { string FromObject { get; } Type SelectedType { get; } - void WriteSelectClause(CommandBuilder sql); - string[] SelectFields(); ISelector BuildSelector(IMartenSession session); - IQueryHandler BuildHandler(IMartenSession session, Statement topStatement, Statement currentStatement); + IQueryHandler BuildHandler(IMartenSession session, ISqlFragment topStatement, ISqlFragment currentStatement); ISelectClause UseStatistics(QueryStatistics statistics); } + diff --git a/src/Marten/Linq/SqlGeneration/IdSelectorStatement.cs b/src/Marten/Linq/SqlGeneration/IdSelectorStatement.cs deleted file mode 100644 index bf44b20d709..00000000000 --- a/src/Marten/Linq/SqlGeneration/IdSelectorStatement.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Marten.Internal; -using Marten.Linq.Fields; -using Weasel.Postgresql; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.SqlGeneration; - -internal class IdSelectorStatement: Statement -{ - public IdSelectorStatement(IMartenSession session, IFieldMapping fields, Statement parent): base(fields) - { - parent.InsertAfter(this); - - ConvertToCommonTableExpression(session); - - // Important when doing n-deep sub-collection querying - // And you need to remember the original FromObject - // of the original parent rather than looking at Previous.ExportName - // in the configure() method - FromObject = parent.ExportName; - } - - protected override bool IsSubQuery => true; - - protected override void configure(CommandBuilder sql) - { - startCommonTableExpression(sql); - sql.Append("select ctid, data from "); - sql.Append(FromObject); - sql.Append(" as d"); - writeWhereClause(sql); - endCommonTableExpression(sql); - } -} - -internal class WhereCtIdInSubQuery: ISqlFragment, IReversibleWhereFragment -{ - private readonly string _tableName; - - internal WhereCtIdInSubQuery(string tableName, SubQueryStatement subQueryStatement) - { - _tableName = tableName; - SubQueryStatement = subQueryStatement; - } - - public SubQueryStatement SubQueryStatement { get; } - - /// - /// Psych! Should there be a NOT in front of the sub query - /// - public bool Not { get; set; } - - public ISqlFragment Reverse() - { - Not = !Not; - return this; - } - - public void Apply(CommandBuilder builder) - { - if (Not) - { - builder.Append("NOT("); - } - - builder.Append("d.ctid in (select ctid from "); - builder.Append(_tableName); - builder.Append(")"); - - if (Not) - { - builder.Append(")"); - } - } - - public bool Contains(string sqlText) - { - return false; - } -} diff --git a/src/Marten/Linq/SqlGeneration/JsonStatement.cs b/src/Marten/Linq/SqlGeneration/JsonStatement.cs deleted file mode 100644 index 0006304b85b..00000000000 --- a/src/Marten/Linq/SqlGeneration/JsonStatement.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using JasperFx.Core.Reflection; -using Marten.Linq.Fields; -using Marten.Linq.Includes; - -namespace Marten.Linq.SqlGeneration; - -internal class JsonStatement: SelectorStatement -{ - public JsonStatement(Type documentType, IFieldMapping fields, Statement parent): base( - typeof(DataSelectClause<>).CloseAndBuildAs(parent.ExportName, - documentType), fields) - { - } - - private JsonStatement(ISelectClause selectClause, IFieldMapping fields): base(selectClause, fields) - { - } - - - public override SelectorStatement UseAsEndOfTempTableAndClone( - IncludeIdentitySelectorStatement includeIdentitySelectorStatement) - { - includeIdentitySelectorStatement.IncludeDataInTempTable = true; - - var clone = new JsonStatement(SelectClause, Fields) - { - SelectClause = - SelectClause.As() - .CloneToOtherTable(includeIdentitySelectorStatement.ExportName), - Orderings = Orderings, - Mode = StatementMode.Select, - ExportName = ExportName - }; - - SelectClause = includeIdentitySelectorStatement; - - Limit = Offset = 0; - - return clone; - } -} diff --git a/src/Marten/Linq/SqlGeneration/NewScalarSelectClause.cs b/src/Marten/Linq/SqlGeneration/NewScalarSelectClause.cs new file mode 100644 index 00000000000..7db29bc4f7a --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/NewScalarSelectClause.cs @@ -0,0 +1,146 @@ +using System; +using System.Data.Common; +using System.Threading; +using System.Threading.Tasks; +using JasperFx.Core.Reflection; +using Marten.Internal; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Marten.Linq.QueryHandlers; +using Marten.Linq.Selectors; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration; + +internal class NewScalarSelectClause: ISelectClause, ISelector, IScalarSelectClause, ISelector + where T : struct +{ + private static readonly string NullResultMessage = + $"The cast to value type '{typeof(T).FullNameInCode()}' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type."; + + public NewScalarSelectClause(string locator, string from) + { + FromObject = from; + MemberName = locator; + } + + public NewScalarSelectClause(IQueryableMember member, string from) + { + FromObject = from; + + MemberName = member.TypedLocator; + } + + public string MemberName { get; private set; } + + public ISelectClause CloneToOtherTable(string tableName) + { + return new ScalarSelectClause(MemberName, tableName); + } + + public void ApplyOperator(string op) + { + MemberName = $"{op}({MemberName})"; + } + + public ISelectClause CloneToDouble() + { + return new ScalarSelectClause(MemberName, FromObject); + } + + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + + public Type SelectedType => typeof(T); + + public string FromObject { get; } + + public void Apply(CommandBuilder sql) + { + sql.Append("select "); + sql.Append(MemberName); + sql.Append(" from "); + sql.Append(FromObject); + sql.Append(" as d"); + } + + public string[] SelectFields() + { + return new[] { MemberName }; + } + + public ISelector BuildSelector(IMartenSession session) + { + return this; + } + + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment statement, + ISqlFragment currentStatement) + { + var selector = (ISelector)BuildSelector(session); + + return LinqQueryParser.BuildHandler(selector, statement); + } + + public ISelectClause UseStatistics(QueryStatistics statistics) + { + return new StatsSelectClause(this, statistics); + } + + async Task ISelector.ResolveAsync(DbDataReader reader, CancellationToken token) + { + if (await reader.IsDBNullAsync(0, token).ConfigureAwait(false)) + { + return null; + } + + return await reader.GetFieldValueAsync(0, token).ConfigureAwait(false); + } + + T? ISelector.Resolve(DbDataReader reader) + { + try + { + if (reader.IsDBNull(0)) + { + return null; + } + + return reader.GetFieldValue(0); + } + catch (InvalidCastException e) + { + throw new InvalidOperationException(NullResultMessage, e); + } + } + + public T Resolve(DbDataReader reader) + { + try + { + if (reader.IsDBNull(0)) + { + return default; + } + + return reader.GetFieldValue(0); + } + catch (InvalidCastException e) + { + throw new InvalidOperationException(NullResultMessage, e); + } + } + + public async Task ResolveAsync(DbDataReader reader, CancellationToken token) + { + if (await reader.IsDBNullAsync(0, token).ConfigureAwait(false)) + { + return default; + } + + return await reader.GetFieldValueAsync(0, token).ConfigureAwait(false); + } +} diff --git a/src/Marten/Linq/SqlGeneration/NewScalarStringSelectClause.cs b/src/Marten/Linq/SqlGeneration/NewScalarStringSelectClause.cs new file mode 100644 index 00000000000..978f8a8fbc4 --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/NewScalarStringSelectClause.cs @@ -0,0 +1,106 @@ +using System; +using System.Data.Common; +using System.Threading; +using System.Threading.Tasks; +using Marten.Internal; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Marten.Linq.QueryHandlers; +using Marten.Linq.Selectors; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration; + +internal class NewScalarStringSelectClause: ISelectClause, IScalarSelectClause, ISelector +{ + public NewScalarStringSelectClause(string member, string from) + { + FromObject = from; + MemberName = member; + } + + public NewScalarStringSelectClause(IQueryableMember member, string from) + { + FromObject = from; + + MemberName = member.TypedLocator; + } + + public string MemberName { get; private set; } + + public ISelectClause CloneToOtherTable(string tableName) + { + return new NewScalarStringSelectClause(MemberName, tableName); + } + + + public void ApplyOperator(string op) + { + MemberName = $"{op}({MemberName})"; + } + + public ISelectClause CloneToDouble() + { + throw new NotSupportedException(); + } + + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + + public Type SelectedType => typeof(string); + + public string FromObject { get; } + + public void Apply(CommandBuilder sql) + { + sql.Append("select "); + sql.Append(MemberName); + sql.Append(" from "); + sql.Append(FromObject); + sql.Append(" as d"); + } + + public string[] SelectFields() + { + return new[] { MemberName }; + } + + public ISelector BuildSelector(IMartenSession session) + { + return this; + } + + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment statement, + ISqlFragment currentStatement) + { + return LinqQueryParser.BuildHandler(this, statement); + } + + public ISelectClause UseStatistics(QueryStatistics statistics) + { + return new StatsSelectClause(this, statistics); + } + + public string Resolve(DbDataReader reader) + { + if (reader.IsDBNull(0)) + { + return null; + } + + return reader.GetFieldValue(0); + } + + public async Task ResolveAsync(DbDataReader reader, CancellationToken token) + { + if (await reader.IsDBNullAsync(0, token).ConfigureAwait(false)) + { + return null; + } + + return await reader.GetFieldValueAsync(0, token).ConfigureAwait(false); + } +} diff --git a/src/Marten/Linq/SqlGeneration/OrderByFragment.cs b/src/Marten/Linq/SqlGeneration/OrderByFragment.cs new file mode 100644 index 00000000000..269cd20fd8a --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/OrderByFragment.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Linq; +using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration; + +public class OrderByFragment: ISqlFragment +{ + public List Expressions { get; } = new(); + + public void Apply(CommandBuilder builder) + { + if (!Expressions.Any()) + { + return; + } + + builder.Append(" order by "); + builder.Append(Expressions[0]); + for (var i = 1; i < Expressions.Count; i++) + { + builder.Append(", "); + builder.Append(Expressions[i]); + } + } + + public bool Contains(string sqlText) + { + return Expressions.Any(x => x.Contains(sqlText)); + } +} diff --git a/src/Marten/Linq/SqlGeneration/ScalarSelectClause.cs b/src/Marten/Linq/SqlGeneration/ScalarSelectClause.cs index 128f07d0e58..a95ecd84545 100644 --- a/src/Marten/Linq/SqlGeneration/ScalarSelectClause.cs +++ b/src/Marten/Linq/SqlGeneration/ScalarSelectClause.cs @@ -2,14 +2,14 @@ using System.Data.Common; using System.Threading; using System.Threading.Tasks; -using JasperFx.CodeGeneration; using JasperFx.Core.Reflection; using Marten.Internal; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; @@ -21,41 +21,46 @@ internal class ScalarSelectClause: ISelectClause, ISelector, IScalarSelect public ScalarSelectClause(string locator, string from) { FromObject = from; - FieldName = locator; + MemberName = locator; } - public ScalarSelectClause(IField field, string from) + public ScalarSelectClause(IQueryableMember field, string from) { FromObject = from; - FieldName = field.TypedLocator; + MemberName = field.TypedLocator; } - public string FieldName { get; private set; } + public string MemberName { get; private set; } public ISelectClause CloneToOtherTable(string tableName) { - return new ScalarSelectClause(FieldName, tableName); + return new ScalarSelectClause(MemberName, tableName); } public void ApplyOperator(string op) { - FieldName = $"{op}({FieldName})"; + MemberName = $"{op}({MemberName})"; } public ISelectClause CloneToDouble() { - return new ScalarSelectClause(FieldName, FromObject); + return new ScalarSelectClause(MemberName, FromObject); + } + + bool ISqlFragment.Contains(string sqlText) + { + return false; } public Type SelectedType => typeof(T); public string FromObject { get; } - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { sql.Append("select "); - sql.Append(FieldName); + sql.Append(MemberName); sql.Append(" from "); sql.Append(FromObject); sql.Append(" as d"); @@ -63,7 +68,7 @@ public void WriteSelectClause(CommandBuilder sql) public string[] SelectFields() { - return new[] { FieldName }; + return new[] { MemberName }; } public ISelector BuildSelector(IMartenSession session) @@ -71,12 +76,12 @@ public ISelector BuildSelector(IMartenSession session) return this; } - public IQueryHandler BuildHandler(IMartenSession session, Statement statement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment statement, + ISqlFragment currentStatement) { var selector = (ISelector)BuildSelector(session); - return LinqHandlerBuilder.BuildHandler(selector, statement); + return LinqQueryParser.BuildHandler(selector, statement); } public ISelectClause UseStatistics(QueryStatistics statistics) @@ -137,4 +142,9 @@ public async Task ResolveAsync(DbDataReader reader, CancellationToken token) return await reader.GetFieldValueAsync(0, token).ConfigureAwait(false); } + + public override string ToString() + { + return $"Select {typeof(T).ShortNameInCode()} from {FromObject}"; + } } diff --git a/src/Marten/Linq/SqlGeneration/ScalarSelectManyStringStatement.cs b/src/Marten/Linq/SqlGeneration/ScalarSelectManyStringStatement.cs deleted file mode 100644 index 84f4dea0370..00000000000 --- a/src/Marten/Linq/SqlGeneration/ScalarSelectManyStringStatement.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Marten.Linq.SqlGeneration; - -internal class ScalarSelectManyStringStatement: SelectorStatement -{ - public ScalarSelectManyStringStatement(SelectorStatement parent): base( - new ScalarStringSelectClause("data", parent.ExportName), null) - { - } -} diff --git a/src/Marten/Linq/SqlGeneration/ScalarStringSelectClause.cs b/src/Marten/Linq/SqlGeneration/ScalarStringSelectClause.cs index b7157d4228c..92734ccfdfd 100644 --- a/src/Marten/Linq/SqlGeneration/ScalarStringSelectClause.cs +++ b/src/Marten/Linq/SqlGeneration/ScalarStringSelectClause.cs @@ -3,11 +3,12 @@ using System.Threading; using System.Threading.Tasks; using Marten.Internal; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; @@ -16,27 +17,27 @@ internal class ScalarStringSelectClause: ISelectClause, IScalarSelectClause, ISe public ScalarStringSelectClause(string field, string from) { FromObject = from; - FieldName = field; + MemberName = field; } - public ScalarStringSelectClause(IField field, string from) + public ScalarStringSelectClause(IQueryableMember field, string from) { FromObject = from; - FieldName = field.TypedLocator; + MemberName = field.TypedLocator; } - public string FieldName { get; private set; } + public string MemberName { get; private set; } public ISelectClause CloneToOtherTable(string tableName) { - return new ScalarStringSelectClause(FieldName, tableName); + return new ScalarStringSelectClause(MemberName, tableName); } public void ApplyOperator(string op) { - FieldName = $"{op}({FieldName})"; + MemberName = $"{op}({MemberName})"; } public ISelectClause CloneToDouble() @@ -44,14 +45,19 @@ public ISelectClause CloneToDouble() throw new NotSupportedException(); } + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + public Type SelectedType => typeof(string); public string FromObject { get; } - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { sql.Append("select "); - sql.Append(FieldName); + sql.Append(MemberName); sql.Append(" from "); sql.Append(FromObject); sql.Append(" as d"); @@ -59,7 +65,7 @@ public void WriteSelectClause(CommandBuilder sql) public string[] SelectFields() { - return new[] { FieldName }; + return new[] { MemberName }; } public ISelector BuildSelector(IMartenSession session) @@ -67,10 +73,10 @@ public ISelector BuildSelector(IMartenSession session) return this; } - public IQueryHandler BuildHandler(IMartenSession session, Statement statement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment statement, + ISqlFragment currentStatement) { - return LinqHandlerBuilder.BuildHandler(this, statement); + return LinqQueryParser.BuildHandler(this, statement); } public ISelectClause UseStatistics(QueryStatistics statistics) @@ -97,4 +103,9 @@ public async Task ResolveAsync(DbDataReader reader, CancellationToken to return await reader.GetFieldValueAsync(0, token).ConfigureAwait(false); } + + public override string ToString() + { + return $"Select string value from {FromObject}"; + } } diff --git a/src/Marten/Linq/SqlGeneration/SelectorStatement.cs b/src/Marten/Linq/SqlGeneration/SelectorStatement.cs index a2d92568289..b80a2d0e9fd 100644 --- a/src/Marten/Linq/SqlGeneration/SelectorStatement.cs +++ b/src/Marten/Linq/SqlGeneration/SelectorStatement.cs @@ -1,49 +1,59 @@ using System; -using System.Linq.Expressions; -using JasperFx.Core.Reflection; +using System.Linq; +using JasperFx.Core; using Marten.Internal; -using Marten.Linq.Fields; -using Marten.Linq.Includes; -using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; +using Marten.Linq.SqlGeneration.Filters; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; -internal abstract class SelectorStatement: Statement +public class SelectorStatement: Statement, IWhereFragmentHolder { - protected SelectorStatement(ISelectClause selectClause, IFieldMapping fields): base(fields) - { - SelectClause = selectClause; - FromObject = SelectClause.FromObject; - } - - public ISelectClause SelectClause { get; internal set; } + public int? Limit { get; set; } + public int? Offset { get; set; } + public OrderByFragment Ordering { get; internal set; } = new(); + public ISelectClause SelectClause { get; internal set; } public bool IsDistinct { get; set; } + public void Register(ISqlFragment fragment) + { + Wheres.Add(fragment); + } + protected override void configure(CommandBuilder sql) { startCommonTableExpression(sql); - SelectClause.WriteSelectClause(sql); + SelectClause.Apply(sql); - writeWhereClause(sql); + if (Wheres.Any()) + { + sql.Append(" where "); + Wheres[0].Apply(sql); + for (var i = 1; i < Wheres.Count; i++) + { + sql.Append(" and "); + Wheres[i].Apply(sql); + } + } - writeOrderClause(sql); + Ordering.Apply(sql); - if (Offset > 0) + if (Offset.HasValue) { sql.Append(" OFFSET "); - sql.AppendParameter(Offset); + sql.AppendParameter(Offset.Value); } - if (Limit > 0) + if (Limit.HasValue) { sql.Append(" LIMIT "); - sql.AppendParameter(Limit); + sql.AppendParameter(Limit.Value); } endCommonTableExpression(sql); @@ -60,82 +70,11 @@ public void ToCount() SelectClause = new CountClause(SelectClause.FromObject); } - public IQueryHandler BuildSingleResultHandler(IMartenSession session, Statement topStatement) - { - var selector = (ISelector)SelectClause.BuildSelector(session); - return new OneResultHandler(topStatement, selector, ReturnDefaultWhenEmpty, CanBeMultiples); - } - - public void ToScalar(Expression selectClauseSelector) - { - var field = Fields.FieldFor(selectClauseSelector); - - if (field.FieldType == typeof(string)) - { - SelectClause = new ScalarStringSelectClause(field, SelectClause.FromObject); - } - else if (field.FieldType.IsSimple() || field.FieldType == typeof(Guid) || field.FieldType == typeof(decimal) || - field.FieldType == typeof(DateTimeOffset)) - { - SelectClause = - typeof(ScalarSelectClause<>).CloseAndBuildAs(field, SelectClause.FromObject, - field.FieldType); - } - else - { - SelectClause = - typeof(DataSelectClause<>).CloseAndBuildAs(SelectClause.FromObject, field.RawLocator, - field.FieldType); - } - } - - public SelectorStatement ToSelectMany(IField collectionField, IMartenSession session, bool isComplex, - Type elementType) + public void ApplyAggregateOperator(string databaseOperator) { - if (elementType.IsSimple()) - { - var selection = $"jsonb_array_elements_text({collectionField.JSONBLocator})"; - - SelectClause = typeof(DataSelectClause<>).CloseAndBuildAs(SelectClause.FromObject, selection, - elementType); - - Mode = StatementMode.CommonTableExpression; - ExportName = session.NextTempTableName() + "CTE"; - - var next = elementType == typeof(string) - ? new ScalarSelectManyStringStatement(this) - : typeof(ScalarSelectManyStatement<>).CloseAndBuildAs(this, session.Serializer, elementType); - - InsertAfter(next); - - return (SelectorStatement)next; - } - - var childFields = session.Options.ChildTypeMappingFor(elementType); - - if (isComplex) - { - var selection = $"jsonb_array_elements({collectionField.JSONBLocator})"; - SelectClause = typeof(DataSelectClause<>).CloseAndBuildAs(SelectClause.FromObject, selection, - elementType); - - Mode = StatementMode.CommonTableExpression; - ExportName = session.NextTempTableName() + "CTE"; - - var statement = new JsonStatement(elementType, childFields, this); - - InsertAfter(statement); - - return statement; - } - else - { - var selection = $"jsonb_array_elements_text({collectionField.JSONBLocator})"; - SelectClause = typeof(DataSelectClause<>).CloseAndBuildAs(SelectClause.FromObject, selection, - elementType); - - return this; - } + ApplySqlOperator(databaseOperator); + SingleValue = true; + ReturnDefaultWhenEmpty = true; } public void ApplySqlOperator(string databaseOperator) @@ -157,32 +96,57 @@ public void ApplySqlOperator(string databaseOperator) } } - public void ApplyAggregateOperator(string databaseOperator) + public IQueryHandler BuildSingleResultHandler(IMartenSession session, Statement topStatement) { - ApplySqlOperator(databaseOperator); - SingleValue = true; - ReturnDefaultWhenEmpty = true; + var selector = (ISelector)SelectClause.BuildSelector(session); + return new OneResultHandler(topStatement, selector, ReturnDefaultWhenEmpty, CanBeMultiples); } - public void ToSelectTransform(Expression selectExpression, ISerializer serializer) + public override string ToString() { - var builder = new SelectTransformBuilder(selectExpression, Fields, serializer); - var transformField = builder.SelectedFieldExpression; - - SelectClause = - typeof(DataSelectClause<>).CloseAndBuildAs(SelectClause.FromObject, transformField, - selectExpression.Type); + return $"Selector statement: {SelectClause}"; } - - public void UseStatistics(QueryStatistics statistics) + protected override void compileAnySubQueries(IMartenSession session) { - SelectClause = SelectClause.UseStatistics(statistics); - } + if (Wheres[0] is CompoundWhereFragment compound && compound.Children.OfType().Any()) + { + var subQueries = compound.Children.OfType().ToArray(); + if (compound.Separator.ContainsIgnoreCase("and")) + { + var others = compound.Children.Where(x => !subQueries.Contains(x)).ToArray(); - public virtual SelectorStatement UseAsEndOfTempTableAndClone( - IncludeIdentitySelectorStatement includeIdentitySelectorStatement) - { - throw new NotSupportedException(); + ISqlFragment topLevel = null; + switch (others.Length) + { + case 0: + break; + + case 1: + topLevel = others.Single(); + break; + + default: + topLevel = CompoundWhereFragment.And(others); + break; + } + + foreach (var subQuery in subQueries) subQuery.PlaceUnnestAbove(session, this, topLevel); + + // We've moved all the non-sub query filters up to the various explode statements + Wheres.Clear(); + Wheres.Add(CompoundWhereFragment.And(subQueries)); + } + else + { + foreach (var subQuery in subQueries) subQuery.PlaceUnnestAbove(session, this); + } + } + else if (Wheres[0] is ISubQueryFilter subQuery) + { + subQuery.PlaceUnnestAbove(session, this); + } + + // The else is perfectly fine as is } } diff --git a/src/Marten/Linq/SqlGeneration/SqlFragmentExtensions.cs b/src/Marten/Linq/SqlGeneration/SqlFragmentExtensions.cs deleted file mode 100644 index fbb6d4424d6..00000000000 --- a/src/Marten/Linq/SqlGeneration/SqlFragmentExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Linq.SqlGeneration; - -[Obsolete("this needs to move to Weasel")] -public static class SqlFragmentExtensions -{ - public static ISqlFragment CombineFragments(this IList fragments) - { - switch (fragments.Count) - { - case 0: - return null; - - case 1: - return fragments.Single(); - - default: - return CompoundWhereFragment.And(fragments); - } - } -} diff --git a/src/Marten/Linq/SqlGeneration/Statement.WhereParsing.cs b/src/Marten/Linq/SqlGeneration/Statement.WhereParsing.cs new file mode 100644 index 00000000000..9e8ee03887b --- /dev/null +++ b/src/Marten/Linq/SqlGeneration/Statement.WhereParsing.cs @@ -0,0 +1,90 @@ +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Marten.Exceptions; +using Marten.Internal; +using Marten.Internal.Storage; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Marten.Linq.SqlGeneration.Filters; +using Weasel.Postgresql.SqlGeneration; + +namespace Marten.Linq.SqlGeneration; + +public abstract partial class Statement: IWhereFragmentHolder +{ + public List Wheres { get; } = new(); + + public ISqlFragment[] AllFilters() + { + return Wheres.SelectMany(enumerateWheres).ToArray(); + } + + private ISqlFragment[] enumerateWheres(ISqlFragment where) + { + if (where is CompoundWhereFragment compound) + { + return compound.Children.SelectMany(enumerateWheres).ToArray(); + } + + return new[] { where }; + } + + void IWhereFragmentHolder.Register(ISqlFragment filter) + { + if (filter != null) + { + Wheres.Add(filter); + } + } + + public void ParseWhereClause(IReadOnlyList wheres, IMartenSession session, + IQueryableMemberCollection collection, + IDocumentStorage? storage = null) + { + if (!wheres.Any()) + { + var filter = storage?.DefaultWhereFragment(); + if (filter != null) + { + Wheres.Add(filter); + } + + return; + } + + var parser = new WhereClauseParser(session.Options, collection, this); + foreach (var expression in wheres) parser.Visit(expression); + + if (storage != null) + { + if (Wheres.Count == 1) + { + var combinedWhere = storage.FilterDocuments(Wheres.Single(), session); + Wheres.Clear(); + Wheres.Add(combinedWhere); + } + else + { + var combined = CompoundWhereFragment.And(Wheres); + var combinedWhere = storage.FilterDocuments(combined, session); + Wheres.Clear(); + Wheres.Add(combinedWhere); + } + } + + if (Wheres.Any()) + { + compileAnySubQueries(session); + } + } + + protected virtual void compileAnySubQueries(IMartenSession session) + { + if (Wheres.OfType().Any() || + Wheres.OfType().Any(x => x.Children.OfType().Any())) + { + throw new BadLinqExpressionException("Sub Query filters are not supported for this operation"); + } + } +} diff --git a/src/Marten/Linq/SqlGeneration/Statement.cs b/src/Marten/Linq/SqlGeneration/Statement.cs index d26a8582a1a..1c1b5ee01f2 100644 --- a/src/Marten/Linq/SqlGeneration/Statement.cs +++ b/src/Marten/Linq/SqlGeneration/Statement.cs @@ -1,265 +1,146 @@ -using System; -using System.Collections.Generic; using System.Linq; using JasperFx.Core; -using Marten.Exceptions; +using JasperFx.Core.Reflection; using Marten.Internal; -using Marten.Linq.Fields; -using Marten.Linq.Parsing; using Npgsql; -using Remotion.Linq.Clauses; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; -public interface IPagedStatement +public abstract partial class Statement: ISqlFragment { - int Offset { get; set; } - int Limit { get; set; } -} - -public class PagedStatement: IPagedStatement -{ - public static readonly PagedStatement Empty = new(0, 0); - - private PagedStatement(int offset, int limit) - { - Offset = offset; - Limit = limit; - } - - public PagedStatement(Statement statement) - { - Offset = statement.Offset; - Limit = statement.Limit; - } - - public int Offset { get; set; } - public int Limit { get; set; } -} - -/// -/// Internal model used to generate SQL within Linq queries -/// -public abstract class Statement: IPagedStatement -{ - private Statement _next; - - protected Statement(IFieldMapping fields) - { - Fields = fields; - } - - public string FromObject { get; protected set; } - - public Statement Previous { get; private set; } - - public Statement Next - { - get => _next; - private set - { - _next = value; - if (value != null) - { - value.Previous = this; - } - } - } + public Statement Next { get; set; } + public Statement Previous { get; set; } public StatementMode Mode { get; set; } = StatementMode.Select; /// /// For CTEs /// - public string ExportName { get; protected set; } - - - public IList<(Ordering Ordering, bool CaseInsensitive)> Orderings { get; protected set; } = - new List<(Ordering, bool)>(); - - public IFieldMapping Fields { get; } - - public IList WhereClauses { get; } = new List(); - - protected virtual bool IsSubQuery => false; - - public ISqlFragment Where { get; internal set; } + public string ExportName { get; protected internal set; } public bool SingleValue { get; set; } public bool ReturnDefaultWhenEmpty { get; set; } public bool CanBeMultiples { get; set; } - public int Offset { get; set; } - public int Limit { get; set; } - - public Statement Top() - { - return Previous == null ? this : Previous.Top(); - } - - public Statement Current() - { - return Next == null ? this : Next.Current(); - } - - public void Configure(CommandBuilder sql) + public void Apply(CommandBuilder builder) { - configure(sql); + configure(builder); if (Next != null) { - sql.Append(" "); - Next.Configure(sql); + builder.Append(" "); + Next.Apply(builder); } } - protected abstract void configure(CommandBuilder builder); - - - protected virtual void writeWhereClause(CommandBuilder sql) + bool ISqlFragment.Contains(string sqlText) { - if (Where != null) - { - sql.Append(" where "); - Where.Apply(sql); - } + return Wheres.Any(x => x.Contains(sqlText)); } - protected void writeOrderByFragment(CommandBuilder sql, Ordering clause, bool caseInsensitive) - { - string locator; - try - { - var field = Fields.FieldFor(clause.Expression); - locator = field.ToOrderExpression(clause.Expression); - } - catch (Exception e) - { - throw new BadLinqExpressionException($"Invalid OrderBy() expression '{clause.Expression}'", e); - } - - if (caseInsensitive) - { - sql.Append("lower("); - } - - sql.Append(locator); - if (caseInsensitive) + public void InsertAfter(Statement descendent) + { + if (Next != null) { - sql.Append(")"); + Next.Previous = descendent; + descendent.Next = Next; } - if (clause.OrderingDirection == OrderingDirection.Desc) - { - sql.Append(" desc"); - } + Next = descendent; + descendent.Previous = this; } - protected virtual ISqlFragment buildWhereFragment(IMartenSession session) + /// + /// Place the descendent at the very end + /// + /// + public void AddToEnd(Statement descendent) { - if (!WhereClauses.Any()) + if (Next != null) { - return null; + Next.AddToEnd(descendent); } - - var parser = new WhereClauseParser(session, this) { InSubQuery = IsSubQuery }; - - if (WhereClauses.Count == 1) + else { - return parser.Build(WhereClauses.Single()); + Next = descendent; + descendent.Previous = this; } - - var wheres = WhereClauses.Select(x => parser.Build(x)).ToArray(); - return CompoundWhereFragment.And(wheres); } - protected void writeOrderClause(CommandBuilder sql) + public void InsertBefore(Statement antecedent) { - if (Orderings.Any()) + if (Previous != null) { - sql.Append(" order by "); - writeOrderByFragment(sql, Orderings[0].Ordering, Orderings[0].CaseInsensitive); - for (var i = 1; i < Orderings.Count; i++) - { - sql.Append(", "); - writeOrderByFragment(sql, Orderings[i].Ordering, Orderings[i].CaseInsensitive); - } + Previous.Next = antecedent; + antecedent.Previous = Previous; } + + antecedent.Next = this; + Previous = antecedent; } - public void CompileStructure(IMartenSession session) + public Statement Top() { - CompileLocal(session); - Next?.CompileStructure(session); + return Previous == null ? this : Previous.Top(); } - public virtual void CompileLocal(IMartenSession session) + public SelectorStatement SelectorStatement() { - // Where clauses are pre-built in the case of includes - Where ??= buildWhereFragment(session); + return (Next == null ? this : Next.SelectorStatement()).As(); } - public void ConvertToCommonTableExpression(IMartenSession session) { ExportName ??= session.NextTempTableName() + "CTE"; Mode = StatementMode.CommonTableExpression; } - public void InsertBefore(Statement antecedent) - { - if (Previous != null) - { - Previous.Next = antecedent; - } - - antecedent.Next = this; - } + protected abstract void configure(CommandBuilder sql); - public void InsertAfter(Statement descendent) + protected void startCommonTableExpression(CommandBuilder sql) { - if (Next != null) + if (Mode == StatementMode.CommonTableExpression) { - descendent.Next = Next; - } + sql.Append(Previous == null ? "WITH " : " , "); - Next = descendent; + sql.Append(ExportName); + sql.Append(" as (\n"); + } } - protected void startCommonTableExpression(CommandBuilder sql) + protected void endCommonTableExpression(CommandBuilder sql, string suffix = null) { - if (Mode == StatementMode.Select) + switch (Mode) { - return; - } + case StatementMode.Select: + sql.Append(";"); - sql.Append(Previous == null ? "WITH " : " , "); + if (Next != null) + { + sql.Append("\n"); + } - sql.Append(ExportName); - sql.Append(" as (\n"); - } + return; + case StatementMode.Inner: + return; - protected void endCommonTableExpression(CommandBuilder sql, string suffix = null) - { - if (Mode == StatementMode.Select) - { - return; - } + case StatementMode.CommonTableExpression: + if (suffix.IsNotEmpty()) + { + sql.Append(suffix); + } - if (suffix.IsNotEmpty()) - { - sql.Append(suffix); + sql.Append("\n)\n"); + break; } - - sql.Append("\n)\n"); } public NpgsqlCommand BuildCommand() { var builder = new CommandBuilder(); - Configure(builder); + Apply(builder); return builder.Compile(); } diff --git a/src/Marten/Linq/SqlGeneration/StatementMode.cs b/src/Marten/Linq/SqlGeneration/StatementMode.cs index e43ed1a5ee2..558f98a5983 100644 --- a/src/Marten/Linq/SqlGeneration/StatementMode.cs +++ b/src/Marten/Linq/SqlGeneration/StatementMode.cs @@ -3,5 +3,6 @@ namespace Marten.Linq.SqlGeneration; public enum StatementMode { Select, - CommonTableExpression + CommonTableExpression, + Inner } diff --git a/src/Marten/Linq/SqlGeneration/StatementOperation.cs b/src/Marten/Linq/SqlGeneration/StatementOperation.cs index 045f5dc31ab..0d446c60e15 100644 --- a/src/Marten/Linq/SqlGeneration/StatementOperation.cs +++ b/src/Marten/Linq/SqlGeneration/StatementOperation.cs @@ -9,31 +9,32 @@ using Marten.Internal.Operations; using Marten.Internal.Sessions; using Marten.Internal.Storage; -using Marten.Linq.Parsing; -using Remotion.Linq.Clauses; using Weasel.Postgresql; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; -internal class StatementOperation: DocumentStatement, IStorageOperation +internal class StatementOperation: Statement, IStorageOperation { private readonly IOperationFragment _operation; + private readonly IDocumentStorage _storage; - public StatementOperation(IDocumentStorage storage, IOperationFragment operation): base(storage) + public StatementOperation(IDocumentStorage storage, IOperationFragment operation) { + _storage = storage; _operation = operation; DocumentType = storage.SourceType; } + public StatementOperation(IDocumentStorage storage, IOperationFragment operation, ISqlFragment where): this(storage, + operation) + { + Wheres.Add(where); + } + public void ConfigureCommand(CommandBuilder builder, IMartenSession session) { - if (Previous != null) - { - Top().Configure(builder); - return; - } - configure(builder); + Apply(builder); } public Type DocumentType { get; } @@ -53,21 +54,36 @@ public OperationRole Role() return _operation.Role(); } - protected override void configure(CommandBuilder builder) + protected override void configure(CommandBuilder sql) + { + _operation.Apply(sql); + writeWhereClause(sql); + } + + protected void writeWhereClause(CommandBuilder sql) { - _operation.Apply(builder); - writeWhereClause(builder); + if (Wheres.Any()) + { + sql.Append(" where "); + Wheres[0].Apply(sql); + for (var i = 1; i < Wheres.Count; i++) + { + sql.Append(" and "); + Wheres[i].Apply(sql); + } + } } public ISqlFragment ApplyFiltering(DocumentSessionBase session, Expression> expression) { - var queryExpression = session.Query().Where(expression).Expression; - var model = MartenQueryParser.Flyweight.GetParsedQuery(queryExpression); - var where = model.BodyClauses.OfType().Single(); - WhereClauses.Add(where); + Expression body = expression; + if (expression is LambdaExpression l) + { + body = l.Body; + } - CompileLocal(session); + ParseWhereClause(new[] { body }, session, _storage.QueryMembers, _storage); - return Where; + return Wheres.SingleOrDefault(); } } diff --git a/src/Marten/Linq/SqlGeneration/StatsSelectClause.cs b/src/Marten/Linq/SqlGeneration/StatsSelectClause.cs index 04105f73b9d..1b269740284 100644 --- a/src/Marten/Linq/SqlGeneration/StatsSelectClause.cs +++ b/src/Marten/Linq/SqlGeneration/StatsSelectClause.cs @@ -5,6 +5,7 @@ using Marten.Linq.QueryHandlers; using Marten.Linq.Selectors; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; @@ -20,11 +21,16 @@ public StatsSelectClause(ISelectClause inner, QueryStatistics statistics) public ISelectClause Inner { get; } + bool ISqlFragment.Contains(string sqlText) + { + return false; + } + public Type SelectedType => Inner.SelectedType; public string FromObject => Inner.FromObject; - public void WriteSelectClause(CommandBuilder sql) + public void Apply(CommandBuilder sql) { sql.Append("select "); sql.Append(Inner.SelectFields().Join(", ")); @@ -45,8 +51,8 @@ public ISelector BuildSelector(IMartenSession session) return Inner.BuildSelector(session); } - public IQueryHandler BuildHandler(IMartenSession session, Statement topStatement, - Statement currentStatement) + public IQueryHandler BuildHandler(IMartenSession session, ISqlFragment topStatement, + ISqlFragment currentStatement) { var selector = (ISelector)Inner.BuildSelector(session); diff --git a/src/Marten/Linq/SqlGeneration/SubQueryStatement.cs b/src/Marten/Linq/SqlGeneration/SubQueryStatement.cs deleted file mode 100644 index e416692c415..00000000000 --- a/src/Marten/Linq/SqlGeneration/SubQueryStatement.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using Marten.Internal; -using Weasel.Postgresql; - -namespace Marten.Linq.SqlGeneration; - -internal class SubQueryStatement: Statement -{ - private readonly string _locatorForElements; - private readonly string _sourceTable; - - public SubQueryStatement(string locatorForElements, IMartenSession session, Statement sourceStatement): base(null) - { - _sourceTable = sourceStatement.FromObject ?? throw new ArgumentNullException(nameof(sourceStatement)); - if (sourceStatement.FromObject.IsEmpty()) - { - throw new ArgumentOutOfRangeException(nameof(sourceStatement), - "The source statement should not contain any empty FromObject"); - } - - _locatorForElements = locatorForElements ?? throw new ArgumentNullException(nameof(locatorForElements)); - - ConvertToCommonTableExpression(session); - sourceStatement.InsertBefore(this); - } - - protected override void configure(CommandBuilder sql) - { - startCommonTableExpression(sql); - - sql.Append("select ctid, "); - sql.Append(_locatorForElements); - sql.Append(" as data from "); - - sql.Append(_sourceTable); - - - if (Where != null) - { - sql.Append(" as d WHERE "); - Where.Apply(sql); - - endCommonTableExpression(sql); - } - else - { - endCommonTableExpression(sql, " as d"); - } - } -} diff --git a/src/Marten/Linq/SqlGeneration/WhereFragmentExtensions.cs b/src/Marten/Linq/SqlGeneration/WhereFragmentExtensions.cs index a5fc631c022..726cc57aea0 100644 --- a/src/Marten/Linq/SqlGeneration/WhereFragmentExtensions.cs +++ b/src/Marten/Linq/SqlGeneration/WhereFragmentExtensions.cs @@ -1,6 +1,6 @@ using System.Linq; using Marten.Events.Archiving; -using Marten.Linq.Filters; +using Marten.Linq.SqlGeneration.Filters; using Weasel.Postgresql.SqlGeneration; namespace Marten.Linq.SqlGeneration; diff --git a/src/Marten/LinqExtensions.cs b/src/Marten/LinqExtensions.cs index 2155ff6e775..c8444d2a9b4 100644 --- a/src/Marten/LinqExtensions.cs +++ b/src/Marten/LinqExtensions.cs @@ -47,7 +47,6 @@ public static bool IsOneOf(this T variable, IList matches) /// /// /// - /// when called for collection public static bool In(this T variable, params T[] matches) { if (typeof(T).IsArray || typeof(T).IsGenericEnumerable()) diff --git a/src/Marten/LinqParsing.cs b/src/Marten/LinqParsing.cs index 14c8704d835..bdbc05d8337 100644 --- a/src/Marten/LinqParsing.cs +++ b/src/Marten/LinqParsing.cs @@ -2,16 +2,18 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using JasperFx.Core; using Marten.Events.Archiving; using Marten.Linq.CreatedAt; -using Marten.Linq.Fields; using Marten.Linq.LastModified; using Marten.Linq.MatchesSql; +using Marten.Linq.Members; using Marten.Linq.Parsing; using Marten.Linq.Parsing.Methods; +using Marten.Linq.Parsing.Methods.FullText; +using Marten.Linq.Parsing.Methods.Strings; using Marten.Linq.SoftDeletes; -using Weasel.Postgresql.SqlGeneration; namespace Marten; @@ -21,7 +23,7 @@ public interface IReadOnlyLinqParsing /// Registered extensions to the Marten Linq support for special handling of /// specific .Net types /// - public IReadOnlyList FieldSources { get; } + public IReadOnlyList FieldSources { get; } /// /// Custom Linq expression parsers for your own methods @@ -35,16 +37,19 @@ public class LinqParsing: IReadOnlyLinqParsing private static readonly IList _parsers = new List { new StringContains(), - new EnumerableContains(), new StringEndsWith(), new StringStartsWith(), new StringEquals(), new SimpleEqualsParser(), + new AnySubQueryParser(), + + // Keep this below the string methods! + new EnumerableContains(), + new AllMethodParser(), // Added new IsOneOf(), new EqualsIgnoreCaseParser(), - new IsInGenericEnumerable(), new IsEmpty(), new IsSupersetOf(), new IsSubsetOf(), @@ -74,7 +79,8 @@ public class LinqParsing: IReadOnlyLinqParsing new MatchesSqlParser(), // dictionaries - new DictionaryExpressions(), + new DictionaryContainsKey(), + //new DictionaryContains(), // full text search new Search(), @@ -84,59 +90,41 @@ public class LinqParsing: IReadOnlyLinqParsing new NgramSearch() }; + private readonly StoreOptions _options; + /// /// Add custom Linq expression parsers for your own methods /// public readonly IList MethodCallParsers = new List(); - private ImHashMap> _methodParsing = - ImHashMap>.Empty; + private ImHashMap _methodParsers = ImHashMap.Empty; - internal LinqParsing() + internal LinqParsing(StoreOptions options) { + _options = options; } /// /// Register extensions to the Marten Linq support for special handling of /// specific .Net types /// - public IList FieldSources { get; } = new List(); + public IList MemberSources { get; } = new List(); - IReadOnlyList IReadOnlyLinqParsing.FieldSources => FieldSources.ToList(); + IReadOnlyList IReadOnlyLinqParsing.FieldSources => MemberSources.ToList(); IReadOnlyList IReadOnlyLinqParsing.MethodCallParsers => _parsers.ToList(); - internal ISqlFragment BuildWhereFragment(IFieldMapping mapping, MethodCallExpression expression, - IReadOnlyStoreOptions options) - { - var parser = FindMethodParser(expression); - - if (parser == null) - { - throw new NotSupportedException( - $"Marten does not (yet) support Linq queries using the {expression.Method.DeclaringType.FullName}.{expression.Method.Name}() method"); - } - - return parser.Parse(mapping, options, expression); - } - internal IMethodCallParser FindMethodParser(MethodCallExpression expression) { - if (_methodParsing.TryFind(expression.Method.DeclaringType, out var byName)) + if (_methodParsers.TryFind(expression.Method.MetadataToken, out var parser)) { - if (byName.TryFind(expression.Method.Name, out var p)) - { - return p; - } + return parser; } - byName ??= ImHashMap.Empty; - var parser = determineMethodParser(expression); - byName = byName.AddOrUpdate(expression.Method.Name, parser); - _methodParsing = _methodParsing.AddOrUpdate(expression.Method.DeclaringType, byName); - + parser = determineMethodParser(expression); + _methodParsers = _methodParsers.AddOrUpdate(expression.Method.MetadataToken, parser); return parser; } diff --git a/src/Marten/Marten.csproj b/src/Marten/Marten.csproj index a498c018275..77aabb45c50 100644 --- a/src/Marten/Marten.csproj +++ b/src/Marten/Marten.csproj @@ -12,14 +12,14 @@ true - - - - + + + + - - + + @@ -65,5 +65,5 @@ - + diff --git a/src/Marten/MartenRegistry.cs b/src/Marten/MartenRegistry.cs index 6d0f5103c6e..81f29143173 100644 --- a/src/Marten/MartenRegistry.cs +++ b/src/Marten/MartenRegistry.cs @@ -16,7 +16,6 @@ using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.Tables; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten; @@ -419,7 +418,7 @@ public DocumentMappingExpression ForeignKey( { _builder.Alter = m => { - var visitor = new FindMembers(); + var visitor = new MemberFinder(); visitor.Visit(expression); var foreignKeyDefinition = m.AddForeignKey(visitor.Members.ToArray(), typeof(TReference)); @@ -447,7 +446,7 @@ public DocumentMappingExpression ForeignKey(Expression> expre { _builder.Alter = m => { - var members = FindMembers.Determine(expression); + var members = MemberFinder.Determine(expression); var duplicateField = m.DuplicateField(members); @@ -507,7 +506,7 @@ public DocumentMappingExpression Identity(Expression> member) { _builder.Alter = mapping => { - var members = FindMembers.Determine(member); + var members = MemberFinder.Determine(member); if (members.Length != 1) { throw new InvalidOperationException( @@ -801,7 +800,7 @@ public bool Enabled /// public void MapTo(Expression> memberExpression) { - var member = FindMembers.Determine(memberExpression).Single(); + var member = MemberFinder.Determine(memberExpression).Single(); _parent._builder.Alter = m => { var metadataColumn = _source(m.Metadata); diff --git a/src/Marten/Properties/AssemblyInfo.cs b/src/Marten/Properties/AssemblyInfo.cs index 663ff66b110..436111423e8 100644 --- a/src/Marten/Properties/AssemblyInfo.cs +++ b/src/Marten/Properties/AssemblyInfo.cs @@ -8,6 +8,7 @@ [assembly: InternalsVisibleTo("Marten.AsyncDaemon.Testing")] [assembly: InternalsVisibleTo("ConfigurationTests")] [assembly: InternalsVisibleTo("CoreTests")] +[assembly: InternalsVisibleTo("LinqTests")] [assembly: InternalsVisibleTo("DocumentDbTests")] [assembly: InternalsVisibleTo("EventSourcingTests")] [assembly: InternalsVisibleTo("Examples")] diff --git a/src/Marten/Schema/ChildDocument.cs b/src/Marten/Schema/ChildDocument.cs deleted file mode 100644 index b0ad7157ba1..00000000000 --- a/src/Marten/Schema/ChildDocument.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using Marten.Linq.Fields; -using Marten.Storage; -using Remotion.Linq; -using Weasel.Core; -using Weasel.Postgresql.SqlGeneration; - -namespace Marten.Schema; - -public class ChildDocument: FieldMapping -{ - public ChildDocument(string locator, Type documentType, StoreOptions options): base(locator, documentType, options) - { - DocumentType = documentType; - } - - public Type DocumentType { get; set; } - public TenancyStyle TenancyStyle => TenancyStyle.Single; - - public DbObjectName TableName => throw new NotSupportedException(); - - public DuplicatedField[] DuplicatedFields { get; } - - public ISqlFragment FilterDocuments(QueryModel model, ISqlFragment query) - { - return query; - } - - public ISqlFragment DefaultWhereFragment() - { - return null; - } -} diff --git a/src/Marten/Schema/ComputedIndex.cs b/src/Marten/Schema/ComputedIndex.cs index a9010cd4287..bfe9fdb42a0 100644 --- a/src/Marten/Schema/ComputedIndex.cs +++ b/src/Marten/Schema/ComputedIndex.cs @@ -2,6 +2,8 @@ using System.Linq; using System.Reflection; using JasperFx.Core.Reflection; +using Marten.Linq; +using Marten.Linq.Parsing; using Marten.Schema.Indexing.Unique; using Marten.Storage.Metadata; using Marten.Util; @@ -77,17 +79,17 @@ private IEnumerable buildColumns() { foreach (var m in _members) { - var field = _mapping.FieldFor(m); + var member = _mapping.QueryMembers.MemberFor(m); var casing = Casing; - if (field.FieldType != typeof(string)) + if (member.MemberType != typeof(string)) { // doesn't make sense to lower-case this particular member casing = Casings.Default; } - var sql = field.FieldType.IsEnumerable() - ? field.RawLocator.Replace("d.", "") - : field.TypedLocator.Replace("d.", ""); + var sql = member.MemberType.IsEnumerable() + ? member.RawLocator.Replace("d.", "") + : member.TypedLocator.Replace("d.", ""); switch (casing) { case Casings.Upper: diff --git a/src/Marten/Schema/DocumentMapping.cs b/src/Marten/Schema/DocumentMapping.cs index f3564045478..7b511c49002 100644 --- a/src/Marten/Schema/DocumentMapping.cs +++ b/src/Marten/Schema/DocumentMapping.cs @@ -7,12 +7,13 @@ using JasperFx.Core; using JasperFx.Core.Reflection; using Marten.Exceptions; -using Marten.Linq.Fields; +using Marten.Linq; +using Marten.Linq.Members; +using Marten.Linq.Parsing; using Marten.Schema.Identity; using Marten.Schema.Identity.Sequences; using Marten.Schema.Indexing.Unique; using Marten.Storage; -using Marten.Util; using NpgsqlTypes; using Weasel.Core; using Weasel.Postgresql; @@ -48,18 +49,18 @@ public interface IDocumentType string DdlTemplate { get; } IReadOnlyHiloSettings HiloSettings { get; } TenancyStyle TenancyStyle { get; } - DuplicatedField[] DuplicatedFields { get; } + IReadOnlyList DuplicatedFields { get; } bool IsHierarchy(); IEnumerable IndexesFor(string column); string AliasFor(Type subclassType); Type TypeFor(string alias); - IField FieldFor(string memberName); } -public class DocumentMapping: FieldMapping, IDocumentMapping, IDocumentType +public class DocumentMapping: IDocumentMapping, IDocumentType { private static readonly Regex _aliasSanitizer = new("<|>", RegexOptions.Compiled); private static readonly Type[] _validIdTypes = { typeof(int), typeof(Guid), typeof(long), typeof(string) }; + private readonly List _duplicates = new(); private readonly Lazy _schema; private string _alias; @@ -68,13 +69,19 @@ public class DocumentMapping: FieldMapping, IDocumentMapping, IDocumentType private HiloSettings _hiloSettings; private MemberInfo _idMember; - public DocumentMapping(Type documentType, StoreOptions storeOptions): base("d.data", documentType, storeOptions) + public DocumentMapping(Type documentType, StoreOptions storeOptions) { + if (documentType.IsSimple()) + { + throw new ArgumentOutOfRangeException(nameof(documentType),"This type cannot be used as a Marten document"); + } + StoreOptions = storeOptions ?? throw new ArgumentNullException(nameof(storeOptions)); DocumentType = documentType ?? throw new ArgumentNullException(nameof(documentType)); Alias = defaultDocumentAliasName(documentType); + QueryMembers = new DocumentQueryableMemberCollection(this, StoreOptions); IdMember = FindIdMember(documentType); Metadata = new DocumentMetadataCollection(this); @@ -88,6 +95,8 @@ public DocumentMapping(Type documentType, StoreOptions storeOptions): base("d.da _schema = new Lazy(() => new DocumentSchema(this)); } + internal DocumentQueryableMemberCollection QueryMembers { get; } + public IList IgnoredIndexes { get; } = new List(); internal StoreOptions StoreOptions { get; } @@ -131,10 +140,6 @@ public MemberInfo IdMember if (_idMember != null) { - removeIdField(); - - var idField = new IdField(_idMember); - setField(_idMember.Name, idField); IdStrategy = defineIdStrategy(DocumentType, StoreOptions); } } @@ -195,6 +200,9 @@ public string Alias } } + public PropertySearching PropertySearching { get; set; } = PropertySearching.JSON_Locator_Only; + public DeleteStyle DeleteStyle { get; set; } = DeleteStyle.Remove; + public IIdGeneration IdStrategy { get; set; } public bool StructuralTyped { get; set; } @@ -207,7 +215,7 @@ public string Alias IDocumentType IDocumentType.Root => this; - public DuplicatedField[] DuplicatedFields => fields().OfType().ToArray(); + public IReadOnlyList DuplicatedFields => _duplicates; public bool IsHierarchy() { @@ -306,7 +314,9 @@ public static DocumentMapping For(string databaseSchemaName = SchemaConsta { var storeOptions = new StoreOptions { DatabaseSchemaName = databaseSchemaName }; - return new DocumentMapping(storeOptions); + var documentMapping = new DocumentMapping(storeOptions); + documentMapping.CompileAndValidate(); + return documentMapping; } public static MemberInfo FindIdMember(Type documentType) @@ -518,8 +528,9 @@ private NgramIndex AddNgramIndexIfDoesNotExist(NgramIndex index) public DocumentForeignKey AddForeignKey(string memberName, Type referenceType) { - var field = FieldFor(memberName); - return AddForeignKey(field.Members, referenceType); + var member = DocumentType.GetProperty(memberName) ?? (MemberInfo)DocumentType.GetField(memberName); + + return AddForeignKey(new MemberInfo[]{member}, referenceType); } public DocumentForeignKey AddForeignKey(MemberInfo[] members, Type referenceType) @@ -598,17 +609,22 @@ private static string defaultDocumentAliasName(Type documentType) public DuplicatedField DuplicateField(string memberName, string pgType = null, bool notNull = false) { - var field = FieldFor(memberName); + var member = (QueryableMember)QueryMembers.MemberFor(memberName); - var duplicate = new DuplicatedField(StoreOptions.Advanced.DuplicatedFieldEnumStorage, field, - StoreOptions.Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime, notNull); + var enumStorage = StoreOptions.Advanced.DuplicatedFieldEnumStorage; + var dateTimeStorage = StoreOptions.Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime; + var duplicate = member is ValueCollectionMember collectionMember + ? new DuplicatedArrayField(enumStorage, collectionMember, dateTimeStorage, notNull) + : new DuplicatedField(enumStorage, (QueryableMember)member, dateTimeStorage, notNull); if (pgType.IsNotEmpty()) { duplicate.PgType = pgType; } - setField(memberName, duplicate); + QueryMembers.ReplaceMember(member.Member, duplicate); + + _duplicates.Add(duplicate); return duplicate; } @@ -616,11 +632,35 @@ public DuplicatedField DuplicateField(string memberName, string pgType = null, b public DuplicatedField DuplicateField(MemberInfo[] members, string pgType = null, string columnName = null, bool notNull = false) { - var field = FieldFor(members); - var memberName = members.Select(x => x.Name).Join("."); + var member = QueryMembers.FindMember(members[0]); + var parent = (IHasChildrenMembers)QueryMembers; + for (var i = 1; i < members.Length; i++) + { + parent = member.As(); + member = parent.FindMember(members[i]); + } - var duplicatedField = new DuplicatedField(StoreOptions.Advanced.DuplicatedFieldEnumStorage, field, - StoreOptions.Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime, notNull); + if (member is DuplicatedField d) + { + if (pgType != null) d.PgType = pgType; + if (columnName != null) d.ColumnName = columnName; + d.NotNull = notNull; + return d; + } + + if (member is not QueryableMember) + { + throw new ArgumentOutOfRangeException(nameof(members), + $"{members.Select(x => x.Name).Join(".")} of type {member.MemberType.FullNameInCode()} cannot be used as a Duplicated Field by Marten"); + } + + var enumStorage = StoreOptions.Advanced.DuplicatedFieldEnumStorage; + var dateTimeStorage = StoreOptions.Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime; + var duplicatedField = member is ValueCollectionMember collectionMember + ? new DuplicatedArrayField(enumStorage, collectionMember, dateTimeStorage, notNull) + : new DuplicatedField(enumStorage, (QueryableMember)member, dateTimeStorage, notNull); + + parent.ReplaceMember(members.Last(), duplicatedField); if (pgType.IsNotEmpty()) { @@ -632,7 +672,7 @@ public DuplicatedField DuplicateField(MemberInfo[] members, string pgType = null duplicatedField.ColumnName = columnName; } - setField(memberName, duplicatedField); + _duplicates.Add(duplicatedField); return duplicatedField; } @@ -664,9 +704,8 @@ internal void CompileAndValidate() $"{DocumentType.FullName} must be configured for soft deletion to map soft deleted metadata."); } - - var idField = new IdField(IdMember); - setField(IdMember.Name, idField); + var idField = new IdMember(IdMember); + QueryMembers.ReplaceMember(IdMember, idField); } @@ -684,16 +723,6 @@ public DocumentMapping(StoreOptions storeOptions): base(typeof(T), storeOptions) configure?.Invoke(null, new object[] { this }); } - /// - /// Find a field by lambda expression representing a property or field - /// - /// - /// - public IField FieldFor(Expression> expression) - { - return FieldFor(FindMembers.Determine(expression)); - } - /// /// Marks a property or field on this document type as a searchable field that is also duplicated in the /// database document table @@ -761,7 +790,7 @@ public void UniqueIndex(UniqueIndexType indexType, string indexName, var members = expressions .Select(e => { - var visitor = new Marten.Linq.Parsing.FindMembers(); + var visitor = new Marten.Linq.Parsing.MemberFinder(); visitor.Visit(e); return visitor.Members.ToArray(); }) diff --git a/src/Marten/Schema/FullTextIndex.cs b/src/Marten/Schema/FullTextIndex.cs index 501ea999f00..18daec6c145 100644 --- a/src/Marten/Schema/FullTextIndex.cs +++ b/src/Marten/Schema/FullTextIndex.cs @@ -1,6 +1,8 @@ using System.Linq; using System.Reflection; using JasperFx.Core; +using Marten.Linq; +using Marten.Linq.Parsing; using Weasel.Core; using Weasel.Postgresql.Tables; @@ -78,7 +80,7 @@ protected override string deriveIndexName() private static string GetDataConfig(DocumentMapping mapping, MemberInfo[][] members) { var dataConfig = members - .Select(m => $"({mapping.FieldFor(m).RawLocator.Replace("d.", "")})") + .Select(m => $"({mapping.QueryMembers.MemberFor(m).RawLocator.Replace("d.", "")})") .Join(" || ' ' || "); return $"({dataConfig})"; diff --git a/src/Marten/Schema/IDocumentMapping.cs b/src/Marten/Schema/IDocumentMapping.cs index 7376440f476..1ee4bd528cb 100644 --- a/src/Marten/Schema/IDocumentMapping.cs +++ b/src/Marten/Schema/IDocumentMapping.cs @@ -14,4 +14,7 @@ internal interface IDocumentMapping Type IdType { get; } DbObjectName TableName { get; } + + public PropertySearching PropertySearching { get; } + public DeleteStyle DeleteStyle { get; } } diff --git a/src/Marten/Schema/NgramIndex.cs b/src/Marten/Schema/NgramIndex.cs index cfed7db202f..0116b64843b 100644 --- a/src/Marten/Schema/NgramIndex.cs +++ b/src/Marten/Schema/NgramIndex.cs @@ -2,6 +2,8 @@ using System.Linq; using System.Reflection; using JasperFx.Core; +using Marten.Linq; +using Marten.Linq.Parsing; using Weasel.Core; using Weasel.Postgresql.Tables; @@ -75,7 +77,7 @@ protected override string deriveIndexName() private static string GetDataConfig(DocumentMapping mapping, MemberInfo[] members) { var dataConfig = members - .Select(m => $"{mapping.FieldFor(m).TypedLocator.Replace("d.", "")}") + .Select(m => $"{mapping.QueryMembers.MemberFor(members).TypedLocator.Replace("d.", "")}") .Join(" || ' ' || "); return $"{dataConfig}"; diff --git a/src/Marten/Schema/SubClassMapping.cs b/src/Marten/Schema/SubClassMapping.cs index e7346591adf..6b215d37771 100644 --- a/src/Marten/Schema/SubClassMapping.cs +++ b/src/Marten/Schema/SubClassMapping.cs @@ -4,6 +4,8 @@ using System.Reflection; using JasperFx.Core; using JasperFx.Core.Reflection; +using Marten.Linq; +using Marten.Linq.Members; using Weasel.Core; namespace Marten.Schema; @@ -22,6 +24,8 @@ public SubClassMapping(Type documentType, DocumentMapping parent, StoreOptions s Parent = parent; Alias = alias ?? GetTypeMartenAlias(documentType); Aliases = new[] { Alias }; + + QueryMembers = new DocumentQueryableMemberCollection(this, storeOptions); } public SubClassMapping(Type documentType, DocumentMapping parent, StoreOptions storeOptions, @@ -37,6 +41,10 @@ public SubClassMapping(Type documentType, DocumentMapping parent, StoreOptions s .Select(GetTypeMartenAlias).Concat(Aliases).ToArray(); } + public PropertySearching PropertySearching => Parent.PropertySearching; + + public IQueryableMemberCollection QueryMembers { get; } + public DocumentMapping Inner { get; } public DocumentMapping Parent { get; } diff --git a/src/Marten/Services/BatchQuerying/BatchedQuery.cs b/src/Marten/Services/BatchQuerying/BatchedQuery.cs index 0ef8b1f889a..d1d9adb995d 100644 --- a/src/Marten/Services/BatchQuerying/BatchedQuery.cs +++ b/src/Marten/Services/BatchQuerying/BatchedQuery.cs @@ -11,9 +11,9 @@ using Marten.Internal.Sessions; using Marten.Internal.Storage; using Marten.Linq; +using Marten.Linq.Parsing; using Marten.Linq.QueryHandlers; using Marten.Util; -using Remotion.Linq.Clauses; namespace Marten.Services.BatchQuerying; @@ -225,7 +225,7 @@ private Task load(TId id) where T : class where TId : notnull throw new DocumentIdTypeMismatchException(storage, typeof(TId)); } - private Task addItem(IQueryable queryable, ResultOperatorBase op) + private Task addItem(IQueryable queryable, SingleValueMode? op) { var handler = queryable.As>().BuildHandler(op); return AddItem(handler); @@ -233,12 +233,12 @@ private Task addItem(IQueryable queryable, ResultO public Task Any(IMartenQueryable queryable) { - return addItem(queryable, LinqConstants.AnyOperator); + return addItem(queryable, SingleValueMode.Any); } public Task Count(IMartenQueryable queryable) { - return addItem(queryable, LinqConstants.LongCountOperator); + return addItem(queryable, SingleValueMode.LongCount); } internal Task> Query(IMartenQueryable queryable) @@ -249,42 +249,42 @@ internal Task> Query(IMartenQueryable queryable) public Task First(IMartenQueryable queryable) { - return addItem(queryable, LinqConstants.FirstOperator); + return addItem(queryable, SingleValueMode.First); } public Task FirstOrDefault(IMartenQueryable queryable) { - return addItem(queryable, LinqConstants.FirstOrDefaultOperator); + return addItem(queryable, SingleValueMode.FirstOrDefault); } public Task Single(IMartenQueryable queryable) { - return addItem(queryable, LinqConstants.SingleOperator); + return addItem(queryable, SingleValueMode.Single); } public Task SingleOrDefault(IMartenQueryable queryable) { - return addItem(queryable, LinqConstants.SingleOrDefaultOperator); + return addItem(queryable, SingleValueMode.SingleOrDefault); } public Task Min(IQueryable queryable) { - return addItem(queryable, LinqConstants.MinOperator); + return addItem(queryable, SingleValueMode.Min); } public Task Max(IQueryable queryable) { - return addItem(queryable, LinqConstants.MaxOperator); + return addItem(queryable, SingleValueMode.Max); } public Task Sum(IQueryable queryable) { - return addItem(queryable, LinqConstants.SumOperator); + return addItem(queryable, SingleValueMode.Sum); } public Task Average(IQueryable queryable) { - return addItem(queryable, LinqConstants.AverageOperator); + return addItem(queryable, SingleValueMode.Average); } internal class BatchLoadByKeys: IBatchLoadByKeys where TDoc : class diff --git a/src/Marten/Storage/DocumentTable.cs b/src/Marten/Storage/DocumentTable.cs index df416c83408..aa3871bd80e 100644 --- a/src/Marten/Storage/DocumentTable.cs +++ b/src/Marten/Storage/DocumentTable.cs @@ -47,7 +47,9 @@ public DocumentTable(DocumentMapping mapping): base(mapping.TableName) AddIfActive(_mapping.Metadata.Headers); foreach (var field in mapping.DuplicatedFields.Where(x => !x.OnlyForSearching)) + { AddColumn(new DuplicatedFieldColumn(field)); + } if (mapping.IsHierarchy()) { diff --git a/src/Marten/Storage/DuplicatedFieldColumn.cs b/src/Marten/Storage/DuplicatedFieldColumn.cs index 19d4ade0be5..a5d6dc79372 100644 --- a/src/Marten/Storage/DuplicatedFieldColumn.cs +++ b/src/Marten/Storage/DuplicatedFieldColumn.cs @@ -1,4 +1,4 @@ -using Marten.Linq.Fields; +using Marten.Linq.Members; using Weasel.Postgresql.Tables; namespace Marten.Storage; diff --git a/src/Marten/Storage/Metadata/EntityMetadataQueryHandler.cs b/src/Marten/Storage/Metadata/EntityMetadataQueryHandler.cs index c3d6c410d2e..1d8bcb9a526 100644 --- a/src/Marten/Storage/Metadata/EntityMetadataQueryHandler.cs +++ b/src/Marten/Storage/Metadata/EntityMetadataQueryHandler.cs @@ -26,9 +26,9 @@ public EntityMetadataQueryHandler(object id, IDocumentStorage storage) SourceType = storage.DocumentType; - if (storage.Fields is DocumentMapping m) + if (storage is IHaveMetadataColumns m) { - _columns = m.Schema.Table.Columns.OfType().ToArray(); + _columns = m.MetadataColumns(); } else { diff --git a/src/Marten/Storage/Metadata/MetadataColumn.cs b/src/Marten/Storage/Metadata/MetadataColumn.cs index fb348227a69..8afa01a37ee 100644 --- a/src/Marten/Storage/Metadata/MetadataColumn.cs +++ b/src/Marten/Storage/Metadata/MetadataColumn.cs @@ -9,13 +9,13 @@ using JasperFx.Core.Reflection; using Marten.Internal; using Marten.Internal.CodeGeneration; +using Marten.Linq.Parsing; using Marten.Schema; using Marten.Schema.Arguments; using Marten.Util; using Weasel.Core; using Weasel.Postgresql; using Weasel.Postgresql.Tables; -using FindMembers = Marten.Linq.Parsing.FindMembers; namespace Marten.Storage.Metadata; @@ -100,7 +100,7 @@ internal abstract class MetadataColumn: MetadataColumn protected MetadataColumn(string name, Expression> property): base(name, PostgresqlProvider.Instance.GetDatabaseType(typeof(T), EnumStorage.AsInteger), typeof(T)) { - var member = FindMembers.Determine(property).Last(); + var member = MemberFinder.Determine(property).Last(); _memberName = member.Name; _setter = LambdaBuilder.Setter(member); } diff --git a/src/Marten/StoreOptions.MemberFactory.cs b/src/Marten/StoreOptions.MemberFactory.cs new file mode 100644 index 00000000000..986fe627bed --- /dev/null +++ b/src/Marten/StoreOptions.MemberFactory.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using JasperFx.Core; +using JasperFx.Core.Reflection; +using Marten.Linq; +using Marten.Linq.Members; +using Marten.Linq.Parsing; +using Newtonsoft.Json.Linq; +using Weasel.Postgresql; + +#nullable enable + +namespace Marten; + +public partial class StoreOptions +{ + internal IQueryableMember CreateQueryableMember(MemberInfo member, IQueryableMember parent) + { + if (member == null) + { + throw new ArgumentNullException(nameof(member)); + } + + var memberType = member.GetMemberType(); + if (memberType == null) + throw new ArgumentOutOfRangeException(nameof(member), $"Cannot determine member type for {member}"); + + var serializer = Serializer(); + var casing = serializer.Casing; + + if (memberType == typeof(string)) return new StringMember(parent, casing, member); + + // Thank you Newtonsoft. This has to be tested before the IDictionary<,> test + if (memberType == typeof(JObject)) + { + return new ChildDocument(this, parent, casing, member); + } + + if (memberType.Closes(typeof(IDictionary<,>))) + { + var fieldType = typeof(DictionaryMember<,>).MakeGenericType(memberType!.GetGenericArguments()); + return (IQueryableMember)Activator.CreateInstance(fieldType, parent, casing, member)!; + } + + if (memberType!.IsEnum) + { + return serializer.EnumStorage == Weasel.Core.EnumStorage.AsInteger + ? new EnumAsIntegerMember(parent, serializer.Casing, member) + : new EnumAsStringMember(parent, serializer.Casing, member); + } + + if (memberType == typeof(DateTime)) + { + return new DateTimeMember(this, parent, casing, member); + } + + if (memberType == typeof(DateTimeOffset)) + { + return new DateTimeOffsetMember(this, parent, casing, member); + } + + if (isEnumerable(memberType)) + { + var elementType = memberType.DetermineElementType(); + + if (elementType.IsValueTypeForQuerying()) + { + return new ValueCollectionMember(parent, casing, member); + } + + return new ChildCollectionMember(this, parent, casing, member); + } + + var pgType = PostgresqlProvider.Instance.GetDatabaseType(memberType, serializer.EnumStorage); + + if (pgType.EqualsIgnoreCase("jsonb")) + { + return new ChildDocument(this, parent, casing, member); + } + + if (pgType == "boolean") + { + return new BooleanMember(parent, casing, member, "boolean"); + } + + if (pgType.IsNotEmpty()) + { + return new SimpleCastMember(parent, casing, member, pgType); + } + + throw new NotSupportedException("Just no there yet for fields of type " + memberType.FullNameInCode()); + } + + private static bool isEnumerable(Type fieldType) + { + return fieldType.IsArray || fieldType.Closes(typeof(IEnumerable<>)); + } +} diff --git a/src/Marten/StoreOptions.cs b/src/Marten/StoreOptions.cs index 2f797f35e62..b57e80fc41e 100644 --- a/src/Marten/StoreOptions.cs +++ b/src/Marten/StoreOptions.cs @@ -15,7 +15,7 @@ using Marten.Exceptions; using Marten.Internal; using Marten.Linq; -using Marten.Linq.Fields; +using Marten.Linq.Members; using Marten.Metadata; using Marten.Schema; using Marten.Schema.Identity.Sequences; @@ -37,9 +37,6 @@ public partial class StoreOptions: IReadOnlyStoreOptions, IMigrationLogger { internal readonly List> SerializationConfigurations = new(); - private readonly ConcurrentDictionary> _childDocs - = new(); - private readonly IList _policies = new List { new VersionedPolicy(), new SoftDeletedPolicy(), new TrackedPolicy(), new TenancyPolicy() @@ -61,8 +58,6 @@ private readonly ConcurrentDictionary public readonly MartenRegistry Schema; - private ImHashMap _childFieldMappings = ImHashMap.Empty; - private string _databaseSchemaName = SchemaConstants.DefaultSchema; private IMartenLogger _logger = new NulloMartenLogger(); @@ -86,6 +81,8 @@ public StoreOptions() Advanced = new AdvancedOptions(this); Projections = new ProjectionOptions(this); + + Linq = new LinqParsing(this); } internal IList CompiledQueryTypes { get; } = new List(); @@ -140,7 +137,7 @@ public StoreOptions() /// /// Extension point to add custom Linq query parsers /// - public LinqParsing Linq { get; } = new(); + public LinqParsing Linq { get; } /// /// Apply conventional policies to how documents are mapped @@ -240,6 +237,16 @@ IDocumentType IReadOnlyStoreOptions.FindOrResolveDocumentType(Type documentType) return (Storage.FindMapping(documentType).Root as IDocumentType)!; } + void IReadOnlyStoreOptions.AssertDocumentTypeIsSoftDeleted(Type documentType) + { + var mapping = Storage.FindMapping(documentType) as IDocumentMapping; + if (mapping is null || mapping.DeleteStyle == DeleteStyle.Remove) + { + throw new InvalidOperationException( + $"Document type {documentType.FullNameInCode()} is not configured as soft deleted"); + } + } + /// /// Get or set the tenancy model for this DocumentStore /// @@ -437,25 +444,6 @@ internal void Validate() } } - /// - /// These mappings should only be used for Linq querying within the SelectMany() body - /// - /// - /// - internal IFieldMapping ChildTypeMappingFor(Type type) - { - if (_childFieldMappings.TryFind(type, out var mapping)) - { - return mapping; - } - - mapping = new FieldMapping("d.data", type, this); - - _childFieldMappings = _childFieldMappings.AddOrUpdate(type, mapping); - - return mapping; - } - /// /// Meant for testing scenarios to "help" .Net understand where the IHostEnvironment for the /// Host. You may have to specify the relative path to the entry project folder from the AppContext.BaseDirectory diff --git a/src/Marten/Util/CommandExtensions.cs b/src/Marten/Util/CommandExtensions.cs index a633a00ec89..e0863ec5ff3 100644 --- a/src/Marten/Util/CommandExtensions.cs +++ b/src/Marten/Util/CommandExtensions.cs @@ -7,17 +7,18 @@ using Marten.Schema.Arguments; using Npgsql; using Weasel.Postgresql; +using Weasel.Postgresql.SqlGeneration; namespace Marten.Util; internal static class CommandExtensions { - public static NpgsqlCommand BuildCommand(this IMartenSession session, Statement statement) + public static NpgsqlCommand BuildCommand(this IMartenSession session, ISqlFragment statement) { var command = new NpgsqlCommand(); var builder = new CommandBuilder(command); - statement.Configure(builder); + statement.Apply(builder); command.CommandText = builder.ToString(); diff --git a/src/Marten/Util/StringExtensions.cs b/src/Marten/Util/StringExtensions.cs index e61d71824b0..5f7b3e52191 100644 --- a/src/Marten/Util/StringExtensions.cs +++ b/src/Marten/Util/StringExtensions.cs @@ -1,5 +1,9 @@ #nullable enable +using System.Reflection; +using System.Text.Json.Serialization; using JasperFx.Core; +using JasperFx.Core.Reflection; +using Newtonsoft.Json; using Newtonsoft.Json.Serialization; namespace Marten.Util; @@ -20,4 +24,20 @@ public static string FormatCase(this string s, Casing casing) => Casing.SnakeCase => s.ToSnakeCase(), _ => s }; + + public static string ToJsonKey(this MemberInfo member, Casing casing) + { + var memberLocator = member.Name.FormatCase(casing); + if (member.TryGetAttribute(out var newtonsoftAtt) && newtonsoftAtt.PropertyName is not null) + { + memberLocator = newtonsoftAtt.PropertyName; + } + + if (member.TryGetAttribute(out var stjAtt)) + { + memberLocator = stjAtt.Name; + } + + return memberLocator; + } }